BControlLook: Add methods for getting insets

* Update the previously unused frame_type and background_type enums.
* Add methods GetFrameInsets(), GetBackgroundInsets(), GetInsets() to
  get the insets for a given frame type, background type, or both
  respectively.
This commit is contained in:
Ingo Weinhold
2013-12-22 02:48:23 +01:00
parent d3e73d457e
commit 8719e0dc4b
2 changed files with 101 additions and 5 deletions
+21 -5
View File
@@ -35,16 +35,20 @@ public:
enum frame_type {
B_BUTTON_FRAME,
B_MENU_FRAME,
B_LISTVIEW_FRAME,
B_INPUT_FRAME
B_GROUP_FRAME,
B_MENU_FIELD_FRAME,
B_SCROLL_VIEW_FRAME,
B_TEXT_CONTROL_FRAME,
};
enum background_type {
B_BUTTON_BACKGROUND,
B_MENU_BACKGROUND,
B_LISTVIEW_BACKGROUND,
B_INPUT_BACKGROUND
B_MENU_BAR_BACKGROUND,
B_MENU_FIELD_BACKGROUND,
B_MENU_ITEM_BACKGROUND,
B_HORIZONTAL_SCROLL_BAR_BACKGROUND,
B_VERTICAL_SCROLL_BAR_BACKGROUND,
};
enum {
@@ -332,6 +336,18 @@ public:
const rgb_color& base, uint32 flags,
const BPoint& where);
virtual void GetFrameInsets(frame_type frameType,
uint32 flags, float& _left, float& _top,
float& _right, float& _bottom);
virtual void GetBackgroundInsets(
background_type backgroundType,
uint32 flags, float& _left, float& _top,
float& _right, float& _bottom);
void GetInsets(frame_type frameType,
background_type backgroundType,
uint32 flags, float& _left, float& _top,
float& _right, float& _bottom);
void SetBackgroundInfo(
const BMessage& backgroundInfo);
+80
View File
@@ -1901,6 +1901,86 @@ BControlLook::DrawLabel(BView* view, const char* label, const rgb_color& base,
}
void
BControlLook::GetFrameInsets(frame_type frameType, uint32 flags, float& _left,
float& _top, float& _right, float& _bottom)
{
// All frames have the same inset on each side.
float inset = 0;
switch (frameType) {
case B_BUTTON_FRAME:
inset = (flags & B_DEFAULT_BUTTON) != 0 ? 6 : 3;
break;
case B_GROUP_FRAME:
case B_MENU_FIELD_FRAME:
inset = 3;
break;
case B_SCROLL_VIEW_FRAME:
case B_TEXT_CONTROL_FRAME:
inset = 2;
break;
}
_left = inset;
_top = inset;
_right = inset;
_bottom = inset;
}
void
BControlLook::GetBackgroundInsets(background_type backgroundType,
uint32 flags, float& _left, float& _top, float& _right, float& _bottom)
{
// Most backgrounds have the same inset on each side.
float inset = 0;
switch (backgroundType) {
case B_BUTTON_BACKGROUND:
case B_MENU_BACKGROUND:
case B_MENU_BAR_BACKGROUND:
case B_MENU_FIELD_BACKGROUND:
case B_MENU_ITEM_BACKGROUND:
inset = 1;
break;
case B_HORIZONTAL_SCROLL_BAR_BACKGROUND:
_left = 2;
_top = 0;
_right = 1;
_bottom = 0;
return;
case B_VERTICAL_SCROLL_BAR_BACKGROUND:
_left = 0;
_top = 2;
_right = 0;
_bottom = 1;
return;
}
_left = inset;
_top = inset;
_right = inset;
_bottom = inset;
}
void
BControlLook::GetInsets(frame_type frameType, background_type backgroundType,
uint32 flags, float& _left, float& _top, float& _right, float& _bottom)
{
GetFrameInsets(frameType, flags, _left, _top, _right, _bottom);
float left, top, right, bottom;
GetBackgroundInsets(backgroundType, flags, left, top, right, bottom);
_left += left;
_top += top;
_right += right;
_bottom += bottom;
}
void
BControlLook::SetBackgroundInfo(const BMessage& backgroundInfo)
{