diff --git a/ImageControlLook.cpp b/ImageControlLook.cpp index 4dff014..0d15c34 100644 --- a/ImageControlLook.cpp +++ b/ImageControlLook.cpp @@ -22,6 +22,9 @@ ImageControlLook::ImageControlLook(image_id id) { for (int i = 0; i < 3; i++) fButton[i].fill(NULL); + fCheckBox_Checked.fill(NULL); + fCheckBox_Unchecked.fill(NULL); + fImageRoot = BPath("/boot/home/Desktop/projects/haiku/ImageControlLook/data/ImageThemes/OS-X-Leopard/"); } @@ -97,6 +100,25 @@ ImageControlLook::DrawButtonBackground(BView* view, BRect& rect, const BRect& up } +void +ImageControlLook::DrawCheckBox(BView* view, BRect& rect, const BRect& updateRect, + const rgb_color& base, uint32 flags) +{ + BBitmap* checkBox = NULL; + if (((BControl*)view)->Value() == B_CONTROL_ON) + checkBox = _Image("CheckBox-Checked", _FlagsToState(flags & ~B_ACTIVATED)); + else + checkBox = _Image("CheckBox-Unchecked", _FlagsToState(flags)); + + if (checkBox == NULL) + HaikuControlLook::DrawCheckBox(view, rect, updateRect, base, flags); + else { + view->SetDrawingMode(B_OP_ALPHA); + view->DrawBitmap(checkBox, rect); + } +} + + uint32 ImageControlLook::_FlagsToState(uint32 flags) { @@ -116,10 +138,9 @@ ImageControlLook::_DrawButtonBackground(BView* view, BRect& rect, const BRect& u bool popupIndicator, uint32 flags, uint32 borders, orientation orientation) { uint32 state = _FlagsToState(flags); - - BBitmap* tile = _Image("Button", ICL_MIDDLE, state); - BBitmap* left = _Image("Button", ICL_LEFT, state); - BBitmap* right = _Image("Button", ICL_RIGHT, state); + BBitmap* tile = _Image("Button", state, ICL_MIDDLE); + BBitmap* left = _Image("Button", state, ICL_LEFT); + BBitmap* right = _Image("Button", state, ICL_RIGHT); if (orientation == B_VERTICAL || tile == NULL) return false; @@ -162,16 +183,35 @@ ImageControlLook::_DrawButtonBackground(BView* view, BRect& rect, const BRect& u BBitmap* -ImageControlLook::_Image(const char* type, uint32 side, uint32 state) +ImageControlLook::_Image(const char* type, uint32 state, uint32 side) { - if (fButton[side][state] == NULL) - fButton[side][state] = BTranslationUtils::GetBitmapFile(_ImagePath(type, side, state)); - return fButton[side][state]; + SidedImages* sideList = NULL; + UnsidedImages* nosideList = NULL; + BBitmap* image = NULL; + + if (strcmp(type, "Button") == 0) + sideList = &fButton; + else if (strcmp(type, "CheckBox-Unchecked") == 0) + nosideList = &fCheckBox_Unchecked; + else if (strcmp(type, "CheckBox-Checked") == 0) + nosideList = &fCheckBox_Checked; + + if (sideList != NULL && (*sideList)[side][state] == NULL) + (*sideList)[side][state] = BTranslationUtils::GetBitmapFile(_ImagePath(type, state, side)); + if (sideList != NULL) + image = (*sideList)[side][state]; + + if (nosideList != NULL && (*nosideList)[state] == NULL) + (*nosideList)[state] = BTranslationUtils::GetBitmapFile(_ImagePath(type, state)); + if (nosideList != NULL) + image = (*nosideList)[state]; + + return image; } const char* -ImageControlLook::_ImagePath(const char* type, uint32 side, uint32 state) +ImageControlLook::_ImagePath(const char* type, uint32 state, uint32 side) { BString leaf = kStates[state]; leaf << kSides[side]; @@ -179,7 +219,7 @@ ImageControlLook::_ImagePath(const char* type, uint32 side, uint32 state) BPath imgPath(fImageRoot.Path()); imgPath.Append(type); imgPath.Append(leaf); - printf("[ImageControlLook] Loaded %s\n", imgPath.Path()); + printf("[ImageControlLook] Searching for %s…\n", imgPath.Path()); return imgPath.Path(); } diff --git a/ImageControlLook.h b/ImageControlLook.h index 947918b..09a81ff 100644 --- a/ImageControlLook.h +++ b/ImageControlLook.h @@ -23,7 +23,8 @@ using BPrivate::HaikuControlLook; enum { ICL_MIDDLE, ICL_LEFT, - ICL_RIGHT + ICL_RIGHT, + ICL_NO_SIDE }; enum { @@ -36,7 +37,11 @@ enum { const char* kStates[] = { "Normal", "Inactive", "Hover", "Disabled", "Activated" }; -const char* kSides[] = { "Middle", "Left", "Right" }; +const char* kSides[] = { "Middle", "Left", "Right", "" }; + + +typedef std::array, 3> SidedImages; +typedef std::array UnsidedImages; class ImageControlLook : public HaikuControlLook { @@ -92,6 +97,11 @@ public: uint32 borders = B_ALL_BORDERS, orientation orientation = B_HORIZONTAL); + virtual void DrawCheckBox(BView* view, BRect& rect, + const BRect& updateRect, + const rgb_color& base, + uint32 flags = 0); + protected: bool _DrawButtonBackground(BView* view, BRect& rect, const BRect& updateRect, bool popupIndicator, @@ -100,12 +110,15 @@ protected: private: uint32 _FlagsToState(uint32 flags); - BBitmap* _Image(const char* type, uint32 side, uint32 state); - const char* _ImagePath(const char* type, uint32 side, uint32 state); + BBitmap* _Image(const char* type, uint32 state, uint32 side = ICL_NO_SIDE); + const char* _ImagePath(const char* type, uint32 state, + uint32 side = ICL_NO_SIDE); BPath fImageRoot; - std::array, 3> fButton; + SidedImages fButton; + UnsidedImages fCheckBox_Checked; + UnsidedImages fCheckBox_Unchecked; }; #endif // IMAGE_CONTROL_LOOK_H diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Activated b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Activated new file mode 100644 index 0000000..5858e78 Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Activated differ diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Disabled b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Disabled new file mode 100644 index 0000000..e5074c5 Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Disabled differ diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Hover b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Hover new file mode 100644 index 0000000..96e5e44 Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Hover differ diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Inactive b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Inactive new file mode 100644 index 0000000..2c8d67d Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Inactive differ diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Normal b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Normal new file mode 100644 index 0000000..23d71eb Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Checked/Normal differ diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Activated b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Activated new file mode 100644 index 0000000..510db89 Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Activated differ diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Disabled b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Disabled new file mode 100644 index 0000000..9b22b0c Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Disabled differ diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Hover b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Hover new file mode 100644 index 0000000..ee6f270 Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Hover differ diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Inactive b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Inactive new file mode 100644 index 0000000..9ca98a3 Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Inactive differ diff --git a/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Normal b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Normal new file mode 100644 index 0000000..59c2e83 Binary files /dev/null and b/data/ImageThemes/OS-X-Leopard/CheckBox-Unchecked/Normal differ