1 /* 2 * Copyright 2009-2012, 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 9 #include <Alignment.h> 10 #include <Font.h> 11 #include <Rect.h> 12 #include <Slider.h> 13 14 15 class BControl; 16 class BGradientLinear; 17 class BView; 18 19 20 // WARNING! This is experimental API and may change! Be prepared to 21 // recompile your software in a next version of haiku. 22 23 24 namespace BPrivate { 25 26 27 class BControlLook { 28 public: 29 BControlLook(); 30 virtual ~BControlLook(); 31 32 // TODO: Probably more convenient to pull these enums into global 33 // namespace and rename them to e.g. "B_CONTROL_LOOK_FOCUSED" instead of 34 // "BControlLook::B_FOCUSED". 35 36 enum frame_type { 37 B_BUTTON_FRAME, 38 B_MENU_FRAME, 39 B_LISTVIEW_FRAME, 40 B_INPUT_FRAME 41 }; 42 43 enum background_type { 44 B_BUTTON_BACKGROUND, 45 B_MENU_BACKGROUND, 46 B_LISTVIEW_BACKGROUND, 47 B_INPUT_BACKGROUND 48 }; 49 50 enum { 51 B_LEFT_BORDER = 1 << 0, 52 B_RIGHT_BORDER = 1 << 1, 53 B_TOP_BORDER = 1 << 2, 54 B_BOTTOM_BORDER = 1 << 3, 55 56 B_ALL_BORDERS = B_LEFT_BORDER | B_RIGHT_BORDER 57 | B_TOP_BORDER | B_BOTTOM_BORDER 58 }; 59 60 enum { 61 B_LEFT_ARROW = 0, 62 B_RIGHT_ARROW = 1, 63 B_UP_ARROW = 2, 64 B_DOWN_ARROW = 3, 65 B_LEFT_UP_ARROW = 4, 66 B_RIGHT_UP_ARROW = 5, 67 B_RIGHT_DOWN_ARROW = 6, 68 B_LEFT_DOWN_ARROW = 7 69 }; 70 71 enum { 72 B_FOCUSED = 1 << 0, 73 B_CLICKED = 1 << 1, // some controls activate on mouse up 74 B_ACTIVATED = 1 << 2, 75 B_HOVER = 1 << 3, 76 B_DISABLED = 1 << 4, 77 B_DEFAULT_BUTTON = 1 << 5, 78 B_IGNORE_OUTLINE = 1 << 6, 79 80 B_BLEND_FRAME = 1 << 16 81 }; 82 83 virtual BAlignment DefaultLabelAlignment() const; 84 virtual float DefaultLabelSpacing() const; 85 86 // TODO: Make methods virtual before R1 release 87 /*virtual*/ float DefaultItemSpacing() const; 88 89 static float ComposeSpacing(float spacing); 90 91 /*virtual*/ uint32 Flags(BControl* control) const; 92 93 virtual void DrawButtonFrame(BView* view, BRect& rect, 94 const BRect& updateRect, 95 const rgb_color& base, 96 const rgb_color& background, 97 uint32 flags = 0, 98 uint32 borders = B_ALL_BORDERS); 99 /*virtual*/ void DrawButtonFrame(BView* view, BRect& rect, 100 const BRect& updateRect, 101 float radius, 102 const rgb_color& base, 103 const rgb_color& background, 104 uint32 flags = 0, 105 uint32 borders = B_ALL_BORDERS); 106 /*virtual*/ void DrawButtonFrame(BView* view, BRect& rect, 107 const BRect& updateRect, 108 float leftTopRadius, 109 float rightTopRadius, 110 float leftBottomRadius, 111 float rightBottomRadius, 112 const rgb_color& base, 113 const rgb_color& background, 114 uint32 flags = 0, 115 uint32 borders = B_ALL_BORDERS); 116 117 virtual void DrawButtonBackground(BView* view, BRect& rect, 118 const BRect& updateRect, 119 const rgb_color& base, 120 uint32 flags = 0, 121 uint32 borders = B_ALL_BORDERS, 122 orientation orientation = B_HORIZONTAL); 123 /*virtual*/ void DrawButtonBackground(BView* view, BRect& rect, 124 const BRect& updateRect, 125 float radius, 126 const rgb_color& base, 127 uint32 flags = 0, 128 uint32 borders = B_ALL_BORDERS, 129 orientation orientation = B_HORIZONTAL); 130 /*virtual*/ void DrawButtonBackground(BView* view, BRect& rect, 131 const BRect& updateRect, 132 float leftTopRadius, 133 float rightTopRadius, 134 float leftBottomRadius, 135 float rightBottomRadius, 136 const rgb_color& base, 137 uint32 flags = 0, 138 uint32 borders = B_ALL_BORDERS, 139 orientation orientation = B_HORIZONTAL); 140 141 virtual void DrawMenuBarBackground(BView* view, BRect& rect, 142 const BRect& updateRect, 143 const rgb_color& base, 144 uint32 flags = 0, 145 uint32 borders = B_ALL_BORDERS); 146 147 virtual void DrawMenuFieldFrame(BView* view, BRect& rect, 148 const BRect& updateRect, 149 const rgb_color& base, 150 const rgb_color& background, 151 uint32 flags = 0, 152 uint32 borders = B_ALL_BORDERS); 153 /*virtual*/ void DrawMenuFieldFrame(BView* view, BRect& rect, 154 const BRect& updateRect, 155 float radius, 156 const rgb_color& base, 157 const rgb_color& background, 158 uint32 flags = 0, 159 uint32 borders = B_ALL_BORDERS); 160 /*virtual*/ void DrawMenuFieldFrame(BView* view, BRect& rect, 161 const BRect& updateRect, 162 float leftTopRadius, 163 float rightTopRadius, 164 float leftBottomRadius, 165 float rightBottomRadius, 166 const rgb_color& base, 167 const rgb_color& background, 168 uint32 flags = 0, 169 uint32 borders = B_ALL_BORDERS); 170 171 virtual void DrawMenuFieldBackground(BView* view, 172 BRect& rect, const BRect& updateRect, 173 const rgb_color& base, bool popupIndicator, 174 uint32 flags = 0); 175 /*virtual*/ void DrawMenuFieldBackground(BView* view, 176 BRect& rect, const BRect& updateRect, 177 float radius, const rgb_color& base, 178 bool popupIndicator, uint32 flags = 0); 179 /*virtual*/ void DrawMenuFieldBackground(BView* view, 180 BRect& rect, const BRect& updateRect, 181 float leftTopRadius, 182 float rightTopRadius, 183 float leftBottomRadius, 184 float rightBottomRadius, 185 const rgb_color& base, 186 bool popupIndicator, uint32 flags = 0); 187 virtual void DrawMenuFieldBackground(BView* view, 188 BRect& rect, const BRect& updateRect, 189 const rgb_color& base, uint32 flags = 0, 190 uint32 borders = B_ALL_BORDERS); 191 192 virtual void DrawMenuBackground(BView* view, 193 BRect& rect, const BRect& updateRect, 194 const rgb_color& base, uint32 flags = 0, 195 uint32 borders = B_ALL_BORDERS); 196 197 virtual void DrawMenuItemBackground(BView* view, 198 BRect& rect, const BRect& updateRect, 199 const rgb_color& base, uint32 flags = 0, 200 uint32 borders = B_ALL_BORDERS); 201 202 virtual void DrawStatusBar(BView* view, BRect& rect, 203 const BRect& updateRect, 204 const rgb_color& base, 205 const rgb_color& barColor, 206 float progressPosition); 207 208 virtual void DrawCheckBox(BView* view, BRect& rect, 209 const BRect& updateRect, 210 const rgb_color& base, 211 uint32 flags = 0); 212 213 virtual void DrawRadioButton(BView* view, BRect& rect, 214 const BRect& updateRect, 215 const rgb_color& base, 216 uint32 flags = 0); 217 218 virtual void DrawScrollBarBackground(BView* view, 219 BRect& rect1, BRect& rect2, 220 const BRect& updateRect, 221 const rgb_color& base, uint32 flags, 222 orientation orientation); 223 virtual void DrawScrollBarBackground(BView* view, 224 BRect& rect, const BRect& updateRect, 225 const rgb_color& base, uint32 flags, 226 orientation orientation); 227 228 /*virtual*/ void DrawScrollViewFrame(BView* view, 229 BRect& rect, const BRect& updateRect, 230 BRect verticalScrollBarFrame, 231 BRect horizontalScrollBarFrame, 232 const rgb_color& base, 233 border_style border, 234 uint32 flags = 0, 235 uint32 borders = B_ALL_BORDERS); 236 237 /*virtual*/ void DrawArrowShape(BView* view, 238 BRect& rect, const BRect& updateRect, 239 const rgb_color& base, uint32 direction, 240 uint32 flags = 0, 241 float tint = B_DARKEN_MAX_TINT); 242 243 virtual rgb_color SliderBarColor(const rgb_color& base); 244 245 virtual void DrawSliderBar(BView* view, BRect rect, 246 const BRect& updateRect, 247 const rgb_color& base, 248 rgb_color leftFillColor, 249 rgb_color rightFillColor, 250 float sliderScale, uint32 flags, 251 orientation orientation); 252 virtual void DrawSliderBar(BView* view, BRect rect, 253 const BRect& updateRect, 254 const rgb_color& base, rgb_color fillColor, 255 uint32 flags, orientation orientation); 256 257 virtual void DrawSliderThumb(BView* view, BRect& rect, 258 const BRect& updateRect, 259 const rgb_color& base, uint32 flags, 260 orientation orientation); 261 262 /*virtual*/ void DrawSliderTriangle(BView* view, BRect& rect, 263 const BRect& updateRect, 264 const rgb_color& base, uint32 flags, 265 orientation orientation); 266 virtual void DrawSliderTriangle(BView* view, BRect& rect, 267 const BRect& updateRect, 268 const rgb_color& base, 269 const rgb_color& fill, uint32 flags, 270 orientation orientation); 271 272 virtual void DrawSliderHashMarks(BView* view, BRect& rect, 273 const BRect& updateRect, 274 const rgb_color& base, int32 count, 275 hash_mark_location location, 276 uint32 flags, orientation orientation); 277 278 virtual void DrawActiveTab(BView* view, BRect& rect, 279 const BRect& updateRect, 280 const rgb_color& base, uint32 flags = 0, 281 uint32 borders = B_ALL_BORDERS); 282 283 virtual void DrawInactiveTab(BView* view, BRect& rect, 284 const BRect& updateRect, 285 const rgb_color& base, uint32 flags = 0, 286 uint32 borders = B_ALL_BORDERS); 287 288 /*virtual*/ void DrawSplitter(BView* view, BRect& rect, 289 const BRect& updateRect, 290 const rgb_color& base, 291 orientation orientation, 292 uint32 flags = 0, 293 uint32 borders = B_ALL_BORDERS); 294 295 // various borders 296 297 virtual void DrawBorder(BView* view, BRect& rect, 298 const BRect& updateRect, 299 const rgb_color& base, 300 border_style border, uint32 flags = 0, 301 uint32 borders = B_ALL_BORDERS); 302 303 virtual void DrawRaisedBorder(BView* view, BRect& rect, 304 const BRect& updateRect, 305 const rgb_color& base, uint32 flags = 0, 306 uint32 borders = B_ALL_BORDERS); 307 308 virtual void DrawGroupFrame(BView* view, BRect& rect, 309 const BRect& updateRect, 310 const rgb_color& base, 311 uint32 borders = B_ALL_BORDERS); 312 313 virtual void DrawTextControlBorder(BView* view, BRect& rect, 314 const BRect& updateRect, 315 const rgb_color& base, uint32 flags = 0, 316 uint32 borders = B_ALL_BORDERS); 317 318 // aligned labels 319 320 /*virtual*/ void DrawLabel(BView* view, const char* label, 321 BRect rect, const BRect& updateRect, 322 const rgb_color& base, uint32 flags); 323 virtual void DrawLabel(BView* view, const char* label, 324 BRect rect, const BRect& updateRect, 325 const rgb_color& base, uint32 flags, 326 const BAlignment& alignment); 327 // TODO: Would be nice to have a (non-virtual) version of this method 328 // which takes an array of labels and locations. That would save some 329 // setup with the view graphics state. 330 /*virtual*/ void DrawLabel(BView* view, const char* label, 331 const rgb_color& base, uint32 flags, 332 const BPoint& where); 333 334 void SetBackgroundInfo( 335 const BMessage& backgroundInfo); 336 337 protected: 338 void _DrawButtonFrame(BView* view, BRect& rect, 339 const BRect& updateRect, 340 float leftTopRadius, 341 float rightTopRadius, 342 float leftBottomRadius, 343 float rightBottomRadius, 344 const rgb_color& base, 345 const rgb_color& background, 346 float contrast, float brightness = 1.0, 347 uint32 flags = 0, 348 uint32 borders = B_ALL_BORDERS); 349 350 void _DrawOuterResessedFrame(BView* view, 351 BRect& rect, const rgb_color& base, 352 float contrast = 1.0f, 353 float brightness = 1.0f, 354 uint32 flags = 0, 355 uint32 borders = B_ALL_BORDERS); 356 357 void _DrawFrame(BView* view, BRect& rect, 358 const rgb_color& left, 359 const rgb_color& top, 360 const rgb_color& right, 361 const rgb_color& bottom, 362 uint32 borders = B_ALL_BORDERS); 363 void _DrawFrame(BView* view, BRect& rect, 364 const rgb_color& left, 365 const rgb_color& top, 366 const rgb_color& right, 367 const rgb_color& bottom, 368 const rgb_color& rightTop, 369 const rgb_color& leftBottom, 370 uint32 borders = B_ALL_BORDERS); 371 372 void _DrawButtonBackground(BView* view, BRect& rect, 373 const BRect& updateRect, 374 float leftTopRadius, 375 float rightTopRadius, 376 float leftBottomRadius, 377 float rightBottomRadius, 378 const rgb_color& base, 379 uint32 flags = 0, 380 uint32 borders = B_ALL_BORDERS, 381 orientation orientation = B_HORIZONTAL); 382 383 void _DrawMenuFieldBackgroundOutside(BView* view, 384 BRect& rect, const BRect& updateRect, 385 float leftTopRadius, 386 float rightTopRadius, 387 float leftBottomRadius, 388 float rightBottomRadius, 389 const rgb_color& base, 390 bool popupIndicator = false, 391 uint32 flags = 0); 392 393 void _DrawMenuFieldBackgroundInside(BView* view, 394 BRect& rect, const BRect& updateRect, 395 float leftTopRadius, 396 float rightTopRadius, 397 float leftBottomRadius, 398 float rightBottomRadius, 399 const rgb_color& base, uint32 flags = 0, 400 uint32 borders = B_ALL_BORDERS); 401 402 // Rounded corner methods 403 void _DrawRoundCornerLeftTop(BView* view, 404 BRect& cornerRect, const BRect& updateRect, 405 const rgb_color& background, 406 const rgb_color& edgeColor, 407 const rgb_color& frameColor, 408 const rgb_color& bevelColor, 409 const BGradientLinear& fillGradient); 410 411 void _DrawRoundCornerFrameLeftTop(BView* view, 412 BRect& cornerRect, const BRect& updateRect, 413 const rgb_color& background, 414 const rgb_color& edgeColor, 415 const rgb_color& frameColor); 416 417 void _DrawRoundCornerBackgroundLeftTop(BView* view, 418 BRect& cornerRect, const BRect& updateRect, 419 const rgb_color& bevelColor, 420 const BGradientLinear& fillGradient); 421 422 void _DrawRoundCornerRightTop(BView* view, 423 BRect& cornerRect, const BRect& updateRect, 424 const rgb_color& background, 425 const rgb_color& edgeTopColor, 426 const rgb_color& edgeRightColor, 427 const rgb_color& frameTopColor, 428 const rgb_color& frameRightColor, 429 const rgb_color& bevelTopColor, 430 const rgb_color& bevelRightColor, 431 const BGradientLinear& fillGradient); 432 433 void _DrawRoundCornerFrameRightTop(BView* view, 434 BRect& cornerRect, const BRect& updateRect, 435 const rgb_color& background, 436 const rgb_color& edgeTopColor, 437 const rgb_color& edgeRightColor, 438 const rgb_color& frameTopColor, 439 const rgb_color& frameRightColor); 440 441 void _DrawRoundCornerBackgroundRightTop(BView* view, 442 BRect& cornerRect, const BRect& updateRect, 443 const rgb_color& bevelTopColor, 444 const rgb_color& bevelRightColor, 445 const BGradientLinear& fillGradient); 446 447 void _DrawRoundCornerLeftBottom(BView* view, 448 BRect& cornerRect, const BRect& updateRect, 449 const rgb_color& background, 450 const rgb_color& edgeLeftColor, 451 const rgb_color& edgeBottomColor, 452 const rgb_color& frameLeftColor, 453 const rgb_color& frameBottomColor, 454 const rgb_color& bevelLeftColor, 455 const rgb_color& bevelBottomColor, 456 const BGradientLinear& fillGradient); 457 458 void _DrawRoundCornerFrameLeftBottom(BView* view, 459 BRect& cornerRect, const BRect& updateRect, 460 const rgb_color& background, 461 const rgb_color& edgeLeftColor, 462 const rgb_color& edgeBottomColor, 463 const rgb_color& frameLeftColor, 464 const rgb_color& frameBottomColor); 465 466 void _DrawRoundCornerBackgroundLeftBottom(BView* view, 467 BRect& cornerRect, const BRect& updateRect, 468 const rgb_color& bevelLeftColor, 469 const rgb_color& bevelBottomColor, 470 const BGradientLinear& fillGradient); 471 472 void _DrawRoundCornerRightBottom(BView* view, 473 BRect& cornerRect, const BRect& updateRect, 474 const rgb_color& background, 475 const rgb_color& edgeColor, 476 const rgb_color& frameColor, 477 const rgb_color& bevelColor, 478 const BGradientLinear& fillGradient); 479 480 void _DrawRoundCornerFrameRightBottom(BView* view, 481 BRect& cornerRect, const BRect& updateRect, 482 const rgb_color& background, 483 const rgb_color& edgeColor, 484 const rgb_color& frameColor); 485 486 void _DrawRoundCornerBackgroundRightBottom( 487 BView* view, 488 BRect& cornerRect, const BRect& updateRect, 489 const rgb_color& bevelColor, 490 const BGradientLinear& fillGradient); 491 492 void _DrawRoundBarCorner(BView* view, BRect& rect, 493 const BRect& updateRect, 494 const rgb_color& edgeLightColor, 495 const rgb_color& edgeShadowColor, 496 const rgb_color& frameLightColor, 497 const rgb_color& frameShadowColor, 498 const rgb_color& fillLightColor, 499 const rgb_color& fillShadowColor, 500 float leftInset, float topInset, 501 float rightInset, float bottomInset, 502 orientation orientation); 503 504 // Border color methods 505 rgb_color _EdgeLightColor(const rgb_color& base, 506 float contrast, float brightness, 507 uint32 flags); 508 509 rgb_color _EdgeShadowColor(const rgb_color& base, 510 float contrast, float brightness, 511 uint32 flags); 512 513 rgb_color _FrameLightColor(const rgb_color& base, 514 uint32 flags); 515 516 rgb_color _FrameShadowColor(const rgb_color& base, 517 uint32 flags); 518 519 rgb_color _BevelLightColor(const rgb_color& base, 520 uint32 flags); 521 522 rgb_color _BevelShadowColor(const rgb_color& base, 523 uint32 flags); 524 525 // Background gradient methods 526 void _FillGradient(BView* view, const BRect& rect, 527 const rgb_color& base, float topTint, 528 float bottomTint, 529 orientation orientation = B_HORIZONTAL); 530 531 void _FillGlossyGradient(BView* view, 532 const BRect& rect, const rgb_color& base, 533 float topTint, float middle1Tint, 534 float middle2Tint, float bottomTint, 535 orientation orientation = B_HORIZONTAL); 536 537 void _MakeGradient(BGradientLinear& gradient, 538 const BRect& rect, const rgb_color& base, 539 float topTint, float bottomTint, 540 orientation orientation = B_HORIZONTAL) const; 541 542 void _MakeGlossyGradient(BGradientLinear& gradient, 543 const BRect& rect, const rgb_color& base, 544 float topTint, float middle1Tint, 545 float middle2Tint, float bottomTint, 546 orientation orientation = B_HORIZONTAL) const; 547 548 void _MakeButtonGradient(BGradientLinear& gradient, 549 BRect& rect, const rgb_color& base, 550 uint32 flags, orientation orientation = B_HORIZONTAL) const; 551 552 bool _RadioButtonAndCheckBoxMarkColor( 553 const rgb_color& base, rgb_color& color, 554 uint32 flags) const; 555 556 private: 557 bool fCachedOutline; 558 int32 fCachedWorkspace; 559 BMessage fBackgroundInfo; 560 561 uint32 _reserved[20]; 562 }; 563 564 extern BControlLook* be_control_look; 565 566 567 } // namespace BPrivate 568 569 using BPrivate::BControlLook; 570 using BPrivate::be_control_look; 571 572 573 #endif // _CONTROL_LOOK_H 574