1
0
Disbranĉigi 0

Add BCheckBox support (w OS-X-Leopard)

Also generalizes the use of pointers in _Image(), defining types for them, etc.
This commit is contained in:
Jaidyn Ann 2022-06-12 12:08:29 -05:00
parent 0e8dc4a4d6
commit 02c30ad63d
12 changed files with 68 additions and 15 deletions

View File

@ -22,6 +22,9 @@ ImageControlLook::ImageControlLook(image_id id)
{ {
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
fButton[i].fill(NULL); 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/"); 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 uint32
ImageControlLook::_FlagsToState(uint32 flags) 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) bool popupIndicator, uint32 flags, uint32 borders, orientation orientation)
{ {
uint32 state = _FlagsToState(flags); uint32 state = _FlagsToState(flags);
BBitmap* tile = _Image("Button", state, ICL_MIDDLE);
BBitmap* tile = _Image("Button", ICL_MIDDLE, state); BBitmap* left = _Image("Button", state, ICL_LEFT);
BBitmap* left = _Image("Button", ICL_LEFT, state); BBitmap* right = _Image("Button", state, ICL_RIGHT);
BBitmap* right = _Image("Button", ICL_RIGHT, state);
if (orientation == B_VERTICAL || tile == NULL) if (orientation == B_VERTICAL || tile == NULL)
return false; return false;
@ -162,16 +183,35 @@ ImageControlLook::_DrawButtonBackground(BView* view, BRect& rect, const BRect& u
BBitmap* BBitmap*
ImageControlLook::_Image(const char* type, uint32 side, uint32 state) ImageControlLook::_Image(const char* type, uint32 state, uint32 side)
{ {
if (fButton[side][state] == NULL) SidedImages* sideList = NULL;
fButton[side][state] = BTranslationUtils::GetBitmapFile(_ImagePath(type, side, state)); UnsidedImages* nosideList = NULL;
return fButton[side][state]; 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* const char*
ImageControlLook::_ImagePath(const char* type, uint32 side, uint32 state) ImageControlLook::_ImagePath(const char* type, uint32 state, uint32 side)
{ {
BString leaf = kStates[state]; BString leaf = kStates[state];
leaf << kSides[side]; leaf << kSides[side];
@ -179,7 +219,7 @@ ImageControlLook::_ImagePath(const char* type, uint32 side, uint32 state)
BPath imgPath(fImageRoot.Path()); BPath imgPath(fImageRoot.Path());
imgPath.Append(type); imgPath.Append(type);
imgPath.Append(leaf); imgPath.Append(leaf);
printf("[ImageControlLook] Loaded %s\n", imgPath.Path()); printf("[ImageControlLook] Searching for %s…\n", imgPath.Path());
return imgPath.Path(); return imgPath.Path();
} }

View File

@ -23,7 +23,8 @@ using BPrivate::HaikuControlLook;
enum { enum {
ICL_MIDDLE, ICL_MIDDLE,
ICL_LEFT, ICL_LEFT,
ICL_RIGHT ICL_RIGHT,
ICL_NO_SIDE
}; };
enum { enum {
@ -36,7 +37,11 @@ enum {
const char* kStates[] = { "Normal", "Inactive", "Hover", "Disabled", "Activated" }; const char* kStates[] = { "Normal", "Inactive", "Hover", "Disabled", "Activated" };
const char* kSides[] = { "Middle", "Left", "Right" }; const char* kSides[] = { "Middle", "Left", "Right", "" };
typedef std::array<std::array<BBitmap*, 5>, 3> SidedImages;
typedef std::array<BBitmap*, 5> UnsidedImages;
class ImageControlLook : public HaikuControlLook { class ImageControlLook : public HaikuControlLook {
@ -92,6 +97,11 @@ public:
uint32 borders = B_ALL_BORDERS, uint32 borders = B_ALL_BORDERS,
orientation orientation = B_HORIZONTAL); orientation orientation = B_HORIZONTAL);
virtual void DrawCheckBox(BView* view, BRect& rect,
const BRect& updateRect,
const rgb_color& base,
uint32 flags = 0);
protected: protected:
bool _DrawButtonBackground(BView* view, BRect& rect, bool _DrawButtonBackground(BView* view, BRect& rect,
const BRect& updateRect, bool popupIndicator, const BRect& updateRect, bool popupIndicator,
@ -100,12 +110,15 @@ protected:
private: private:
uint32 _FlagsToState(uint32 flags); uint32 _FlagsToState(uint32 flags);
BBitmap* _Image(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 side, uint32 state); const char* _ImagePath(const char* type, uint32 state,
uint32 side = ICL_NO_SIDE);
BPath fImageRoot; BPath fImageRoot;
std::array<std::array<BBitmap*, 5>, 3> fButton; SidedImages fButton;
UnsidedImages fCheckBox_Checked;
UnsidedImages fCheckBox_Unchecked;
}; };
#endif // IMAGE_CONTROL_LOOK_H #endif // IMAGE_CONTROL_LOOK_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 893 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 B