vfs: check userland buffers before reading them.
[haiku.git] / src / apps / gradients / GradientsView.cpp
blobe8330e96ef493f7ddc983681eef14ace8fcf9a68
1 /*
2 * Copyright (c) 2008-2009, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Artur Wyszynski <harakash@gmail.com>
7 */
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()
30 void
31 GradientsView::Draw(BRect update)
33 switch (fType) {
34 case BGradient::TYPE_LINEAR:
35 DrawLinear(update);
36 break;
38 case BGradient::TYPE_RADIAL:
39 DrawRadial(update);
40 break;
42 case BGradient::TYPE_RADIAL_FOCUS:
43 DrawRadialFocus(update);
44 break;
46 case BGradient::TYPE_DIAMOND:
47 DrawDiamond(update);
48 break;
50 case BGradient::TYPE_CONIC:
51 DrawConic(update);
52 break;
54 case BGradient::TYPE_NONE:
55 default:
56 break;
61 void
62 GradientsView::DrawLinear(BRect update)
64 BGradientLinear gradient;
65 rgb_color c;
66 c.red = 255;
67 c.green = 0;
68 c.blue = 0;
69 gradient.AddColor(c, 0);
70 c.red = 0;
71 c.green = 255;
72 c.blue = 0;
73 gradient.AddColor(c, 127);
74 c.red = 0;
75 c.green = 0;
76 c.blue = 255;
77 gradient.AddColor(c, 255);
79 // RoundRect
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);
86 // Rect
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);
93 // Triangle
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),
99 gradient);
101 // Ellipse
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);
110 void
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);
118 // RoundRect
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);
125 // Rect
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);
131 // Triangle
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),
136 gradient);
138 // Ellipse
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);
146 void
147 GradientsView::DrawRadialFocus(BRect update)
149 BGradientRadialFocus gradient;
150 rgb_color c;
151 c.red = 255;
152 c.green = 0;
153 c.blue = 0;
154 gradient.AddColor(c, 0);
155 c.red = 0;
156 c.green = 255;
157 c.blue = 0;
158 gradient.AddColor(c, 127);
159 c.red = 0;
160 c.green = 0;
161 c.blue = 255;
162 gradient.AddColor(c, 255);
164 // RoundRect
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);
170 // Rect
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);
176 // Triangle
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),
181 gradient);
183 // Ellipse
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);
191 void
192 GradientsView::DrawDiamond(BRect update)
194 BGradientDiamond gradient;
195 rgb_color c;
196 c.red = 255;
197 c.green = 0;
198 c.blue = 0;
199 gradient.AddColor(c, 0);
200 c.red = 0;
201 c.green = 255;
202 c.blue = 0;
203 gradient.AddColor(c, 127);
204 c.red = 0;
205 c.green = 0;
206 c.blue = 255;
207 gradient.AddColor(c, 255);
209 // RoundRect
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);
215 // Rect
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);
221 // Triangle
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),
226 gradient);
228 // Ellipse
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);
236 void
237 GradientsView::DrawConic(BRect update)
239 BGradientConic gradient;
240 rgb_color c;
241 c.red = 255;
242 c.green = 0;
243 c.blue = 0;
244 gradient.AddColor(c, 0);
245 c.red = 0;
246 c.green = 255;
247 c.blue = 0;
248 gradient.AddColor(c, 127);
249 c.red = 0;
250 c.green = 0;
251 c.blue = 255;
252 gradient.AddColor(c, 255);
254 // RoundRect
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);
260 // Rect
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);
266 // Triangle
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),
271 gradient);
273 // Ellipse
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);
281 void
282 GradientsView::SetType(BGradient::Type type)
284 fType = type;
285 Invalidate();