Add DrawSliderThumb() + DrawSliderTriangle()
As per usual, also includes appropriate images in the OSX theme. Also abstracts drawing of controls to the handy _DrawImage() and _DrawTiledImage() methods.
|
@ -1,12 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2021 Haiku, Inc.
|
|
||||||
* Copyright 2022, Jaidyn Levesque <jadedctrl@teknik.io>
|
* Copyright 2022, Jaidyn Levesque <jadedctrl@teknik.io>
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* All rights reserved. Distributed under the terms of the MIT license.
|
||||||
*
|
|
||||||
* Authors:
|
|
||||||
* Stephan Aßmus, superstippi@gmx.de
|
|
||||||
* John Scipione, jscipione@gmail.com
|
|
||||||
* Nahuel Tello, ntello@unarix.com.ar
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ImageControlLook.h"
|
#include "ImageControlLook.h"
|
||||||
|
@ -24,6 +18,8 @@ ImageControlLook::ImageControlLook(image_id id)
|
||||||
fButton[i].fill(NULL);
|
fButton[i].fill(NULL);
|
||||||
fCheckBox_Checked.fill(NULL);
|
fCheckBox_Checked.fill(NULL);
|
||||||
fCheckBox_Unchecked.fill(NULL);
|
fCheckBox_Unchecked.fill(NULL);
|
||||||
|
fSliderThumb.fill(NULL);
|
||||||
|
fSliderTriangle.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/");
|
||||||
}
|
}
|
||||||
|
@ -73,7 +69,7 @@ void
|
||||||
ImageControlLook::DrawButtonBackground(BView* view, BRect& rect, const BRect& updateRect,
|
ImageControlLook::DrawButtonBackground(BView* view, BRect& rect, const BRect& updateRect,
|
||||||
const rgb_color& base, uint32 flags, uint32 borders, orientation orientation)
|
const rgb_color& base, uint32 flags, uint32 borders, orientation orientation)
|
||||||
{
|
{
|
||||||
if (!_DrawButtonBackground(view, rect, updateRect, false, flags, borders, orientation))
|
if (!_DrawTiledImage("Button", _FlagsToState(flags), view, rect, updateRect, orientation))
|
||||||
HaikuControlLook::DrawButtonBackground(view, rect, updateRect, base, flags, borders,
|
HaikuControlLook::DrawButtonBackground(view, rect, updateRect, base, flags, borders,
|
||||||
orientation);
|
orientation);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +79,7 @@ void
|
||||||
ImageControlLook::DrawButtonBackground(BView* view, BRect& rect, const BRect& updateRect,
|
ImageControlLook::DrawButtonBackground(BView* view, BRect& rect, const BRect& updateRect,
|
||||||
float radius, const rgb_color& base, uint32 flags, uint32 borders, orientation orientation)
|
float radius, const rgb_color& base, uint32 flags, uint32 borders, orientation orientation)
|
||||||
{
|
{
|
||||||
if (!_DrawButtonBackground(view, rect, updateRect, false, flags, borders, orientation))
|
if (!_DrawTiledImage("Button", _FlagsToState(flags), view, rect, updateRect, orientation))
|
||||||
HaikuControlLook::DrawButtonBackground(view, rect, updateRect, radius, base, flags, borders,
|
HaikuControlLook::DrawButtonBackground(view, rect, updateRect, radius, base, flags, borders,
|
||||||
orientation);
|
orientation);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +90,7 @@ ImageControlLook::DrawButtonBackground(BView* view, BRect& rect, const BRect& up
|
||||||
float leftTopRadius, float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
|
float leftTopRadius, float rightTopRadius, float leftBottomRadius, float rightBottomRadius,
|
||||||
const rgb_color& base, uint32 flags, uint32 borders, orientation orientation)
|
const rgb_color& base, uint32 flags, uint32 borders, orientation orientation)
|
||||||
{
|
{
|
||||||
if (!_DrawButtonBackground(view, rect, updateRect, false, flags, borders, orientation))
|
if (!_DrawTiledImage("Button", _FlagsToState(flags), view, rect, updateRect, orientation))
|
||||||
HaikuControlLook::DrawButtonBackground(view, rect, updateRect, leftTopRadius,
|
HaikuControlLook::DrawButtonBackground(view, rect, updateRect, leftTopRadius,
|
||||||
rightTopRadius,leftBottomRadius, rightBottomRadius, base, flags, borders, orientation);
|
rightTopRadius,leftBottomRadius, rightBottomRadius, base, flags, borders, orientation);
|
||||||
}
|
}
|
||||||
|
@ -104,43 +100,66 @@ void
|
||||||
ImageControlLook::DrawCheckBox(BView* view, BRect& rect, const BRect& updateRect,
|
ImageControlLook::DrawCheckBox(BView* view, BRect& rect, const BRect& updateRect,
|
||||||
const rgb_color& base, uint32 flags)
|
const rgb_color& base, uint32 flags)
|
||||||
{
|
{
|
||||||
BBitmap* checkBox = NULL;
|
bool drawn = false;
|
||||||
if (((BControl*)view)->Value() == B_CONTROL_ON)
|
if (((BControl*)view)->Value() == B_CONTROL_ON)
|
||||||
checkBox = _Image("CheckBox-Checked", _FlagsToState(flags & ~B_ACTIVATED));
|
drawn = _DrawImage("CheckBox-Checked", _FlagsToState(flags & ~B_ACTIVATED), view, rect);
|
||||||
else
|
else
|
||||||
checkBox = _Image("CheckBox-Unchecked", _FlagsToState(flags));
|
drawn = _DrawImage("CheckBox-Unchecked", _FlagsToState(flags), view, rect);
|
||||||
|
|
||||||
if (checkBox == NULL)
|
if (!drawn)
|
||||||
HaikuControlLook::DrawCheckBox(view, rect, updateRect, base, flags);
|
HaikuControlLook::DrawCheckBox(view, rect, updateRect, base, flags);
|
||||||
else {
|
|
||||||
view->SetDrawingMode(B_OP_ALPHA);
|
|
||||||
view->DrawBitmap(checkBox, rect);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32
|
void
|
||||||
ImageControlLook::_FlagsToState(uint32 flags)
|
ImageControlLook::DrawSliderThumb(BView* view, BRect& rect, const BRect& updateRect,
|
||||||
|
const rgb_color& base, uint32 flags, orientation orientation)
|
||||||
{
|
{
|
||||||
uint32 state = ICL_NORMAL;
|
if (!_DrawImage("SliderThumb", _FlagsToState(flags), view, rect, orientation))
|
||||||
if (flags & B_DISABLED)
|
HaikuControlLook::DrawSliderThumb(view, rect, updateRect, base, flags, orientation);
|
||||||
state = ICL_DISABLED;
|
}
|
||||||
else if (flags & (B_ACTIVATED | B_PARTIALLY_ACTIVATED | B_CLICKED))
|
|
||||||
state = ICL_ACTIVATED;
|
|
||||||
else if (flags & (B_HOVER | B_FOCUSED))
|
void
|
||||||
state = ICL_HOVER;
|
ImageControlLook::DrawSliderTriangle(BView* view, BRect& rect, const BRect& updateRect,
|
||||||
return state;
|
const rgb_color& base, uint32 flags, orientation orientation)
|
||||||
|
{
|
||||||
|
if (!_DrawImage("SliderTriangle", _FlagsToState(flags), view, rect, orientation))
|
||||||
|
HaikuControlLook::DrawSliderTriangle(view, rect, updateRect, base, flags, orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ImageControlLook::DrawSliderTriangle(BView* view, BRect& rect, const BRect& updateRect,
|
||||||
|
const rgb_color& base, const rgb_color& fill, uint32 flags, orientation orientation)
|
||||||
|
{
|
||||||
|
if (!_DrawImage("SliderTriangle", _FlagsToState(flags), view, rect, orientation))
|
||||||
|
HaikuControlLook::DrawSliderTriangle(view, rect, updateRect, base, fill, flags,
|
||||||
|
orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ImageControlLook::_DrawButtonBackground(BView* view, BRect& rect, const BRect& updateRect,
|
ImageControlLook::_DrawImage(const char* type, uint32 state, BView* view, BRect rect,
|
||||||
bool popupIndicator, uint32 flags, uint32 borders, orientation orientation)
|
orientation orientation)
|
||||||
{
|
{
|
||||||
uint32 state = _FlagsToState(flags);
|
BBitmap* image = _Image(type, state);
|
||||||
BBitmap* tile = _Image("Button", state, ICL_MIDDLE);
|
if (image != NULL && orientation == B_HORIZONTAL) {
|
||||||
BBitmap* left = _Image("Button", state, ICL_LEFT);
|
view->SetDrawingMode(B_OP_ALPHA);
|
||||||
BBitmap* right = _Image("Button", state, ICL_RIGHT);
|
view->DrawBitmap(image, rect);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ImageControlLook::_DrawTiledImage(const char* type, uint32 state, BView* view, BRect rect,
|
||||||
|
BRect updateRect, orientation orientation)
|
||||||
|
{
|
||||||
|
BBitmap* tile = _Image(type, state, ICL_MIDDLE);
|
||||||
|
BBitmap* left = _Image(type, state, ICL_LEFT);
|
||||||
|
BBitmap* right = _Image(type, state, ICL_RIGHT);
|
||||||
|
|
||||||
if (orientation == B_VERTICAL || tile == NULL)
|
if (orientation == B_VERTICAL || tile == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
@ -163,19 +182,21 @@ ImageControlLook::_DrawButtonBackground(BView* view, BRect& rect, const BRect& u
|
||||||
for (float left = minX; left + sliceWidth < maxX; left += sliceWidth) {
|
for (float left = minX; left + sliceWidth < maxX; left += sliceWidth) {
|
||||||
tileRect.left = left;
|
tileRect.left = left;
|
||||||
tileRect.right = left + sliceWidth;
|
tileRect.right = left + sliceWidth;
|
||||||
|
if (tileRect.Intersects(updateRect))
|
||||||
view->DrawBitmap(tile, tileRect);
|
view->DrawBitmap(tile, tileRect);
|
||||||
}
|
}
|
||||||
tileRect.right = maxX;
|
tileRect.right = maxX;
|
||||||
tileRect.left = maxX - sliceWidth;
|
tileRect.left = maxX - sliceWidth;
|
||||||
|
if (tileRect.Intersects(updateRect))
|
||||||
view->DrawBitmap(tile, tileRect);
|
view->DrawBitmap(tile, tileRect);
|
||||||
|
|
||||||
BRect sideRect(0, 0, minX, rect.Height());
|
BRect sideRect(0, 0, minX, rect.Height());
|
||||||
if (left != NULL && (borders & B_LEFT_BORDER))
|
if (left != NULL && sideRect.Intersects(updateRect))
|
||||||
view->DrawBitmap(left, sideRect);
|
view->DrawBitmap(left, sideRect);
|
||||||
|
|
||||||
sideRect.left = maxX;
|
sideRect.left = maxX;
|
||||||
sideRect.right = view->Bounds().right;
|
sideRect.right = view->Bounds().right;
|
||||||
if (right != NULL && (borders & B_RIGHT_BORDER))
|
if (right != NULL && sideRect.Intersects(updateRect))
|
||||||
view->DrawBitmap(right, sideRect);
|
view->DrawBitmap(right, sideRect);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -195,6 +216,10 @@ ImageControlLook::_Image(const char* type, uint32 state, uint32 side)
|
||||||
nosideList = &fCheckBox_Unchecked;
|
nosideList = &fCheckBox_Unchecked;
|
||||||
else if (strcmp(type, "CheckBox-Checked") == 0)
|
else if (strcmp(type, "CheckBox-Checked") == 0)
|
||||||
nosideList = &fCheckBox_Checked;
|
nosideList = &fCheckBox_Checked;
|
||||||
|
else if (strcmp(type, "SliderThumb") == 0)
|
||||||
|
nosideList = &fSliderThumb;
|
||||||
|
else if (strcmp(type, "SliderTriangle") == 0)
|
||||||
|
nosideList = &fSliderTriangle;
|
||||||
|
|
||||||
if (sideList != NULL && (*sideList)[side][state] == NULL)
|
if (sideList != NULL && (*sideList)[side][state] == NULL)
|
||||||
(*sideList)[side][state] = BTranslationUtils::GetBitmapFile(_ImagePath(type, state, side));
|
(*sideList)[side][state] = BTranslationUtils::GetBitmapFile(_ImagePath(type, state, side));
|
||||||
|
@ -224,6 +249,20 @@ ImageControlLook::_ImagePath(const char* type, uint32 state, uint32 side)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32
|
||||||
|
ImageControlLook::_FlagsToState(uint32 flags)
|
||||||
|
{
|
||||||
|
uint32 state = ICL_NORMAL;
|
||||||
|
if (flags & B_DISABLED)
|
||||||
|
state = ICL_DISABLED;
|
||||||
|
else if (flags & (B_ACTIVATED | B_PARTIALLY_ACTIVATED | B_CLICKED))
|
||||||
|
state = ICL_ACTIVATED;
|
||||||
|
else if (flags & (B_HOVER | B_FOCUSED))
|
||||||
|
state = ICL_HOVER;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" BControlLook* (instantiate_control_look)(image_id id)
|
extern "C" BControlLook* (instantiate_control_look)(image_id id)
|
||||||
{
|
{
|
||||||
return new (std::nothrow)ImageControlLook(id);
|
return new (std::nothrow)ImageControlLook(id);
|
||||||
|
|
|
@ -102,23 +102,41 @@ public:
|
||||||
const rgb_color& base,
|
const rgb_color& base,
|
||||||
uint32 flags = 0);
|
uint32 flags = 0);
|
||||||
|
|
||||||
protected:
|
virtual void DrawSliderThumb(BView* view, BRect& rect,
|
||||||
bool _DrawButtonBackground(BView* view, BRect& rect,
|
const BRect& updateRect,
|
||||||
const BRect& updateRect, bool popupIndicator,
|
const rgb_color& base, uint32 flags,
|
||||||
uint32 flags, uint32 borders,
|
orientation orientation);
|
||||||
|
|
||||||
|
virtual void DrawSliderTriangle(BView* view, BRect& rect,
|
||||||
|
const BRect& updateRect,
|
||||||
|
const rgb_color& base, uint32 flags,
|
||||||
|
orientation orientation);
|
||||||
|
virtual void DrawSliderTriangle(BView* view, BRect& rect,
|
||||||
|
const BRect& updateRect,
|
||||||
|
const rgb_color& base,
|
||||||
|
const rgb_color& fill, uint32 flags,
|
||||||
orientation orientation);
|
orientation orientation);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 _FlagsToState(uint32 flags);
|
bool _DrawImage(const char* type, uint32 state, BView* view, BRect rect,
|
||||||
|
orientation orientation = B_HORIZONTAL);
|
||||||
|
bool _DrawTiledImage(const char* type, uint32 state, BView* view,
|
||||||
|
BRect rect, BRect updateRect,
|
||||||
|
orientation orientation = B_HORIZONTAL);
|
||||||
|
|
||||||
BBitmap* _Image(const char* type, uint32 state, uint32 side = ICL_NO_SIDE);
|
BBitmap* _Image(const char* type, uint32 state, uint32 side = ICL_NO_SIDE);
|
||||||
const char* _ImagePath(const char* type, uint32 state,
|
const char* _ImagePath(const char* type, uint32 state,
|
||||||
uint32 side = ICL_NO_SIDE);
|
uint32 side = ICL_NO_SIDE);
|
||||||
|
|
||||||
|
uint32 _FlagsToState(uint32 flags);
|
||||||
|
|
||||||
BPath fImageRoot;
|
BPath fImageRoot;
|
||||||
|
|
||||||
SidedImages fButton;
|
SidedImages fButton;
|
||||||
UnsidedImages fCheckBox_Checked;
|
UnsidedImages fCheckBox_Checked;
|
||||||
UnsidedImages fCheckBox_Unchecked;
|
UnsidedImages fCheckBox_Unchecked;
|
||||||
|
UnsidedImages fSliderThumb;
|
||||||
|
UnsidedImages fSliderTriangle;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMAGE_CONTROL_LOOK_H
|
#endif // IMAGE_CONTROL_LOOK_H
|
||||||
|
|
After Width: | Height: | Size: 136 B |
After Width: | Height: | Size: 93 B |
After Width: | Height: | Size: 135 B |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 901 B |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |