mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-01 10:21:04 +00:00
Minor refactor in skin properties
- Add get_skin_property(ui::Widget*) function to avoid duplicating code to create a SkinProperty. - A SkinSliderProperty is not a SkinProperty: now it has its own name.
This commit is contained in:
parent
8e81fb808d
commit
e0a28c1d46
@ -404,30 +404,17 @@ void setup_mini_look(Widget* widget)
|
|||||||
|
|
||||||
void setup_look(Widget* widget, LookType lookType)
|
void setup_look(Widget* widget, LookType lookType)
|
||||||
{
|
{
|
||||||
SharedPtr<SkinProperty> skinProp;
|
SkinPropertyPtr skinProp = get_skin_property(widget);
|
||||||
|
|
||||||
skinProp = widget->getProperty(SkinProperty::SkinPropertyName);
|
|
||||||
if (skinProp == NULL)
|
|
||||||
skinProp.reset(new SkinProperty);
|
|
||||||
|
|
||||||
skinProp->setLook(lookType);
|
skinProp->setLook(lookType);
|
||||||
widget->setProperty(skinProp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_bevels(Widget* widget, int b1, int b2, int b3, int b4)
|
void setup_bevels(Widget* widget, int b1, int b2, int b3, int b4)
|
||||||
{
|
{
|
||||||
SharedPtr<SkinProperty> skinProp;
|
SkinPropertyPtr skinProp = get_skin_property(widget);
|
||||||
|
|
||||||
skinProp = widget->getProperty(SkinProperty::SkinPropertyName);
|
|
||||||
if (skinProp == NULL)
|
|
||||||
skinProp.reset(new SkinProperty);
|
|
||||||
|
|
||||||
skinProp->setUpperLeft(b1);
|
skinProp->setUpperLeft(b1);
|
||||||
skinProp->setUpperRight(b2);
|
skinProp->setUpperRight(b2);
|
||||||
skinProp->setLowerLeft(b3);
|
skinProp->setLowerLeft(b3);
|
||||||
skinProp->setLowerRight(b4);
|
skinProp->setLowerRight(b4);
|
||||||
|
|
||||||
widget->setProperty(skinProp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the IconInterface pointer interface of the button to show the
|
// Sets the IconInterface pointer interface of the button to show the
|
||||||
|
@ -128,7 +128,7 @@ void ColorSliders::addSlider(Channel channel, const char* labelText, int min, in
|
|||||||
m_entry.push_back(entry);
|
m_entry.push_back(entry);
|
||||||
m_channel.push_back(channel);
|
m_channel.push_back(channel);
|
||||||
|
|
||||||
slider->setProperty(PropertyPtr(new SkinSliderProperty(new ColorSliderBgPainter(channel))));
|
slider->setProperty(SkinSliderPropertyPtr(new SkinSliderProperty(new ColorSliderBgPainter(channel))));
|
||||||
slider->setDoubleBuffered(true);
|
slider->setDoubleBuffered(true);
|
||||||
|
|
||||||
slider->Change.connect(Bind<void>(&ColorSliders::onSliderChange, this, m_slider.size()-1));
|
slider->Change.connect(Bind<void>(&ColorSliders::onSliderChange, this, m_slider.size()-1));
|
||||||
@ -201,7 +201,7 @@ void ColorSliders::updateSlidersBgColor(const app::Color& color)
|
|||||||
|
|
||||||
void ColorSliders::updateSliderBgColor(Slider* slider, const app::Color& color)
|
void ColorSliders::updateSliderBgColor(Slider* slider, const app::Color& color)
|
||||||
{
|
{
|
||||||
SharedPtr<SkinSliderProperty> sliderProperty(slider->getProperty("SkinProperty"));
|
SkinSliderPropertyPtr sliderProperty(slider->getProperty(SkinSliderProperty::Name));
|
||||||
|
|
||||||
static_cast<ColorSliderBgPainter*>(sliderProperty->getBgPainter())->setColor(color);
|
static_cast<ColorSliderBgPainter*>(sliderProperty->getBgPainter())->setColor(color);
|
||||||
|
|
||||||
|
@ -22,13 +22,15 @@
|
|||||||
|
|
||||||
#include "app/ui/skin/skin_property.h"
|
#include "app/ui/skin/skin_property.h"
|
||||||
|
|
||||||
|
#include "ui/widget.h"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
namespace skin {
|
namespace skin {
|
||||||
|
|
||||||
const char* SkinProperty::SkinPropertyName = "SkinProperty";
|
const char* SkinProperty::Name = "SkinProperty";
|
||||||
|
|
||||||
SkinProperty::SkinProperty()
|
SkinProperty::SkinProperty()
|
||||||
: Property(SkinPropertyName)
|
: Property(Name)
|
||||||
{
|
{
|
||||||
m_look = NormalLook;
|
m_look = NormalLook;
|
||||||
m_upperLeft = 0;
|
m_upperLeft = 0;
|
||||||
@ -41,5 +43,18 @@ SkinProperty::~SkinProperty()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkinPropertyPtr get_skin_property(ui::Widget* widget)
|
||||||
|
{
|
||||||
|
SkinPropertyPtr skinProp;
|
||||||
|
|
||||||
|
skinProp = widget->getProperty(SkinProperty::Name);
|
||||||
|
if (skinProp == NULL) {
|
||||||
|
skinProp.reset(new SkinProperty);
|
||||||
|
widget->setProperty(skinProp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return skinProp;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace skin
|
} // namespace skin
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
@ -19,8 +19,13 @@
|
|||||||
#ifndef APP_UI_SKIN_SKIN_PROPERTY_H_INCLUDED
|
#ifndef APP_UI_SKIN_SKIN_PROPERTY_H_INCLUDED
|
||||||
#define APP_UI_SKIN_SKIN_PROPERTY_H_INCLUDED
|
#define APP_UI_SKIN_SKIN_PROPERTY_H_INCLUDED
|
||||||
|
|
||||||
|
#include "base/shared_ptr.h"
|
||||||
#include "ui/property.h"
|
#include "ui/property.h"
|
||||||
|
|
||||||
|
namespace ui {
|
||||||
|
class Widget;
|
||||||
|
}
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
namespace skin {
|
namespace skin {
|
||||||
|
|
||||||
@ -35,7 +40,7 @@ namespace app {
|
|||||||
// Property to show widgets with a special look (e.g.: buttons or sliders with mini-borders)
|
// Property to show widgets with a special look (e.g.: buttons or sliders with mini-borders)
|
||||||
class SkinProperty : public ui::Property {
|
class SkinProperty : public ui::Property {
|
||||||
public:
|
public:
|
||||||
static const char* SkinPropertyName;
|
static const char* Name;
|
||||||
|
|
||||||
SkinProperty();
|
SkinProperty();
|
||||||
~SkinProperty();
|
~SkinProperty();
|
||||||
@ -61,6 +66,10 @@ namespace app {
|
|||||||
int m_lowerRight;
|
int m_lowerRight;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef SharedPtr<SkinProperty> SkinPropertyPtr;
|
||||||
|
|
||||||
|
SkinPropertyPtr get_skin_property(ui::Widget* widget);
|
||||||
|
|
||||||
} // namespace skin
|
} // namespace skin
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
|
||||||
|
@ -25,8 +25,11 @@
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace skin {
|
namespace skin {
|
||||||
|
|
||||||
|
const char* SkinSliderProperty::Name = "SkinSliderProperty";
|
||||||
|
|
||||||
SkinSliderProperty::SkinSliderProperty(ISliderBgPainter* painter)
|
SkinSliderProperty::SkinSliderProperty(ISliderBgPainter* painter)
|
||||||
: m_painter(painter)
|
: Property(Name)
|
||||||
|
, m_painter(painter)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
#ifndef APP_UI_SKIN_SKIN_SLIDER_PROPERTY_H_INCLUDED
|
#ifndef APP_UI_SKIN_SKIN_SLIDER_PROPERTY_H_INCLUDED
|
||||||
#define APP_UI_SKIN_SKIN_SLIDER_PROPERTY_H_INCLUDED
|
#define APP_UI_SKIN_SKIN_SLIDER_PROPERTY_H_INCLUDED
|
||||||
|
|
||||||
#include "gfx/rect.h"
|
|
||||||
#include "app/ui/skin/skin_property.h"
|
#include "app/ui/skin/skin_property.h"
|
||||||
|
#include "base/shared_ptr.h"
|
||||||
|
#include "gfx/rect.h"
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
class Slider;
|
class Slider;
|
||||||
@ -35,8 +36,10 @@ namespace app {
|
|||||||
virtual void paint(ui::Slider* slider, ui::Graphics* graphics, const gfx::Rect& rc) = 0;
|
virtual void paint(ui::Slider* slider, ui::Graphics* graphics, const gfx::Rect& rc) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SkinSliderProperty : public SkinProperty {
|
class SkinSliderProperty : public ui::Property {
|
||||||
public:
|
public:
|
||||||
|
static const char* Name;
|
||||||
|
|
||||||
// The given painter is deleted automatically when this
|
// The given painter is deleted automatically when this
|
||||||
// property the destroyed.
|
// property the destroyed.
|
||||||
SkinSliderProperty(ISliderBgPainter* painter);
|
SkinSliderProperty(ISliderBgPainter* painter);
|
||||||
@ -48,6 +51,8 @@ namespace app {
|
|||||||
ISliderBgPainter* m_painter;
|
ISliderBgPainter* m_painter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef SharedPtr<SkinSliderProperty> SkinSliderPropertyPtr;
|
||||||
|
|
||||||
} // namespace skin
|
} // namespace skin
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
|
||||||
|
@ -851,7 +851,7 @@ void SkinTheme::paintButton(PaintEvent& ev)
|
|||||||
|
|
||||||
// Tool buttons are smaller
|
// Tool buttons are smaller
|
||||||
LookType look = NormalLook;
|
LookType look = NormalLook;
|
||||||
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
|
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
|
||||||
if (skinPropery != NULL)
|
if (skinPropery != NULL)
|
||||||
look = skinPropery->getLook();
|
look = skinPropery->getLook();
|
||||||
|
|
||||||
@ -926,7 +926,7 @@ void SkinTheme::paintCheckBox(PaintEvent& ev)
|
|||||||
|
|
||||||
// Check box look
|
// Check box look
|
||||||
LookType look = NormalLook;
|
LookType look = NormalLook;
|
||||||
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
|
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
|
||||||
if (skinPropery != NULL)
|
if (skinPropery != NULL)
|
||||||
look = skinPropery->getLook();
|
look = skinPropery->getLook();
|
||||||
|
|
||||||
@ -990,7 +990,7 @@ void SkinTheme::paintEntry(PaintEvent& ev)
|
|||||||
y2 = widget->getBounds().y2()-1;
|
y2 = widget->getBounds().y2()-1;
|
||||||
|
|
||||||
bool isMiniLook = false;
|
bool isMiniLook = false;
|
||||||
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
|
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
|
||||||
if (skinPropery != NULL)
|
if (skinPropery != NULL)
|
||||||
isMiniLook = (skinPropery->getLook() == MiniLook);
|
isMiniLook = (skinPropery->getLook() == MiniLook);
|
||||||
|
|
||||||
@ -1404,12 +1404,13 @@ void SkinTheme::paintSlider(PaintEvent& ev)
|
|||||||
// customized background (e.g. RGB sliders)
|
// customized background (e.g. RGB sliders)
|
||||||
ISliderBgPainter* bgPainter = NULL;
|
ISliderBgPainter* bgPainter = NULL;
|
||||||
|
|
||||||
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
|
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
|
||||||
if (skinPropery != NULL)
|
if (skinPropery != NULL)
|
||||||
isMiniLook = (skinPropery->getLook() == MiniLook);
|
isMiniLook = (skinPropery->getLook() == MiniLook);
|
||||||
|
|
||||||
if (SkinSliderProperty* sliderProperty = dynamic_cast<SkinSliderProperty*>(skinPropery.get()))
|
SkinSliderPropertyPtr skinSliderPropery = widget->getProperty(SkinSliderProperty::Name);
|
||||||
bgPainter = sliderProperty->getBgPainter();
|
if (skinSliderPropery != NULL)
|
||||||
|
bgPainter = skinSliderPropery->getBgPainter();
|
||||||
|
|
||||||
// Draw customized background
|
// Draw customized background
|
||||||
if (bgPainter) {
|
if (bgPainter) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user