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
BControlLook()15db68ff23SAugustin Cavalier BControlLook::BControlLook()
16db68ff23SAugustin Cavalier :
17d63b75faSPhilippe Saint-Pierre fCachedWorkspace(-1)
182f86ba45SStephan Aßmus {
192f86ba45SStephan Aßmus }
202f86ba45SStephan Aßmus
212f86ba45SStephan Aßmus
~BControlLook()222f86ba45SStephan Aßmus BControlLook::~BControlLook()
232f86ba45SStephan Aßmus {
242f86ba45SStephan Aßmus }
252f86ba45SStephan Aßmus
262f86ba45SStephan Aßmus
2782ab3167SAlex Wilson float
ComposeSpacing(float spacing)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:
41c1353b74SAugustin 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
ComposeIconSize(int32 size)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
65*e6a598a2SMáximo Castañeda bool
ShouldDraw(BView * view,const BRect & rect,const BRect & updateRect)66*e6a598a2SMáximo Castañeda BControlLook::ShouldDraw(BView* view, const BRect& rect, const BRect& updateRect)
67*e6a598a2SMáximo Castañeda {
68*e6a598a2SMáximo Castañeda if (!rect.IsValid())
69*e6a598a2SMáximo Castañeda return false;
70*e6a598a2SMáximo Castañeda
71*e6a598a2SMáximo Castañeda BPoint points[4];
72*e6a598a2SMáximo Castañeda points[0] = rect.LeftTop();
73*e6a598a2SMáximo Castañeda points[1] = rect.RightBottom();
74*e6a598a2SMáximo Castañeda points[2] = rect.LeftBottom();
75*e6a598a2SMáximo Castañeda points[3] = rect.RightTop();
76*e6a598a2SMáximo Castañeda
77*e6a598a2SMáximo Castañeda view->TransformTo(B_VIEW_COORDINATES).Apply(points, 4);
78*e6a598a2SMáximo Castañeda
79*e6a598a2SMáximo Castañeda BRect dest;
80*e6a598a2SMáximo Castañeda dest.left = dest.right = points[0].x;
81*e6a598a2SMáximo Castañeda dest.top = dest.bottom = points[0].y;
82*e6a598a2SMáximo Castañeda for (int i = 1; i < 4; i++) {
83*e6a598a2SMáximo Castañeda dest.left = std::min(dest.left, points[i].x);
84*e6a598a2SMáximo Castañeda dest.right = std::max(dest.right, points[i].x);
85*e6a598a2SMáximo Castañeda dest.top = std::min(dest.top, points[i].y);
86*e6a598a2SMáximo Castañeda dest.bottom = std::max(dest.bottom, points[i].y);
87*e6a598a2SMáximo Castañeda }
88*e6a598a2SMáximo Castañeda dest.left = floorf(dest.left);
89*e6a598a2SMáximo Castañeda dest.right = ceilf(dest.right);
90*e6a598a2SMáximo Castañeda dest.top = floorf(dest.top);
91*e6a598a2SMáximo Castañeda dest.bottom = ceilf(dest.bottom);
92*e6a598a2SMáximo Castañeda
93*e6a598a2SMáximo Castañeda return dest.Intersects(updateRect);
94*e6a598a2SMáximo Castañeda }
95*e6a598a2SMáximo Castañeda
96*e6a598a2SMáximo Castañeda
97d63b75faSPhilippe Saint-Pierre void
DrawLabel(BView * view,const char * label,const BBitmap * icon,BRect rect,const BRect & updateRect,const rgb_color & base,uint32 flags,const rgb_color * textColor)981b848ee7SIngo Weinhold BControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon,
997a96554cSlooncraz BRect rect, const BRect& updateRect, const rgb_color& base, uint32 flags,
1007a96554cSlooncraz const rgb_color* textColor)
1011b848ee7SIngo Weinhold {
1021b848ee7SIngo Weinhold DrawLabel(view, label, icon, rect, updateRect, base, flags,
1037a96554cSlooncraz DefaultLabelAlignment(), textColor);
1041b848ee7SIngo Weinhold }
1051b848ee7SIngo Weinhold
1061b848ee7SIngo Weinhold
1071b848ee7SIngo Weinhold void
GetInsets(frame_type frameType,background_type backgroundType,uint32 flags,float & _left,float & _top,float & _right,float & _bottom)1088719e0dcSIngo Weinhold BControlLook::GetInsets(frame_type frameType, background_type backgroundType,
1098719e0dcSIngo Weinhold uint32 flags, float& _left, float& _top, float& _right, float& _bottom)
1108719e0dcSIngo Weinhold {
1118719e0dcSIngo Weinhold GetFrameInsets(frameType, flags, _left, _top, _right, _bottom);
1128719e0dcSIngo Weinhold
1138719e0dcSIngo Weinhold float left, top, right, bottom;
1148719e0dcSIngo Weinhold GetBackgroundInsets(backgroundType, flags, left, top, right, bottom);
1158719e0dcSIngo Weinhold
1168719e0dcSIngo Weinhold _left += left;
1178719e0dcSIngo Weinhold _top += top;
1188719e0dcSIngo Weinhold _right += right;
1198719e0dcSIngo Weinhold _bottom += bottom;
1208719e0dcSIngo Weinhold }
1218719e0dcSIngo Weinhold
1228719e0dcSIngo Weinhold
123409d65c0SPascal Abresch float
GetScrollBarWidth(orientation orientation)124409d65c0SPascal Abresch BControlLook::GetScrollBarWidth(orientation orientation)
125409d65c0SPascal Abresch {
1268672fc27SAugustin Cavalier return ComposeSpacing(B_USE_CORNER_SPACING);
127409d65c0SPascal Abresch }
128409d65c0SPascal Abresch
129409d65c0SPascal Abresch
1308719e0dcSIngo Weinhold void
SetBackgroundInfo(const BMessage & backgroundInfo)131d452ff66SAxel Dörfler BControlLook::SetBackgroundInfo(const BMessage& backgroundInfo)
132d63b75faSPhilippe Saint-Pierre {
133d452ff66SAxel Dörfler fBackgroundInfo = backgroundInfo;
134d63b75faSPhilippe Saint-Pierre fCachedWorkspace = -1;
135d63b75faSPhilippe Saint-Pierre }
136d63b75faSPhilippe Saint-Pierre
137d63b75faSPhilippe Saint-Pierre
138fb3493dfSJohn Scipione extern "C" void
B_IF_GCC_2(_ReservedControlLook1__Q28BPrivate12BControlLook,_ZN8BPrivate12BControlLook21_ReservedControlLook1Ev)139fb3493dfSJohn Scipione B_IF_GCC_2(_ReservedControlLook1__Q28BPrivate12BControlLook,
140fb3493dfSJohn Scipione _ZN8BPrivate12BControlLook21_ReservedControlLook1Ev)(
141fb3493dfSJohn Scipione BControlLook* controlLook, BView* view, BRect& rect,
142fb3493dfSJohn Scipione const BRect& updateRect, const rgb_color& base, uint32 flags,
143fb3493dfSJohn Scipione uint32 borders, border_style borderStyle, uint32 side)
144fb3493dfSJohn Scipione {
145fb3493dfSJohn Scipione controlLook->DrawTabFrame(view, rect, updateRect, base, flags, borders,
146fb3493dfSJohn Scipione borderStyle, side);
147fb3493dfSJohn Scipione }
148fb3493dfSJohn Scipione
149fb3493dfSJohn Scipione
1501482b250SJohn Scipione extern "C" void
B_IF_GCC_2(_ReservedControlLook2__Q28BPrivate12BControlLook,_ZN8BPrivate12BControlLook21_ReservedControlLook2Ev)1511482b250SJohn Scipione B_IF_GCC_2(_ReservedControlLook2__Q28BPrivate12BControlLook,
1521482b250SJohn Scipione _ZN8BPrivate12BControlLook21_ReservedControlLook2Ev)(
1531482b250SJohn Scipione BControlLook* controlLook, BView* view, BRect rect,
1541482b250SJohn Scipione const BRect& updateRect, const rgb_color& base, uint32 flags,
1551482b250SJohn Scipione int32 direction, orientation orientation, bool down)
1561482b250SJohn Scipione {
1571482b250SJohn Scipione controlLook->DrawScrollBarButton(view, rect, updateRect, base, flags,
1581482b250SJohn Scipione direction, orientation, down);
1591482b250SJohn Scipione }
1601482b250SJohn Scipione
1611482b250SJohn Scipione
1621482b250SJohn Scipione extern "C" void
B_IF_GCC_2(_ReservedControlLook3__Q28BPrivate12BControlLook,_ZN8BPrivate12BControlLook21_ReservedControlLook3Ev)1631482b250SJohn Scipione B_IF_GCC_2(_ReservedControlLook3__Q28BPrivate12BControlLook,
1641482b250SJohn Scipione _ZN8BPrivate12BControlLook21_ReservedControlLook3Ev)(
1651482b250SJohn Scipione BControlLook* controlLook, BView* view, BRect rect,
1661482b250SJohn Scipione const BRect& updateRect, const rgb_color& base, uint32 flags,
1671482b250SJohn Scipione int32 direction, orientation orientation, uint32 knobStyle)
1681482b250SJohn Scipione {
1691482b250SJohn Scipione controlLook->DrawScrollBarThumb(view, rect, updateRect, base, flags,
1701482b250SJohn Scipione orientation, knobStyle);
1711482b250SJohn Scipione }
1721482b250SJohn Scipione
1731482b250SJohn Scipione
1741482b250SJohn Scipione extern "C" void
B_IF_GCC_2(_ReservedControlLook4__Q28BPrivate12BControlLook,_ZN8BPrivate12BControlLook21_ReservedControlLook4Ev)1751482b250SJohn Scipione B_IF_GCC_2(_ReservedControlLook4__Q28BPrivate12BControlLook,
1761482b250SJohn Scipione _ZN8BPrivate12BControlLook21_ReservedControlLook4Ev)(
1771482b250SJohn Scipione BControlLook* controlLook, BView* view, BRect rect,
1781482b250SJohn Scipione const BRect& updateRect, const rgb_color& base, uint32 flags,
1791482b250SJohn Scipione orientation orientation)
1801482b250SJohn Scipione {
1811482b250SJohn Scipione controlLook->DrawScrollBarBorder(view, rect, updateRect, base, flags,
1821482b250SJohn Scipione orientation);
1831482b250SJohn Scipione }
1841482b250SJohn Scipione
1851482b250SJohn Scipione
186409d65c0SPascal Abresch extern "C" float
B_IF_GCC_2(_ReservedControlLook5__Q28BPrivate12BControlLook,_ZN8BPrivate12BControlLook21_ReservedControlLook5Ev)187409d65c0SPascal Abresch B_IF_GCC_2(_ReservedControlLook5__Q28BPrivate12BControlLook,
188409d65c0SPascal Abresch _ZN8BPrivate12BControlLook21_ReservedControlLook5Ev)(
189409d65c0SPascal Abresch BControlLook* controlLook, orientation orientation)
190409d65c0SPascal Abresch {
191409d65c0SPascal Abresch return controlLook->GetScrollBarWidth(orientation);
192409d65c0SPascal Abresch }
193409d65c0SPascal Abresch
194409d65c0SPascal Abresch
_ReservedControlLook6()195fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook6() {}
_ReservedControlLook7()196fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook7() {}
_ReservedControlLook8()197fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook8() {}
_ReservedControlLook9()198fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook9() {}
_ReservedControlLook10()199fd25b902SAugustin Cavalier void BControlLook::_ReservedControlLook10() {}
200fd25b902SAugustin Cavalier
201fd25b902SAugustin Cavalier
202629397f2SFrançois Revol // Initialized in InterfaceDefs.cpp
2032f86ba45SStephan Aßmus BControlLook* be_control_look = NULL;
2042f86ba45SStephan Aßmus
2052f86ba45SStephan Aßmus } // namespace BPrivate
206