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:
David Capello 2013-12-05 01:19:46 -03:00
parent 8e81fb808d
commit e0a28c1d46
7 changed files with 49 additions and 29 deletions

View File

@ -404,30 +404,17 @@ void setup_mini_look(Widget* widget)
void setup_look(Widget* widget, LookType lookType)
{
SharedPtr<SkinProperty> skinProp;
skinProp = widget->getProperty(SkinProperty::SkinPropertyName);
if (skinProp == NULL)
skinProp.reset(new SkinProperty);
SkinPropertyPtr skinProp = get_skin_property(widget);
skinProp->setLook(lookType);
widget->setProperty(skinProp);
}
void setup_bevels(Widget* widget, int b1, int b2, int b3, int b4)
{
SharedPtr<SkinProperty> skinProp;
skinProp = widget->getProperty(SkinProperty::SkinPropertyName);
if (skinProp == NULL)
skinProp.reset(new SkinProperty);
SkinPropertyPtr skinProp = get_skin_property(widget);
skinProp->setUpperLeft(b1);
skinProp->setUpperRight(b2);
skinProp->setLowerLeft(b3);
skinProp->setLowerRight(b4);
widget->setProperty(skinProp);
}
// Sets the IconInterface pointer interface of the button to show the

View File

@ -128,7 +128,7 @@ void ColorSliders::addSlider(Channel channel, const char* labelText, int min, in
m_entry.push_back(entry);
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->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)
{
SharedPtr<SkinSliderProperty> sliderProperty(slider->getProperty("SkinProperty"));
SkinSliderPropertyPtr sliderProperty(slider->getProperty(SkinSliderProperty::Name));
static_cast<ColorSliderBgPainter*>(sliderProperty->getBgPainter())->setColor(color);

View File

@ -22,13 +22,15 @@
#include "app/ui/skin/skin_property.h"
#include "ui/widget.h"
namespace app {
namespace skin {
const char* SkinProperty::SkinPropertyName = "SkinProperty";
const char* SkinProperty::Name = "SkinProperty";
SkinProperty::SkinProperty()
: Property(SkinPropertyName)
: Property(Name)
{
m_look = NormalLook;
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 app

View File

@ -19,8 +19,13 @@
#ifndef APP_UI_SKIN_SKIN_PROPERTY_H_INCLUDED
#define APP_UI_SKIN_SKIN_PROPERTY_H_INCLUDED
#include "base/shared_ptr.h"
#include "ui/property.h"
namespace ui {
class Widget;
}
namespace app {
namespace skin {
@ -35,7 +40,7 @@ namespace app {
// Property to show widgets with a special look (e.g.: buttons or sliders with mini-borders)
class SkinProperty : public ui::Property {
public:
static const char* SkinPropertyName;
static const char* Name;
SkinProperty();
~SkinProperty();
@ -61,6 +66,10 @@ namespace app {
int m_lowerRight;
};
typedef SharedPtr<SkinProperty> SkinPropertyPtr;
SkinPropertyPtr get_skin_property(ui::Widget* widget);
} // namespace skin
} // namespace app

View File

@ -25,8 +25,11 @@
namespace app {
namespace skin {
const char* SkinSliderProperty::Name = "SkinSliderProperty";
SkinSliderProperty::SkinSliderProperty(ISliderBgPainter* painter)
: m_painter(painter)
: Property(Name)
, m_painter(painter)
{
}

View File

@ -19,8 +19,9 @@
#ifndef 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 "base/shared_ptr.h"
#include "gfx/rect.h"
namespace ui {
class Slider;
@ -35,8 +36,10 @@ namespace app {
virtual void paint(ui::Slider* slider, ui::Graphics* graphics, const gfx::Rect& rc) = 0;
};
class SkinSliderProperty : public SkinProperty {
class SkinSliderProperty : public ui::Property {
public:
static const char* Name;
// The given painter is deleted automatically when this
// property the destroyed.
SkinSliderProperty(ISliderBgPainter* painter);
@ -48,6 +51,8 @@ namespace app {
ISliderBgPainter* m_painter;
};
typedef SharedPtr<SkinSliderProperty> SkinSliderPropertyPtr;
} // namespace skin
} // namespace app

View File

@ -851,7 +851,7 @@ void SkinTheme::paintButton(PaintEvent& ev)
// Tool buttons are smaller
LookType look = NormalLook;
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
if (skinPropery != NULL)
look = skinPropery->getLook();
@ -926,7 +926,7 @@ void SkinTheme::paintCheckBox(PaintEvent& ev)
// Check box look
LookType look = NormalLook;
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
if (skinPropery != NULL)
look = skinPropery->getLook();
@ -990,7 +990,7 @@ void SkinTheme::paintEntry(PaintEvent& ev)
y2 = widget->getBounds().y2()-1;
bool isMiniLook = false;
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
if (skinPropery != NULL)
isMiniLook = (skinPropery->getLook() == MiniLook);
@ -1404,12 +1404,13 @@ void SkinTheme::paintSlider(PaintEvent& ev)
// customized background (e.g. RGB sliders)
ISliderBgPainter* bgPainter = NULL;
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
if (skinPropery != NULL)
isMiniLook = (skinPropery->getLook() == MiniLook);
if (SkinSliderProperty* sliderProperty = dynamic_cast<SkinSliderProperty*>(skinPropery.get()))
bgPainter = sliderProperty->getBgPainter();
SkinSliderPropertyPtr skinSliderPropery = widget->getProperty(SkinSliderProperty::Name);
if (skinSliderPropery != NULL)
bgPainter = skinSliderPropery->getBgPainter();
// Draw customized background
if (bgPainter) {