From 8719e0dc4bf8495cd70c2dc3d25a5165f7ea3d16 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 22 Dec 2013 01:57:36 +0100 Subject: [PATCH] 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. --- headers/os/interface/ControlLook.h | 26 ++++++++-- src/kits/interface/ControlLook.cpp | 80 ++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/headers/os/interface/ControlLook.h b/headers/os/interface/ControlLook.h index 8039f14793..3db12f76e1 100644 --- a/headers/os/interface/ControlLook.h +++ b/headers/os/interface/ControlLook.h @@ -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); diff --git a/src/kits/interface/ControlLook.cpp b/src/kits/interface/ControlLook.cpp index baab42d1c5..e4e0292ab6 100644 --- a/src/kits/interface/ControlLook.cpp +++ b/src/kits/interface/ControlLook.cpp @@ -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) {