xref: /haiku/src/kits/interface/ControlLook.cpp (revision c1353b749c85dd89eca7c76be41c9d2c82f8dd16)
12f86ba45SStephan Aßmus /*
21482b250SJohn Scipione  * Copyright 2012-2020 Haiku, Inc. All rights reserved.
32f86ba45SStephan Aßmus  * Distributed under the terms of the MIT License.
42f86ba45SStephan Aßmus  */
5d452ff66SAxel Dörfler 
62f86ba45SStephan Aßmus #include <ControlLook.h>
72f86ba45SStephan Aßmus 
88672fc27SAugustin Cavalier #include <algorithm>
9fb3493dfSJohn Scipione #include <binary_compatibility/Interface.h>
10fb3493dfSJohn Scipione 
11a884b43bSJohn Scipione 
122f86ba45SStephan Aßmus namespace BPrivate {
132f86ba45SStephan Aßmus 
14a884b43bSJohn Scipione 
15db68ff23SAugustin Cavalier BControlLook::BControlLook()
16db68ff23SAugustin Cavalier 	:
17d63b75faSPhilippe Saint-Pierre 	fCachedWorkspace(-1)
182f86ba45SStephan Aßmus {
192f86ba45SStephan Aßmus }
202f86ba45SStephan Aßmus 
212f86ba45SStephan Aßmus 
222f86ba45SStephan Aßmus BControlLook::~BControlLook()
232f86ba45SStephan Aßmus {
242f86ba45SStephan Aßmus }
252f86ba45SStephan Aßmus 
262f86ba45SStephan Aßmus 
2782ab3167SAlex Wilson float
286648dd3cSAlex Wilson BControlLook::ComposeSpacing(float spacing)
2982ab3167SAlex Wilson {
30e047b40aSAxel Dörfler 	switch ((int)spacing) {
31e047b40aSAxel Dörfler 		case B_USE_DEFAULT_SPACING:
32e047b40aSAxel Dörfler 		case B_USE_ITEM_SPACING:
3382ab3167SAlex Wilson 			return be_control_look->DefaultItemSpacing();
34e047b40aSAxel Dörfler 		case B_USE_HALF_ITEM_SPACING:
35a8b89c6bSStephan Aßmus 			return ceilf(be_control_look->DefaultItemSpacing() * 0.5f);
36e047b40aSAxel Dörfler 		case B_USE_WINDOW_SPACING:
376648dd3cSAlex Wilson 			return be_control_look->DefaultItemSpacing();
38e047b40aSAxel Dörfler 		case B_USE_SMALL_SPACING:
39a8b89c6bSStephan Aßmus 			return ceilf(be_control_look->DefaultItemSpacing() * 0.7f);
408672fc27SAugustin Cavalier 		case B_USE_CORNER_SPACING:
41*c1353b74SAugustin Cavalier 			return ceilf(be_control_look->DefaultItemSpacing() * 1.272f);
42e047b40aSAxel Dörfler 		case B_USE_BIG_SPACING:
438672fc27SAugustin Cavalier 			return ceilf(be_control_look->DefaultItemSpacing() * 1.8f);
448672fc27SAugustin Cavalier 
458672fc27SAugustin Cavalier 		case B_USE_BORDER_SPACING:
468672fc27SAugustin Cavalier 			return std::max(1.0f, floorf(be_control_look->DefaultItemSpacing() / 11.0f));
476648dd3cSAlex Wilson 	}
48e047b40aSAxel Dörfler 
496648dd3cSAlex Wilson 	return spacing;
5082ab3167SAlex Wilson }
5182ab3167SAlex Wilson 
5282ab3167SAlex Wilson 
53874a2a72SAugustin Cavalier BSize
54874a2a72SAugustin Cavalier BControlLook::ComposeIconSize(int32 size)
55874a2a72SAugustin Cavalier {
56874a2a72SAugustin Cavalier 	float scale = be_plain_font->Size() / 12.0f;
57874a2a72SAugustin Cavalier 	if (scale < 1.0f)
58874a2a72SAugustin Cavalier 		scale = 1.0f;
59874a2a72SAugustin Cavalier 
601be85605SAugustin Cavalier 	const int32 scaled = (int32)(size * scale);
61874a2a72SAugustin Cavalier 	return BSize(scaled - 1, scaled - 1);
62874a2a72SAugustin Cavalier }
63874a2a72SAugustin Cavalier 
64874a2a72SAugustin Cavalier 
65d63b75faSPhilippe Saint-Pierre void
661b848ee7SIngo Weinhold BControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon,
677a96554cSlooncraz 	BRect rect, const BRect& updateRect, const rgb_color& base, uint32 flags,
687a96554cSlooncraz 	const rgb_color* textColor)
691b848ee7SIngo Weinhold {
701b848ee7SIngo Weinhold 	DrawLabel(view, label, icon, rect, updateRect, base, flags,
717a96554cSlooncraz 		DefaultLabelAlignment(), textColor);
721b848ee7SIngo Weinhold }
731b848ee7SIngo Weinhold 
741b848ee7SIngo Weinhold 
751b848ee7SIngo Weinhold void
768719e0dcSIngo Weinhold BControlLook::GetInsets(frame_type frameType, background_type backgroundType,
778719e0dcSIngo Weinhold 	uint32 flags, float& _left, float& _top, float& _right, float& _bottom)
788719e0dcSIngo Weinhold {
798719e0dcSIngo Weinhold 	GetFrameInsets(frameType, flags, _left, _top, _right, _bottom);
808719e0dcSIngo Weinhold 
818719e0dcSIngo Weinhold 	float left, top, right, bottom;
828719e0dcSIngo Weinhold 	GetBackgroundInsets(backgroundType, flags, left, top, right, bottom);
838719e0dcSIngo Weinhold 
848719e0dcSIngo Weinhold 	_left += left;
858719e0dcSIngo Weinhold 	_top += top;
868719e0dcSIngo Weinhold 	_right += right;
878719e0dcSIngo Weinhold 	_bottom += bottom;
888719e0dcSIngo Weinhold }
898719e0dcSIngo Weinhold 
908719e0dcSIngo Weinhold 
91409d65c0SPascal Abresch float
92409d65c0SPascal Abresch BControlLook::GetScrollBarWidth(orientation orientation)
93409d65c0SPascal Abresch {
948672fc27SAugustin Cavalier 	return ComposeSpacing(B_USE_CORNER_SPACING);
95409d65c0SPascal Abresch }
96409d65c0SPascal Abresch 
97409d65c0SPascal Abresch 
988719e0dcSIngo Weinhold void
99d452ff66SAxel Dörfler BControlLook::SetBackgroundInfo(const BMessage& backgroundInfo)
100d63b75faSPhilippe Saint-Pierre {
101d452ff66SAxel Dörfler 	fBackgroundInfo = backgroundInfo;
102d63b75faSPhilippe Saint-Pierre 	fCachedWorkspace = -1;
103d63b75faSPhilippe Saint-Pierre }
104d63b75faSPhilippe Saint-Pierre 
105d63b75faSPhilippe Saint-Pierre 
106fb3493dfSJohn Scipione extern "C" void
107fb3493dfSJohn Scipione B_IF_GCC_2(_ReservedControlLook1__Q28BPrivate12BControlLook,
108fb3493dfSJohn Scipione 		_ZN8BPrivate12BControlLook21_ReservedControlLook1Ev)(
109fb3493dfSJohn Scipione 	BControlLook* controlLook, BView* view, BRect& rect,
110fb3493dfSJohn Scipione 	const BRect& updateRect, const rgb_color& base, uint32 flags,
111fb3493dfSJohn Scipione 	uint32 borders, border_style borderStyle, uint32 side)
112fb3493dfSJohn Scipione {
113fb3493dfSJohn Scipione 	controlLook->DrawTabFrame(view, rect, updateRect, base, flags, borders,
114fb3493dfSJohn Scipione 		borderStyle, side);
115fb3493dfSJohn Scipione }
116fb3493dfSJohn Scipione 
117fb3493dfSJohn Scipione 
1181482b250SJohn Scipione extern "C" void
1191482b250SJohn Scipione B_IF_GCC_2(_ReservedControlLook2__Q28BPrivate12BControlLook,
1201482b250SJohn Scipione 		_ZN8BPrivate12BControlLook21_ReservedControlLook2Ev)(
1211482b250SJohn Scipione 	BControlLook* controlLook, BView* view, BRect rect,
1221482b250SJohn Scipione 		const BRect& updateRect, const rgb_color& base, uint32 flags,
1231482b250SJohn Scipione 		int32 direction, orientation orientation, bool down)
1241482b250SJohn Scipione {
1251482b250SJohn Scipione 	controlLook->DrawScrollBarButton(view, rect, updateRect, base, flags,
1261482b250SJohn Scipione 		direction, orientation, down);
1271482b250SJohn Scipione }
1281482b250SJohn Scipione 
1291482b250SJohn Scipione 
1301482b250SJohn Scipione extern "C" void
1311482b250SJohn Scipione B_IF_GCC_2(_ReservedControlLook3__Q28BPrivate12BControlLook,
1321482b250SJohn Scipione 		_ZN8BPrivate12BControlLook21_ReservedControlLook3Ev)(
1331482b250SJohn Scipione 	BControlLook* controlLook, BView* view, BRect rect,
1341482b250SJohn Scipione 		const BRect& updateRect, const rgb_color& base, uint32 flags,
1351482b250SJohn Scipione 		int32 direction, orientation orientation, uint32 knobStyle)
1361482b250SJohn Scipione {
1371482b250SJohn Scipione 	controlLook->DrawScrollBarThumb(view, rect, updateRect, base, flags,
1381482b250SJohn Scipione 		orientation, knobStyle);
1391482b250SJohn Scipione }
1401482b250SJohn Scipione 
1411482b250SJohn Scipione 
1421482b250SJohn Scipione extern "C" void
1431482b250SJohn Scipione B_IF_GCC_2(_ReservedControlLook4__Q28BPrivate12BControlLook,
1441482b250SJohn Scipione 		_ZN8BPrivate12BControlLook21_ReservedControlLook4Ev)(
1451482b250SJohn Scipione 	BControlLook* controlLook, BView* view, BRect rect,
1461482b250SJohn Scipione 		const BRect& updateRect, const rgb_color& base, uint32 flags,
1471482b250SJohn Scipione 		orientation orientation)
1481482b250SJohn Scipione {
1491482b250SJohn Scipione 	controlLook->DrawScrollBarBorder(view, rect, updateRect, base, flags,
1501482b250SJohn Scipione 		orientation);
1511482b250SJohn Scipione }
1521482b250SJohn Scipione 
1531482b250SJohn Scipione 
154409d65c0SPascal Abresch extern "C" float
155409d65c0SPascal Abresch B_IF_GCC_2(_ReservedControlLook5__Q28BPrivate12BControlLook,
156409d65c0SPascal Abresch 		_ZN8BPrivate12BControlLook21_ReservedControlLook5Ev)(
157409d65c0SPascal Abresch 	BControlLook* controlLook, orientation orientation)
158409d65c0SPascal Abresch {
159409d65c0SPascal Abresch 	return controlLook->GetScrollBarWidth(orientation);
160409d65c0SPascal Abresch }
161409d65c0SPascal Abresch 
162409d65c0SPascal Abresch 
163fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook6() {}
164fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook7() {}
165fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook8() {}
166fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook9() {}
167fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook10() {}
168fd25b902SAugustin Cavalier 
169fd25b902SAugustin Cavalier 
170629397f2SFrançois Revol // Initialized in InterfaceDefs.cpp
1712f86ba45SStephan Aßmus BControlLook* be_control_look = NULL;
1722f86ba45SStephan Aßmus 
1732f86ba45SStephan Aßmus } // namespace BPrivate
174