1 /* 2 * Copyright 2009, 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 #include <Alignment.h> 9 #include <Font.h> 10 #include <Rect.h> 11 #include <Slider.h> 12 13 14 class BControl; 15 class BGradientLinear; 16 class BView; 17 18 19 // WARNING! This is experimental API and may change! Be prepared to 20 // recompile your software in a next version of haiku. 21 22 23 namespace BPrivate { 24 25 26 class BControlLook { 27 public: 28 BControlLook(); 29 virtual ~BControlLook(); 30 31 // TODO: Probably more convenient to pull these enums into global 32 // namespace and rename them to e.g. "B_CONTROL_LOOK_FOCUSED" instead of 33 // "BControlLook::B_FOCUSED". 34 35 enum frame_type { 36 B_BUTTON_FRAME, 37 B_MENU_FRAME, 38 B_LISTVIEW_FRAME, 39 B_INPUT_FRAME 40 }; 41 42 enum background_type { 43 B_BUTTON_BACKGROUND, 44 B_MENU_BACKGROUND, 45 B_LISTVIEW_BACKGROUND, 46 B_INPUT_BACKGROUND 47 }; 48 49 enum { 50 B_LEFT_BORDER = 1 << 0, 51 B_RIGHT_BORDER = 1 << 1, 52 B_TOP_BORDER = 1 << 2, 53 B_BOTTOM_BORDER = 1 << 3, 54 55 B_ALL_BORDERS = B_LEFT_BORDER | B_RIGHT_BORDER 56 | B_TOP_BORDER | B_BOTTOM_BORDER 57 }; 58 59 enum { 60 B_LEFT_ARROW = 0, 61 B_RIGHT_ARROW = 1, 62 B_UP_ARROW = 2, 63 B_DOWN_ARROW = 3 64 }; 65 66 enum { 67 B_FOCUSED = 1 << 0, 68 B_CLICKED = 1 << 1, // some controls activate on mouse up 69 B_ACTIVATED = 1 << 2, 70 B_HOVER = 1 << 3, 71 B_DISABLED = 1 << 4, 72 B_DEFAULT_BUTTON = 1 << 5, 73 74 B_BLEND_FRAME = 1 << 16 75 }; 76 77 virtual BAlignment DefaultLabelAlignment() const; 78 virtual float DefaultLabelSpacing() const; 79 80 /* TODO: virtual*/ 81 float DefaultItemSpacing() const; 82 83 static float ComposeSpacing(float spacing); 84 85 uint32 Flags(BControl* control) const; 86 87 virtual void DrawButtonFrame(BView* view, BRect& rect, 88 const BRect& updateRect, 89 const rgb_color& base, 90 const rgb_color& background, 91 uint32 flags = 0, 92 uint32 borders = B_ALL_BORDERS); 93 94 virtual void DrawButtonBackground(BView* view, BRect& rect, 95 const BRect& updateRect, 96 const rgb_color& base, 97 uint32 flags = 0, 98 uint32 borders = B_ALL_BORDERS, 99 enum orientation orientation 100 = B_HORIZONTAL); 101 102 virtual void DrawMenuBarBackground(BView* view, BRect& rect, 103 const BRect& updateRect, 104 const rgb_color& base, 105 uint32 flags = 0, 106 uint32 borders = B_ALL_BORDERS); 107 108 virtual void DrawMenuFieldFrame(BView* view, BRect& rect, 109 const BRect& updateRect, 110 const rgb_color& base, 111 const rgb_color& background, 112 uint32 flags = 0, 113 uint32 borders = B_ALL_BORDERS); 114 115 virtual void DrawMenuFieldBackground(BView* view, 116 BRect& rect, const BRect& updateRect, 117 const rgb_color& base, bool popupIndicator, 118 uint32 flags = 0); 119 120 virtual void DrawMenuFieldBackground(BView* view, 121 BRect& rect, const BRect& updateRect, 122 const rgb_color& base, uint32 flags = 0, 123 uint32 borders = B_ALL_BORDERS); 124 125 virtual void DrawMenuBackground(BView* view, 126 BRect& rect, const BRect& updateRect, 127 const rgb_color& base, uint32 flags = 0, 128 uint32 borders = B_ALL_BORDERS); 129 130 virtual void DrawMenuItemBackground(BView* view, 131 BRect& rect, const BRect& updateRect, 132 const rgb_color& base, uint32 flags = 0, 133 uint32 borders = B_ALL_BORDERS); 134 135 virtual void DrawStatusBar(BView* view, BRect& rect, 136 const BRect& updateRect, 137 const rgb_color& base, 138 const rgb_color& barColor, 139 float progressPosition); 140 141 virtual void DrawCheckBox(BView* view, BRect& rect, 142 const BRect& updateRect, 143 const rgb_color& base, 144 uint32 flags = 0); 145 146 virtual void DrawRadioButton(BView* view, BRect& rect, 147 const BRect& updateRect, 148 const rgb_color& base, 149 uint32 flags = 0); 150 151 virtual void DrawScrollBarBackground(BView* view, 152 BRect& rect1, BRect& rect2, 153 const BRect& updateRect, 154 const rgb_color& base, uint32 flags, 155 enum orientation orientation); 156 157 virtual void DrawScrollBarBackground(BView* view, 158 BRect& rect, const BRect& updateRect, 159 const rgb_color& base, uint32 flags, 160 enum orientation orientation); 161 162 // TODO: Make all these virtual before R1 release 163 void DrawScrollViewFrame(BView* view, 164 BRect& rect, const BRect& updateRect, 165 BRect verticalScrollBarFrame, 166 BRect horizontalScrollBarFrame, 167 const rgb_color& base, 168 border_style border, 169 uint32 flags = 0, 170 uint32 borders = B_ALL_BORDERS); 171 172 void DrawArrowShape(BView* view, 173 BRect& rect, const BRect& updateRect, 174 const rgb_color& base, uint32 direction, 175 uint32 flags = 0, 176 float tint = B_DARKEN_MAX_TINT); 177 178 virtual rgb_color SliderBarColor(const rgb_color& base); 179 180 virtual void DrawSliderBar(BView* view, BRect rect, 181 const BRect& updateRect, 182 const rgb_color& base, 183 rgb_color leftFillColor, 184 rgb_color rightFillColor, 185 float sliderScale, uint32 flags, 186 enum orientation orientation); 187 188 virtual void DrawSliderBar(BView* view, BRect rect, 189 const BRect& updateRect, 190 const rgb_color& base, rgb_color fillColor, 191 uint32 flags, enum orientation orientation); 192 193 virtual void DrawSliderThumb(BView* view, BRect& rect, 194 const BRect& updateRect, 195 const rgb_color& base, uint32 flags, 196 enum orientation orientation); 197 198 void DrawSliderTriangle(BView* view, BRect& rect, 199 const BRect& updateRect, 200 const rgb_color& base, uint32 flags, 201 enum orientation orientation); 202 203 virtual void DrawSliderTriangle(BView* view, BRect& rect, 204 const BRect& updateRect, 205 const rgb_color& base, 206 const rgb_color& fill, uint32 flags, 207 enum orientation orientation); 208 209 virtual void DrawSliderHashMarks(BView* view, BRect& rect, 210 const BRect& updateRect, 211 const rgb_color& base, int32 count, 212 hash_mark_location location, 213 uint32 flags, enum orientation orientation); 214 215 virtual void DrawActiveTab(BView* view, BRect& rect, 216 const BRect& updateRect, 217 const rgb_color& base, uint32 flags = 0, 218 uint32 borders = B_ALL_BORDERS); 219 220 virtual void DrawInactiveTab(BView* view, BRect& rect, 221 const BRect& updateRect, 222 const rgb_color& base, uint32 flags = 0, 223 uint32 borders = B_ALL_BORDERS); 224 225 /*virtual*/ void DrawSplitter(BView* view, BRect& rect, 226 const BRect& updateRect, 227 const rgb_color& base, 228 enum orientation orientation, 229 uint32 flags = 0, 230 uint32 borders = B_ALL_BORDERS); 231 232 // various borders 233 234 virtual void DrawBorder(BView* view, BRect& rect, 235 const BRect& updateRect, 236 const rgb_color& base, 237 border_style border, uint32 flags = 0, 238 uint32 borders = B_ALL_BORDERS); 239 240 virtual void DrawRaisedBorder(BView* view, BRect& rect, 241 const BRect& updateRect, 242 const rgb_color& base, uint32 flags = 0, 243 uint32 borders = B_ALL_BORDERS); 244 245 virtual void DrawGroupFrame(BView* view, BRect& rect, 246 const BRect& updateRect, 247 const rgb_color& base, 248 uint32 borders = B_ALL_BORDERS); 249 250 virtual void DrawTextControlBorder(BView* view, BRect& rect, 251 const BRect& updateRect, 252 const rgb_color& base, uint32 flags = 0, 253 uint32 borders = B_ALL_BORDERS); 254 255 // aligned labels 256 257 void DrawLabel(BView* view, const char* label, 258 BRect rect, const BRect& updateRect, 259 const rgb_color& base, uint32 flags); 260 261 virtual void DrawLabel(BView* view, const char* label, 262 BRect rect, const BRect& updateRect, 263 const rgb_color& base, uint32 flags, 264 const BAlignment& alignment); 265 266 // TODO: This should also be virtual 267 // TODO: Would be nice to have a (non-virtual) version of this method 268 // which takes an array of labels and locations. That would save some 269 // setup with the view graphics state. 270 void DrawLabel(BView* view, const char* label, 271 const rgb_color& base, uint32 flags, 272 const BPoint& where); 273 274 protected: 275 void _DrawButtonFrame(BView* view, BRect& rect, 276 const BRect& updateRect, 277 const rgb_color& base, 278 const rgb_color& background, 279 float contrast, float brightness = 1.0, 280 uint32 flags = 0, 281 uint32 borders = B_ALL_BORDERS); 282 283 void _DrawOuterResessedFrame(BView* view, 284 BRect& rect, const rgb_color& base, 285 float contrast = 1.0f, 286 float brightness = 1.0f, 287 uint32 flags = 0, 288 uint32 borders = B_ALL_BORDERS); 289 290 void _DrawFrame(BView* view, BRect& rect, 291 const rgb_color& left, 292 const rgb_color& top, 293 const rgb_color& right, 294 const rgb_color& bottom, 295 uint32 borders = B_ALL_BORDERS); 296 297 void _DrawFrame(BView* view, BRect& rect, 298 const rgb_color& left, 299 const rgb_color& top, 300 const rgb_color& right, 301 const rgb_color& bottom, 302 const rgb_color& rightTop, 303 const rgb_color& leftBottom, 304 uint32 borders = B_ALL_BORDERS); 305 306 void _FillGradient(BView* view, const BRect& rect, 307 const rgb_color& base, float topTint, 308 float bottomTint, 309 enum orientation orientation 310 = B_HORIZONTAL); 311 312 void _FillGlossyGradient(BView* view, 313 const BRect& rect, const rgb_color& base, 314 float topTint, float middle1Tint, 315 float middle2Tint, float bottomTint, 316 enum orientation orientation 317 = B_HORIZONTAL); 318 319 void _MakeGradient(BGradientLinear& gradient, 320 const BRect& rect, const rgb_color& base, 321 float topTint, float bottomTint, 322 enum orientation orientation 323 = B_HORIZONTAL) const; 324 325 void _MakeGlossyGradient(BGradientLinear& gradient, 326 const BRect& rect, const rgb_color& base, 327 float topTint, float middle1Tint, 328 float middle2Tint, float bottomTint, 329 enum orientation orientation 330 = B_HORIZONTAL) const; 331 332 bool _RadioButtonAndCheckBoxMarkColor( 333 const rgb_color& base, rgb_color& color, 334 uint32 flags) const; 335 336 void _DrawRoundBarCorner(BView* view, BRect& rect, 337 const BRect& updateRect, 338 const rgb_color& edgeLightColor, 339 const rgb_color& edgeShadowColor, 340 const rgb_color& frameLightColor, 341 const rgb_color& frameShadowColor, 342 const rgb_color& fillLightColor, 343 const rgb_color& fillShadowColor, 344 float leftInset, float topInset, 345 float rightInset, float bottomInset, 346 enum orientation orientation); 347 348 void _DrawRoundCornerLeftTop(BView* view, 349 BRect& rect, const BRect& updateRect, 350 const rgb_color& base, 351 const rgb_color& edgeColor, 352 const rgb_color& frameColor, 353 const rgb_color& bevelColor, 354 const BGradientLinear& fillGradient); 355 void _DrawRoundCornerRightTop(BView* view, 356 BRect& rect, const BRect& updateRect, 357 const rgb_color& base, 358 const rgb_color& edgeTopColor, 359 const rgb_color& edgeRightColor, 360 const rgb_color& frameTopColor, 361 const rgb_color& frameRightColor, 362 const rgb_color& bevelTopColor, 363 const rgb_color& bevelRightColor, 364 const BGradientLinear& fillGradient); 365 }; 366 367 extern BControlLook* be_control_look; 368 369 370 } // namespace BPrivate 371 372 using BPrivate::BControlLook; 373 using BPrivate::be_control_look; 374 375 #endif // _CONTROL_LOOK_H 376