1 /* 2 * Copyright 2012-2020 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include <ControlLook.h> 7 8 #include <algorithm> 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_CORNER_SPACING: 41 return ceilf(be_control_look->DefaultItemSpacing() * 1.272f); 42 case B_USE_BIG_SPACING: 43 return ceilf(be_control_look->DefaultItemSpacing() * 1.8f); 44 45 case B_USE_BORDER_SPACING: 46 return std::max(1.0f, floorf(be_control_look->DefaultItemSpacing() / 11.0f)); 47 } 48 49 return spacing; 50 } 51 52 53 BSize 54 BControlLook::ComposeIconSize(int32 size) 55 { 56 float scale = be_plain_font->Size() / 12.0f; 57 if (scale < 1.0f) 58 scale = 1.0f; 59 60 const int32 scaled = (int32)(size * scale); 61 return BSize(scaled - 1, scaled - 1); 62 } 63 64 65 void 66 BControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon, 67 BRect rect, const BRect& updateRect, const rgb_color& base, uint32 flags, 68 const rgb_color* textColor) 69 { 70 DrawLabel(view, label, icon, rect, updateRect, base, flags, 71 DefaultLabelAlignment(), textColor); 72 } 73 74 75 void 76 BControlLook::GetInsets(frame_type frameType, background_type backgroundType, 77 uint32 flags, float& _left, float& _top, float& _right, float& _bottom) 78 { 79 GetFrameInsets(frameType, flags, _left, _top, _right, _bottom); 80 81 float left, top, right, bottom; 82 GetBackgroundInsets(backgroundType, flags, left, top, right, bottom); 83 84 _left += left; 85 _top += top; 86 _right += right; 87 _bottom += bottom; 88 } 89 90 91 float 92 BControlLook::GetScrollBarWidth(orientation orientation) 93 { 94 return ComposeSpacing(B_USE_CORNER_SPACING); 95 } 96 97 98 void 99 BControlLook::SetBackgroundInfo(const BMessage& backgroundInfo) 100 { 101 fBackgroundInfo = backgroundInfo; 102 fCachedWorkspace = -1; 103 } 104 105 106 extern "C" void 107 B_IF_GCC_2(_ReservedControlLook1__Q28BPrivate12BControlLook, 108 _ZN8BPrivate12BControlLook21_ReservedControlLook1Ev)( 109 BControlLook* controlLook, BView* view, BRect& rect, 110 const BRect& updateRect, const rgb_color& base, uint32 flags, 111 uint32 borders, border_style borderStyle, uint32 side) 112 { 113 controlLook->DrawTabFrame(view, rect, updateRect, base, flags, borders, 114 borderStyle, side); 115 } 116 117 118 extern "C" void 119 B_IF_GCC_2(_ReservedControlLook2__Q28BPrivate12BControlLook, 120 _ZN8BPrivate12BControlLook21_ReservedControlLook2Ev)( 121 BControlLook* controlLook, BView* view, BRect rect, 122 const BRect& updateRect, const rgb_color& base, uint32 flags, 123 int32 direction, orientation orientation, bool down) 124 { 125 controlLook->DrawScrollBarButton(view, rect, updateRect, base, flags, 126 direction, orientation, down); 127 } 128 129 130 extern "C" void 131 B_IF_GCC_2(_ReservedControlLook3__Q28BPrivate12BControlLook, 132 _ZN8BPrivate12BControlLook21_ReservedControlLook3Ev)( 133 BControlLook* controlLook, BView* view, BRect rect, 134 const BRect& updateRect, const rgb_color& base, uint32 flags, 135 int32 direction, orientation orientation, uint32 knobStyle) 136 { 137 controlLook->DrawScrollBarThumb(view, rect, updateRect, base, flags, 138 orientation, knobStyle); 139 } 140 141 142 extern "C" void 143 B_IF_GCC_2(_ReservedControlLook4__Q28BPrivate12BControlLook, 144 _ZN8BPrivate12BControlLook21_ReservedControlLook4Ev)( 145 BControlLook* controlLook, BView* view, BRect rect, 146 const BRect& updateRect, const rgb_color& base, uint32 flags, 147 orientation orientation) 148 { 149 controlLook->DrawScrollBarBorder(view, rect, updateRect, base, flags, 150 orientation); 151 } 152 153 154 extern "C" float 155 B_IF_GCC_2(_ReservedControlLook5__Q28BPrivate12BControlLook, 156 _ZN8BPrivate12BControlLook21_ReservedControlLook5Ev)( 157 BControlLook* controlLook, orientation orientation) 158 { 159 return controlLook->GetScrollBarWidth(orientation); 160 } 161 162 163 void BControlLook::_ReservedControlLook6() {} 164 void BControlLook::_ReservedControlLook7() {} 165 void BControlLook::_ReservedControlLook8() {} 166 void BControlLook::_ReservedControlLook9() {} 167 void BControlLook::_ReservedControlLook10() {} 168 169 170 // Initialized in InterfaceDefs.cpp 171 BControlLook* be_control_look = NULL; 172 173 } // namespace BPrivate 174