xref: /haiku/headers/os/interface/ControlLook.h (revision c90684742e7361651849be4116d0e5de3a817194)
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 	static	float				ComposeItemSpacing(float spacing);
83 
84 			uint32				Flags(BControl* control) const;
85 
86 	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
87 									const BRect& updateRect,
88 									const rgb_color& base,
89 									const rgb_color& background,
90 									uint32 flags = 0,
91 									uint32 borders = B_ALL_BORDERS);
92 
93 	virtual void				DrawButtonBackground(BView* view, BRect& rect,
94 									const BRect& updateRect,
95 									const rgb_color& base,
96 									uint32 flags = 0,
97 									uint32 borders = B_ALL_BORDERS,
98 									enum orientation orientation
99 										= B_HORIZONTAL);
100 
101 	virtual void				DrawMenuBarBackground(BView* view, BRect& rect,
102 									const BRect& updateRect,
103 									const rgb_color& base,
104 									uint32 flags = 0,
105 									uint32 borders = B_ALL_BORDERS);
106 
107 	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
108 									const BRect& updateRect,
109 									const rgb_color& base,
110 									const rgb_color& background,
111 									uint32 flags = 0,
112 									uint32 borders = B_ALL_BORDERS);
113 
114 	virtual void				DrawMenuFieldBackground(BView* view,
115 									BRect& rect, const BRect& updateRect,
116 									const rgb_color& base, bool popupIndicator,
117 									uint32 flags = 0);
118 
119 	virtual void				DrawMenuFieldBackground(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				DrawMenuBackground(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				DrawMenuItemBackground(BView* view,
130 									BRect& rect, const BRect& updateRect,
131 									const rgb_color& base, uint32 flags = 0,
132 									uint32 borders = B_ALL_BORDERS);
133 
134 	virtual void				DrawStatusBar(BView* view, BRect& rect,
135 									const BRect& updateRect,
136 									const rgb_color& base,
137 									const rgb_color& barColor,
138 									float progressPosition);
139 
140 	virtual void				DrawCheckBox(BView* view, BRect& rect,
141 									const BRect& updateRect,
142 									const rgb_color& base,
143 									uint32 flags = 0);
144 
145 	virtual void				DrawRadioButton(BView* view, BRect& rect,
146 									const BRect& updateRect,
147 									const rgb_color& base,
148 									uint32 flags = 0);
149 
150 	virtual void				DrawScrollBarBackground(BView* view,
151 									BRect& rect1, BRect& rect2,
152 									const BRect& updateRect,
153 									const rgb_color& base, uint32 flags,
154 									enum orientation orientation);
155 
156 	virtual void				DrawScrollBarBackground(BView* view,
157 									BRect& rect, const BRect& updateRect,
158 									const rgb_color& base, uint32 flags,
159 									enum orientation orientation);
160 
161 	// TODO: Make all these virtual before R1 release
162 			void				DrawScrollViewFrame(BView* view,
163 									BRect& rect, const BRect& updateRect,
164 									BRect verticalScrollBarFrame,
165 									BRect horizontalScrollBarFrame,
166 									const rgb_color& base,
167 									border_style border,
168 									uint32 flags = 0,
169 									uint32 borders = B_ALL_BORDERS);
170 
171 			void				DrawArrowShape(BView* view,
172 									BRect& rect, const BRect& updateRect,
173 									const rgb_color& base, uint32 direction,
174 									uint32 flags = 0,
175 									float tint = B_DARKEN_MAX_TINT);
176 
177 	virtual	rgb_color			SliderBarColor(const rgb_color& base);
178 
179 	virtual void				DrawSliderBar(BView* view, BRect rect,
180 									const BRect& updateRect,
181 									const rgb_color& base,
182 									rgb_color leftFillColor,
183 									rgb_color rightFillColor,
184 									float sliderScale, uint32 flags,
185 									enum orientation orientation);
186 
187 	virtual	void				DrawSliderBar(BView* view, BRect rect,
188 									const BRect& updateRect,
189 									const rgb_color& base, rgb_color fillColor,
190 									uint32 flags, enum orientation orientation);
191 
192 	virtual	void				DrawSliderThumb(BView* view, BRect& rect,
193 									const BRect& updateRect,
194 									const rgb_color& base, uint32 flags,
195 									enum orientation orientation);
196 
197 			void				DrawSliderTriangle(BView* view, BRect& rect,
198 									const BRect& updateRect,
199 									const rgb_color& base, uint32 flags,
200 									enum orientation orientation);
201 
202 	virtual	void				DrawSliderTriangle(BView* view, BRect& rect,
203 									const BRect& updateRect,
204 									const rgb_color& base,
205 									const rgb_color& fill, uint32 flags,
206 									enum orientation orientation);
207 
208 	virtual	void				DrawSliderHashMarks(BView* view, BRect& rect,
209 									const BRect& updateRect,
210 									const rgb_color& base, int32 count,
211 									hash_mark_location location,
212 									uint32 flags, enum orientation orientation);
213 
214 	virtual void				DrawActiveTab(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				DrawInactiveTab(BView* view, BRect& rect,
220 									const BRect& updateRect,
221 									const rgb_color& base, uint32 flags = 0,
222 									uint32 borders = B_ALL_BORDERS);
223 
224 	/*virtual*/	void			DrawSplitter(BView* view, BRect& rect,
225 									const BRect& updateRect,
226 									const rgb_color& base,
227 									enum orientation orientation,
228 									uint32 flags = 0,
229 									uint32 borders = B_ALL_BORDERS);
230 
231 	// various borders
232 
233 	virtual void				DrawBorder(BView* view, BRect& rect,
234 									const BRect& updateRect,
235 									const rgb_color& base,
236 									border_style border, uint32 flags = 0,
237 									uint32 borders = B_ALL_BORDERS);
238 
239 	virtual void				DrawRaisedBorder(BView* view, BRect& rect,
240 									const BRect& updateRect,
241 									const rgb_color& base, uint32 flags = 0,
242 									uint32 borders = B_ALL_BORDERS);
243 
244 	virtual void				DrawGroupFrame(BView* view, BRect& rect,
245 									const BRect& updateRect,
246 									const rgb_color& base,
247 									uint32 borders = B_ALL_BORDERS);
248 
249 	virtual void				DrawTextControlBorder(BView* view, BRect& rect,
250 									const BRect& updateRect,
251 									const rgb_color& base, uint32 flags = 0,
252 									uint32 borders = B_ALL_BORDERS);
253 
254 	// aligned labels
255 
256 			void				DrawLabel(BView* view, const char* label,
257 									BRect rect, const BRect& updateRect,
258 									const rgb_color& base, uint32 flags);
259 
260 	virtual void				DrawLabel(BView* view, const char* label,
261 									BRect rect, const BRect& updateRect,
262 									const rgb_color& base, uint32 flags,
263 									const BAlignment& alignment);
264 
265 	// TODO: This should also be virtual
266 	// TODO: Would be nice to have a (non-virtual) version of this method
267 	// which takes an array of labels and locations. That would save some
268 	// setup with the view graphics state.
269 			void				DrawLabel(BView* view, const char* label,
270 									const rgb_color& base, uint32 flags,
271 									const BPoint& where);
272 
273 protected:
274 			void				_DrawButtonFrame(BView* view, BRect& rect,
275 									const BRect& updateRect,
276 									const rgb_color& base,
277 									const rgb_color& background,
278 									float contrast, float brightness = 1.0,
279 									uint32 flags = 0,
280 									uint32 borders = B_ALL_BORDERS);
281 
282 			void				_DrawOuterResessedFrame(BView* view,
283 									BRect& rect, const rgb_color& base,
284 									float contrast = 1.0f,
285 									float brightness = 1.0f,
286 									uint32 flags = 0,
287 									uint32 borders = B_ALL_BORDERS);
288 
289 			void				_DrawFrame(BView* view, BRect& rect,
290 									const rgb_color& left,
291 									const rgb_color& top,
292 									const rgb_color& right,
293 									const rgb_color& bottom,
294 									uint32 borders = B_ALL_BORDERS);
295 
296 			void				_DrawFrame(BView* view, BRect& rect,
297 									const rgb_color& left,
298 									const rgb_color& top,
299 									const rgb_color& right,
300 									const rgb_color& bottom,
301 									const rgb_color& rightTop,
302 									const rgb_color& leftBottom,
303 									uint32 borders = B_ALL_BORDERS);
304 
305 			void				_FillGradient(BView* view, const BRect& rect,
306 									const rgb_color& base, float topTint,
307 									float bottomTint,
308 									enum orientation orientation
309 										= B_HORIZONTAL);
310 
311 			void				_FillGlossyGradient(BView* view,
312 									const BRect& rect, const rgb_color& base,
313 									float topTint, float middle1Tint,
314 									float middle2Tint, float bottomTint,
315 									enum orientation orientation
316 										= B_HORIZONTAL);
317 
318 			void				_MakeGradient(BGradientLinear& gradient,
319 									const BRect& rect, const rgb_color& base,
320 									float topTint, float bottomTint,
321 									enum orientation orientation
322 										= B_HORIZONTAL) const;
323 
324 			void				_MakeGlossyGradient(BGradientLinear& gradient,
325 									const BRect& rect, const rgb_color& base,
326 									float topTint, float middle1Tint,
327 									float middle2Tint, float bottomTint,
328 									enum orientation orientation
329 										= B_HORIZONTAL) const;
330 
331 			bool				_RadioButtonAndCheckBoxMarkColor(
332 									const rgb_color& base, rgb_color& color,
333 									uint32 flags) const;
334 
335 			void				_DrawRoundBarCorner(BView* view, BRect& rect,
336 									const BRect& updateRect,
337 									const rgb_color& edgeLightColor,
338 									const rgb_color& edgeShadowColor,
339 									const rgb_color& frameLightColor,
340 									const rgb_color& frameShadowColor,
341 									const rgb_color& fillLightColor,
342 									const rgb_color& fillShadowColor,
343 									float leftInset, float topInset,
344 									float rightInset, float bottomInset,
345 									enum orientation orientation);
346 
347 			void				_DrawRoundCornerLeftTop(BView* view,
348 									BRect& rect, const BRect& updateRect,
349 									const rgb_color& base,
350 									const rgb_color& edgeColor,
351 									const rgb_color& frameColor,
352 									const rgb_color& bevelColor,
353 									const BGradientLinear& fillGradient);
354 			void				_DrawRoundCornerRightTop(BView* view,
355 									BRect& rect, const BRect& updateRect,
356 									const rgb_color& base,
357 									const rgb_color& edgeTopColor,
358 									const rgb_color& edgeRightColor,
359 									const rgb_color& frameTopColor,
360 									const rgb_color& frameRightColor,
361 									const rgb_color& bevelTopColor,
362 									const rgb_color& bevelRightColor,
363 									const BGradientLinear& fillGradient);
364 };
365 
366 extern BControlLook* be_control_look;
367 
368 
369 } // namespace BPrivate
370 
371 using BPrivate::BControlLook;
372 using BPrivate::be_control_look;
373 
374 #endif // _CONTROL_LOOK_H
375