xref: /haiku/src/kits/interface/ControlLook.cpp (revision 7b3e89c0944ae1efa9a8fc66c7303874b7a344b2)
1 /*
2  * Copyright 2012-2020 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <ControlLook.h>
8 
9 #include <binary_compatibility/Interface.h>
10 
11 
12 namespace BPrivate {
13 
14 
15 BControlLook::BControlLook()
16 	:
17 	fCachedWorkspace(-1)
18 {
19 }
20 
21 
22 BControlLook::~BControlLook()
23 {
24 }
25 
26 
27 float
28 BControlLook::ComposeSpacing(float spacing)
29 {
30 	switch ((int)spacing) {
31 		case B_USE_DEFAULT_SPACING:
32 		case B_USE_ITEM_SPACING:
33 			return be_control_look->DefaultItemSpacing();
34 		case B_USE_HALF_ITEM_SPACING:
35 			return ceilf(be_control_look->DefaultItemSpacing() * 0.5f);
36 		case B_USE_WINDOW_SPACING:
37 			return be_control_look->DefaultItemSpacing();
38 		case B_USE_SMALL_SPACING:
39 			return ceilf(be_control_look->DefaultItemSpacing() * 0.7f);
40 		case B_USE_BIG_SPACING:
41 			return ceilf(be_control_look->DefaultItemSpacing() * 1.3f);
42 	}
43 
44 	return spacing;
45 }
46 
47 
48 BSize
49 BControlLook::ComposeIconSize(int32 size)
50 {
51 	float scale = be_plain_font->Size() / 12.0f;
52 	if (scale < 1.0f)
53 		scale = 1.0f;
54 
55 	const int32 scaled = (int32)(size * scale);
56 	return BSize(scaled - 1, scaled - 1);
57 }
58 
59 
60 void
61 BControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon,
62 	BRect rect, const BRect& updateRect, const rgb_color& base, uint32 flags,
63 	const rgb_color* textColor)
64 {
65 	DrawLabel(view, label, icon, rect, updateRect, base, flags,
66 		DefaultLabelAlignment(), textColor);
67 }
68 
69 
70 void
71 BControlLook::GetInsets(frame_type frameType, background_type backgroundType,
72 	uint32 flags, float& _left, float& _top, float& _right, float& _bottom)
73 {
74 	GetFrameInsets(frameType, flags, _left, _top, _right, _bottom);
75 
76 	float left, top, right, bottom;
77 	GetBackgroundInsets(backgroundType, flags, left, top, right, bottom);
78 
79 	_left += left;
80 	_top += top;
81 	_right += right;
82 	_bottom += bottom;
83 }
84 
85 
86 float
87 BControlLook::GetScrollBarWidth(orientation orientation)
88 {
89 	// this matches HaikuControlLook.cpp currently
90 	if (be_plain_font->Size() <= 12.0f)
91 		return 14.0f;
92 	return be_plain_font->Size() / 12.0f * 14.0f;
93 }
94 
95 
96 void
97 BControlLook::SetBackgroundInfo(const BMessage& backgroundInfo)
98 {
99 	fBackgroundInfo = backgroundInfo;
100 	fCachedWorkspace = -1;
101 }
102 
103 
104 extern "C" void
105 B_IF_GCC_2(_ReservedControlLook1__Q28BPrivate12BControlLook,
106 		_ZN8BPrivate12BControlLook21_ReservedControlLook1Ev)(
107 	BControlLook* controlLook, BView* view, BRect& rect,
108 	const BRect& updateRect, const rgb_color& base, uint32 flags,
109 	uint32 borders, border_style borderStyle, uint32 side)
110 {
111 	controlLook->DrawTabFrame(view, rect, updateRect, base, flags, borders,
112 		borderStyle, side);
113 }
114 
115 
116 extern "C" void
117 B_IF_GCC_2(_ReservedControlLook2__Q28BPrivate12BControlLook,
118 		_ZN8BPrivate12BControlLook21_ReservedControlLook2Ev)(
119 	BControlLook* controlLook, BView* view, BRect rect,
120 		const BRect& updateRect, const rgb_color& base, uint32 flags,
121 		int32 direction, orientation orientation, bool down)
122 {
123 	controlLook->DrawScrollBarButton(view, rect, updateRect, base, flags,
124 		direction, orientation, down);
125 }
126 
127 
128 extern "C" void
129 B_IF_GCC_2(_ReservedControlLook3__Q28BPrivate12BControlLook,
130 		_ZN8BPrivate12BControlLook21_ReservedControlLook3Ev)(
131 	BControlLook* controlLook, BView* view, BRect rect,
132 		const BRect& updateRect, const rgb_color& base, uint32 flags,
133 		int32 direction, orientation orientation, uint32 knobStyle)
134 {
135 	controlLook->DrawScrollBarThumb(view, rect, updateRect, base, flags,
136 		orientation, knobStyle);
137 }
138 
139 
140 extern "C" void
141 B_IF_GCC_2(_ReservedControlLook4__Q28BPrivate12BControlLook,
142 		_ZN8BPrivate12BControlLook21_ReservedControlLook4Ev)(
143 	BControlLook* controlLook, BView* view, BRect rect,
144 		const BRect& updateRect, const rgb_color& base, uint32 flags,
145 		orientation orientation)
146 {
147 	controlLook->DrawScrollBarBorder(view, rect, updateRect, base, flags,
148 		orientation);
149 }
150 
151 
152 extern "C" float
153 B_IF_GCC_2(_ReservedControlLook5__Q28BPrivate12BControlLook,
154 		_ZN8BPrivate12BControlLook21_ReservedControlLook5Ev)(
155 	BControlLook* controlLook, orientation orientation)
156 {
157 	return controlLook->GetScrollBarWidth(orientation);
158 }
159 
160 
161 void BControlLook::_ReservedControlLook6() {}
162 void BControlLook::_ReservedControlLook7() {}
163 void BControlLook::_ReservedControlLook8() {}
164 void BControlLook::_ReservedControlLook9() {}
165 void BControlLook::_ReservedControlLook10() {}
166 
167 
168 // Initialized in InterfaceDefs.cpp
169 BControlLook* be_control_look = NULL;
170 
171 } // namespace BPrivate
172