ControlLook.h revision ec1b18c5
1/*
2 * Copyright 2009-2017, 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
9#include <Alignment.h>
10#include <Font.h>
11#include <Rect.h>
12#include <Slider.h>
13
14
15class BBitmap;
16class BControl;
17class BGradientLinear;
18class BView;
19
20
21// WARNING! This is experimental API and may change! Be prepared to
22// recompile your software in a next version of haiku.
23
24
25namespace BPrivate {
26
27
28class BControlLook {
29public:
30								BControlLook();
31	virtual						~BControlLook();
32
33	// TODO: Probably more convenient to pull these enums into global
34	// namespace and rename them to e.g. "B_CONTROL_LOOK_FOCUSED" instead of
35	// "BControlLook::B_FOCUSED".
36
37	enum frame_type {
38		B_BUTTON_FRAME,
39		B_GROUP_FRAME,
40		B_MENU_FIELD_FRAME,
41		B_SCROLL_VIEW_FRAME,
42		B_TEXT_CONTROL_FRAME,
43	};
44
45	enum background_type {
46		B_BUTTON_BACKGROUND,
47		B_BUTTON_WITH_POP_UP_BACKGROUND,
48		B_MENU_BACKGROUND,
49		B_MENU_BAR_BACKGROUND,
50		B_MENU_FIELD_BACKGROUND,
51		B_MENU_ITEM_BACKGROUND,
52		B_HORIZONTAL_SCROLL_BAR_BACKGROUND,
53		B_VERTICAL_SCROLL_BAR_BACKGROUND,
54	};
55
56	enum {
57		B_LEFT_BORDER		= 1 << 0,
58		B_RIGHT_BORDER		= 1 << 1,
59		B_TOP_BORDER		= 1 << 2,
60		B_BOTTOM_BORDER		= 1 << 3,
61
62		B_ALL_BORDERS		= B_LEFT_BORDER | B_RIGHT_BORDER
63								| B_TOP_BORDER | B_BOTTOM_BORDER
64	};
65
66	enum {
67		B_LEFT_ARROW		= 0,
68		B_RIGHT_ARROW		= 1,
69		B_UP_ARROW			= 2,
70		B_DOWN_ARROW		= 3,
71		B_LEFT_UP_ARROW		= 4,
72		B_RIGHT_UP_ARROW	= 5,
73		B_RIGHT_DOWN_ARROW	= 6,
74		B_LEFT_DOWN_ARROW	= 7
75	};
76
77	enum {
78		B_FOCUSED				= 1 << 0,
79		B_CLICKED				= 1 << 1, // some controls activate on mouse up
80		B_ACTIVATED				= 1 << 2,
81		B_HOVER					= 1 << 3,
82		B_DISABLED				= 1 << 4,
83		B_DEFAULT_BUTTON		= 1 << 5,
84		B_IGNORE_OUTLINE		= 1 << 6,
85		B_PARTIALLY_ACTIVATED	= 1 << 7, // like B_ACTIVATED, but for tri-state
86		B_FLAT					= 1 << 8, // flat look (e.g. button background)
87		B_INVALID				= 1 << 9, // invalid value, use B_FAILURE_COLOR
88		B_IS_CONTROL			= 1 << 10, // use control colors
89		B_SCROLLABLE			= 1 << 11, // scroll bar within bounds
90
91		B_BLEND_FRAME			= 1 << 16,
92	};
93
94	virtual BAlignment			DefaultLabelAlignment() const = 0;
95	virtual float				DefaultLabelSpacing() const = 0;
96
97	virtual	float				DefaultItemSpacing() const = 0;
98
99	static	float				ComposeSpacing(float spacing);
100
101	virtual uint32				Flags(BControl* control) const = 0;
102
103	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
104									const BRect& updateRect,
105									const rgb_color& base,
106									const rgb_color& background,
107									uint32 flags = 0,
108									uint32 borders = B_ALL_BORDERS) = 0;
109	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
110									const BRect& updateRect,
111									float radius,
112									const rgb_color& base,
113									const rgb_color& background,
114									uint32 flags = 0,
115									uint32 borders = B_ALL_BORDERS) = 0;
116	virtual	void				DrawButtonFrame(BView* view, BRect& rect,
117									const BRect& updateRect,
118									float leftTopRadius,
119									float rightTopRadius,
120									float leftBottomRadius,
121									float rightBottomRadius,
122									const rgb_color& base,
123									const rgb_color& background,
124									uint32 flags = 0,
125									uint32 borders = B_ALL_BORDERS) = 0;
126
127	virtual	void				DrawButtonBackground(BView* view, BRect& rect,
128									const BRect& updateRect,
129									const rgb_color& base,
130									uint32 flags = 0,
131									uint32 borders = B_ALL_BORDERS,
132									orientation orientation = B_HORIZONTAL) = 0;
133	virtual	void				DrawButtonBackground(BView* view, BRect& rect,
134									const BRect& updateRect,
135									float radius,
136									const rgb_color& base,
137									uint32 flags = 0,
138									uint32 borders = B_ALL_BORDERS,
139									orientation orientation = B_HORIZONTAL) = 0;
140	virtual	void				DrawButtonBackground(BView* view, BRect& rect,
141									const BRect& updateRect,
142									float leftTopRadius,
143									float rightTopRadius,
144									float leftBottomRadius,
145									float rightBottomRadius,
146									const rgb_color& base,
147									uint32 flags = 0,
148									uint32 borders = B_ALL_BORDERS,
149									orientation orientation = B_HORIZONTAL) = 0;
150
151	virtual	void				DrawMenuBarBackground(BView* view, BRect& rect,
152									const BRect& updateRect,
153									const rgb_color& base,
154									uint32 flags = 0,
155									uint32 borders = B_ALL_BORDERS) = 0;
156
157	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
158									const BRect& updateRect,
159									const rgb_color& base,
160									const rgb_color& background,
161									uint32 flags = 0,
162									uint32 borders = B_ALL_BORDERS) = 0;
163	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
164									const BRect& updateRect,
165									float radius,
166									const rgb_color& base,
167									const rgb_color& background,
168									uint32 flags = 0,
169									uint32 borders = B_ALL_BORDERS) = 0;
170	virtual	void				DrawMenuFieldFrame(BView* view, BRect& rect,
171									const BRect& updateRect,
172									float leftTopRadius,
173									float rightTopRadius,
174									float leftBottomRadius,
175									float rightBottomRadius,
176									const rgb_color& base,
177									const rgb_color& background,
178									uint32 flags = 0,
179									uint32 borders = B_ALL_BORDERS) = 0;
180
181	virtual	void				DrawMenuFieldBackground(BView* view,
182									BRect& rect, const BRect& updateRect,
183									const rgb_color& base, bool popupIndicator,
184									uint32 flags = 0) = 0;
185	virtual	void				DrawMenuFieldBackground(BView* view,
186									BRect& rect, const BRect& updateRect,
187									float radius, const rgb_color& base,
188									bool popupIndicator, uint32 flags = 0) = 0;
189	virtual	void				DrawMenuFieldBackground(BView* view,
190									BRect& rect, const BRect& updateRect,
191									float leftTopRadius,
192									float rightTopRadius,
193									float leftBottomRadius,
194									float rightBottomRadius,
195									const rgb_color& base,
196									bool popupIndicator, uint32 flags = 0) = 0;
197	virtual	void				DrawMenuFieldBackground(BView* view,
198									BRect& rect, const BRect& updateRect,
199									const rgb_color& base, uint32 flags = 0,
200									uint32 borders = B_ALL_BORDERS) = 0;
201
202	virtual	void				DrawMenuBackground(BView* view,
203									BRect& rect, const BRect& updateRect,
204									const rgb_color& base, uint32 flags = 0,
205									uint32 borders = B_ALL_BORDERS) = 0;
206
207	virtual	void				DrawMenuItemBackground(BView* view,
208									BRect& rect, const BRect& updateRect,
209									const rgb_color& base, uint32 flags = 0,
210									uint32 borders = B_ALL_BORDERS) = 0;
211
212	virtual	void				DrawStatusBar(BView* view, BRect& rect,
213									const BRect& updateRect,
214									const rgb_color& base,
215									const rgb_color& barColor,
216									float progressPosition) = 0;
217
218	virtual	void				DrawCheckBox(BView* view, BRect& rect,
219									const BRect& updateRect,
220									const rgb_color& base,
221									uint32 flags = 0) = 0;
222
223	virtual	void				DrawRadioButton(BView* view, BRect& rect,
224									const BRect& updateRect,
225									const rgb_color& base,
226									uint32 flags = 0) = 0;
227
228	virtual	void				DrawScrollBar(BView* view, BRect& rect,
229									const BRect& updateRect,
230									const rgb_color& base, uint32 flags,
231									orientation orientation,
232									bool doubleArrows = false,
233									int32 buttonDown = -1) = 0;
234	virtual	void				DrawScrollBarThumb(BView* view, BRect& rect,
235									BRect& thumbRect, const BRect& updateRect,
236									const rgb_color& base, uint32 flags,
237									orientation orientation,
238									uint32 knobStyle = 0) = 0;
239
240	virtual	void				DrawScrollViewFrame(BView* view,
241									BRect& rect, const BRect& updateRect,
242									BRect verticalScrollBarFrame,
243									BRect horizontalScrollBarFrame,
244									const rgb_color& base,
245									border_style borderStyle,
246									uint32 flags = 0,
247									uint32 borders = B_ALL_BORDERS) = 0;
248
249	virtual	void				DrawArrowShape(BView* view,
250									BRect& rect, const BRect& updateRect,
251									const rgb_color& base, uint32 direction,
252									uint32 flags = 0,
253									float tint = B_DARKEN_MAX_TINT) = 0;
254
255	virtual	rgb_color			SliderBarColor(const rgb_color& base) = 0;
256
257	virtual	void				DrawSliderBar(BView* view, BRect rect,
258									const BRect& updateRect,
259									const rgb_color& base,
260									rgb_color leftFillColor,
261									rgb_color rightFillColor,
262									float sliderScale, uint32 flags,
263									orientation orientation) = 0;
264	virtual	void				DrawSliderBar(BView* view, BRect rect,
265									const BRect& updateRect,
266									const rgb_color& base, rgb_color fillColor,
267									uint32 flags, orientation orientation) = 0;
268
269	virtual	void				DrawSliderThumb(BView* view, BRect& rect,
270									const BRect& updateRect,
271									const rgb_color& base, uint32 flags,
272									orientation orientation) = 0;
273
274	virtual	void				DrawSliderTriangle(BView* view, BRect& rect,
275									const BRect& updateRect,
276									const rgb_color& base, uint32 flags,
277									orientation orientation) = 0;
278	virtual	void				DrawSliderTriangle(BView* view, BRect& rect,
279									const BRect& updateRect,
280									const rgb_color& base,
281									const rgb_color& fill, uint32 flags,
282									orientation orientation) = 0;
283
284	virtual	void				DrawSliderHashMarks(BView* view, BRect& rect,
285									const BRect& updateRect,
286									const rgb_color& base, int32 count,
287									hash_mark_location location,
288									uint32 flags, orientation orientation) = 0;
289
290	virtual	void				DrawActiveTab(BView* view, BRect& rect,
291									const BRect& updateRect,
292									const rgb_color& base, uint32 flags = 0,
293									uint32 borders = B_ALL_BORDERS,
294									uint32 side = B_TOP_BORDER) = 0;
295
296	virtual	void				DrawInactiveTab(BView* view, BRect& rect,
297									const BRect& updateRect,
298									const rgb_color& base, uint32 flags = 0,
299									uint32 borders = B_ALL_BORDERS,
300									uint32 side = B_TOP_BORDER) = 0;
301
302	virtual	void				DrawSplitter(BView* view, BRect& rect,
303									const BRect& updateRect,
304									const rgb_color& base,
305									orientation orientation,
306									uint32 flags = 0,
307									uint32 borders = B_ALL_BORDERS) = 0;
308
309	// various borders
310
311	virtual	void				DrawBorder(BView* view, BRect& rect,
312									const BRect& updateRect,
313									const rgb_color& base,
314									border_style borderStyle, uint32 flags = 0,
315									uint32 borders = B_ALL_BORDERS) = 0;
316
317	virtual	void				DrawRaisedBorder(BView* view, BRect& rect,
318									const BRect& updateRect,
319									const rgb_color& base, uint32 flags = 0,
320									uint32 borders = B_ALL_BORDERS) = 0;
321
322	virtual	void				DrawGroupFrame(BView* view, BRect& rect,
323									const BRect& updateRect,
324									const rgb_color& base,
325									uint32 borders = B_ALL_BORDERS) = 0;
326
327	virtual	void				DrawTextControlBorder(BView* view, BRect& rect,
328									const BRect& updateRect,
329									const rgb_color& base, uint32 flags = 0,
330									uint32 borders = B_ALL_BORDERS) = 0;
331
332	// aligned labels
333
334	virtual	void				DrawLabel(BView* view, const char* label,
335									BRect rect, const BRect& updateRect,
336									const rgb_color& base, uint32 flags,
337									const rgb_color* textColor = NULL) = 0;
338	virtual	void				DrawLabel(BView* view, const char* label,
339									BRect rect, const BRect& updateRect,
340									const rgb_color& base, uint32 flags,
341									const BAlignment& alignment,
342									const rgb_color* textColor = NULL) = 0;
343	// TODO: Would be nice to have a (non-virtual) version of this method
344	// which takes an array of labels and locations. That would save some
345	// setup with the view graphics state.
346	virtual	void				DrawLabel(BView* view, const char* label,
347									const rgb_color& base, uint32 flags,
348									const BPoint& where,
349									const rgb_color* textColor = NULL) = 0;
350
351			void				DrawLabel(BView* view, const char* label,
352									const BBitmap* icon, BRect rect,
353									const BRect& updateRect,
354									const rgb_color& base, uint32 flags,
355									const rgb_color* textColor = NULL);
356	virtual	void				DrawLabel(BView* view, const char* label,
357									const BBitmap* icon, BRect rect,
358									const BRect& updateRect,
359									const rgb_color& base, uint32 flags,
360									const BAlignment& alignment,
361									const rgb_color* textColor = NULL) = 0;
362
363	virtual	void				GetFrameInsets(frame_type frameType,
364									uint32 flags, float& _left, float& _top,
365									float& _right, float& _bottom) = 0;
366	virtual	void				GetBackgroundInsets(
367									background_type backgroundType,
368									uint32 flags, float& _left, float& _top,
369									float& _right, float& _bottom) = 0;
370			void				GetInsets(frame_type frameType,
371									background_type backgroundType,
372									uint32 flags, float& _left, float& _top,
373									float& _right, float& _bottom);
374
375	virtual	void				DrawButtonWithPopUpBackground(BView* view,
376									BRect& rect, const BRect& updateRect,
377									const rgb_color& base,
378									uint32 flags = 0,
379									uint32 borders = B_ALL_BORDERS,
380									orientation orientation = B_HORIZONTAL) = 0;
381	virtual	void				DrawButtonWithPopUpBackground(BView* view,
382									BRect& rect, const BRect& updateRect,
383									float radius,
384									const rgb_color& base,
385									uint32 flags = 0,
386									uint32 borders = B_ALL_BORDERS,
387									orientation orientation = B_HORIZONTAL) = 0;
388	virtual	void				DrawButtonWithPopUpBackground(BView* view,
389									BRect& rect, const BRect& updateRect,
390									float leftTopRadius,
391									float rightTopRadius,
392									float leftBottomRadius,
393									float rightBottomRadius,
394									const rgb_color& base,
395									uint32 flags = 0,
396									uint32 borders = B_ALL_BORDERS,
397									orientation orientation = B_HORIZONTAL) = 0;
398
399			void				SetBackgroundInfo(
400									const BMessage& backgroundInfo);
401
402protected:
403			int32				fCachedWorkspace;
404			BMessage			fBackgroundInfo;
405
406			uint32				_reserved[20];
407};
408
409extern BControlLook* be_control_look;
410
411
412} // namespace BPrivate
413
414using BPrivate::BControlLook;
415using BPrivate::be_control_look;
416
417
418#endif // _CONTROL_LOOK_H
419