2 * Copyright (c) 2008-2009, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
6 * Artur Wyszynski <harakash@gmail.com>
10 #include "GradientsView.h"
11 #include <GradientLinear.h>
12 #include <GradientRadial.h>
13 #include <GradientRadialFocus.h>
14 #include <GradientDiamond.h>
15 #include <GradientConic.h>
18 GradientsView::GradientsView(const BRect
&rect
)
19 : BView(rect
, "gradientsview", B_FOLLOW_ALL
, B_WILL_DRAW
| B_PULSE_NEEDED
),
20 fType(BGradient::TYPE_LINEAR
)
25 GradientsView::~GradientsView()
31 GradientsView::Draw(BRect update
)
34 case BGradient::TYPE_LINEAR
:
38 case BGradient::TYPE_RADIAL
:
42 case BGradient::TYPE_RADIAL_FOCUS
:
43 DrawRadialFocus(update
);
46 case BGradient::TYPE_DIAMOND
:
50 case BGradient::TYPE_CONIC
:
54 case BGradient::TYPE_NONE
:
62 GradientsView::DrawLinear(BRect update
)
64 BGradientLinear gradient
;
69 gradient
.AddColor(c
, 0);
73 gradient
.AddColor(c
, 127);
77 gradient
.AddColor(c
, 255);
80 SetHighColor(0, 0, 0);
81 FillRoundRect(BRect(10, 10, 110, 110), 5, 5);
82 gradient
.SetStart(BPoint(120, 10));
83 gradient
.SetEnd(BPoint(220, 110));
84 FillRoundRect(BRect(120, 10, 220, 110), 5, 5, gradient
);
87 SetHighColor(0, 0, 0);
88 FillRect(BRect(10, 120, 110, 220));
89 gradient
.SetStart(BPoint(120, 120));
90 gradient
.SetEnd(BPoint(220, 220));
91 FillRect(BRect(120, 120, 220, 220), gradient
);
94 SetHighColor(0, 0, 0);
95 FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330));
96 gradient
.SetStart(BPoint(60, 230));
97 gradient
.SetEnd(BPoint(60, 330));
98 FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330),
102 SetHighColor(0, 0, 0);
103 FillEllipse(BPoint(60, 390), 50, 50);
104 gradient
.SetStart(BPoint(60, 340));
105 gradient
.SetEnd(BPoint(60, 440));
106 FillEllipse(BPoint(170, 390), 50, 50, gradient
);
111 GradientsView::DrawRadial(BRect update
)
113 BGradientRadial gradient
;
114 gradient
.AddColor(make_color(255, 0, 0), 0);
115 gradient
.AddColor(make_color(0, 255, 0), 127);
116 gradient
.AddColor(make_color(0, 0, 255), 255);
119 SetHighColor(0, 0, 0);
120 FillRoundRect(BRect(10, 10, 110, 110), 5, 5);
121 gradient
.SetCenter(BPoint(170, 60));
122 gradient
.SetRadius(50);
123 FillRoundRect(BRect(120, 10, 220, 110), 5, 5, gradient
);
126 SetHighColor(0, 0, 0);
127 FillRect(BRect(10, 120, 110, 220));
128 gradient
.SetCenter(BPoint(170, 170));
129 FillRect(BRect(120, 120, 220, 220), gradient
);
132 SetHighColor(0, 0, 0);
133 FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330));
134 gradient
.SetCenter(BPoint(170, 280));
135 FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330),
139 SetHighColor(0, 0, 0);
140 FillEllipse(BPoint(60, 390), 50, 50);
141 gradient
.SetCenter(BPoint(170, 390));
142 FillEllipse(BPoint(170, 390), 50, 50, gradient
);
147 GradientsView::DrawRadialFocus(BRect update
)
149 BGradientRadialFocus gradient
;
154 gradient
.AddColor(c
, 0);
158 gradient
.AddColor(c
, 127);
162 gradient
.AddColor(c
, 255);
165 SetHighColor(0, 0, 0);
166 FillRoundRect(BRect(10, 10, 110, 110), 5, 5);
167 gradient
.SetCenter(BPoint(170, 60));
168 FillRoundRect(BRect(120, 10, 220, 110), 5, 5, gradient
);
171 SetHighColor(0, 0, 0);
172 FillRect(BRect(10, 120, 110, 220));
173 gradient
.SetCenter(BPoint(170, 170));
174 FillRect(BRect(120, 120, 220, 220), gradient
);
177 SetHighColor(0, 0, 0);
178 FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330));
179 gradient
.SetCenter(BPoint(170, 280));
180 FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330),
184 SetHighColor(0, 0, 0);
185 FillEllipse(BPoint(60, 390), 50, 50);
186 gradient
.SetCenter(BPoint(170, 390));
187 FillEllipse(BPoint(170, 390), 50, 50, gradient
);
192 GradientsView::DrawDiamond(BRect update
)
194 BGradientDiamond gradient
;
199 gradient
.AddColor(c
, 0);
203 gradient
.AddColor(c
, 127);
207 gradient
.AddColor(c
, 255);
210 SetHighColor(0, 0, 0);
211 FillRoundRect(BRect(10, 10, 110, 110), 5, 5);
212 gradient
.SetCenter(BPoint(170, 60));
213 FillRoundRect(BRect(120, 10, 220, 110), 5, 5, gradient
);
216 SetHighColor(0, 0, 0);
217 FillRect(BRect(10, 120, 110, 220));
218 gradient
.SetCenter(BPoint(170, 170));
219 FillRect(BRect(120, 120, 220, 220), gradient
);
222 SetHighColor(0, 0, 0);
223 FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330));
224 gradient
.SetCenter(BPoint(170, 280));
225 FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330),
229 SetHighColor(0, 0, 0);
230 FillEllipse(BPoint(60, 390), 50, 50);
231 gradient
.SetCenter(BPoint(170, 390));
232 FillEllipse(BPoint(170, 390), 50, 50, gradient
);
237 GradientsView::DrawConic(BRect update
)
239 BGradientConic gradient
;
244 gradient
.AddColor(c
, 0);
248 gradient
.AddColor(c
, 127);
252 gradient
.AddColor(c
, 255);
255 SetHighColor(0, 0, 0);
256 FillRoundRect(BRect(10, 10, 110, 110), 5, 5);
257 gradient
.SetCenter(BPoint(170, 60));
258 FillRoundRect(BRect(120, 10, 220, 110), 5, 5, gradient
);
261 SetHighColor(0, 0, 0);
262 FillRect(BRect(10, 120, 110, 220));
263 gradient
.SetCenter(BPoint(170, 170));
264 FillRect(BRect(120, 120, 220, 220), gradient
);
267 SetHighColor(0, 0, 0);
268 FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330));
269 gradient
.SetCenter(BPoint(170, 280));
270 FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330),
274 SetHighColor(0, 0, 0);
275 FillEllipse(BPoint(60, 390), 50, 50);
276 gradient
.SetCenter(BPoint(170, 390));
277 FillEllipse(BPoint(170, 390), 50, 50, gradient
);
282 GradientsView::SetType(BGradient::Type type
)