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 }; 66 67 enum { 68 B_FOCUSED = 1 << 0, 69 B_CLICKED = 1 << 1, // some controls activate on mouse up 70 B_ACTIVATED = 1 << 2, 71 B_HOVER = 1 << 3, 72 B_DISABLED = 1 << 4, 73 B_DEFAULT_BUTTON = 1 << 5, 74 B_IGNORE_OUTLINE = 1 << 6, 75 76 B_BLEND_FRAME = 1 << 16 77 }; 78 79 virtual BAlignment DefaultLabelAlignment() const; 80 virtual float DefaultLabelSpacing() const; 81 82 // TODO: Make methods virtual before R1 release 83 /*virtual*/ float DefaultItemSpacing() const; 84 85 static float ComposeSpacing(float spacing); 86 87 /*virtual*/ uint32 Flags(BControl* control) const; 88 89 virtual void DrawButtonFrame(BView* view, BRect& rect, 90 const BRect& updateRect, 91 const rgb_color& base, 92 const rgb_color& background, 93 uint32 flags = 0, 94 uint32 borders = B_ALL_BORDERS); 95 /*virtual*/ void DrawButtonFrame(BView* view, BRect& rect, 96 const BRect& updateRect, 97 float radius, 98 const rgb_color& base, 99 const rgb_color& background, 100 uint32 flags = 0, 101 uint32 borders = B_ALL_BORDERS); 102 /*virtual*/ void DrawButtonFrame(BView* view, BRect& rect, 103 const BRect& updateRect, 104 float leftTopRadius, 105 float rightTopRadius, 106 float leftBottomRadius, 107 float rightBottomRadius, 108 const rgb_color& base, 109 const rgb_color& background, 110 uint32 flags = 0, 111 uint32 borders = B_ALL_BORDERS); 112 113 virtual void DrawButtonBackground(BView* view, BRect& rect, 114 const BRect& updateRect, 115 const rgb_color& base, 116 uint32 flags = 0, 117 uint32 borders = B_ALL_BORDERS, 118 enum orientation orientation 119 = B_HORIZONTAL); 120 /*virtual*/ void DrawButtonBackground(BView* view, BRect& rect, 121 const BRect& updateRect, 122 float radius, 123 const rgb_color& base, 124 uint32 flags = 0, 125 uint32 borders = B_ALL_BORDERS, 126 enum orientation orientation 127 = B_HORIZONTAL); 128 /*virtual*/ void DrawButtonBackground(BView* view, BRect& rect, 129 const BRect& updateRect, 130 float leftTopRadius, 131 float rightTopRadius, 132 float leftBottomRadius, 133 float rightBottomRadius, 134 const rgb_color& base, 135 uint32 flags = 0, 136 uint32 borders = B_ALL_BORDERS, 137 enum orientation orientation 138 = B_HORIZONTAL); 139 140 virtual void DrawMenuBarBackground(BView* view, BRect& rect, 141 const BRect& updateRect, 142 const rgb_color& base, 143 uint32 flags = 0, 144 uint32 borders = B_ALL_BORDERS); 145 146 virtual void DrawMenuFieldFrame(BView* view, BRect& rect, 147 const BRect& updateRect, 148 const rgb_color& base, 149 const rgb_color& background, 150 uint32 flags = 0, 151 uint32 borders = B_ALL_BORDERS); 152 /*virtual*/ void DrawMenuFieldFrame(BView* view, BRect& rect, 153 const BRect& updateRect, 154 float radius, 155 const rgb_color& base, 156 const rgb_color& background, 157 uint32 flags = 0, 158 uint32 borders = B_ALL_BORDERS); 159 /*virtual*/ void DrawMenuFieldFrame(BView* view, BRect& rect, 160 const BRect& updateRect, 161 float leftTopRadius, 162 float rightTopRadius, 163 float leftBottomRadius, 164 float rightBottomRadius, 165 const rgb_color& base, 166 const rgb_color& background, 167 uint32 flags = 0, 168 uint32 borders = B_ALL_BORDERS); 169 170 virtual void DrawMenuFieldBackground(BView* view, 171 BRect& rect, const BRect& updateRect, 172 const rgb_color& base, bool popupIndicator, 173 uint32 flags = 0); 174 /*virtual*/ void DrawMenuFieldBackground(BView* view, 175 BRect& rect, const BRect& updateRect, 176 float radius, const rgb_color& base, 177 bool popupIndicator, uint32 flags = 0); 178 /*virtual*/ void DrawMenuFieldBackground(BView* view, 179 BRect& rect, const BRect& updateRect, 180 float leftTopRadius, 181 float rightTopRadius, 182 float leftBottomRadius, 183 float rightBottomRadius, 184 const rgb_color& base, 185 bool popupIndicator, uint32 flags = 0); 186 virtual void DrawMenuFieldBackground(BView* view, 187 BRect& rect, const BRect& updateRect, 188 const rgb_color& base, uint32 flags = 0, 189 uint32 borders = B_ALL_BORDERS); 190 191 virtual void DrawMenuBackground(BView* view, 192 BRect& rect, const BRect& updateRect, 193 const rgb_color& base, uint32 flags = 0, 194 uint32 borders = B_ALL_BORDERS); 195 196 virtual void DrawMenuItemBackground(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 DrawStatusBar(BView* view, BRect& rect, 202 const BRect& updateRect, 203 const rgb_color& base, 204 const rgb_color& barColor, 205 float progressPosition); 206 207 virtual void DrawCheckBox(BView* view, BRect& rect, 208 const BRect& updateRect, 209 const rgb_color& base, 210 uint32 flags = 0); 211 212 virtual void DrawRadioButton(BView* view, BRect& rect, 213 const BRect& updateRect, 214 const rgb_color& base, 215 uint32 flags = 0); 216 217 virtual void DrawScrollBarBackground(BView* view, 218 BRect& rect1, BRect& rect2, 219 const BRect& updateRect, 220 const rgb_color& base, uint32 flags, 221 enum orientation orientation); 222 virtual void DrawScrollBarBackground(BView* view, 223 BRect& rect, const BRect& updateRect, 224 const rgb_color& base, uint32 flags, 225 enum orientation orientation); 226 227 /*virtual*/ void DrawScrollViewFrame(BView* view, 228 BRect& rect, const BRect& updateRect, 229 BRect verticalScrollBarFrame, 230 BRect horizontalScrollBarFrame, 231 const rgb_color& base, 232 border_style border, 233 uint32 flags = 0, 234 uint32 borders = B_ALL_BORDERS); 235 236 /*virtual*/ void DrawArrowShape(BView* view, 237 BRect& rect, const BRect& updateRect, 238 const rgb_color& base, uint32 direction, 239 uint32 flags = 0, 240 float tint = B_DARKEN_MAX_TINT); 241 242 virtual rgb_color SliderBarColor(const rgb_color& base); 243 244 virtual void DrawSliderBar(BView* view, BRect rect, 245 const BRect& updateRect, 246 const rgb_color& base, 247 rgb_color leftFillColor, 248 rgb_color rightFillColor, 249 float sliderScale, uint32 flags, 250 enum orientation orientation); 251 virtual void DrawSliderBar(BView* view, BRect rect, 252 const BRect& updateRect, 253 const rgb_color& base, rgb_color fillColor, 254 uint32 flags, enum orientation orientation); 255 256 virtual void DrawSliderThumb(BView* view, BRect& rect, 257 const BRect& updateRect, 258 const rgb_color& base, uint32 flags, 259 enum orientation orientation); 260 261 /*virtual*/ void DrawSliderTriangle(BView* view, BRect& rect, 262 const BRect& updateRect, 263 const rgb_color& base, uint32 flags, 264 enum orientation orientation); 265 virtual void DrawSliderTriangle(BView* view, BRect& rect, 266 const BRect& updateRect, 267 const rgb_color& base, 268 const rgb_color& fill, uint32 flags, 269 enum orientation orientation); 270 271 virtual void DrawSliderHashMarks(BView* view, BRect& rect, 272 const BRect& updateRect, 273 const rgb_color& base, int32 count, 274 hash_mark_location location, 275 uint32 flags, enum orientation orientation); 276 277 virtual void DrawActiveTab(BView* view, BRect& rect, 278 const BRect& updateRect, 279 const rgb_color& base, uint32 flags = 0, 280 uint32 borders = B_ALL_BORDERS); 281 282 virtual void DrawInactiveTab(BView* view, BRect& rect, 283 const BRect& updateRect, 284 const rgb_color& base, uint32 flags = 0, 285 uint32 borders = B_ALL_BORDERS); 286 287 /*virtual*/ void DrawSplitter(BView* view, BRect& rect, 288 const BRect& updateRect, 289 const rgb_color& base, 290 enum orientation orientation, 291 uint32 flags = 0, 292 uint32 borders = B_ALL_BORDERS); 293 294 // various borders 295 296 virtual void DrawBorder(BView* view, BRect& rect, 297 const BRect& updateRect, 298 const rgb_color& base, 299 border_style border, uint32 flags = 0, 300 uint32 borders = B_ALL_BORDERS); 301 302 virtual void DrawRaisedBorder(BView* view, BRect& rect, 303 const BRect& updateRect, 304 const rgb_color& base, uint32 flags = 0, 305 uint32 borders = B_ALL_BORDERS); 306 307 virtual void DrawGroupFrame(BView* view, BRect& rect, 308 const BRect& updateRect, 309 const rgb_color& base, 310 uint32 borders = B_ALL_BORDERS); 311 312 virtual void DrawTextControlBorder(BView* view, BRect& rect, 313 const BRect& updateRect, 314 const rgb_color& base, uint32 flags = 0, 315 uint32 borders = B_ALL_BORDERS); 316 317 // aligned labels 318 319 /*virtual*/ void DrawLabel(BView* view, const char* label, 320 BRect rect, const BRect& updateRect, 321 const rgb_color& base, uint32 flags); 322 virtual void DrawLabel(BView* view, const char* label, 323 BRect rect, const BRect& updateRect, 324 const rgb_color& base, uint32 flags, 325 const BAlignment& alignment); 326 // TODO: Would be nice to have a (non-virtual) version of this method 327 // which takes an array of labels and locations. That would save some 328 // setup with the view graphics state. 329 /*virtual*/ void DrawLabel(BView* view, const char* label, 330 const rgb_color& base, uint32 flags, 331 const BPoint& where); 332 333 void SetBackgroundInfo( 334 const BMessage& backgroundInfo); 335 336 protected: 337 void _DrawButtonFrame(BView* view, BRect& rect, 338 const BRect& updateRect, 339 float leftTopRadius, 340 float rightTopRadius, 341 float leftBottomRadius, 342 float rightBottomRadius, 343 const rgb_color& base, 344 const rgb_color& background, 345 float contrast, float brightness = 1.0, 346 uint32 flags = 0, 347 uint32 borders = B_ALL_BORDERS); 348 349 void _DrawOuterResessedFrame(BView* view, 350 BRect& rect, const rgb_color& base, 351 float contrast = 1.0f, 352 float brightness = 1.0f, 353 uint32 flags = 0, 354 uint32 borders = B_ALL_BORDERS); 355 356 void _DrawFrame(BView* view, BRect& rect, 357 const rgb_color& left, 358 const rgb_color& top, 359 const rgb_color& right, 360 const rgb_color& bottom, 361 uint32 borders = B_ALL_BORDERS); 362 void _DrawFrame(BView* view, BRect& rect, 363 const rgb_color& left, 364 const rgb_color& top, 365 const rgb_color& right, 366 const rgb_color& bottom, 367 const rgb_color& rightTop, 368 const rgb_color& leftBottom, 369 uint32 borders = B_ALL_BORDERS); 370 371 void _DrawButtonBackground(BView* view, BRect& rect, 372 const BRect& updateRect, 373 float leftTopRadius, 374 float rightTopRadius, 375 float leftBottomRadius, 376 float rightBottomRadius, 377 const rgb_color& base, 378 uint32 flags = 0, 379 uint32 borders = B_ALL_BORDERS, 380 enum orientation orientation 381 = 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 enum 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 enum orientation orientation 530 = B_HORIZONTAL); 531 532 void _FillGlossyGradient(BView* view, 533 const BRect& rect, const rgb_color& base, 534 float topTint, float middle1Tint, 535 float middle2Tint, float bottomTint, 536 enum orientation orientation 537 = B_HORIZONTAL); 538 539 void _MakeGradient(BGradientLinear& gradient, 540 const BRect& rect, const rgb_color& base, 541 float topTint, float bottomTint, 542 enum orientation orientation 543 = B_HORIZONTAL) const; 544 545 void _MakeGlossyGradient(BGradientLinear& gradient, 546 const BRect& rect, const rgb_color& base, 547 float topTint, float middle1Tint, 548 float middle2Tint, float bottomTint, 549 enum orientation orientation 550 = B_HORIZONTAL) const; 551 552 void _MakeButtonGradient(BGradientLinear& gradient, 553 BRect& rect, const rgb_color& base, 554 uint32 flags, enum orientation orientation 555 = B_HORIZONTAL) const; 556 557 bool _RadioButtonAndCheckBoxMarkColor( 558 const rgb_color& base, rgb_color& color, 559 uint32 flags) const; 560 561 private: 562 bool fCachedOutline; 563 int32 fCachedWorkspace; 564 BMessage fBackgroundInfo; 565 566 uint32 _reserved[20]; 567 }; 568 569 extern BControlLook* be_control_look; 570 571 572 } // namespace BPrivate 573 574 using BPrivate::BControlLook; 575 using BPrivate::be_control_look; 576 577 578 #endif // _CONTROL_LOOK_H 579