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