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