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