xref: /haiku/headers/os/interface/ControlLook.h (revision 2069f565e8ed3556b30cf2f5e3aa54450128b8c2)
1 /*
2  * Copyright 2009, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _CONTROL_LOOK_H
6 #define _CONTROL_LOOK_H
7 
8 #include <Alignment.h>
9 #include <Font.h>
10 #include <Rect.h>
11 #include <Slider.h>
12 
13 
14 class BControl;
15 class BGradientLinear;
16 class BView;
17 
18 
19 // WARNING! This is experimental API and may change! Be prepared to
20 // recompile your software in a next version of haiku.
21 
22 
23 namespace BPrivate {
24 
25 
26 class BControlLook {
27 public:
28 								BControlLook();
29 	virtual						~BControlLook();
30 
31 	enum frame_type {
32 		B_BUTTON_FRAME,
33 		B_MENU_FRAME,
34 		B_LISTVIEW_FRAME,
35 		B_INPUT_FRAME
36 	};
37 
38 	enum background_type {
39 		B_BUTTON_BACKGROUND,
40 		B_MENU_BACKGROUND,
41 		B_LISTVIEW_BACKGROUND,
42 		B_INPUT_BACKGROUND
43 	};
44 
45 	enum {
46 		B_LEFT_BORDER		= 1 << 0,
47 		B_RIGHT_BORDER		= 1 << 1,
48 		B_TOP_BORDER		= 1 << 2,
49 		B_BOTTOM_BORDER		= 1 << 3,
50 
51 		B_ALL_BORDERS		= B_LEFT_BORDER | B_RIGHT_BORDER
52 								| B_TOP_BORDER | B_BOTTOM_BORDER
53 	};
54 
55 	enum {
56 		B_LEFT_ARROW		= 0,
57 		B_RIGHT_ARROW		= 1,
58 		B_UP_ARROW			= 2,
59 		B_DOWN_ARROW		= 3
60 	};
61 
62 	enum {
63 		B_FOCUSED			= 1 << 0,
64 		B_CLICKED			= 1 << 1, // some controls activate on mouse up
65 		B_ACTIVATED			= 1 << 2,
66 		B_HOVER				= 1 << 3,
67 		B_DISABLED			= 1 << 4,
68 		B_DEFAULT_BUTTON	= 1 << 5,
69 
70 		B_BLEND_FRAME		= 1 << 16
71 	};
72 
73 	virtual BAlignment			DefaultLabelAlignment() const;
74 	virtual float				DefaultLabelSpacing() const;
75 
76 	/* TODO: virtual*/
77 			float				DefaultItemSpacing() const;
78 
79 			uint32				Flags(BControl* control) const;
80 
81 	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
82 									const BRect& updateRect,
83 									const rgb_color& base,
84 									const rgb_color& background,
85 									uint32 flags = 0,
86 									uint32 borders = B_ALL_BORDERS);
87 
88 	virtual void				DrawButtonBackground(BView* view, BRect& rect,
89 									const BRect& updateRect,
90 									const rgb_color& base,
91 									uint32 flags = 0,
92 									uint32 borders = B_ALL_BORDERS,
93 									enum orientation orientation
94 										= B_HORIZONTAL);
95 
96 	virtual void				DrawMenuBarBackground(BView* view, BRect& rect,
97 									const BRect& updateRect,
98 									const rgb_color& base,
99 									uint32 flags = 0,
100 									uint32 borders = B_ALL_BORDERS);
101 
102 	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
103 									const BRect& updateRect,
104 									const rgb_color& base,
105 									const rgb_color& background,
106 									uint32 flags = 0,
107 									uint32 borders = B_ALL_BORDERS);
108 
109 	virtual void				DrawMenuFieldBackground(BView* view,
110 									BRect& rect, const BRect& updateRect,
111 									const rgb_color& base, bool popupIndicator,
112 									uint32 flags = 0);
113 
114 	virtual void				DrawMenuFieldBackground(BView* view,
115 									BRect& rect, const BRect& updateRect,
116 									const rgb_color& base, uint32 flags = 0,
117 									uint32 borders = B_ALL_BORDERS);
118 
119 	virtual void				DrawMenuBackground(BView* view,
120 									BRect& rect, const BRect& updateRect,
121 									const rgb_color& base, uint32 flags = 0,
122 									uint32 borders = B_ALL_BORDERS);
123 
124 	virtual void				DrawMenuItemBackground(BView* view,
125 									BRect& rect, const BRect& updateRect,
126 									const rgb_color& base, uint32 flags = 0,
127 									uint32 borders = B_ALL_BORDERS);
128 
129 	virtual void				DrawStatusBar(BView* view, BRect& rect,
130 									const BRect& updateRect,
131 									const rgb_color& base,
132 									const rgb_color& barColor,
133 									float progressPosition);
134 
135 	virtual void				DrawCheckBox(BView* view, BRect& rect,
136 									const BRect& updateRect,
137 									const rgb_color& base,
138 									uint32 flags = 0);
139 
140 	virtual void				DrawRadioButton(BView* view, BRect& rect,
141 									const BRect& updateRect,
142 									const rgb_color& base,
143 									uint32 flags = 0);
144 
145 	virtual void				DrawScrollBarBackground(BView* view,
146 									BRect& rect1, BRect& rect2,
147 									const BRect& updateRect,
148 									const rgb_color& base, uint32 flags,
149 									enum orientation orientation);
150 
151 	virtual void				DrawScrollBarBackground(BView* view,
152 									BRect& rect, const BRect& updateRect,
153 									const rgb_color& base, uint32 flags,
154 									enum orientation orientation);
155 
156 	// TODO: Make all these virtual before R1 release
157 			void				DrawScrollViewFrame(BView* view,
158 									BRect& rect, const BRect& updateRect,
159 									BRect verticalScrollBarFrame,
160 									BRect horizontalScrollBarFrame,
161 									const rgb_color& base,
162 									border_style border,
163 									uint32 flags = 0,
164 									uint32 borders = B_ALL_BORDERS);
165 
166 			void				DrawArrowShape(BView* view,
167 									BRect& rect, const BRect& updateRect,
168 									const rgb_color& base, uint32 direction,
169 									uint32 flags = 0,
170 									float tint = B_DARKEN_MAX_TINT);
171 
172 	virtual	rgb_color			SliderBarColor(const rgb_color& base);
173 
174 	virtual void				DrawSliderBar(BView* view, BRect rect,
175 									const BRect& updateRect,
176 									const rgb_color& base,
177 									rgb_color leftFillColor,
178 									rgb_color rightFillColor,
179 									float sliderScale, uint32 flags,
180 									enum orientation orientation);
181 
182 	virtual	void				DrawSliderBar(BView* view, BRect rect,
183 									const BRect& updateRect,
184 									const rgb_color& base, rgb_color fillColor,
185 									uint32 flags, enum orientation orientation);
186 
187 	virtual	void				DrawSliderThumb(BView* view, BRect& rect,
188 									const BRect& updateRect,
189 									const rgb_color& base, uint32 flags,
190 									enum orientation orientation);
191 
192 			void				DrawSliderTriangle(BView* view, BRect& rect,
193 									const BRect& updateRect,
194 									const rgb_color& base, uint32 flags,
195 									enum orientation orientation);
196 
197 	virtual	void				DrawSliderTriangle(BView* view, BRect& rect,
198 									const BRect& updateRect,
199 									const rgb_color& base,
200 									const rgb_color& fill, uint32 flags,
201 									enum orientation orientation);
202 
203 	virtual	void				DrawSliderHashMarks(BView* view, BRect& rect,
204 									const BRect& updateRect,
205 									const rgb_color& base, int32 count,
206 									hash_mark_location location,
207 									uint32 flags, enum orientation orientation);
208 
209 	virtual void				DrawActiveTab(BView* view, BRect& rect,
210 									const BRect& updateRect,
211 									const rgb_color& base, uint32 flags = 0,
212 									uint32 borders = B_ALL_BORDERS);
213 
214 	virtual void				DrawInactiveTab(BView* view, BRect& rect,
215 									const BRect& updateRect,
216 									const rgb_color& base, uint32 flags = 0,
217 									uint32 borders = B_ALL_BORDERS);
218 
219 	/*virtual*/	void			DrawSplitter(BView* view, BRect& rect,
220 									const BRect& updateRect,
221 									const rgb_color& base,
222 									enum orientation orientation,
223 									uint32 flags = 0,
224 									uint32 borders = B_ALL_BORDERS);
225 
226 	// various borders
227 
228 	virtual void				DrawBorder(BView* view, BRect& rect,
229 									const BRect& updateRect,
230 									const rgb_color& base,
231 									border_style border, uint32 flags = 0,
232 									uint32 borders = B_ALL_BORDERS);
233 
234 	virtual void				DrawRaisedBorder(BView* view, BRect& rect,
235 									const BRect& updateRect,
236 									const rgb_color& base, uint32 flags = 0,
237 									uint32 borders = B_ALL_BORDERS);
238 
239 	virtual void				DrawGroupFrame(BView* view, BRect& rect,
240 									const BRect& updateRect,
241 									const rgb_color& base,
242 									uint32 borders = B_ALL_BORDERS);
243 
244 	virtual void				DrawTextControlBorder(BView* view, BRect& rect,
245 									const BRect& updateRect,
246 									const rgb_color& base, uint32 flags = 0,
247 									uint32 borders = B_ALL_BORDERS);
248 
249 	// aligned labels
250 
251 			void				DrawLabel(BView* view, const char* label,
252 									BRect rect, const BRect& updateRect,
253 									const rgb_color& base, uint32 flags);
254 
255 	virtual void				DrawLabel(BView* view, const char* label,
256 									BRect rect, const BRect& updateRect,
257 									const rgb_color& base, uint32 flags,
258 									const BAlignment& alignment);
259 
260 	// TODO: This should also be virtual
261 	// TODO: Would be nice to have a (non-virtual) version of this method
262 	// which takes an array of labels and locations. That would save some
263 	// setup with the view graphics state.
264 			void				DrawLabel(BView* view, const char* label,
265 									const rgb_color& base, uint32 flags,
266 									const BPoint& where);
267 
268 protected:
269 			void				_DrawButtonFrame(BView* view, BRect& rect,
270 									const BRect& updateRect,
271 									const rgb_color& base,
272 									const rgb_color& background,
273 									float contrast, float brightness = 1.0,
274 									uint32 flags = 0,
275 									uint32 borders = B_ALL_BORDERS);
276 
277 			void				_DrawOuterResessedFrame(BView* view,
278 									BRect& rect, const rgb_color& base,
279 									float contrast = 1.0f,
280 									float brightness = 1.0f,
281 									uint32 flags = 0,
282 									uint32 borders = B_ALL_BORDERS);
283 
284 			void				_DrawFrame(BView* view, BRect& rect,
285 									const rgb_color& left,
286 									const rgb_color& top,
287 									const rgb_color& right,
288 									const rgb_color& bottom,
289 									uint32 borders = B_ALL_BORDERS);
290 
291 			void				_DrawFrame(BView* view, BRect& rect,
292 									const rgb_color& left,
293 									const rgb_color& top,
294 									const rgb_color& right,
295 									const rgb_color& bottom,
296 									const rgb_color& rightTop,
297 									const rgb_color& leftBottom,
298 									uint32 borders = B_ALL_BORDERS);
299 
300 			void				_FillGradient(BView* view, const BRect& rect,
301 									const rgb_color& base, float topTint,
302 									float bottomTint,
303 									enum orientation orientation
304 										= B_HORIZONTAL);
305 
306 			void				_FillGlossyGradient(BView* view,
307 									const BRect& rect, const rgb_color& base,
308 									float topTint, float middle1Tint,
309 									float middle2Tint, float bottomTint,
310 									enum orientation orientation
311 										= B_HORIZONTAL);
312 
313 			void				_MakeGradient(BGradientLinear& gradient,
314 									const BRect& rect, const rgb_color& base,
315 									float topTint, float bottomTint,
316 									enum orientation orientation
317 										= B_HORIZONTAL) const;
318 
319 			void				_MakeGlossyGradient(BGradientLinear& gradient,
320 									const BRect& rect, const rgb_color& base,
321 									float topTint, float middle1Tint,
322 									float middle2Tint, float bottomTint,
323 									enum orientation orientation
324 										= B_HORIZONTAL) const;
325 
326 			bool				_RadioButtonAndCheckBoxMarkColor(
327 									const rgb_color& base, rgb_color& color,
328 									uint32 flags) const;
329 
330 			void				_DrawRoundBarCorner(BView* view, BRect& rect,
331 									const BRect& updateRect,
332 									const rgb_color& edgeLightColor,
333 									const rgb_color& edgeShadowColor,
334 									const rgb_color& frameLightColor,
335 									const rgb_color& frameShadowColor,
336 									const rgb_color& fillLightColor,
337 									const rgb_color& fillShadowColor,
338 									float leftInset, float topInset,
339 									float rightInset, float bottomInset,
340 									enum orientation orientation);
341 
342 			void				_DrawRoundCornerLeftTop(BView* view,
343 									BRect& rect, const BRect& updateRect,
344 									const rgb_color& base,
345 									const rgb_color& edgeColor,
346 									const rgb_color& frameColor,
347 									const rgb_color& bevelColor,
348 									const BGradientLinear& fillGradient);
349 			void				_DrawRoundCornerRightTop(BView* view,
350 									BRect& rect, const BRect& updateRect,
351 									const rgb_color& base,
352 									const rgb_color& edgeTopColor,
353 									const rgb_color& edgeRightColor,
354 									const rgb_color& frameTopColor,
355 									const rgb_color& frameRightColor,
356 									const rgb_color& bevelTopColor,
357 									const rgb_color& bevelRightColor,
358 									const BGradientLinear& fillGradient);
359 };
360 
361 extern BControlLook* be_control_look;
362 
363 
364 } // namespace BPrivate
365 
366 using BPrivate::BControlLook;
367 using BPrivate::be_control_look;
368 
369 #endif // _CONTROL_LOOK_H
370