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