Remove SkinParts enum

Now we generate the list of SkinTheme parts from the skin.xml file using
the gen utility.

Several refactors included in SkinTheme class to simplify code.
This commit is contained in:
David Capello 2015-08-04 19:38:52 -03:00
parent 43a3ee8bce
commit 53a925e86d
35 changed files with 566 additions and 937 deletions

View File

@ -220,37 +220,37 @@ private:
int c = 0; int c = 0;
for (int v=0; v<3; ++v) { for (int v=0; v<3; ++v) {
for (int u=0; u<3; ++u) { for (int u=0; u<3; ++u) {
const char* iconId = "canvas_empty"; SkinPartPtr icon = theme->parts.canvasEmpty();
if (c == sel) { if (c == sel) {
iconId = "canvas_c"; icon = theme->parts.canvasC();
} }
else if (u+1 < 3 && (u+1)+3*v == sel) { else if (u+1 < 3 && (u+1)+3*v == sel) {
iconId = "canvas_w"; icon = theme->parts.canvasW();
} }
else if (u-1 >= 0 && (u-1)+3*v == sel) { else if (u-1 >= 0 && (u-1)+3*v == sel) {
iconId = "canvas_e"; icon = theme->parts.canvasE();
} }
else if (v+1 < 3 && u+3*(v+1) == sel) { else if (v+1 < 3 && u+3*(v+1) == sel) {
iconId = "canvas_n"; icon = theme->parts.canvasN();
} }
else if (v-1 >= 0 && u+3*(v-1) == sel) { else if (v-1 >= 0 && u+3*(v-1) == sel) {
iconId = "canvas_s"; icon = theme->parts.canvasS();
} }
else if (u+1 < 3 && v+1 < 3 && (u+1)+3*(v+1) == sel) { else if (u+1 < 3 && v+1 < 3 && (u+1)+3*(v+1) == sel) {
iconId = "canvas_nw"; icon = theme->parts.canvasNw();
} }
else if (u-1 >= 0 && v+1 < 3 && (u-1)+3*(v+1) == sel) { else if (u-1 >= 0 && v+1 < 3 && (u-1)+3*(v+1) == sel) {
iconId = "canvas_ne"; icon = theme->parts.canvasNe();
} }
else if (u+1 < 3 && v-1 >= 0 && (u+1)+3*(v-1) == sel) { else if (u+1 < 3 && v-1 >= 0 && (u+1)+3*(v-1) == sel) {
iconId = "canvas_sw"; icon = theme->parts.canvasSw();
} }
else if (u-1 >= 0 && v-1 >= 0 && (u-1)+3*(v-1) == sel) { else if (u-1 >= 0 && v-1 >= 0 && (u-1)+3*(v-1) == sel) {
iconId = "canvas_se"; icon = theme->parts.canvasSe();
} }
dir()->getItem(c)->setIcon(theme->get_part(iconId)); dir()->getItem(c)->setIcon(icon);
++c; ++c;
} }
} }

View File

@ -13,7 +13,8 @@
#include "app/modules/gfx.h" #include "app/modules/gfx.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/ui/skin/skin_parts.h" #include "app/ui/skin/button_icon_impl.h"
#include "app/ui/skin/skin_theme.h"
#include "base/bind.h" #include "base/bind.h"
#include "doc/image.h" #include "doc/image.h"
#include "ui/box.h" #include "ui/box.h"
@ -25,9 +26,9 @@
namespace app { namespace app {
using namespace app::skin;
using namespace filters; using namespace filters;
using namespace ui; using namespace ui;
using namespace app::skin;
FilterTargetButtons::FilterTargetButtons(int imgtype, bool withChannels) FilterTargetButtons::FilterTargetButtons(int imgtype, bool withChannels)
: Box(VERTICAL) : Box(VERTICAL)
@ -91,10 +92,12 @@ FilterTargetButtons::FilterTargetButtons(int imgtype, bool withChannels)
withChannels ? 0: 2, withChannels ? 0: 2,
withChannels ? 0: 2, 2, 2); withChannels ? 0: 2, 2, 2);
setup_mini_look(images); setup_mini_look(images);
set_gfxicon_to_button(images,
getTargetNormalIcon(), images->setIconInterface(
getTargetSelectedIcon(), -1, new ButtonIconImpl(getTargetNormalIcon(),
CENTER | MIDDLE); getTargetSelectedIcon(),
SkinPartPtr(nullptr),
CENTER | MIDDLE));
// Make hierarchy // Make hierarchy
ADD(hbox, r, onChannelChange); ADD(hbox, r, onChannelChange);
@ -170,39 +173,44 @@ void FilterTargetButtons::onImagesChange(ButtonBase* button)
m_target |= TARGET_ALL_FRAMES; m_target |= TARGET_ALL_FRAMES;
} }
set_gfxicon_to_button(button, button->setIconInterface(
getTargetNormalIcon(), new ButtonIconImpl(getTargetNormalIcon(),
getTargetSelectedIcon(), -1, getTargetSelectedIcon(),
CENTER | MIDDLE); SkinPartPtr(nullptr),
CENTER | MIDDLE));
TargetChange(); TargetChange();
} }
int FilterTargetButtons::getTargetNormalIcon() const SkinPartPtr FilterTargetButtons::getTargetNormalIcon() const
{ {
SkinTheme* theme = SkinTheme::instance();
if (m_target & TARGET_ALL_FRAMES) { if (m_target & TARGET_ALL_FRAMES) {
return (m_target & TARGET_ALL_LAYERS) ? return (m_target & TARGET_ALL_LAYERS) ?
PART_TARGET_FRAMES_LAYERS: theme->parts.targetFramesLayers():
PART_TARGET_FRAMES; theme->parts.targetFrames();
} }
else { else {
return (m_target & TARGET_ALL_LAYERS) ? return (m_target & TARGET_ALL_LAYERS) ?
PART_TARGET_LAYERS: theme->parts.targetLayers():
PART_TARGET_ONE; theme->parts.targetOne();
} }
} }
int FilterTargetButtons::getTargetSelectedIcon() const SkinPartPtr FilterTargetButtons::getTargetSelectedIcon() const
{ {
SkinTheme* theme = SkinTheme::instance();
if (m_target & TARGET_ALL_FRAMES) { if (m_target & TARGET_ALL_FRAMES) {
return (m_target & TARGET_ALL_LAYERS) ? return (m_target & TARGET_ALL_LAYERS) ?
PART_TARGET_FRAMES_LAYERS_SELECTED: theme->parts.targetFramesLayersSelected():
PART_TARGET_FRAMES_SELECTED; theme->parts.targetFramesSelected();
} }
else { else {
return (m_target & TARGET_ALL_LAYERS) ? return (m_target & TARGET_ALL_LAYERS) ?
PART_TARGET_LAYERS_SELECTED: theme->parts.targetLayersSelected():
PART_TARGET_ONE_SELECTED; theme->parts.targetOneSelected();
} }
} }

View File

@ -9,6 +9,7 @@
#define APP_COMMANDS_FILTERS_FILTER_TARGET_BUTTONS_H_INCLUDED #define APP_COMMANDS_FILTERS_FILTER_TARGET_BUTTONS_H_INCLUDED
#pragma once #pragma once
#include "app/ui/skin/skin_part.h"
#include "base/signal.h" #include "base/signal.h"
#include "filters/target.h" #include "filters/target.h"
#include "ui/box.h" #include "ui/box.h"
@ -37,8 +38,8 @@ namespace app {
private: private:
void selectTargetButton(const char* name, Target specificTarget); void selectTargetButton(const char* name, Target specificTarget);
int getTargetNormalIcon() const; skin::SkinPartPtr getTargetNormalIcon() const;
int getTargetSelectedIcon() const; skin::SkinPartPtr getTargetSelectedIcon() const;
Target m_target; Target m_target;
}; };

View File

@ -100,7 +100,7 @@ void draw_color_button(ui::Graphics* g,
const Rect& rc, const app::Color& color, const Rect& rc, const app::Color& color,
bool hot, bool drag) bool hot, bool drag)
{ {
SkinTheme* theme = (SkinTheme*)ui::CurrentTheme::get(); SkinTheme* theme = SkinTheme::instance();
int scale = ui::guiscale(); int scale = ui::guiscale();
// Draw background (the color) // Draw background (the color)
@ -111,25 +111,22 @@ void draw_color_button(ui::Graphics* g,
rc.h-2*scale), color); rc.h-2*scale), color);
// Draw opaque border // Draw opaque border
{ theme->drawRect(
int parts[8] = { g, rc,
PART_COLORBAR_0_NW, theme->parts.colorbar0()->getBitmapNW(),
PART_COLORBAR_0_N, theme->parts.colorbar0()->getBitmapN(),
PART_COLORBAR_1_NE, theme->parts.colorbar1()->getBitmapNE(),
PART_COLORBAR_1_E, theme->parts.colorbar1()->getBitmapE(),
PART_COLORBAR_3_SE, theme->parts.colorbar3()->getBitmapSE(),
PART_COLORBAR_2_S, theme->parts.colorbar2()->getBitmapS(),
PART_COLORBAR_2_SW, theme->parts.colorbar2()->getBitmapSW(),
PART_COLORBAR_0_W theme->parts.colorbar0()->getBitmapW());
};
theme->draw_bounds_array(g, rc, parts);
}
// Draw hot // Draw hot
if (hot) { if (hot) {
theme->draw_bounds_nw(g, theme->drawRect(
gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - 1*scale), g, gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - 1*scale),
PART_COLORBAR_BORDER_HOTFG_NW); theme->parts.colorbarBorderHotfg().get());
} }
} }

View File

@ -28,7 +28,6 @@
#include "app/ui/main_menu_bar.h" #include "app/ui/main_menu_bar.h"
#include "app/ui/main_menu_bar.h" #include "app/ui/main_menu_bar.h"
#include "app/ui/main_window.h" #include "app/ui/main_window.h"
#include "app/ui/skin/button_icon_impl.h"
#include "app/ui/skin/skin_property.h" #include "app/ui/skin/skin_property.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h" #include "app/ui/status_bar.h"
@ -264,23 +263,6 @@ void setup_bevels(Widget* widget, int b1, int b2, int b3, int b4)
skinProp->setLowerRight(b4); skinProp->setLowerRight(b4);
} }
// Sets the IconInterface pointer interface of the button to show the
// specified set of icons. Each icon is a part of the SkinTheme.
void set_gfxicon_to_button(ButtonBase* button,
int normal_part_id,
int selected_part_id,
int disabled_part_id, int icon_align)
{
ButtonIconImpl* buttonIcon =
new ButtonIconImpl(static_cast<SkinTheme*>(button->getTheme()),
normal_part_id,
selected_part_id,
disabled_part_id,
icon_align);
button->setIconInterface(buttonIcon);
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Button style (convert radio or check buttons and draw it like // Button style (convert radio or check buttons and draw it like
// normal buttons) // normal buttons)

View File

@ -45,11 +45,6 @@ namespace app {
ui::Widget* setup_look(ui::Widget* widget, skin::LookType lookType); ui::Widget* setup_look(ui::Widget* widget, skin::LookType lookType);
void setup_bevels(ui::Widget* widget, int b1, int b2, int b3, int b4); void setup_bevels(ui::Widget* widget, int b1, int b2, int b3, int b4);
void set_gfxicon_to_button(ui::ButtonBase* button,
int normal_part_id,
int selected_part_id,
int disabled_part_id, int icon_align);
ui::CheckBox* check_button_new(const char* text, int b1, int b2, int b3, int b4); ui::CheckBox* check_button_new(const char* text, int b1, int b2, int b3, int b4);
// This function can be used to reinvalidate a specific rectangle if // This function can be used to reinvalidate a specific rectangle if

View File

@ -65,11 +65,11 @@ AniControls::AniControls()
{ {
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
addItem(theme->get_part(PART_ANI_FIRST)); addItem(theme->parts.aniFirst());
addItem(theme->get_part(PART_ANI_PREVIOUS)); addItem(theme->parts.aniPrevious());
addItem(theme->get_part(PART_ANI_PLAY)); addItem(theme->parts.aniPlay());
addItem(theme->get_part(PART_ANI_NEXT)); addItem(theme->parts.aniNext());
addItem(theme->get_part(PART_ANI_LAST)); addItem(theme->parts.aniLast());
ItemChange.connect(Bind(&AniControls::onPlayButton, this)); ItemChange.connect(Bind(&AniControls::onPlayButton, this));
setTriggerOnMouseUp(true); setTriggerOnMouseUp(true);
@ -81,8 +81,9 @@ void AniControls::updateUsingEditor(Editor* editor)
{ {
SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(this->getTheme());
getItem(ACTION_PLAY)->setIcon( getItem(ACTION_PLAY)->setIcon(
theme->get_part( (editor && editor->isPlaying() ?
(editor && editor->isPlaying()) ? PART_ANI_STOP: PART_ANI_PLAY)); theme->parts.aniStop():
theme->parts.aniPlay()));
} }
void AniControls::onPlayButton() void AniControls::onPlayButton()

View File

@ -47,11 +47,9 @@ public:
, m_delegate(delegate) , m_delegate(delegate)
, m_brush(brush) , m_brush(brush)
, m_slot(slot) { , m_slot(slot) {
setIcon(BrushPopup::createSurfaceForBrush(brush)); SkinPartPtr icon(new SkinPart);
} icon->setBitmap(0, BrushPopup::createSurfaceForBrush(brush));
setIcon(icon);
~Item() {
icon()->dispose();
} }
const BrushRef& brush() const { const BrushRef& brush() const {

View File

@ -48,7 +48,7 @@ ButtonSet::Item::Item()
setup_mini_font(this); setup_mini_font(this);
} }
void ButtonSet::Item::setIcon(she::Surface* icon) void ButtonSet::Item::setIcon(const SkinPartPtr& icon)
{ {
m_icon = icon; m_icon = icon;
invalidate(); invalidate();
@ -65,25 +65,25 @@ void ButtonSet::Item::onPaint(ui::PaintEvent& ev)
Graphics* g = ev.getGraphics(); Graphics* g = ev.getGraphics();
gfx::Rect rc = getClientBounds(); gfx::Rect rc = getClientBounds();
gfx::Color fg, bg; gfx::Color fg, bg;
int nw; SkinPartPtr nw;
if (!gfx::is_transparent(getBgColor())) if (!gfx::is_transparent(getBgColor()))
g->fillRect(getBgColor(), g->getClipBounds()); g->fillRect(getBgColor(), g->getClipBounds());
if (isSelected() || hasMouseOver()) { if (isSelected() || hasMouseOver()) {
if (hasCapture()) { if (hasCapture()) {
nw = PART_TOOLBUTTON_PUSHED_NW; nw = theme->parts.toolbuttonPushed();
fg = theme->colors.buttonSelectedText(); fg = theme->colors.buttonSelectedText();
bg = theme->colors.buttonSelectedFace(); bg = theme->colors.buttonSelectedFace();
} }
else { else {
nw = PART_TOOLBUTTON_HOT_NW; nw = theme->parts.toolbuttonHot();
fg = theme->colors.buttonHotText(); fg = theme->colors.buttonHotText();
bg = theme->colors.buttonHotFace(); bg = theme->colors.buttonHotFace();
} }
} }
else { else {
nw = PART_TOOLBUTTON_LAST_NW; nw = theme->parts.toolbuttonLast();
fg = theme->colors.buttonNormalText(); fg = theme->colors.buttonNormalText();
bg = theme->colors.buttonNormalFace(); bg = theme->colors.buttonNormalFace();
} }
@ -92,16 +92,17 @@ void ButtonSet::Item::onPaint(ui::PaintEvent& ev)
if (info.col < info.grid_cols-1) rc.w+=1*guiscale(); if (info.col < info.grid_cols-1) rc.w+=1*guiscale();
if (info.row < info.grid_rows-1) rc.h+=3*guiscale(); if (info.row < info.grid_rows-1) rc.h+=3*guiscale();
theme->draw_bounds_nw(g, rc, nw, bg); theme->drawRect(g, rc, nw.get(), bg);
if (m_icon) { if (m_icon) {
int u = rc.x + rc.w/2 - m_icon->width()/2; gfx::Size iconSize = m_icon->getSize();
int v = rc.y + rc.h/2 - m_icon->height()/2 - 1*guiscale(); int u = rc.x + rc.w/2 - iconSize.w/2;
int v = rc.y + rc.h/2 - iconSize.h/2 - 1*guiscale();
if (isSelected() && hasCapture()) if (isSelected() && hasCapture())
g->drawColoredRgbaSurface(m_icon, theme->colors.buttonSelectedText(), u, v); g->drawColoredRgbaSurface(m_icon->getBitmap(0), theme->colors.buttonSelectedText(), u, v);
else else
g->drawRgbaSurface(m_icon, u, v); g->drawRgbaSurface(m_icon->getBitmap(0), u, v);
} }
if (!getText().empty()) { if (!getText().empty()) {
@ -192,7 +193,7 @@ void ButtonSet::addItem(const std::string& text, int hspan, int vspan)
addItem(item, hspan, vspan); addItem(item, hspan, vspan);
} }
void ButtonSet::addItem(she::Surface* icon, int hspan, int vspan) void ButtonSet::addItem(const skin::SkinPartPtr& icon, int hspan, int vspan)
{ {
Item* item = new Item(); Item* item = new Item();
item->setIcon(icon); item->setIcon(icon);

View File

@ -9,6 +9,7 @@
#define APP_UI_BUTTON_SET_H_INCLUDED #define APP_UI_BUTTON_SET_H_INCLUDED
#pragma once #pragma once
#include "app/ui/skin/skin_part.h"
#include "base/signal.h" #include "base/signal.h"
#include "ui/grid.h" #include "ui/grid.h"
@ -21,21 +22,21 @@ namespace app {
class Item : public ui::Widget { class Item : public ui::Widget {
public: public:
Item(); Item();
void setIcon(she::Surface* icon); void setIcon(const skin::SkinPartPtr& icon);
she::Surface* icon() const { return m_icon; } skin::SkinPartPtr icon() const { return m_icon; }
ButtonSet* buttonSet(); ButtonSet* buttonSet();
protected: protected:
void onPaint(ui::PaintEvent& ev) override; void onPaint(ui::PaintEvent& ev) override;
bool onProcessMessage(ui::Message* msg) override; bool onProcessMessage(ui::Message* msg) override;
void onPreferredSize(ui::PreferredSizeEvent& ev) override; void onPreferredSize(ui::PreferredSizeEvent& ev) override;
private: private:
she::Surface* m_icon; skin::SkinPartPtr m_icon;
}; };
ButtonSet(int columns); ButtonSet(int columns);
void addItem(const std::string& text, int hspan = 1, int vspan = 1); void addItem(const std::string& text, int hspan = 1, int vspan = 1);
void addItem(she::Surface* icon, int hspan = 1, int vspan = 1); void addItem(const skin::SkinPartPtr& icon, int hspan = 1, int vspan = 1);
void addItem(Item* item, int hspan = 1, int vspan = 1); void addItem(Item* item, int hspan = 1, int vspan = 1);
Item* getItem(int index); Item* getItem(int index);

View File

@ -100,10 +100,10 @@ protected:
ColorBar::ScrollableView::ScrollableView() ColorBar::ScrollableView::ScrollableView()
{ {
SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
int l = theme->get_part(PART_EDITOR_SELECTED_W)->width(); int l = theme->parts.editorSelected()->getBitmapW()->width();
int t = theme->get_part(PART_EDITOR_SELECTED_N)->height(); int t = theme->parts.editorSelected()->getBitmapN()->height();
int r = theme->get_part(PART_EDITOR_SELECTED_E)->width(); int r = theme->parts.editorSelected()->getBitmapE()->width();
int b = theme->get_part(PART_EDITOR_SELECTED_S)->height(); int b = theme->parts.editorSelected()->getBitmapS()->height();
setBorder(gfx::Border(l, t, r, b)); setBorder(gfx::Border(l, t, r, b));
} }
@ -112,10 +112,11 @@ void ColorBar::ScrollableView::onPaint(ui::PaintEvent& ev)
{ {
ui::Graphics* g = ev.getGraphics(); ui::Graphics* g = ev.getGraphics();
SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
theme->draw_bounds_nw(g,
getClientBounds(), theme->drawRect(
hasFocus() ? PART_EDITOR_SELECTED_NW: g, getClientBounds(),
PART_EDITOR_NORMAL_NW, (hasFocus() ? theme->parts.editorSelected().get():
theme->parts.editorNormal().get()),
gfx::ColorNone); gfx::ColorNone);
} }
@ -223,10 +224,10 @@ ColorBar::ColorBar(int align)
// Change labels foreground color // Change labels foreground color
m_buttons.ItemChange.connect(Bind<void>(&ColorBar::onPaletteButtonClick, this)); m_buttons.ItemChange.connect(Bind<void>(&ColorBar::onPaletteButtonClick, this));
m_buttons.addItem(theme->get_part(PART_PAL_EDIT)); m_buttons.addItem(theme->parts.palEdit());
m_buttons.addItem(theme->get_part(PART_PAL_SORT)); m_buttons.addItem(theme->parts.palSort());
m_buttons.addItem(theme->get_part(PART_PAL_PRESETS)); m_buttons.addItem(theme->parts.palPresets());
m_buttons.addItem(theme->get_part(PART_PAL_OPTIONS)); m_buttons.addItem(theme->parts.palOptions());
// Tooltips // Tooltips
TooltipManager* tooltipManager = new TooltipManager(); TooltipManager* tooltipManager = new TooltipManager();

View File

@ -83,8 +83,9 @@ void ColorSpectrum::onPaint(ui::PaintEvent& ev)
ui::Graphics* g = ev.getGraphics(); ui::Graphics* g = ev.getGraphics();
SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
theme->draw_bounds_nw(g, getClientBounds(), theme->drawRect(g, getClientBounds(),
PART_EDITOR_NORMAL_NW, getBgColor()); theme->parts.editorNormal().get(),
getBgColor());
gfx::Rect rc = getClientBounds().shrink(3*ui::guiscale()); gfx::Rect rc = getClientBounds().shrink(3*ui::guiscale());
if (rc.isEmpty()) if (rc.isEmpty())

View File

@ -63,26 +63,26 @@ public:
BrushTypeField(ContextBar* owner) BrushTypeField(ContextBar* owner)
: ButtonSet(1) : ButtonSet(1)
, m_owner(owner) , m_owner(owner)
, m_bitmap(BrushPopup::createSurfaceForBrush(BrushRef(nullptr)))
, m_popupWindow(this) { , m_popupWindow(this) {
addItem(m_bitmap); SkinPartPtr part(new SkinPart);
part->setBitmap(
0, BrushPopup::createSurfaceForBrush(BrushRef(nullptr)));
addItem(part);
m_popupWindow.BrushChange.connect(&BrushTypeField::onBrushChange, this); m_popupWindow.BrushChange.connect(&BrushTypeField::onBrushChange, this);
} }
~BrushTypeField() { ~BrushTypeField() {
closePopup(); closePopup();
m_bitmap->dispose();
} }
void updateBrush(tools::Tool* tool = nullptr) { void updateBrush(tools::Tool* tool = nullptr) {
if (m_bitmap) SkinPartPtr part(new SkinPart);
m_bitmap->dispose(); part->setBitmap(
0, BrushPopup::createSurfaceForBrush(
m_owner->activeBrush(tool)));
m_bitmap = BrushPopup::createSurfaceForBrush( getItem(0)->setIcon(part);
m_owner->activeBrush(tool));
getItem(0)->setIcon(m_bitmap);
} }
void setupTooltips(TooltipManager* tooltipManager) { void setupTooltips(TooltipManager* tooltipManager) {
@ -325,21 +325,21 @@ class ContextBar::InkTypeField : public ButtonSet
public: public:
InkTypeField(ContextBar* owner) : ButtonSet(1) InkTypeField(ContextBar* owner) : ButtonSet(1)
, m_owner(owner) { , m_owner(owner) {
addItem( SkinTheme* theme = SkinTheme::instance();
static_cast<SkinTheme*>(getTheme())->get_part(PART_INK_DEFAULT)); addItem(theme->parts.inkDefault());
} }
void setInkType(InkType inkType) { void setInkType(InkType inkType) {
int part = PART_INK_DEFAULT; SkinTheme* theme = SkinTheme::instance();
SkinPartPtr part = theme->parts.inkDefault();
switch (inkType) { switch (inkType) {
case InkType::ALPHA_COMPOSITING: part = PART_INK_DEFAULT; break; case InkType::ALPHA_COMPOSITING: part = theme->parts.inkDefault(); break;
case InkType::COPY_COLOR: part = PART_INK_COPY_COLOR; break; case InkType::COPY_COLOR: part = theme->parts.inkCopyColor(); break;
case InkType::LOCK_ALPHA: part = PART_INK_LOCK_ALPHA; break; case InkType::LOCK_ALPHA: part = theme->parts.inkLockAlpha(); break;
} }
getItem(0)->setIcon( getItem(0)->setIcon(part);
static_cast<SkinTheme*>(getTheme())->get_part(part));
} }
protected: protected:
@ -483,10 +483,12 @@ public:
: m_icon(1) : m_icon(1)
, m_maskColor(app::Color::fromMask(), IMAGE_RGB) , m_maskColor(app::Color::fromMask(), IMAGE_RGB)
, m_owner(owner) { , m_owner(owner) {
SkinTheme* theme = SkinTheme::instance();
addChild(&m_icon); addChild(&m_icon);
addChild(&m_maskColor); addChild(&m_maskColor);
m_icon.addItem(static_cast<SkinTheme*>(getTheme())->get_part(PART_SELECTION_OPAQUE)); m_icon.addItem(theme->parts.selectionOpaque());
gfx::Size sz = m_icon.getItem(0)->getPreferredSize(); gfx::Size sz = m_icon.getItem(0)->getPreferredSize();
sz.w += 2*guiscale(); sz.w += 2*guiscale();
m_icon.getItem(0)->setMinSize(sz); m_icon.getItem(0)->setMinSize(sz);
@ -536,9 +538,10 @@ private:
void onOpaqueChange() { void onOpaqueChange() {
bool opaque = Preferences::instance().selection.opaque(); bool opaque = Preferences::instance().selection.opaque();
int part = (opaque ? PART_SELECTION_OPAQUE: PART_SELECTION_MASKED); SkinTheme* theme = SkinTheme::instance();
m_icon.getItem(0)->setIcon( SkinPartPtr part = (opaque ? theme->parts.selectionOpaque():
static_cast<SkinTheme*>(getTheme())->get_part(part)); theme->parts.selectionMasked());
m_icon.getItem(0)->setIcon(part);
m_maskColor.setVisible(!opaque); m_maskColor.setVisible(!opaque);
if (!opaque) { if (!opaque) {
@ -559,7 +562,7 @@ class ContextBar::PivotField : public ButtonSet {
public: public:
PivotField() PivotField()
: ButtonSet(1) { : ButtonSet(1) {
addItem(static_cast<SkinTheme*>(getTheme())->get_part(PART_PIVOT_HIDDEN)); addItem(SkinTheme::instance()->parts.pivotHidden());
ItemChange.connect(Bind<void>(&PivotField::onPopup, this)); ItemChange.connect(Bind<void>(&PivotField::onPopup, this));
@ -580,15 +583,15 @@ private:
CheckBox hidden("Hidden pivot by default"); CheckBox hidden("Hidden pivot by default");
HBox box; HBox box;
ButtonSet buttonset(3); ButtonSet buttonset(3);
buttonset.addItem(theme->get_part(PART_PIVOT_NORTHWEST)); buttonset.addItem(theme->parts.pivotNorthwest());
buttonset.addItem(theme->get_part(PART_PIVOT_NORTH)); buttonset.addItem(theme->parts.pivotNorth());
buttonset.addItem(theme->get_part(PART_PIVOT_NORTHEAST)); buttonset.addItem(theme->parts.pivotNortheast());
buttonset.addItem(theme->get_part(PART_PIVOT_WEST)); buttonset.addItem(theme->parts.pivotWest());
buttonset.addItem(theme->get_part(PART_PIVOT_CENTER)); buttonset.addItem(theme->parts.pivotCenter());
buttonset.addItem(theme->get_part(PART_PIVOT_EAST)); buttonset.addItem(theme->parts.pivotEast());
buttonset.addItem(theme->get_part(PART_PIVOT_SOUTHWEST)); buttonset.addItem(theme->parts.pivotSouthwest());
buttonset.addItem(theme->get_part(PART_PIVOT_SOUTH)); buttonset.addItem(theme->parts.pivotSouth());
buttonset.addItem(theme->get_part(PART_PIVOT_SOUTHEAST)); buttonset.addItem(theme->parts.pivotSoutheast());
box.addChild(&buttonset); box.addChild(&buttonset);
menu.addChild(&hidden); menu.addChild(&hidden);
@ -618,9 +621,22 @@ private:
} }
void onPivotChange() { void onPivotChange() {
int part = PART_PIVOT_HIDDEN + int(Preferences::instance().selection.pivot()); SkinTheme* theme = SkinTheme::instance();
getItem(0)->setIcon( SkinPartPtr part;
static_cast<SkinTheme*>(getTheme())->get_part(part)); switch (Preferences::instance().selection.pivot()) {
case app::gen::PivotMode::HIDDEN: part = theme->parts.pivotHidden(); break;
case app::gen::PivotMode::NORTHWEST: part = theme->parts.pivotNorthwest(); break;
case app::gen::PivotMode::NORTH: part = theme->parts.pivotNorth(); break;
case app::gen::PivotMode::NORTHEAST: part = theme->parts.pivotNortheast(); break;
case app::gen::PivotMode::WEST: part = theme->parts.pivotWest(); break;
case app::gen::PivotMode::CENTER: part = theme->parts.pivotCenter(); break;
case app::gen::PivotMode::EAST: part = theme->parts.pivotEast(); break;
case app::gen::PivotMode::SOUTHWEST: part = theme->parts.pivotSouthwest(); break;
case app::gen::PivotMode::SOUTH: part = theme->parts.pivotSouth(); break;
case app::gen::PivotMode::SOUTHEAST: part = theme->parts.pivotSoutheast(); break;
}
if (part)
getItem(0)->setIcon(part);
} }
}; };
@ -693,20 +709,21 @@ public:
} }
void setFreehandAlgorithm(FreehandAlgorithm algo) { void setFreehandAlgorithm(FreehandAlgorithm algo) {
int part = PART_FREEHAND_ALGO_DEFAULT; SkinTheme* theme = SkinTheme::instance();
SkinPartPtr part = theme->parts.freehandAlgoDefault();
m_freehandAlgo = algo; m_freehandAlgo = algo;
switch (m_freehandAlgo) { switch (m_freehandAlgo) {
case kDefaultFreehandAlgorithm: case kDefaultFreehandAlgorithm:
part = PART_FREEHAND_ALGO_DEFAULT; part = theme->parts.freehandAlgoDefault();
break; break;
case kPixelPerfectFreehandAlgorithm: case kPixelPerfectFreehandAlgorithm:
part = PART_FREEHAND_ALGO_PIXEL_PERFECT; part = theme->parts.freehandAlgoPixelPerfect();
break; break;
case kDotsFreehandAlgorithm: case kDotsFreehandAlgorithm:
part = PART_FREEHAND_ALGO_DOTS; part = theme->parts.freehandAlgoDots();
break; break;
} }
m_bitmap = static_cast<SkinTheme*>(getTheme())->get_part(part); m_bitmap = part;
invalidate(); invalidate();
} }
@ -717,24 +734,20 @@ public:
// ContextBar. // ContextBar.
} }
int getWidth() override { gfx::Size getSize() override {
return m_bitmap->width(); return m_bitmap->getSize();
}
int getHeight() override {
return m_bitmap->height();
} }
she::Surface* getNormalIcon() override { she::Surface* getNormalIcon() override {
return m_bitmap; return m_bitmap->getBitmap(0);
} }
she::Surface* getSelectedIcon() override { she::Surface* getSelectedIcon() override {
return m_bitmap; return m_bitmap->getBitmap(0);
} }
she::Surface* getDisabledIcon() override { she::Surface* getDisabledIcon() override {
return m_bitmap; return m_bitmap->getBitmap(0);
} }
int getIconAlign() override { int getIconAlign() override {
@ -771,9 +784,9 @@ private:
Region rgn(m_popupWindow->getBounds().createUnion(getBounds())); Region rgn(m_popupWindow->getBounds().createUnion(getBounds()));
m_popupWindow->setHotRegion(rgn); m_popupWindow->setHotRegion(rgn);
m_freehandAlgoButton = new ButtonSet(3); m_freehandAlgoButton = new ButtonSet(3);
m_freehandAlgoButton->addItem(theme->get_part(PART_FREEHAND_ALGO_DEFAULT)); m_freehandAlgoButton->addItem(theme->parts.freehandAlgoDefault());
m_freehandAlgoButton->addItem(theme->get_part(PART_FREEHAND_ALGO_PIXEL_PERFECT)); m_freehandAlgoButton->addItem(theme->parts.freehandAlgoPixelPerfect());
m_freehandAlgoButton->addItem(theme->get_part(PART_FREEHAND_ALGO_DOTS)); m_freehandAlgoButton->addItem(theme->parts.freehandAlgoDots());
m_freehandAlgoButton->setSelectedItem((int)m_freehandAlgo); m_freehandAlgoButton->setSelectedItem((int)m_freehandAlgo);
m_freehandAlgoButton->ItemChange.connect(&FreehandAlgorithmField::onFreehandAlgoChange, this); m_freehandAlgoButton->ItemChange.connect(&FreehandAlgorithmField::onFreehandAlgoChange, this);
m_freehandAlgoButton->setTransparent(true); m_freehandAlgoButton->setTransparent(true);
@ -804,7 +817,7 @@ private:
Preferences::instance().tool(tool).freehandAlgorithm(m_freehandAlgo); Preferences::instance().tool(tool).freehandAlgorithm(m_freehandAlgo);
} }
she::Surface* m_bitmap; SkinPartPtr m_bitmap;
FreehandAlgorithm m_freehandAlgo; FreehandAlgorithm m_freehandAlgo;
PopupWindow* m_popupWindow; PopupWindow* m_popupWindow;
ButtonSet* m_freehandAlgoButton; ButtonSet* m_freehandAlgoButton;
@ -860,9 +873,9 @@ public:
SelectionModeField() : ButtonSet(3) { SelectionModeField() : ButtonSet(3) {
SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
addItem(theme->get_part(PART_SELECTION_REPLACE)); addItem(theme->parts.selectionReplace());
addItem(theme->get_part(PART_SELECTION_ADD)); addItem(theme->parts.selectionAdd());
addItem(theme->get_part(PART_SELECTION_SUBTRACT)); addItem(theme->parts.selectionSubtract());
setSelectedItem((int)Preferences::instance().selection.mode()); setSelectedItem((int)Preferences::instance().selection.mode());
} }
@ -893,8 +906,8 @@ public:
DropPixelsField() : ButtonSet(2) { DropPixelsField() : ButtonSet(2) {
SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
addItem(theme->get_part(PART_DROP_PIXELS_OK)); addItem(theme->parts.dropPixelsOk());
addItem(theme->get_part(PART_DROP_PIXELS_CANCEL)); addItem(theme->parts.dropPixelsCancel());
setOfferCapture(false); setOfferCapture(false);
} }

View File

@ -27,6 +27,8 @@ DropDownButton::DropDownButton(const char* text)
, m_button(new Button(text)) , m_button(new Button(text))
, m_dropDown(new Button("")) , m_dropDown(new Button(""))
{ {
SkinTheme* theme = SkinTheme::instance();
setup_look(m_button, LeftButtonLook); setup_look(m_button, LeftButtonLook);
setup_look(m_dropDown, RightButtonLook); setup_look(m_dropDown, RightButtonLook);
@ -41,10 +43,9 @@ DropDownButton::DropDownButton(const char* text)
setChildSpacing(0); setChildSpacing(0);
m_dropDown->setIconInterface m_dropDown->setIconInterface
(new ButtonIconImpl(static_cast<SkinTheme*>(m_dropDown->getTheme()), (new ButtonIconImpl(theme->parts.comboboxArrowDown(),
PART_COMBOBOX_ARROW_DOWN, theme->parts.comboboxArrowDownSelected(),
PART_COMBOBOX_ARROW_DOWN_SELECTED, theme->parts.comboboxArrowDownDisabled(),
PART_COMBOBOX_ARROW_DOWN_DISABLED,
CENTER | MIDDLE)); CENTER | MIDDLE));
} }

View File

@ -41,10 +41,10 @@ EditorView::EditorView(EditorView::Type type)
, m_type(type) , m_type(type)
{ {
SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
int l = theme->get_part(PART_EDITOR_SELECTED_W)->width(); int l = theme->parts.editorSelected()->getBitmapW()->width();
int t = theme->get_part(PART_EDITOR_SELECTED_N)->height(); int t = theme->parts.editorSelected()->getBitmapN()->height();
int r = theme->get_part(PART_EDITOR_SELECTED_E)->width(); int r = theme->parts.editorSelected()->getBitmapE()->width();
int b = theme->get_part(PART_EDITOR_SELECTED_S)->height(); int b = theme->parts.editorSelected()->getBitmapS()->height();
setBorder(gfx::Border(l, t, r, b)); setBorder(gfx::Border(l, t, r, b));
setBgColor(gfx::rgba(0, 0, 0)); setBgColor(gfx::rgba(0, 0, 0));
@ -75,9 +75,11 @@ void EditorView::onPaint(PaintEvent& ev)
} }
theme->draw_bounds_nw(g, getClientBounds(), theme->drawRect(
selected ? PART_EDITOR_SELECTED_NW: g, getClientBounds(),
PART_EDITOR_NORMAL_NW, (selected ?
theme->parts.editorSelected().get():
theme->parts.editorNormal().get()),
getBgColor()); getBgColor());
} }

View File

@ -55,7 +55,7 @@ static struct HandlesInfo {
HandleType TransformHandles::getHandleAtPoint(Editor* editor, const gfx::Point& pt, const gfx::Transformation& transform) HandleType TransformHandles::getHandleAtPoint(Editor* editor, const gfx::Point& pt, const gfx::Transformation& transform)
{ {
SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get()); SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get());
she::Surface* gfx = theme->get_part(PART_TRANSFORMATION_HANDLE); she::Surface* gfx = theme->parts.transformationHandle()->getBitmap(0);
fixmath::fixed angle = fixmath::ftofix(128.0 * transform.angle() / PI); fixmath::fixed angle = fixmath::ftofix(128.0 * transform.angle() / PI);
gfx::Transformation::Corners corners; gfx::Transformation::Corners corners;
@ -130,7 +130,7 @@ void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& tr
if (visiblePivot(angle)) { if (visiblePivot(angle)) {
gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners); gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners);
SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get()); SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get());
she::Surface* part = theme->get_part(PART_PIVOT_HANDLE); she::Surface* part = theme->parts.pivotHandle()->getBitmap(0);
g.drawRgbaSurface(part, pivotBounds.x, pivotBounds.y); g.drawRgbaSurface(part, pivotBounds.x, pivotBounds.y);
} }
@ -151,7 +151,7 @@ void TransformHandles::invalidateHandles(Editor* editor, const gfx::Transformati
// Invalidate each corner handle. // Invalidate each corner handle.
for (size_t c=0; c<HANDLES; ++c) { for (size_t c=0; c<HANDLES; ++c) {
she::Surface* part = theme->get_part(PART_TRANSFORMATION_HANDLE); she::Surface* part = theme->parts.transformationHandle()->getBitmap(0);
int u = (screenPoints[handles_info[c].i1].x+screenPoints[handles_info[c].i2].x)/2; int u = (screenPoints[handles_info[c].i1].x+screenPoints[handles_info[c].i2].x)/2;
int v = (screenPoints[handles_info[c].i1].y+screenPoints[handles_info[c].i2].y)/2; int v = (screenPoints[handles_info[c].i1].y+screenPoints[handles_info[c].i2].y)/2;
@ -163,7 +163,7 @@ void TransformHandles::invalidateHandles(Editor* editor, const gfx::Transformati
// Invalidate area where the pivot is. // Invalidate area where the pivot is.
if (visiblePivot(angle)) { if (visiblePivot(angle)) {
gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners); gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners);
she::Surface* part = theme->get_part(PART_PIVOT_HANDLE); she::Surface* part = theme->parts.pivotHandle()->getBitmap(0);
editor->invalidateRect( editor->invalidateRect(
gfx::Rect(pivotBounds.x, pivotBounds.y, gfx::Rect(pivotBounds.x, pivotBounds.y,
@ -176,17 +176,17 @@ gfx::Rect TransformHandles::getPivotHandleBounds(Editor* editor,
const gfx::Transformation::Corners& corners) const gfx::Transformation::Corners& corners)
{ {
SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get()); SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get());
she::Surface* part = theme->get_part(PART_PIVOT_HANDLE); gfx::Size partSize = theme->parts.pivotHandle()->getSize();
gfx::Point screenPivotPos = editor->editorToScreen(transform.pivot()); gfx::Point screenPivotPos = editor->editorToScreen(transform.pivot());
screenPivotPos.x += editor->zoom().apply(1) / 2; screenPivotPos.x += editor->zoom().apply(1) / 2;
screenPivotPos.y += editor->zoom().apply(1) / 2; screenPivotPos.y += editor->zoom().apply(1) / 2;
return gfx::Rect( return gfx::Rect(
screenPivotPos.x-part->width()/2, screenPivotPos.x-partSize.w/2,
screenPivotPos.y-part->height()/2, screenPivotPos.y-partSize.h/2,
part->width(), partSize.w,
part->height()); partSize.h);
} }
bool TransformHandles::inHandle(const gfx::Point& pt, int x, int y, int gfx_w, int gfx_h, fixmath::fixed angle) bool TransformHandles::inHandle(const gfx::Point& pt, int x, int y, int gfx_w, int gfx_h, fixmath::fixed angle)
@ -200,7 +200,7 @@ bool TransformHandles::inHandle(const gfx::Point& pt, int x, int y, int gfx_w, i
void TransformHandles::drawHandle(Graphics* g, int x, int y, fixmath::fixed angle) void TransformHandles::drawHandle(Graphics* g, int x, int y, fixmath::fixed angle)
{ {
SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get()); SkinTheme* theme = static_cast<SkinTheme*>(CurrentTheme::get());
she::Surface* part = theme->get_part(PART_TRANSFORMATION_HANDLE); she::Surface* part = theme->parts.transformationHandle()->getBitmap(0);
adjustHandle(x, y, part->width(), part->height(), angle); adjustHandle(x, y, part->width(), part->height(), angle);

View File

@ -21,7 +21,8 @@
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/recent_files.h" #include "app/recent_files.h"
#include "app/ui/file_list.h" #include "app/ui/file_list.h"
#include "app/ui/skin/skin_parts.h" #include "app/ui/skin/button_icon_impl.h"
#include "app/ui/skin/skin_theme.h"
#include "app/widget_loader.h" #include "app/widget_loader.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/convert_to.h" #include "base/convert_to.h"
@ -239,6 +240,7 @@ FileSelector::FileSelector(FileSelectorType type, FileSelectorDelegate* delegate
, m_delegate(delegate) , m_delegate(delegate)
, m_navigationLocked(false) , m_navigationLocked(false)
{ {
SkinTheme* theme = SkinTheme::instance();
bool withResizeOptions = (delegate && delegate->hasResizeCombobox()); bool withResizeOptions = (delegate && delegate->hasResizeCombobox());
addChild(new ArrowNavigator(this)); addChild(new ArrowNavigator(this));
@ -252,26 +254,26 @@ FileSelector::FileSelector(FileSelectorType type, FileSelectorDelegate* delegate
goUpButton()->setFocusStop(false); goUpButton()->setFocusStop(false);
newFolderButton()->setFocusStop(false); newFolderButton()->setFocusStop(false);
set_gfxicon_to_button(goBackButton(), goBackButton()->setIconInterface(
PART_COMBOBOX_ARROW_LEFT, new ButtonIconImpl(theme->parts.comboboxArrowLeft(),
PART_COMBOBOX_ARROW_LEFT_SELECTED, theme->parts.comboboxArrowLeftSelected(),
PART_COMBOBOX_ARROW_LEFT_DISABLED, theme->parts.comboboxArrowLeftDisabled(),
CENTER | MIDDLE); CENTER | MIDDLE));
set_gfxicon_to_button(goForwardButton(), goForwardButton()->setIconInterface(
PART_COMBOBOX_ARROW_RIGHT, new ButtonIconImpl(theme->parts.comboboxArrowRight(),
PART_COMBOBOX_ARROW_RIGHT_SELECTED, theme->parts.comboboxArrowRightSelected(),
PART_COMBOBOX_ARROW_RIGHT_DISABLED, theme->parts.comboboxArrowRightDisabled(),
CENTER | MIDDLE); CENTER | MIDDLE));
set_gfxicon_to_button(goUpButton(), goUpButton()->setIconInterface(
PART_COMBOBOX_ARROW_UP, new ButtonIconImpl(theme->parts.comboboxArrowUp(),
PART_COMBOBOX_ARROW_UP_SELECTED, theme->parts.comboboxArrowUpSelected(),
PART_COMBOBOX_ARROW_UP_DISABLED, theme->parts.comboboxArrowUpDisabled(),
CENTER | MIDDLE); CENTER | MIDDLE));
set_gfxicon_to_button(newFolderButton(), newFolderButton()->setIconInterface(
PART_NEWFOLDER, new ButtonIconImpl(theme->parts.newfolder(),
PART_NEWFOLDER_SELECTED, theme->parts.newfolderSelected(),
PART_NEWFOLDER, theme->parts.newfolder(),
CENTER | MIDDLE); CENTER | MIDDLE));
setup_mini_look(goBackButton()); setup_mini_look(goBackButton());
setup_mini_look(goForwardButton()); setup_mini_look(goForwardButton());

View File

@ -13,6 +13,7 @@
#include "app/modules/gfx.h" #include "app/modules/gfx.h"
#include "app/modules/gui.h" #include "app/modules/gui.h"
#include "app/ui/skin/button_icon_impl.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "base/bind.h" #include "base/bind.h"
#include "gfx/border.h" #include "gfx/border.h"
@ -30,14 +31,18 @@ PopupWindowPin::PopupWindowPin(const std::string& text, ClickBehavior clickBehav
: PopupWindow(text, clickBehavior) : PopupWindow(text, clickBehavior)
, m_pin("") , m_pin("")
{ {
SkinTheme* theme = SkinTheme::instance();
// Configure the micro check-box look without borders, only the "pin" icon is shown. // Configure the micro check-box look without borders, only the "pin" icon is shown.
setup_look(&m_pin, WithoutBordersLook); setup_look(&m_pin, WithoutBordersLook);
m_pin.setChildSpacing(0); m_pin.setChildSpacing(0);
m_pin.setBorder(gfx::Border(0)); m_pin.setBorder(gfx::Border(0));
m_pin.Click.connect(&PopupWindowPin::onPinClick, this); m_pin.Click.connect(&PopupWindowPin::onPinClick, this);
m_pin.setIconInterface(
set_gfxicon_to_button(&m_pin, PART_UNPINNED, PART_PINNED, PART_UNPINNED, CENTER | MIDDLE); new ButtonIconImpl(theme->parts.unpinned(),
theme->parts.pinned(),
theme->parts.unpinned(),
CENTER | MIDDLE));
} }
void PopupWindowPin::onPinClick(Event& ev) void PopupWindowPin::onPinClick(Event& ev)

View File

@ -46,9 +46,9 @@ class MiniCenterButton : public SkinButton<CheckBox> {
public: public:
MiniCenterButton() MiniCenterButton()
: SkinButton<CheckBox>( : SkinButton<CheckBox>(
PART_WINDOW_CENTER_BUTTON_NORMAL, SkinTheme::instance()->parts.windowCenterButtonNormal(),
PART_WINDOW_CENTER_BUTTON_HOT, SkinTheme::instance()->parts.windowCenterButtonHot(),
PART_WINDOW_CENTER_BUTTON_SELECTED) SkinTheme::instance()->parts.windowCenterButtonSelected())
{ {
setup_bevels(this, 0, 0, 0, 0); setup_bevels(this, 0, 0, 0, 0);
setDecorative(true); setDecorative(true);
@ -56,13 +56,12 @@ public:
} }
protected: protected:
void onSetDecorativeWidgetBounds() override void onSetDecorativeWidgetBounds() override {
{
SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
Widget* window = getParent(); Widget* window = getParent();
gfx::Rect rect(0, 0, 0, 0); gfx::Rect rect(0, 0, 0, 0);
gfx::Size iconSize = theme->get_part_size(PART_WINDOW_PLAY_BUTTON_NORMAL); gfx::Size iconSize = theme->parts.windowPlayButtonNormal()->getSize();
gfx::Size closeSize = theme->get_part_size(PART_WINDOW_CLOSE_BUTTON_NORMAL); gfx::Size closeSize = theme->parts.windowCloseButtonNormal()->getSize();
rect.w = iconSize.w; rect.w = iconSize.w;
rect.h = iconSize.h; rect.h = iconSize.h;
@ -91,11 +90,11 @@ protected:
class MiniPlayButton : public SkinButton<Button> { class MiniPlayButton : public SkinButton<Button> {
public: public:
MiniPlayButton() MiniPlayButton()
: SkinButton<Button>(PART_WINDOW_PLAY_BUTTON_NORMAL, : SkinButton<Button>(SkinPartPtr(nullptr),
PART_WINDOW_PLAY_BUTTON_HOT, SkinPartPtr(nullptr),
PART_WINDOW_PLAY_BUTTON_SELECTED) SkinPartPtr(nullptr))
, m_isPlaying(false) , m_isPlaying(false) {
{ setupIcons();
setup_bevels(this, 0, 0, 0, 0); setup_bevels(this, 0, 0, 0, 0);
setDecorative(true); setDecorative(true);
} }
@ -104,29 +103,21 @@ public:
Signal0<void> Popup; Signal0<void> Popup;
protected: private:
void onClick(Event& ev) override
{ void onClick(Event& ev) override {
m_isPlaying = !m_isPlaying; m_isPlaying = !m_isPlaying;
if (m_isPlaying) setupIcons();
setParts(PART_WINDOW_STOP_BUTTON_NORMAL,
PART_WINDOW_STOP_BUTTON_HOT,
PART_WINDOW_STOP_BUTTON_SELECTED);
else
setParts(PART_WINDOW_PLAY_BUTTON_NORMAL,
PART_WINDOW_PLAY_BUTTON_HOT,
PART_WINDOW_PLAY_BUTTON_SELECTED);
SkinButton<Button>::onClick(ev); SkinButton<Button>::onClick(ev);
} }
void onSetDecorativeWidgetBounds() override void onSetDecorativeWidgetBounds() override {
{
SkinTheme* theme = static_cast<SkinTheme*>(getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
Widget* window = getParent(); Widget* window = getParent();
gfx::Rect rect(0, 0, 0, 0); gfx::Rect rect(0, 0, 0, 0);
gfx::Size playSize = theme->get_part_size(PART_WINDOW_PLAY_BUTTON_NORMAL); gfx::Size playSize = theme->parts.windowPlayButtonNormal()->getSize();
gfx::Size closeSize = theme->get_part_size(PART_WINDOW_CLOSE_BUTTON_NORMAL); gfx::Size closeSize = theme->parts.windowCloseButtonNormal()->getSize();
rect.w = playSize.w; rect.w = playSize.w;
rect.h = playSize.h; rect.h = playSize.h;
@ -138,8 +129,7 @@ protected:
setBounds(rect); setBounds(rect);
} }
bool onProcessMessage(Message* msg) override bool onProcessMessage(Message* msg) override {
{
switch (msg->type()) { switch (msg->type()) {
case kSetCursorMessage: case kSetCursorMessage:
@ -164,7 +154,19 @@ protected:
return SkinButton<Button>::onProcessMessage(msg); return SkinButton<Button>::onProcessMessage(msg);
} }
private: void setupIcons() {
SkinTheme* theme = SkinTheme::instance();
if (m_isPlaying)
setParts(theme->parts.windowStopButtonNormal(),
theme->parts.windowStopButtonHot(),
theme->parts.windowStopButtonSelected());
else
setParts(theme->parts.windowPlayButtonNormal(),
theme->parts.windowPlayButtonHot(),
theme->parts.windowPlayButtonSelected());
}
bool m_isPlaying; bool m_isPlaying;
}; };

View File

@ -18,18 +18,15 @@ namespace app {
using namespace app::skin; using namespace app::skin;
ButtonIconImpl::ButtonIconImpl(SkinTheme* theme, ButtonIconImpl::ButtonIconImpl(const SkinPartPtr& normalIcon,
int normalIcon, const SkinPartPtr& selectedIcon,
int selectedIcon, const SkinPartPtr& disabledIcon,
int disabledIcon,
int iconAlign) int iconAlign)
: m_theme(theme) : m_normalIcon(normalIcon)
, m_normalIcon(normalIcon)
, m_selectedIcon(selectedIcon) , m_selectedIcon(selectedIcon)
, m_disabledIcon(disabledIcon) , m_disabledIcon(disabledIcon)
, m_iconAlign(iconAlign) , m_iconAlign(iconAlign)
{ {
ASSERT(theme != NULL);
} }
void ButtonIconImpl::destroy() void ButtonIconImpl::destroy()
@ -37,29 +34,24 @@ void ButtonIconImpl::destroy()
delete this; delete this;
} }
int ButtonIconImpl::getWidth() gfx::Size ButtonIconImpl::getSize()
{ {
return m_theme->get_part(m_normalIcon)->width(); return m_normalIcon ? m_normalIcon->getSize(): gfx::Size(0, 0);
}
int ButtonIconImpl::getHeight()
{
return m_theme->get_part(m_normalIcon)->height();
} }
she::Surface* ButtonIconImpl::getNormalIcon() she::Surface* ButtonIconImpl::getNormalIcon()
{ {
return m_theme->get_part(m_normalIcon); return m_normalIcon ? m_normalIcon->getBitmap(0): nullptr;
} }
she::Surface* ButtonIconImpl::getSelectedIcon() she::Surface* ButtonIconImpl::getSelectedIcon()
{ {
return m_theme->get_part(m_selectedIcon); return m_selectedIcon ? m_selectedIcon->getBitmap(0): nullptr;
} }
she::Surface* ButtonIconImpl::getDisabledIcon() she::Surface* ButtonIconImpl::getDisabledIcon()
{ {
return m_theme->get_part(m_disabledIcon); return m_disabledIcon ? m_disabledIcon->getBitmap(0): nullptr;
} }
int ButtonIconImpl::getIconAlign() int ButtonIconImpl::getIconAlign()

View File

@ -9,6 +9,7 @@
#define APP_UI_SKIN_BUTTON_ICON_IMPL_H_INCLUDED #define APP_UI_SKIN_BUTTON_ICON_IMPL_H_INCLUDED
#pragma once #pragma once
#include "app/ui/skin/skin_part.h"
#include "ui/button.h" #include "ui/button.h"
namespace app { namespace app {
@ -18,26 +19,23 @@ namespace app {
class ButtonIconImpl : public ui::IButtonIcon { class ButtonIconImpl : public ui::IButtonIcon {
public: public:
ButtonIconImpl(SkinTheme* theme, ButtonIconImpl(const SkinPartPtr& normalIcon,
int normalIcon, const SkinPartPtr& selectedIcon,
int selectedIcon, const SkinPartPtr& disabledIcon,
int disabledIcon,
int iconAlign); int iconAlign);
// IButtonIcon implementation // IButtonIcon implementation
void destroy(); void destroy();
int getWidth(); gfx::Size getSize();
int getHeight();
she::Surface* getNormalIcon(); she::Surface* getNormalIcon();
she::Surface* getSelectedIcon(); she::Surface* getSelectedIcon();
she::Surface* getDisabledIcon(); she::Surface* getDisabledIcon();
int getIconAlign(); int getIconAlign();
public: public:
SkinTheme* m_theme; SkinPartPtr m_normalIcon;
int m_normalIcon; SkinPartPtr m_selectedIcon;
int m_selectedIcon; SkinPartPtr m_disabledIcon;
int m_disabledIcon;
int m_iconAlign; int m_iconAlign;
}; };

View File

@ -9,7 +9,6 @@
#define APP_UI_SKIN_SKIN_BUTTON_H_INCLUDED #define APP_UI_SKIN_SKIN_BUTTON_H_INCLUDED
#pragma once #pragma once
#include "app/ui/skin/skin_parts.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "ui/button.h" #include "ui/button.h"
#include "ui/graphics.h" #include "ui/graphics.h"
@ -21,9 +20,9 @@ namespace app {
template<typename Base = ui::Button> template<typename Base = ui::Button>
class SkinButton : public Base { class SkinButton : public Base {
public: public:
SkinButton(SkinParts partNormal, SkinButton(const SkinPartPtr& partNormal,
SkinParts partHot, const SkinPartPtr& partHot,
SkinParts partSelected) const SkinPartPtr& partSelected)
: Base("") : Base("")
, m_partNormal(partNormal) , m_partNormal(partNormal)
, m_partHot(partHot) , m_partHot(partHot)
@ -31,9 +30,9 @@ namespace app {
{ {
} }
void setParts(SkinParts partNormal, void setParts(const SkinPartPtr& partNormal,
SkinParts partHot, const SkinPartPtr& partHot,
SkinParts partSelected) { const SkinPartPtr& partSelected) {
m_partNormal = partNormal; m_partNormal = partNormal;
m_partHot = partHot; m_partHot = partHot;
m_partSelected = partSelected; m_partSelected = partSelected;
@ -45,7 +44,7 @@ namespace app {
gfx::Rect bounds(Base::getClientBounds()); gfx::Rect bounds(Base::getClientBounds());
ui::Graphics* g = ev.getGraphics(); ui::Graphics* g = ev.getGraphics();
SkinTheme* theme = static_cast<SkinTheme*>(Base::getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(Base::getTheme());
SkinParts part; SkinPartPtr part;
if (Base::isSelected()) if (Base::isSelected())
part = m_partSelected; part = m_partSelected;
@ -54,13 +53,13 @@ namespace app {
else else
part = m_partNormal; part = m_partNormal;
g->drawRgbaSurface(theme->get_part(part), bounds.x, bounds.y); g->drawRgbaSurface(part->getBitmap(0), bounds.x, bounds.y);
} }
private: private:
SkinParts m_partNormal; SkinPartPtr m_partNormal;
SkinParts m_partHot; SkinPartPtr m_partHot;
SkinParts m_partSelected; SkinPartPtr m_partSelected;
}; };
} // namespace skin } // namespace skin

View File

@ -44,5 +44,14 @@ void SkinPart::setBitmap(std::size_t index, she::Surface* bitmap)
m_bitmaps[index] = bitmap; m_bitmaps[index] = bitmap;
} }
gfx::Size SkinPart::getSize() const
{
if (!m_bitmaps.empty())
return gfx::Size(m_bitmaps[0]->width(),
m_bitmaps[0]->height());
else
return gfx::Size(0, 0);
}
} // namespace skin } // namespace skin
} // namespace app } // namespace app

View File

@ -10,6 +10,7 @@
#pragma once #pragma once
#include "base/shared_ptr.h" #include "base/shared_ptr.h"
#include "gfx/size.h"
#include <vector> #include <vector>
@ -27,8 +28,7 @@ namespace app {
SkinPart(); SkinPart();
~SkinPart(); ~SkinPart();
std::size_t size() const { return m_bitmaps.size(); } std::size_t countBitmaps() const { return m_bitmaps.size(); }
void clear(); void clear();
// It doesn't destroy the previous bitmap in the given "index". // It doesn't destroy the previous bitmap in the given "index".
@ -38,6 +38,17 @@ namespace app {
return (index < m_bitmaps.size() ? m_bitmaps[index]: NULL); return (index < m_bitmaps.size() ? m_bitmaps[index]: NULL);
} }
she::Surface* getBitmapNW() const { return getBitmap(0); }
she::Surface* getBitmapN() const { return getBitmap(1); }
she::Surface* getBitmapNE() const { return getBitmap(2); }
she::Surface* getBitmapE() const { return getBitmap(3); }
she::Surface* getBitmapSE() const { return getBitmap(4); }
she::Surface* getBitmapS() const { return getBitmap(5); }
she::Surface* getBitmapSW() const { return getBitmap(6); }
she::Surface* getBitmapW() const { return getBitmap(7); }
gfx::Size getSize() const;
private: private:
Bitmaps m_bitmaps; Bitmaps m_bitmaps;
}; };

View File

@ -1,203 +0,0 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_UI_SKIN_SKIN_PARTS_H_INCLUDED
#define APP_UI_SKIN_SKIN_PARTS_H_INCLUDED
#pragma once
namespace app {
namespace skin {
#define SKIN_PART_NESW(name) \
name##_NW, \
name##_N, \
name##_NE, \
name##_E, \
name##_SE, \
name##_S, \
name##_SW, \
name##_W
// TODO remove this enum, we use skin::Style now.
// Available parts in the skin sheet
enum SkinParts {
PART_NONE,
PART_RADIO_NORMAL,
PART_RADIO_SELECTED,
PART_RADIO_DISABLED,
PART_CHECK_NORMAL,
PART_CHECK_SELECTED,
PART_CHECK_DISABLED,
SKIN_PART_NESW(PART_CHECK_FOCUS),
SKIN_PART_NESW(PART_RADIO_FOCUS),
SKIN_PART_NESW(PART_BUTTON_NORMAL),
SKIN_PART_NESW(PART_BUTTON_HOT),
SKIN_PART_NESW(PART_BUTTON_FOCUSED),
SKIN_PART_NESW(PART_BUTTON_SELECTED),
SKIN_PART_NESW(PART_SUNKEN_NORMAL),
SKIN_PART_NESW(PART_SUNKEN_FOCUSED),
SKIN_PART_NESW(PART_SUNKEN2_NORMAL),
SKIN_PART_NESW(PART_SUNKEN2_FOCUSED),
SKIN_PART_NESW(PART_SUNKEN_MINI_NORMAL),
SKIN_PART_NESW(PART_SUNKEN_MINI_FOCUSED),
PART_WINDOW_CLOSE_BUTTON_NORMAL,
PART_WINDOW_CLOSE_BUTTON_HOT,
PART_WINDOW_CLOSE_BUTTON_SELECTED,
PART_WINDOW_PLAY_BUTTON_NORMAL,
PART_WINDOW_PLAY_BUTTON_HOT,
PART_WINDOW_PLAY_BUTTON_SELECTED,
PART_WINDOW_STOP_BUTTON_NORMAL,
PART_WINDOW_STOP_BUTTON_HOT,
PART_WINDOW_STOP_BUTTON_SELECTED,
PART_WINDOW_CENTER_BUTTON_NORMAL,
PART_WINDOW_CENTER_BUTTON_HOT,
PART_WINDOW_CENTER_BUTTON_SELECTED,
SKIN_PART_NESW(PART_SLIDER_FULL),
SKIN_PART_NESW(PART_SLIDER_EMPTY),
SKIN_PART_NESW(PART_SLIDER_FULL_FOCUSED),
SKIN_PART_NESW(PART_SLIDER_EMPTY_FOCUSED),
SKIN_PART_NESW(PART_MINI_SLIDER_FULL),
SKIN_PART_NESW(PART_MINI_SLIDER_EMPTY),
SKIN_PART_NESW(PART_MINI_SLIDER_FULL_FOCUSED),
SKIN_PART_NESW(PART_MINI_SLIDER_EMPTY_FOCUSED),
PART_MINI_SLIDER_THUMB,
PART_MINI_SLIDER_THUMB_FOCUSED,
PART_SEPARATOR_HORZ,
PART_SEPARATOR_VERT,
PART_COMBOBOX_ARROW_DOWN,
PART_COMBOBOX_ARROW_DOWN_SELECTED,
PART_COMBOBOX_ARROW_DOWN_DISABLED,
PART_COMBOBOX_ARROW_UP,
PART_COMBOBOX_ARROW_UP_SELECTED,
PART_COMBOBOX_ARROW_UP_DISABLED,
PART_COMBOBOX_ARROW_LEFT,
PART_COMBOBOX_ARROW_LEFT_SELECTED,
PART_COMBOBOX_ARROW_LEFT_DISABLED,
PART_COMBOBOX_ARROW_RIGHT,
PART_COMBOBOX_ARROW_RIGHT_SELECTED,
PART_COMBOBOX_ARROW_RIGHT_DISABLED,
PART_NEWFOLDER,
PART_NEWFOLDER_SELECTED,
SKIN_PART_NESW(PART_TOOLBUTTON_NORMAL),
SKIN_PART_NESW(PART_TOOLBUTTON_HOT),
SKIN_PART_NESW(PART_TOOLBUTTON_LAST),
SKIN_PART_NESW(PART_TOOLBUTTON_PUSHED),
SKIN_PART_NESW(PART_EDITOR_NORMAL),
SKIN_PART_NESW(PART_EDITOR_SELECTED),
SKIN_PART_NESW(PART_COLORBAR_0),
SKIN_PART_NESW(PART_COLORBAR_1),
SKIN_PART_NESW(PART_COLORBAR_2),
SKIN_PART_NESW(PART_COLORBAR_3),
SKIN_PART_NESW(PART_COLORBAR_BORDER_FG),
SKIN_PART_NESW(PART_COLORBAR_BORDER_BG),
SKIN_PART_NESW(PART_COLORBAR_BORDER_HOTFG),
SKIN_PART_NESW(PART_TOOLTIP),
SKIN_PART_NESW(PART_TOOLTIP_ARROW),
PART_ANI_FIRST,
PART_ANI_PREVIOUS,
PART_ANI_PLAY,
PART_ANI_STOP,
PART_ANI_NEXT,
PART_ANI_LAST,
PART_PAL_EDIT,
PART_PAL_SORT,
PART_PAL_PRESETS,
PART_PAL_OPTIONS,
PART_TARGET_ONE,
PART_TARGET_ONE_SELECTED,
PART_TARGET_FRAMES,
PART_TARGET_FRAMES_SELECTED,
PART_TARGET_LAYERS,
PART_TARGET_LAYERS_SELECTED,
PART_TARGET_FRAMES_LAYERS,
PART_TARGET_FRAMES_LAYERS_SELECTED,
PART_SCALE_ARROW_1,
PART_SCALE_ARROW_2,
PART_SCALE_ARROW_3,
PART_ROTATE_ARROW_1,
PART_ROTATE_ARROW_2,
PART_ROTATE_ARROW_3,
PART_SELECTION_REPLACE,
PART_SELECTION_REPLACE_SELECTED,
PART_SELECTION_ADD,
PART_SELECTION_ADD_SELECTED,
PART_SELECTION_SUBTRACT,
PART_SELECTION_SUBTRACT_SELECTED,
PART_UNPINNED,
PART_PINNED,
SKIN_PART_NESW(PART_DROP_DOWN_BUTTON_LEFT_NORMAL),
SKIN_PART_NESW(PART_DROP_DOWN_BUTTON_LEFT_HOT),
SKIN_PART_NESW(PART_DROP_DOWN_BUTTON_LEFT_FOCUSED),
SKIN_PART_NESW(PART_DROP_DOWN_BUTTON_LEFT_SELECTED),
SKIN_PART_NESW(PART_DROP_DOWN_BUTTON_RIGHT_NORMAL),
SKIN_PART_NESW(PART_DROP_DOWN_BUTTON_RIGHT_HOT),
SKIN_PART_NESW(PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED),
SKIN_PART_NESW(PART_DROP_DOWN_BUTTON_RIGHT_SELECTED),
PART_TRANSFORMATION_HANDLE,
PART_PIVOT_HANDLE,
PART_DROP_PIXELS_OK,
PART_DROP_PIXELS_OK_SELECTED,
PART_DROP_PIXELS_CANCEL,
PART_DROP_PIXELS_CANCEL_SELECTED,
PART_FREEHAND_ALGO_DEFAULT,
PART_FREEHAND_ALGO_DEFAULT_SELECTED,
PART_FREEHAND_ALGO_PIXEL_PERFECT,
PART_FREEHAND_ALGO_PIXEL_PERFECT_SELECTED,
PART_FREEHAND_ALGO_DOTS,
PART_FREEHAND_ALGO_DOTS_SELECTED,
PART_INK_DEFAULT,
PART_INK_COPY_COLOR,
PART_INK_LOCK_ALPHA,
PART_SELECTION_OPAQUE,
PART_SELECTION_MASKED,
PART_PIVOT_HIDDEN,
PART_PIVOT_NORTHWEST,
PART_PIVOT_NORTH,
PART_PIVOT_NORTHEAST,
PART_PIVOT_WEST,
PART_PIVOT_CENTER,
PART_PIVOT_EAST,
PART_PIVOT_SOUTHWEST,
PART_PIVOT_SOUTH,
PART_PIVOT_SOUTHEAST,
PARTS
};
} // namespace skin
} // namespace app
#endif

View File

@ -49,8 +49,6 @@ namespace skin {
using namespace gfx; using namespace gfx;
using namespace ui; using namespace ui;
static std::map<std::string, int> sheet_mapping;
const char* SkinTheme::kThemeCloseButtonId = "theme_close_button"; const char* SkinTheme::kThemeCloseButtonId = "theme_close_button";
// Controls the "X" button in a window to close it. // Controls the "X" button in a window to close it.
@ -153,146 +151,6 @@ SkinTheme::SkinTheme()
// Initialize all graphics in NULL (these bitmaps are loaded from the skin) // Initialize all graphics in NULL (these bitmaps are loaded from the skin)
m_sheet = NULL; m_sheet = NULL;
m_part.resize(PARTS, NULL);
sheet_mapping["radio_normal"] = PART_RADIO_NORMAL;
sheet_mapping["radio_selected"] = PART_RADIO_SELECTED;
sheet_mapping["radio_disabled"] = PART_RADIO_DISABLED;
sheet_mapping["check_normal"] = PART_CHECK_NORMAL;
sheet_mapping["check_selected"] = PART_CHECK_SELECTED;
sheet_mapping["check_disabled"] = PART_CHECK_DISABLED;
sheet_mapping["check_focus"] = PART_CHECK_FOCUS_NW;
sheet_mapping["radio_focus"] = PART_RADIO_FOCUS_NW;
sheet_mapping["button_normal"] = PART_BUTTON_NORMAL_NW;
sheet_mapping["button_hot"] = PART_BUTTON_HOT_NW;
sheet_mapping["button_focused"] = PART_BUTTON_FOCUSED_NW;
sheet_mapping["button_selected"] = PART_BUTTON_SELECTED_NW;
sheet_mapping["sunken_normal"] = PART_SUNKEN_NORMAL_NW;
sheet_mapping["sunken_focused"] = PART_SUNKEN_FOCUSED_NW;
sheet_mapping["sunken2_normal"] = PART_SUNKEN2_NORMAL_NW;
sheet_mapping["sunken2_focused"] = PART_SUNKEN2_FOCUSED_NW;
sheet_mapping["sunken_mini_normal"] = PART_SUNKEN_MINI_NORMAL_NW;
sheet_mapping["sunken_mini_focused"] = PART_SUNKEN_MINI_FOCUSED_NW;
sheet_mapping["window_close_button_normal"] = PART_WINDOW_CLOSE_BUTTON_NORMAL;
sheet_mapping["window_close_button_hot"] = PART_WINDOW_CLOSE_BUTTON_HOT;
sheet_mapping["window_close_button_selected"] = PART_WINDOW_CLOSE_BUTTON_SELECTED;
sheet_mapping["window_play_button_normal"] = PART_WINDOW_PLAY_BUTTON_NORMAL;
sheet_mapping["window_play_button_hot"] = PART_WINDOW_PLAY_BUTTON_HOT;
sheet_mapping["window_play_button_selected"] = PART_WINDOW_PLAY_BUTTON_SELECTED;
sheet_mapping["window_stop_button_normal"] = PART_WINDOW_STOP_BUTTON_NORMAL;
sheet_mapping["window_stop_button_hot"] = PART_WINDOW_STOP_BUTTON_HOT;
sheet_mapping["window_stop_button_selected"] = PART_WINDOW_STOP_BUTTON_SELECTED;
sheet_mapping["window_center_button_normal"] = PART_WINDOW_CENTER_BUTTON_NORMAL;
sheet_mapping["window_center_button_hot"] = PART_WINDOW_CENTER_BUTTON_HOT;
sheet_mapping["window_center_button_selected"] = PART_WINDOW_CENTER_BUTTON_SELECTED;
sheet_mapping["slider_full"] = PART_SLIDER_FULL_NW;
sheet_mapping["slider_empty"] = PART_SLIDER_EMPTY_NW;
sheet_mapping["slider_full_focused"] = PART_SLIDER_FULL_FOCUSED_NW;
sheet_mapping["slider_empty_focused"] = PART_SLIDER_EMPTY_FOCUSED_NW;
sheet_mapping["mini_slider_full"] = PART_MINI_SLIDER_FULL_NW;
sheet_mapping["mini_slider_empty"] = PART_MINI_SLIDER_EMPTY_NW;
sheet_mapping["mini_slider_full_focused"] = PART_MINI_SLIDER_FULL_FOCUSED_NW;
sheet_mapping["mini_slider_empty_focused"] = PART_MINI_SLIDER_EMPTY_FOCUSED_NW;
sheet_mapping["mini_slider_thumb"] = PART_MINI_SLIDER_THUMB;
sheet_mapping["mini_slider_thumb_focused"] = PART_MINI_SLIDER_THUMB_FOCUSED;
sheet_mapping["separator_horz"] = PART_SEPARATOR_HORZ;
sheet_mapping["separator_vert"] = PART_SEPARATOR_VERT;
sheet_mapping["combobox_arrow_down"] = PART_COMBOBOX_ARROW_DOWN;
sheet_mapping["combobox_arrow_down_selected"] = PART_COMBOBOX_ARROW_DOWN_SELECTED;
sheet_mapping["combobox_arrow_down_disabled"] = PART_COMBOBOX_ARROW_DOWN_DISABLED;
sheet_mapping["combobox_arrow_up"] = PART_COMBOBOX_ARROW_UP;
sheet_mapping["combobox_arrow_up_selected"] = PART_COMBOBOX_ARROW_UP_SELECTED;
sheet_mapping["combobox_arrow_up_disabled"] = PART_COMBOBOX_ARROW_UP_DISABLED;
sheet_mapping["combobox_arrow_left"] = PART_COMBOBOX_ARROW_LEFT;
sheet_mapping["combobox_arrow_left_selected"] = PART_COMBOBOX_ARROW_LEFT_SELECTED;
sheet_mapping["combobox_arrow_left_disabled"] = PART_COMBOBOX_ARROW_LEFT_DISABLED;
sheet_mapping["combobox_arrow_right"] = PART_COMBOBOX_ARROW_RIGHT;
sheet_mapping["combobox_arrow_right_selected"] = PART_COMBOBOX_ARROW_RIGHT_SELECTED;
sheet_mapping["combobox_arrow_right_disabled"] = PART_COMBOBOX_ARROW_RIGHT_DISABLED;
sheet_mapping["newfolder"] = PART_NEWFOLDER;
sheet_mapping["newfolder_selected"] = PART_NEWFOLDER_SELECTED;
sheet_mapping["toolbutton_normal"] = PART_TOOLBUTTON_NORMAL_NW;
sheet_mapping["toolbutton_hot"] = PART_TOOLBUTTON_HOT_NW;
sheet_mapping["toolbutton_last"] = PART_TOOLBUTTON_LAST_NW;
sheet_mapping["toolbutton_pushed"] = PART_TOOLBUTTON_PUSHED_NW;
sheet_mapping["editor_normal"] = PART_EDITOR_NORMAL_NW;
sheet_mapping["editor_selected"] = PART_EDITOR_SELECTED_NW;
sheet_mapping["colorbar_0"] = PART_COLORBAR_0_NW;
sheet_mapping["colorbar_1"] = PART_COLORBAR_1_NW;
sheet_mapping["colorbar_2"] = PART_COLORBAR_2_NW;
sheet_mapping["colorbar_3"] = PART_COLORBAR_3_NW;
sheet_mapping["colorbar_border_fg"] = PART_COLORBAR_BORDER_FG_NW;
sheet_mapping["colorbar_border_bg"] = PART_COLORBAR_BORDER_BG_NW;
sheet_mapping["colorbar_border_hotfg"] = PART_COLORBAR_BORDER_HOTFG_NW;
sheet_mapping["tooltip"] = PART_TOOLTIP_NW;
sheet_mapping["tooltip_arrow"] = PART_TOOLTIP_ARROW_NW;
sheet_mapping["ani_first"] = PART_ANI_FIRST;
sheet_mapping["ani_previous"] = PART_ANI_PREVIOUS;
sheet_mapping["ani_play"] = PART_ANI_PLAY;
sheet_mapping["ani_stop"] = PART_ANI_STOP;
sheet_mapping["ani_next"] = PART_ANI_NEXT;
sheet_mapping["ani_last"] = PART_ANI_LAST;
sheet_mapping["pal_edit"] = PART_PAL_EDIT;
sheet_mapping["pal_sort"] = PART_PAL_SORT;
sheet_mapping["pal_presets"] = PART_PAL_PRESETS;
sheet_mapping["pal_options"] = PART_PAL_OPTIONS;
sheet_mapping["target_one"] = PART_TARGET_ONE;
sheet_mapping["target_one_selected"] = PART_TARGET_ONE_SELECTED;
sheet_mapping["target_frames"] = PART_TARGET_FRAMES;
sheet_mapping["target_frames_selected"] = PART_TARGET_FRAMES_SELECTED;
sheet_mapping["target_layers"] = PART_TARGET_LAYERS;
sheet_mapping["target_layers_selected"] = PART_TARGET_LAYERS_SELECTED;
sheet_mapping["target_frames_layers"] = PART_TARGET_FRAMES_LAYERS;
sheet_mapping["target_frames_layers_selected"] = PART_TARGET_FRAMES_LAYERS_SELECTED;
sheet_mapping["scale_arrow_1"] = PART_SCALE_ARROW_1;
sheet_mapping["scale_arrow_2"] = PART_SCALE_ARROW_2;
sheet_mapping["scale_arrow_3"] = PART_SCALE_ARROW_3;
sheet_mapping["rotate_arrow_1"] = PART_ROTATE_ARROW_1;
sheet_mapping["rotate_arrow_2"] = PART_ROTATE_ARROW_2;
sheet_mapping["rotate_arrow_3"] = PART_ROTATE_ARROW_3;
sheet_mapping["selection_replace"] = PART_SELECTION_REPLACE;
sheet_mapping["selection_replace_selected"] = PART_SELECTION_REPLACE_SELECTED;
sheet_mapping["selection_add"] = PART_SELECTION_ADD;
sheet_mapping["selection_add_selected"] = PART_SELECTION_ADD_SELECTED;
sheet_mapping["selection_subtract"] = PART_SELECTION_SUBTRACT;
sheet_mapping["selection_subtract_selected"] = PART_SELECTION_SUBTRACT_SELECTED;
sheet_mapping["unpinned"] = PART_UNPINNED;
sheet_mapping["pinned"] = PART_PINNED;
sheet_mapping["drop_down_button_left_normal"] = PART_DROP_DOWN_BUTTON_LEFT_NORMAL_NW;
sheet_mapping["drop_down_button_left_hot"] = PART_DROP_DOWN_BUTTON_LEFT_HOT_NW;
sheet_mapping["drop_down_button_left_focused"] = PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_NW;
sheet_mapping["drop_down_button_left_selected"] = PART_DROP_DOWN_BUTTON_LEFT_SELECTED_NW;
sheet_mapping["drop_down_button_right_normal"] = PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_NW;
sheet_mapping["drop_down_button_right_hot"] = PART_DROP_DOWN_BUTTON_RIGHT_HOT_NW;
sheet_mapping["drop_down_button_right_focused"] = PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_NW;
sheet_mapping["drop_down_button_right_selected"] = PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_NW;
sheet_mapping["transformation_handle"] = PART_TRANSFORMATION_HANDLE;
sheet_mapping["pivot_handle"] = PART_PIVOT_HANDLE;
sheet_mapping["drop_pixels_ok"] = PART_DROP_PIXELS_OK;
sheet_mapping["drop_pixels_ok_selected"] = PART_DROP_PIXELS_OK_SELECTED;
sheet_mapping["drop_pixels_cancel"] = PART_DROP_PIXELS_CANCEL;
sheet_mapping["drop_pixels_cancel_selected"] = PART_DROP_PIXELS_CANCEL_SELECTED;
sheet_mapping["freehand_algo_default"] = PART_FREEHAND_ALGO_DEFAULT;
sheet_mapping["freehand_algo_default_selected"] = PART_FREEHAND_ALGO_DEFAULT_SELECTED;
sheet_mapping["freehand_algo_pixel_perfect"] = PART_FREEHAND_ALGO_PIXEL_PERFECT;
sheet_mapping["freehand_algo_pixel_perfect_selected"] = PART_FREEHAND_ALGO_PIXEL_PERFECT_SELECTED;
sheet_mapping["freehand_algo_dots"] = PART_FREEHAND_ALGO_DOTS;
sheet_mapping["freehand_algo_dots_selected"] = PART_FREEHAND_ALGO_DOTS_SELECTED;
sheet_mapping["ink_default"] = PART_INK_DEFAULT;
sheet_mapping["ink_copy_color"] = PART_INK_COPY_COLOR;
sheet_mapping["ink_lock_alpha"] = PART_INK_LOCK_ALPHA;
sheet_mapping["selection_opaque"] = PART_SELECTION_OPAQUE;
sheet_mapping["selection_masked"] = PART_SELECTION_MASKED;
sheet_mapping["pivot_hidden"] = PART_PIVOT_HIDDEN;
sheet_mapping["pivot_northwest"] = PART_PIVOT_NORTHWEST;
sheet_mapping["pivot_north"] = PART_PIVOT_NORTH;
sheet_mapping["pivot_northeast"] = PART_PIVOT_NORTHEAST;
sheet_mapping["pivot_west"] = PART_PIVOT_WEST;
sheet_mapping["pivot_center"] = PART_PIVOT_CENTER;
sheet_mapping["pivot_east"] = PART_PIVOT_EAST;
sheet_mapping["pivot_southwest"] = PART_PIVOT_SOUTHWEST;
sheet_mapping["pivot_south"] = PART_PIVOT_SOUTH;
sheet_mapping["pivot_southeast"] = PART_PIVOT_SOUTHEAST;
} }
SkinTheme::~SkinTheme() SkinTheme::~SkinTheme()
@ -309,9 +167,7 @@ SkinTheme::~SkinTheme()
if (m_sheet) if (m_sheet)
m_sheet->dispose(); m_sheet->dispose();
m_part.clear();
m_parts_by_id.clear(); m_parts_by_id.clear();
sheet_mapping.clear();
// Destroy fonts // Destroy fonts
if (m_defaultFont) if (m_defaultFont)
@ -357,13 +213,6 @@ void SkinTheme::loadFonts()
m_miniFont = loadFont("UserMiniFont", "skins/" + m_selected_skin + "/minifont.png"); m_miniFont = loadFont("UserMiniFont", "skins/" + m_selected_skin + "/minifont.png");
} }
gfx::Size SkinTheme::get_part_size(int part_i) const
{
she::Surface* bmp = get_part(part_i);
ASSERT(bmp);
return gfx::Size(bmp->width(), bmp->height());
}
void SkinTheme::onRegenerate() void SkinTheme::onRegenerate()
{ {
loadSheet(); loadSheet();
@ -371,9 +220,6 @@ void SkinTheme::onRegenerate()
scrollbar_size = 12 * guiscale(); scrollbar_size = 12 * guiscale();
m_part.clear();
m_part.resize(PARTS, NULL);
// Load the skin XML // Load the skin XML
std::string xml_filename = "skins/" + m_selected_skin + "/skin.xml"; std::string xml_filename = "skins/" + m_selected_skin + "/skin.xml";
ResourceFinder rf; ResourceFinder rf;
@ -529,15 +375,6 @@ void SkinTheme::onRegenerate()
part->setBitmap(7, sliceSheet(part->getBitmap(7), gfx::Rect(x, y+h1, w1, h2))); // W part->setBitmap(7, sliceSheet(part->getBitmap(7), gfx::Rect(x, y+h1, w1, h2))); // W
} }
// Prepare the m_part vector (which is used for backward
// compatibility for widgets that doesn't use SkinStyle).
std::map<std::string, int>::iterator it = sheet_mapping.find(part_id);
if (it != sheet_mapping.end()) {
int c = it->second;
for (size_t i=0; i<part->size(); ++i)
m_part[c+i] = part->getBitmap(i);
}
xmlPart = xmlPart->NextSiblingElement(); xmlPart = xmlPart->NextSiblingElement();
} }
} }
@ -690,10 +527,10 @@ void SkinTheme::initWidget(Widget* widget)
case kButtonWidget: case kButtonWidget:
BORDER4( BORDER4(
m_part[PART_BUTTON_NORMAL_W]->width(), parts.buttonNormal()->getBitmapW()->width(),
m_part[PART_BUTTON_NORMAL_N]->height(), parts.buttonNormal()->getBitmapN()->height(),
m_part[PART_BUTTON_NORMAL_E]->width(), parts.buttonNormal()->getBitmapE()->width(),
m_part[PART_BUTTON_NORMAL_S]->height()); parts.buttonNormal()->getBitmapS()->height());
widget->setChildSpacing(0); widget->setChildSpacing(0);
break; break;
@ -702,19 +539,18 @@ void SkinTheme::initWidget(Widget* widget)
widget->setChildSpacing(4 * scale); widget->setChildSpacing(4 * scale);
static_cast<ButtonBase*>(widget)->setIconInterface static_cast<ButtonBase*>(widget)->setIconInterface
(new ButtonIconImpl(static_cast<SkinTheme*>(widget->getTheme()), (new ButtonIconImpl(parts.checkNormal(),
PART_CHECK_NORMAL, parts.checkSelected(),
PART_CHECK_SELECTED, parts.checkDisabled(),
PART_CHECK_DISABLED,
LEFT | MIDDLE)); LEFT | MIDDLE));
break; break;
case kEntryWidget: case kEntryWidget:
BORDER4( BORDER4(
m_part[PART_SUNKEN_NORMAL_W]->width(), parts.sunkenNormal()->getBitmapW()->width(),
m_part[PART_SUNKEN_NORMAL_N]->height(), parts.sunkenNormal()->getBitmapN()->height(),
m_part[PART_SUNKEN_NORMAL_E]->width(), parts.sunkenNormal()->getBitmapE()->width(),
m_part[PART_SUNKEN_NORMAL_S]->height()); parts.sunkenNormal()->getBitmapS()->height());
break; break;
case kGridWidget: case kGridWidget:
@ -748,10 +584,9 @@ void SkinTheme::initWidget(Widget* widget)
16 * guiscale())); 16 * guiscale()));
static_cast<ButtonBase*>(button)->setIconInterface static_cast<ButtonBase*>(button)->setIconInterface
(new ButtonIconImpl(static_cast<SkinTheme*>(button->getTheme()), (new ButtonIconImpl(parts.comboboxArrowDown(),
PART_COMBOBOX_ARROW_DOWN, parts.comboboxArrowDownSelected(),
PART_COMBOBOX_ARROW_DOWN_SELECTED, parts.comboboxArrowDownDisabled(),
PART_COMBOBOX_ARROW_DOWN_DISABLED,
CENTER | MIDDLE)); CENTER | MIDDLE));
} }
break; break;
@ -778,10 +613,9 @@ void SkinTheme::initWidget(Widget* widget)
widget->setChildSpacing(4 * scale); widget->setChildSpacing(4 * scale);
static_cast<ButtonBase*>(widget)->setIconInterface static_cast<ButtonBase*>(widget)->setIconInterface
(new ButtonIconImpl(static_cast<SkinTheme*>(widget->getTheme()), (new ButtonIconImpl(parts.radioNormal(),
PART_RADIO_NORMAL, parts.radioSelected(),
PART_RADIO_SELECTED, parts.radioDisabled(),
PART_RADIO_DISABLED,
LEFT | MIDDLE)); LEFT | MIDDLE));
break; break;
@ -814,10 +648,10 @@ void SkinTheme::initWidget(Widget* widget)
case kSliderWidget: case kSliderWidget:
BORDER4( BORDER4(
m_part[PART_SLIDER_EMPTY_W]->width()-1*scale, parts.sliderEmpty()->getBitmapW()->width()-1*scale,
m_part[PART_SLIDER_EMPTY_N]->height(), parts.sliderEmpty()->getBitmapN()->height(),
m_part[PART_SLIDER_EMPTY_E]->width()-1*scale, parts.sliderEmpty()->getBitmapE()->width()-1*scale,
m_part[PART_SLIDER_EMPTY_S]->height()-1*scale); parts.sliderEmpty()->getBitmapS()->height()-1*scale);
widget->setChildSpacing(widget->getTextHeight()); widget->setChildSpacing(widget->getTextHeight());
widget->setAlign(CENTER | MIDDLE); widget->setAlign(CENTER | MIDDLE);
break; break;
@ -829,10 +663,10 @@ void SkinTheme::initWidget(Widget* widget)
case kViewWidget: case kViewWidget:
BORDER4( BORDER4(
m_part[PART_SUNKEN_NORMAL_W]->width()-1*scale, parts.sunkenNormal()->getBitmapW()->width()-1*scale,
m_part[PART_SUNKEN_NORMAL_N]->height(), parts.sunkenNormal()->getBitmapN()->height(),
m_part[PART_SUNKEN_NORMAL_E]->width()-1*scale, parts.sunkenNormal()->getBitmapE()->width()-1*scale,
m_part[PART_SUNKEN_NORMAL_S]->height()-1*scale); parts.sunkenNormal()->getBitmapS()->height()-1*scale);
widget->setChildSpacing(0); widget->setChildSpacing(0);
widget->setBgColor(colors.windowFace()); widget->setBgColor(colors.windowFace());
break; break;
@ -885,10 +719,7 @@ void SkinTheme::setDecorativeWidgetBounds(Widget* widget)
{ {
if (widget->getId() == kThemeCloseButtonId) { if (widget->getId() == kThemeCloseButtonId) {
Widget* window = widget->getParent(); Widget* window = widget->getParent();
gfx::Rect rect(0, 0, 0, 0); gfx::Rect rect(parts.windowCloseButtonNormal()->getSize());
rect.w = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->width();
rect.h = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->height();
rect.offset(window->getBounds().x2() - 3*guiscale() - rect.w, rect.offset(window->getBounds().x2() - 3*guiscale() - rect.w,
window->getBounds().y + 3*guiscale()); window->getBounds().y + 3*guiscale());
@ -920,12 +751,12 @@ void SkinTheme::paintButton(PaintEvent& ev)
IButtonIcon* iconInterface = widget->getIconInterface(); IButtonIcon* iconInterface = widget->getIconInterface();
gfx::Rect box, text, icon; gfx::Rect box, text, icon;
gfx::Color fg, bg; gfx::Color fg, bg;
int part_nw; SkinPartPtr part_nw;
widget->getTextIconInfo(&box, &text, &icon, widget->getTextIconInfo(&box, &text, &icon,
iconInterface ? iconInterface->getIconAlign(): 0, iconInterface ? iconInterface->getIconAlign(): 0,
iconInterface ? iconInterface->getWidth() : 0, iconInterface ? iconInterface->getSize().w: 0,
iconInterface ? iconInterface->getHeight() : 0); iconInterface ? iconInterface->getSize().h: 0);
// Tool buttons are smaller // Tool buttons are smaller
LookType look = NormalLook; LookType look = NormalLook;
@ -937,19 +768,19 @@ void SkinTheme::paintButton(PaintEvent& ev)
if (widget->isSelected()) { if (widget->isSelected()) {
fg = colors.buttonSelectedText(); fg = colors.buttonSelectedText();
bg = colors.buttonSelectedFace(); bg = colors.buttonSelectedFace();
part_nw = (look == MiniLook ? PART_TOOLBUTTON_NORMAL_NW: part_nw = (look == MiniLook ? parts.toolbuttonNormal():
look == LeftButtonLook ? PART_DROP_DOWN_BUTTON_LEFT_SELECTED_NW: look == LeftButtonLook ? parts.dropDownButtonLeftSelected():
look == RightButtonLook ? PART_DROP_DOWN_BUTTON_RIGHT_SELECTED_NW: look == RightButtonLook ? parts.dropDownButtonRightSelected():
PART_BUTTON_SELECTED_NW); parts.buttonSelected());
} }
// With mouse // With mouse
else if (widget->isEnabled() && widget->hasMouseOver()) { else if (widget->isEnabled() && widget->hasMouseOver()) {
fg = colors.buttonHotText(); fg = colors.buttonHotText();
bg = colors.buttonHotFace(); bg = colors.buttonHotFace();
part_nw = (look == MiniLook ? PART_TOOLBUTTON_HOT_NW: part_nw = (look == MiniLook ? parts.toolbuttonHot():
look == LeftButtonLook ? PART_DROP_DOWN_BUTTON_LEFT_HOT_NW: look == LeftButtonLook ? parts.dropDownButtonLeftHot():
look == RightButtonLook ? PART_DROP_DOWN_BUTTON_RIGHT_HOT_NW: look == RightButtonLook ? parts.dropDownButtonRightHot():
PART_BUTTON_HOT_NW); parts.buttonHot());
} }
// Without mouse // Without mouse
else { else {
@ -957,22 +788,23 @@ void SkinTheme::paintButton(PaintEvent& ev)
bg = colors.buttonNormalFace(); bg = colors.buttonNormalFace();
if (widget->hasFocus()) if (widget->hasFocus())
part_nw = (look == MiniLook ? PART_TOOLBUTTON_HOT_NW: part_nw = (look == MiniLook ? parts.toolbuttonHot():
look == LeftButtonLook ? PART_DROP_DOWN_BUTTON_LEFT_FOCUSED_NW: look == LeftButtonLook ? parts.dropDownButtonLeftFocused():
look == RightButtonLook ? PART_DROP_DOWN_BUTTON_RIGHT_FOCUSED_NW: look == RightButtonLook ? parts.dropDownButtonRightFocused():
PART_BUTTON_FOCUSED_NW); parts.buttonFocused());
else else
part_nw = (look == MiniLook ? PART_TOOLBUTTON_NORMAL_NW: part_nw = (look == MiniLook ? parts.toolbuttonNormal():
look == LeftButtonLook ? PART_DROP_DOWN_BUTTON_LEFT_NORMAL_NW: look == LeftButtonLook ? parts.dropDownButtonLeftNormal():
look == RightButtonLook ? PART_DROP_DOWN_BUTTON_RIGHT_NORMAL_NW: look == RightButtonLook ? parts.dropDownButtonRightNormal():
PART_BUTTON_NORMAL_NW); parts.buttonNormal());
} }
// external background // external background
g->fillRect(BGCOLOR, g->getClipBounds()); g->fillRect(BGCOLOR, g->getClipBounds());
// draw borders // draw borders
draw_bounds_nw(g, widget->getClientBounds(), part_nw, bg); if (part_nw)
drawRect(g, widget->getClientBounds(), part_nw.get(), bg);
// text // text
drawTextString(g, NULL, fg, ColorNone, widget, drawTextString(g, NULL, fg, ColorNone, widget,
@ -999,8 +831,8 @@ void SkinTheme::paintCheckBox(PaintEvent& ev)
widget->getTextIconInfo(&box, &text, &icon, widget->getTextIconInfo(&box, &text, &icon,
iconInterface ? iconInterface->getIconAlign(): 0, iconInterface ? iconInterface->getIconAlign(): 0,
iconInterface ? iconInterface->getWidth() : 0, iconInterface ? iconInterface->getSize().w: 0,
iconInterface ? iconInterface->getHeight() : 0); iconInterface ? iconInterface->getSize().h: 0);
// Check box look // Check box look
LookType look = NormalLook; LookType look = NormalLook;
@ -1028,7 +860,7 @@ void SkinTheme::paintCheckBox(PaintEvent& ev)
// draw focus // draw focus
if (look != WithoutBordersLook && widget->hasFocus()) if (look != WithoutBordersLook && widget->hasFocus())
draw_bounds_nw(g, bounds, PART_CHECK_FOCUS_NW, gfx::ColorNone); drawRect(g, bounds, parts.checkFocus().get(), gfx::ColorNone);
} }
void SkinTheme::paintGrid(PaintEvent& ev) void SkinTheme::paintGrid(PaintEvent& ev)
@ -1063,10 +895,10 @@ void SkinTheme::paintEntry(PaintEvent& ev)
isMiniLook = (skinPropery->getLook() == MiniLook); isMiniLook = (skinPropery->getLook() == MiniLook);
gfx::Color bg = colors.background(); gfx::Color bg = colors.background();
draw_bounds_nw(g, bounds, drawRect(g, bounds,
(widget->hasFocus() ? (widget->hasFocus() ?
(isMiniLook ? PART_SUNKEN_MINI_FOCUSED_NW: PART_SUNKEN_FOCUSED_NW): (isMiniLook ? parts.sunkenMiniFocused().get(): parts.sunkenFocused().get()):
(isMiniLook ? PART_SUNKEN_MINI_NORMAL_NW : PART_SUNKEN_NORMAL_NW)), (isMiniLook ? parts.sunkenMiniNormal().get() : parts.sunkenNormal().get())),
bg); bg);
// Draw the text // Draw the text
@ -1256,9 +1088,9 @@ void SkinTheme::paintMenuItem(ui::PaintEvent& ev)
// Draw an indicator for selected items // Draw an indicator for selected items
if (widget->isSelected()) { if (widget->isSelected()) {
she::Surface* icon = she::Surface* icon =
m_part[widget->isEnabled() ? (widget->isEnabled() ?
PART_CHECK_SELECTED: parts.checkSelected()->getBitmap(0):
PART_CHECK_DISABLED]; parts.checkDisabled()->getBitmap(0));
int x = bounds.x+4*scale-icon->width()/2; int x = bounds.x+4*scale-icon->width()/2;
int y = bounds.y+bounds.h/2-icon->height()/2; int y = bounds.y+bounds.h/2-icon->height()/2;
@ -1336,8 +1168,8 @@ void SkinTheme::paintRadioButton(PaintEvent& ev)
gfx::Rect box, text, icon; gfx::Rect box, text, icon;
widget->getTextIconInfo(&box, &text, &icon, widget->getTextIconInfo(&box, &text, &icon,
iconInterface ? iconInterface->getIconAlign(): 0, iconInterface ? iconInterface->getIconAlign(): 0,
iconInterface ? iconInterface->getWidth() : 0, iconInterface ? iconInterface->getSize().w: 0,
iconInterface ? iconInterface->getHeight() : 0); iconInterface ? iconInterface->getSize().h: 0);
// Background // Background
g->fillRect(bg, g->getClipBounds()); g->fillRect(bg, g->getClipBounds());
@ -1359,7 +1191,7 @@ void SkinTheme::paintRadioButton(PaintEvent& ev)
// Focus // Focus
if (widget->hasFocus()) if (widget->hasFocus())
draw_bounds_nw(g, bounds, PART_RADIO_FOCUS_NW, gfx::ColorNone); drawRect(g, bounds, parts.radioFocus().get(), gfx::ColorNone);
} }
void SkinTheme::paintSeparator(ui::PaintEvent& ev) void SkinTheme::paintSeparator(ui::PaintEvent& ev)
@ -1372,10 +1204,10 @@ void SkinTheme::paintSeparator(ui::PaintEvent& ev)
g->fillRect(BGCOLOR, bounds); g->fillRect(BGCOLOR, bounds);
if (widget->getAlign() & HORIZONTAL) if (widget->getAlign() & HORIZONTAL)
draw_part_as_hline(g, bounds, PART_SEPARATOR_HORZ); drawHline(g, bounds, parts.separatorHorz().get());
if (widget->getAlign() & VERTICAL) if (widget->getAlign() & VERTICAL)
draw_part_as_vline(g, bounds, PART_SEPARATOR_VERT); drawVline(g, bounds, parts.separatorVert().get());
// text // text
if (widget->hasText()) { if (widget->hasText()) {
@ -1434,10 +1266,10 @@ void SkinTheme::paintSlider(PaintEvent& ev)
// Draw customized background // Draw customized background
if (bgPainter) { if (bgPainter) {
int nw = PART_MINI_SLIDER_EMPTY_NW; SkinPartPtr nw = parts.miniSliderEmpty();
she::Surface* thumb = she::Surface* thumb =
widget->hasFocus() ? m_part[PART_MINI_SLIDER_THUMB_FOCUSED]: (widget->hasFocus() ? parts.miniSliderThumbFocused()->getBitmap(0):
m_part[PART_MINI_SLIDER_THUMB]; parts.miniSliderThumb()->getBitmap(0));
// Draw background // Draw background
g->fillRect(BGCOLOR, rc); g->fillRect(BGCOLOR, rc);
@ -1452,7 +1284,7 @@ void SkinTheme::paintSlider(PaintEvent& ev)
3 * guiscale(), 3 * guiscale(),
1 * guiscale())); 1 * guiscale()));
draw_bounds_nw(g, rc, nw, gfx::ColorNone); drawRect(g, rc, nw.get(), gfx::ColorNone);
// Draw background (using the customized ISliderBgPainter implementation) // Draw background (using the customized ISliderBgPainter implementation)
rc.shrink(Border(1, 1, 1, 2) * guiscale()); rc.shrink(Border(1, 1, 1, 2) * guiscale());
@ -1461,29 +1293,29 @@ void SkinTheme::paintSlider(PaintEvent& ev)
} }
else { else {
// Draw borders // Draw borders
int full_part_nw; SkinPartPtr full_part;
int empty_part_nw; SkinPartPtr empty_part;
if (isMiniLook) { if (isMiniLook) {
full_part_nw = widget->hasMouseOver() ? PART_MINI_SLIDER_FULL_FOCUSED_NW: full_part = widget->hasMouseOver() ? parts.miniSliderFullFocused():
PART_MINI_SLIDER_FULL_NW; parts.miniSliderFull();
empty_part_nw = widget->hasMouseOver() ? PART_MINI_SLIDER_EMPTY_FOCUSED_NW: empty_part = widget->hasMouseOver() ? parts.miniSliderEmptyFocused():
PART_MINI_SLIDER_EMPTY_NW; parts.miniSliderEmpty();
} }
else { else {
full_part_nw = widget->hasFocus() ? PART_SLIDER_FULL_FOCUSED_NW: full_part = widget->hasFocus() ? parts.sliderFullFocused():
PART_SLIDER_FULL_NW; parts.sliderFull();
empty_part_nw = widget->hasFocus() ? PART_SLIDER_EMPTY_FOCUSED_NW: empty_part = widget->hasFocus() ? parts.sliderEmptyFocused():
PART_SLIDER_EMPTY_NW; parts.sliderEmpty();
} }
if (value == min) if (value == min)
draw_bounds_nw(g, rc, empty_part_nw, colors.sliderEmptyFace()); drawRect(g, rc, empty_part.get(), colors.sliderEmptyFace());
else if (value == max) else if (value == max)
draw_bounds_nw(g, rc, full_part_nw, colors.sliderFullFace()); drawRect(g, rc, full_part.get(), colors.sliderFullFace());
else else
draw_bounds_nw2(g, rc, x, drawRect2(g, rc, x,
full_part_nw, empty_part_nw, full_part.get(), empty_part.get(),
colors.sliderFullFace(), colors.sliderFullFace(),
colors.sliderEmptyFace()); colors.sliderEmptyFace());
@ -1536,10 +1368,10 @@ void SkinTheme::paintComboBoxEntry(ui::PaintEvent& ev)
gfx::Color fg, bg = colors.background(); gfx::Color fg, bg = colors.background();
draw_bounds_nw(g, bounds, drawRect(g, bounds,
widget->hasFocus() ? (widget->hasFocus() ?
PART_SUNKEN2_FOCUSED_NW: parts.sunken2Focused().get():
PART_SUNKEN2_NORMAL_NW, bg); parts.sunken2Normal().get()), bg);
// Draw the text // Draw the text
x = bounds.x + widget->border().left(); x = bounds.x + widget->border().left();
@ -1599,22 +1431,22 @@ void SkinTheme::paintComboBoxButton(PaintEvent& ev)
Button* widget = static_cast<Button*>(ev.getSource()); Button* widget = static_cast<Button*>(ev.getSource());
Graphics* g = ev.getGraphics(); Graphics* g = ev.getGraphics();
IButtonIcon* iconInterface = widget->getIconInterface(); IButtonIcon* iconInterface = widget->getIconInterface();
int part_nw; SkinPartPtr part_nw;
gfx::Color bg; gfx::Color bg;
if (widget->isSelected()) { if (widget->isSelected()) {
bg = colors.buttonSelectedFace(); bg = colors.buttonSelectedFace();
part_nw = PART_TOOLBUTTON_PUSHED_NW; part_nw = parts.toolbuttonPushed();
} }
// With mouse // With mouse
else if (widget->isEnabled() && widget->hasMouseOver()) { else if (widget->isEnabled() && widget->hasMouseOver()) {
bg = colors.buttonHotFace(); bg = colors.buttonHotFace();
part_nw = PART_TOOLBUTTON_HOT_NW; part_nw = parts.toolbuttonHot();
} }
// Without mouse // Without mouse
else { else {
bg = colors.buttonNormalFace(); bg = colors.buttonNormalFace();
part_nw = PART_TOOLBUTTON_LAST_NW; part_nw = parts.toolbuttonLast();
} }
Rect rc = widget->getClientBounds(); Rect rc = widget->getClientBounds();
@ -1623,13 +1455,13 @@ void SkinTheme::paintComboBoxButton(PaintEvent& ev)
g->fillRect(BGCOLOR, rc); g->fillRect(BGCOLOR, rc);
// draw borders // draw borders
draw_bounds_nw(g, rc, part_nw, bg); drawRect(g, rc, part_nw.get(), bg);
// Paint the icon // Paint the icon
if (iconInterface) { if (iconInterface) {
// Icon // Icon
int x = rc.x + rc.w/2 - iconInterface->getWidth()/2; int x = rc.x + rc.w/2 - iconInterface->getSize().w/2;
int y = rc.y + rc.h/2 - iconInterface->getHeight()/2; int y = rc.y + rc.h/2 - iconInterface->getSize().h/2;
paintIcon(widget, ev.getGraphics(), iconInterface, x, y); paintIcon(widget, ev.getGraphics(), iconInterface, x, y);
} }
@ -1765,16 +1597,16 @@ void SkinTheme::paintWindowButton(ui::PaintEvent& ev)
ButtonBase* widget = static_cast<ButtonBase*>(ev.getSource()); ButtonBase* widget = static_cast<ButtonBase*>(ev.getSource());
Graphics* g = ev.getGraphics(); Graphics* g = ev.getGraphics();
Rect rc = widget->getClientBounds(); Rect rc = widget->getClientBounds();
int part; SkinPartPtr part;
if (widget->isSelected()) if (widget->isSelected())
part = PART_WINDOW_CLOSE_BUTTON_SELECTED; part = parts.windowCloseButtonSelected();
else if (widget->hasMouseOver()) else if (widget->hasMouseOver())
part = PART_WINDOW_CLOSE_BUTTON_HOT; part = parts.windowCloseButtonHot();
else else
part = PART_WINDOW_CLOSE_BUTTON_NORMAL; part = parts.windowCloseButtonNormal();
g->drawRgbaSurface(m_part[part], rc.x, rc.y); g->drawRgbaSurface(part->getBitmap(0), rc.x, rc.y);
} }
void SkinTheme::paintTooltip(PaintEvent& ev) void SkinTheme::paintTooltip(PaintEvent& ev)
@ -1785,24 +1617,25 @@ void SkinTheme::paintTooltip(PaintEvent& ev)
Rect rc = widget->getClientBounds(); Rect rc = widget->getClientBounds();
gfx::Color fg = colors.tooltipText(); gfx::Color fg = colors.tooltipText();
gfx::Color bg = colors.tooltipFace(); gfx::Color bg = colors.tooltipFace();
SkinPartPtr tooltipPart = parts.tooltip();
int nw = PART_TOOLTIP_NW; she::Surface* nw = tooltipPart->getBitmapNW();
int n = PART_TOOLTIP_N; she::Surface* n = tooltipPart->getBitmapN();
int ne = PART_TOOLTIP_NE; she::Surface* ne = tooltipPart->getBitmapNE();
int e = PART_TOOLTIP_E; she::Surface* e = tooltipPart->getBitmapE();
int se = PART_TOOLTIP_SE; she::Surface* se = tooltipPart->getBitmapSE();
int s = PART_TOOLTIP_S; she::Surface* s = tooltipPart->getBitmapS();
int sw = PART_TOOLTIP_SW; she::Surface* sw = tooltipPart->getBitmapSW();
int w = PART_TOOLTIP_W; she::Surface* w = tooltipPart->getBitmapW();
switch (widget->getArrowAlign()) { switch (widget->getArrowAlign()) {
case TOP | LEFT: nw = PART_TOOLTIP_ARROW_NW; break; case TOP | LEFT: nw = parts.tooltipArrow()->getBitmapNW(); break;
case TOP | RIGHT: ne = PART_TOOLTIP_ARROW_NE; break; case TOP | RIGHT: ne = parts.tooltipArrow()->getBitmapNE(); break;
case BOTTOM | LEFT: sw = PART_TOOLTIP_ARROW_SW; break; case BOTTOM | LEFT: sw = parts.tooltipArrow()->getBitmapSW(); break;
case BOTTOM | RIGHT: se = PART_TOOLTIP_ARROW_SE; break; case BOTTOM | RIGHT: se = parts.tooltipArrow()->getBitmapSE(); break;
} }
draw_bounds_template(g, rc, nw, n, ne, e, se, s, sw, w); drawRect(g, rc, nw, n, ne, e, se, s, sw, w);
// Draw arrow in sides // Draw arrow in sides
she::Surface* arrow = NULL; she::Surface* arrow = NULL;
@ -1812,25 +1645,25 @@ void SkinTheme::paintTooltip(PaintEvent& ev)
switch (widget->getArrowAlign()) { switch (widget->getArrowAlign()) {
case TOP: case TOP:
arrow = m_part[PART_TOOLTIP_ARROW_N]; arrow = parts.tooltipArrow()->getBitmapN();
g->drawRgbaSurface(arrow, g->drawRgbaSurface(arrow,
target.x+target.w/2-arrow->width()/2, target.x+target.w/2-arrow->width()/2,
rc.y); rc.y);
break; break;
case BOTTOM: case BOTTOM:
arrow = m_part[PART_TOOLTIP_ARROW_S]; arrow = parts.tooltipArrow()->getBitmapS();
g->drawRgbaSurface(arrow, g->drawRgbaSurface(arrow,
target.x+target.w/2-arrow->width()/2, target.x+target.w/2-arrow->width()/2,
rc.y+rc.h-arrow->height()); rc.y+rc.h-arrow->height());
break; break;
case LEFT: case LEFT:
arrow = m_part[PART_TOOLTIP_ARROW_W]; arrow = parts.tooltipArrow()->getBitmapW();
g->drawRgbaSurface(arrow, g->drawRgbaSurface(arrow,
rc.x, rc.x,
target.y+target.h/2-arrow->height()/2); target.y+target.h/2-arrow->height()/2);
break; break;
case RIGHT: case RIGHT:
arrow = m_part[PART_TOOLTIP_ARROW_E]; arrow = parts.tooltipArrow()->getBitmapE();
g->drawRgbaSurface(arrow, g->drawRgbaSurface(arrow,
rc.x+rc.w-arrow->width(), rc.x+rc.w-arrow->width(),
target.y+target.h/2-arrow->height()/2); target.y+target.h/2-arrow->height()/2);
@ -1838,23 +1671,19 @@ void SkinTheme::paintTooltip(PaintEvent& ev)
} }
// Fill background // Fill background
g->fillRect(bg, Rect(rc).shrink( g->fillRect(
bg, Rect(rc).shrink(
Border( Border(
m_part[w]->width(), w->width(),
m_part[n]->height(), n->height(),
m_part[e]->width(), e->width(),
m_part[s]->height()))); s->height())));
rc.shrink(widget->border()); rc.shrink(widget->border());
g->drawAlignedUIString(widget->getText(), fg, bg, rc, widget->getAlign()); g->drawAlignedUIString(widget->getText(), fg, bg, rc, widget->getAlign());
} }
she::Surface* SkinTheme::get_part(const std::string& id) const
{
return get_part_by_id(id)->getBitmap(0);
}
gfx::Color SkinTheme::getWidgetBgColor(Widget* widget) gfx::Color SkinTheme::getWidgetBgColor(Widget* widget)
{ {
gfx::Color c = widget->getBgColor(); gfx::Color c = widget->getBgColor();
@ -1948,43 +1777,16 @@ void SkinTheme::drawEntryCaret(ui::Graphics* g, Entry* widget, int x, int y)
g->drawVLine(color, u, y-1, h+2); g->drawVLine(color, u, y-1, h+2);
} }
she::Surface* SkinTheme::get_toolicon(const char* tool_id) const she::Surface* SkinTheme::getToolIcon(const char* toolId) const
{ {
std::map<std::string, she::Surface*>::const_iterator it = m_toolicon.find(tool_id); std::map<std::string, she::Surface*>::const_iterator it = m_toolicon.find(toolId);
if (it != m_toolicon.end()) if (it != m_toolicon.end())
return it->second; return it->second;
else else
return NULL; return NULL;
} }
void SkinTheme::draw_bounds_template(Graphics* g, const Rect& rc, void SkinTheme::drawRect(Graphics* g, const Rect& rc,
int nw, int n, int ne, int e, int se, int s, int sw, int w)
{
draw_bounds_template(g, rc,
m_part[nw],
m_part[n],
m_part[ne],
m_part[e],
m_part[se],
m_part[s],
m_part[sw],
m_part[w]);
}
void SkinTheme::draw_bounds_template(ui::Graphics* g, const gfx::Rect& rc, const SkinPartPtr& skinPart)
{
draw_bounds_template(g, rc,
skinPart->getBitmap(0),
skinPart->getBitmap(1),
skinPart->getBitmap(2),
skinPart->getBitmap(3),
skinPart->getBitmap(4),
skinPart->getBitmap(5),
skinPart->getBitmap(6),
skinPart->getBitmap(7));
}
void SkinTheme::draw_bounds_template(Graphics* g, const Rect& rc,
she::Surface* nw, she::Surface* n, she::Surface* ne, she::Surface* nw, she::Surface* n, she::Surface* ne,
she::Surface* e, she::Surface* se, she::Surface* s, she::Surface* e, she::Surface* se, she::Surface* s,
she::Surface* sw, she::Surface* w) she::Surface* sw, she::Surface* w)
@ -2045,42 +1847,17 @@ void SkinTheme::draw_bounds_template(Graphics* g, const Rect& rc,
} }
} }
void SkinTheme::draw_bounds_array(ui::Graphics* g, const gfx::Rect& rc, int parts[8]) void SkinTheme::drawRect(ui::Graphics* g, const gfx::Rect& rc, SkinPart* skinPart, gfx::Color bg)
{ {
int nw = parts[0]; drawRect(g, rc,
int n = parts[1]; skinPart->getBitmap(0),
int ne = parts[2]; skinPart->getBitmap(1),
int e = parts[3]; skinPart->getBitmap(2),
int se = parts[4]; skinPart->getBitmap(3),
int s = parts[5]; skinPart->getBitmap(4),
int sw = parts[6]; skinPart->getBitmap(5),
int w = parts[7]; skinPart->getBitmap(6),
skinPart->getBitmap(7));
draw_bounds_template(g, rc,
nw, n, ne, e,
se, s, sw, w);
}
void SkinTheme::draw_bounds_nw(Graphics* g, const Rect& rc, int nw, gfx::Color bg)
{
draw_bounds_template(g, rc,
nw+0, nw+1, nw+2, nw+3,
nw+4, nw+5, nw+6, nw+7);
// Center
if (!is_transparent(bg)) {
g->fillRect(bg, Rect(rc).shrink(
Border(
m_part[nw+7]->width(),
m_part[nw+1]->height(),
m_part[nw+3]->width(),
m_part[nw+5]->height())));
}
}
void SkinTheme::draw_bounds_nw(ui::Graphics* g, const gfx::Rect& rc, const SkinPartPtr skinPart, gfx::Color bg)
{
draw_bounds_template(g, rc, skinPart);
// Center // Center
if (!is_transparent(bg)) { if (!is_transparent(bg)) {
@ -2097,13 +1874,15 @@ void SkinTheme::draw_bounds_nw(ui::Graphics* g, const gfx::Rect& rc, const SkinP
} }
} }
void SkinTheme::draw_bounds_nw2(Graphics* g, const Rect& rc, int x_mid, int nw1, int nw2, gfx::Color bg1, gfx::Color bg2) void SkinTheme::drawRect2(Graphics* g, const Rect& rc, int x_mid,
SkinPart* nw1, SkinPart* nw2,
gfx::Color bg1, gfx::Color bg2)
{ {
Rect rc2(rc.x, rc.y, x_mid-rc.x+1, rc.h); Rect rc2(rc.x, rc.y, x_mid-rc.x+1, rc.h);
{ {
IntersectClip clip(g, rc2); IntersectClip clip(g, rc2);
if (clip) if (clip)
draw_bounds_nw(g, rc, nw1, bg1); drawRect(g, rc, nw1, bg1);
} }
rc2.x += rc2.w; rc2.x += rc2.w;
@ -2111,42 +1890,42 @@ void SkinTheme::draw_bounds_nw2(Graphics* g, const Rect& rc, int x_mid, int nw1,
IntersectClip clip(g, rc2); IntersectClip clip(g, rc2);
if (clip) if (clip)
draw_bounds_nw(g, rc, nw2, bg2); drawRect(g, rc, nw2, bg2);
} }
void SkinTheme::draw_part_as_hline(ui::Graphics* g, const gfx::Rect& rc, int part) void SkinTheme::drawHline(ui::Graphics* g, const gfx::Rect& rc, SkinPart* part)
{ {
int x; int x;
for (x = rc.x; for (x = rc.x;
x < rc.x2()-m_part[part]->width(); x < rc.x2()-part->getSize().w;
x += m_part[part]->width()) { x += part->getSize().w) {
g->drawRgbaSurface(m_part[part], x, rc.y); g->drawRgbaSurface(part->getBitmap(0), x, rc.y);
} }
if (x < rc.x2()) { if (x < rc.x2()) {
Rect rc2(x, rc.y, rc.w-(x-rc.x), m_part[part]->height()); Rect rc2(x, rc.y, rc.w-(x-rc.x), part->getSize().h);
IntersectClip clip(g, rc2); IntersectClip clip(g, rc2);
if (clip) if (clip)
g->drawRgbaSurface(m_part[part], x, rc.y); g->drawRgbaSurface(part->getBitmap(0), x, rc.y);
} }
} }
void SkinTheme::draw_part_as_vline(ui::Graphics* g, const gfx::Rect& rc, int part) void SkinTheme::drawVline(ui::Graphics* g, const gfx::Rect& rc, SkinPart* part)
{ {
int y; int y;
for (y = rc.y; for (y = rc.y;
y < rc.y2()-m_part[part]->height(); y < rc.y2()-part->getSize().h;
y += m_part[part]->height()) { y += part->getSize().h) {
g->drawRgbaSurface(m_part[part], rc.x, y); g->drawRgbaSurface(part->getBitmap(0), rc.x, y);
} }
if (y < rc.y2()) { if (y < rc.y2()) {
Rect rc2(rc.x, y, m_part[part]->width(), rc.h-(y-rc.y)); Rect rc2(rc.x, y, part->getSize().w, rc.h-(y-rc.y));
IntersectClip clip(g, rc2); IntersectClip clip(g, rc2);
if (clip) if (clip)
g->drawRgbaSurface(m_part[part], rc.x, y); g->drawRgbaSurface(part->getBitmap(0), rc.x, y);
} }
} }

View File

@ -10,7 +10,6 @@
#pragma once #pragma once
#include "app/ui/skin/skin_part.h" #include "app/ui/skin/skin_part.h"
#include "app/ui/skin/skin_parts.h"
#include "app/ui/skin/style_sheet.h" #include "app/ui/skin/style_sheet.h"
#include "gfx/color.h" #include "gfx/color.h"
#include "gfx/fwd.h" #include "gfx/fwd.h"
@ -85,18 +84,17 @@ namespace app {
int get_button_selected_offset() const { return 0; } // TODO Configurable in xml int get_button_selected_offset() const { return 0; } // TODO Configurable in xml
she::Surface* get_part(int part_i) const { return m_part[part_i]; } she::Surface* getToolIcon(const char* toolId) const;
she::Surface* get_part(const std::string& id) const;
she::Surface* get_toolicon(const char* tool_id) const;
gfx::Size get_part_size(int part_i) const;
// Helper functions to draw bounds/hlines with sheet parts // Helper functions to draw bounds/hlines with sheet parts
void draw_bounds_array(ui::Graphics* g, const gfx::Rect& rc, int parts[8]); void drawRect(ui::Graphics* g, const gfx::Rect& rc,
void draw_bounds_nw(ui::Graphics* g, const gfx::Rect& rc, int nw, gfx::Color bg = gfx::ColorNone); she::Surface* nw, she::Surface* n, she::Surface* ne,
void draw_bounds_nw(ui::Graphics* g, const gfx::Rect& rc, const SkinPartPtr skinPart, gfx::Color bg = gfx::ColorNone); she::Surface* e, she::Surface* se, she::Surface* s,
void draw_bounds_nw2(ui::Graphics* g, const gfx::Rect& rc, int x_mid, int nw1, int nw2, gfx::Color bg1, gfx::Color bg2); she::Surface* sw, she::Surface* w);
void draw_part_as_hline(ui::Graphics* g, const gfx::Rect& rc, int part); void drawRect(ui::Graphics* g, const gfx::Rect& rc, SkinPart* skinPart, gfx::Color bg = gfx::ColorNone);
void draw_part_as_vline(ui::Graphics* g, const gfx::Rect& rc, int part); void drawRect2(ui::Graphics* g, const gfx::Rect& rc, int x_mid, SkinPart* nw1, SkinPart* nw2, gfx::Color bg1, gfx::Color bg2);
void drawHline(ui::Graphics* g, const gfx::Rect& rc, SkinPart* skinPart);
void drawVline(ui::Graphics* g, const gfx::Rect& rc, SkinPart* skinPart);
void paintProgressBar(ui::Graphics* g, const gfx::Rect& rc, double progress); void paintProgressBar(ui::Graphics* g, const gfx::Rect& rc, double progress);
Style* getStyle(const std::string& id) { Style* getStyle(const std::string& id) {
@ -122,13 +120,6 @@ namespace app {
private: private:
void loadSheet(); void loadSheet();
void loadFonts(); void loadFonts();
void draw_bounds_template(ui::Graphics* g, const gfx::Rect& rc,
int nw, int n, int ne, int e, int se, int s, int sw, int w);
void draw_bounds_template(ui::Graphics* g, const gfx::Rect& rc, const SkinPartPtr& skinPart);
void draw_bounds_template(ui::Graphics* g, const gfx::Rect& rc,
she::Surface* nw, she::Surface* n, she::Surface* ne,
she::Surface* e, she::Surface* se, she::Surface* s,
she::Surface* sw, she::Surface* w);
she::Surface* sliceSheet(she::Surface* sur, const gfx::Rect& bounds); she::Surface* sliceSheet(she::Surface* sur, const gfx::Rect& bounds);
gfx::Color getWidgetBgColor(ui::Widget* widget); gfx::Color getWidgetBgColor(ui::Widget* widget);
@ -143,7 +134,6 @@ namespace app {
std::string m_selected_skin; std::string m_selected_skin;
she::Surface* m_sheet; she::Surface* m_sheet;
std::vector<she::Surface*> m_part;
std::map<std::string, SkinPartPtr> m_parts_by_id; std::map<std::string, SkinPartPtr> m_parts_by_id;
std::map<std::string, she::Surface*> m_toolicon; std::map<std::string, she::Surface*> m_toolicon;
std::map<std::string, gfx::Color> m_colors_by_id; std::map<std::string, gfx::Color> m_colors_by_id;

View File

@ -39,8 +39,8 @@ void BackgroundRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const cha
{ {
SkinTheme* theme = static_cast<SkinTheme*>(ui::CurrentTheme::get()); SkinTheme* theme = static_cast<SkinTheme*>(ui::CurrentTheme::get());
if (m_part && m_part->size() > 0) { if (m_part && m_part->countBitmaps() > 0) {
if (m_part->size() == 1) { if (m_part->countBitmaps() == 1) {
if (!gfx::is_transparent(m_color)) if (!gfx::is_transparent(m_color))
g->fillRect(m_color, bounds); g->fillRect(m_color, bounds);
@ -65,8 +65,8 @@ void BackgroundRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const cha
} }
} }
} }
else if (m_part->size() == 8) { else if (m_part->countBitmaps() == 8) {
theme->draw_bounds_nw(g, bounds, m_part, m_color); theme->drawRect(g, bounds, m_part.get(), m_color);
} }
} }
else if (!gfx::is_transparent(m_color)) { else if (!gfx::is_transparent(m_color)) {

View File

@ -427,7 +427,7 @@ void StatusBar::onPaint(ui::PaintEvent& ev)
// Color // Color
if (m_state == SHOW_COLOR) { if (m_state == SHOW_COLOR) {
// Draw eyedropper icon // Draw eyedropper icon
she::Surface* icon = theme->get_toolicon("eyedropper"); she::Surface* icon = theme->getToolIcon("eyedropper");
if (icon) { if (icon) {
g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2); g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2);
x += icon->width() + 4*guiscale(); x += icon->width() + 4*guiscale();
@ -457,7 +457,7 @@ void StatusBar::onPaint(ui::PaintEvent& ev)
// Show tool // Show tool
if (m_state == SHOW_TOOL) { if (m_state == SHOW_TOOL) {
// Draw eyedropper icon // Draw eyedropper icon
she::Surface* icon = theme->get_toolicon(m_tool->getId().c_str()); she::Surface* icon = theme->getToolIcon(m_tool->getId().c_str());
if (icon) { if (icon) {
g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2); g->drawRgbaSurface(icon, x, rc.y + rc.h/2 - icon->height()/2);
x += icon->width() + 4*guiscale(); x += icon->width() + 4*guiscale();

View File

@ -66,7 +66,7 @@ private:
static Size getToolIconSize(Widget* widget) static Size getToolIconSize(Widget* widget)
{ {
SkinTheme* theme = static_cast<SkinTheme*>(widget->getTheme()); SkinTheme* theme = static_cast<SkinTheme*>(widget->getTheme());
she::Surface* icon = theme->get_toolicon("configuration"); she::Surface* icon = theme->getToolIcon("configuration");
if (icon) if (icon)
return Size(icon->width(), icon->height()); return Size(icon->width(), icon->height());
else else
@ -316,24 +316,24 @@ void ToolBar::onPaint(ui::PaintEvent& ev)
ToolGroup* tool_group = *it; ToolGroup* tool_group = *it;
Tool* tool = m_selectedInGroup[tool_group]; Tool* tool = m_selectedInGroup[tool_group];
gfx::Color face; gfx::Color face;
int nw; SkinPartPtr nw;
if (App::instance()->activeTool() == tool || m_hotIndex == c) { if (App::instance()->activeTool() == tool || m_hotIndex == c) {
nw = PART_TOOLBUTTON_HOT_NW; nw = theme->parts.toolbuttonHot();
face = hotFace; face = hotFace;
} }
else { else {
nw = c >= 0 && c < groups-1 ? PART_TOOLBUTTON_NORMAL_NW: nw = c >= 0 && c < groups-1 ? theme->parts.toolbuttonNormal():
PART_TOOLBUTTON_LAST_NW; theme->parts.toolbuttonLast();
face = normalFace; face = normalFace;
} }
toolrc = getToolGroupBounds(c); toolrc = getToolGroupBounds(c);
toolrc.offset(-getBounds().x, -getBounds().y); toolrc.offset(-getBounds().x, -getBounds().y);
theme->draw_bounds_nw(g, toolrc, nw, face); theme->drawRect(g, toolrc, nw.get(), face);
// Draw the tool icon // Draw the tool icon
she::Surface* icon = theme->get_toolicon(tool->getId().c_str()); she::Surface* icon = theme->getToolIcon(tool->getId().c_str());
if (icon) { if (icon) {
g->drawRgbaSurface(icon, g->drawRgbaSurface(icon,
toolrc.x+toolrc.w/2-icon->width()/2, toolrc.x+toolrc.w/2-icon->width()/2,
@ -345,13 +345,13 @@ void ToolBar::onPaint(ui::PaintEvent& ev)
toolrc = getToolGroupBounds(ConfigureToolIndex); toolrc = getToolGroupBounds(ConfigureToolIndex);
toolrc.offset(-getBounds().x, -getBounds().y); toolrc.offset(-getBounds().x, -getBounds().y);
bool isHot = (m_hotIndex == ConfigureToolIndex); bool isHot = (m_hotIndex == ConfigureToolIndex);
theme->draw_bounds_nw(g, theme->drawRect(
toolrc, g, toolrc,
isHot ? PART_TOOLBUTTON_HOT_NW: (isHot ? theme->parts.toolbuttonHot().get():
PART_TOOLBUTTON_LAST_NW, theme->parts.toolbuttonLast().get()),
isHot ? hotFace: normalFace); (isHot ? hotFace: normalFace));
she::Surface* icon = theme->get_toolicon("configuration"); she::Surface* icon = theme->getToolIcon("configuration");
if (icon) { if (icon) {
g->drawRgbaSurface(icon, g->drawRgbaSurface(icon,
toolrc.x+toolrc.w/2-icon->width()/2, toolrc.x+toolrc.w/2-icon->width()/2,
@ -363,13 +363,14 @@ void ToolBar::onPaint(ui::PaintEvent& ev)
toolrc.offset(-getBounds().x, -getBounds().y); toolrc.offset(-getBounds().x, -getBounds().y);
isHot = (m_hotIndex == PreviewVisibilityIndex || isHot = (m_hotIndex == PreviewVisibilityIndex ||
App::instance()->getMainWindow()->getPreviewEditor()->isPreviewEnabled()); App::instance()->getMainWindow()->getPreviewEditor()->isPreviewEnabled());
theme->draw_bounds_nw(g, theme->drawRect(
g,
toolrc, toolrc,
isHot ? PART_TOOLBUTTON_HOT_NW: (isHot ? theme->parts.toolbuttonHot().get():
PART_TOOLBUTTON_LAST_NW, theme->parts.toolbuttonLast().get()),
isHot ? hotFace: normalFace); (isHot ? hotFace: normalFace));
icon = theme->get_toolicon("minieditor"); icon = theme->getToolIcon("minieditor");
if (icon) { if (icon) {
g->drawRgbaSurface(icon, g->drawRgbaSurface(icon,
toolrc.x+toolrc.w/2-icon->width()/2, toolrc.x+toolrc.w/2-icon->width()/2,
@ -726,26 +727,27 @@ void ToolBar::ToolStrip::onPaint(PaintEvent& ev)
Tool* tool = *it; Tool* tool = *it;
if (tool->getGroup() == m_group) { if (tool->getGroup() == m_group) {
gfx::Color face; gfx::Color face;
int nw; SkinPartPtr nw;
if (App::instance()->activeTool() == tool || if (App::instance()->activeTool() == tool ||
m_hotTool == tool) { m_hotTool == tool) {
nw = PART_TOOLBUTTON_HOT_NW; nw = theme->parts.toolbuttonHot();
face = theme->colors.buttonHotFace(); face = theme->colors.buttonHotFace();
} }
else { else {
nw = PART_TOOLBUTTON_LAST_NW; nw = theme->parts.toolbuttonLast();
face = theme->colors.buttonNormalFace(); face = theme->colors.buttonNormalFace();
} }
toolrc = getToolBounds(index++); toolrc = getToolBounds(index++);
toolrc.offset(-getBounds().x, -getBounds().y); toolrc.offset(-getBounds().x, -getBounds().y);
theme->draw_bounds_nw(g, toolrc, nw, face); theme->drawRect(g, toolrc, nw.get(), face);
// Draw the tool icon // Draw the tool icon
she::Surface* icon = theme->get_toolicon(tool->getId().c_str()); she::Surface* icon = theme->getToolIcon(tool->getId().c_str());
if (icon) { if (icon) {
g->drawRgbaSurface(icon, g->drawRgbaSurface(
icon,
toolrc.x+toolrc.w/2-icon->width()/2, toolrc.x+toolrc.w/2-icon->width()/2,
toolrc.y+toolrc.h/2-icon->height()/2); toolrc.y+toolrc.h/2-icon->height()/2);
} }

View File

@ -24,7 +24,6 @@
#include "app/ui/color_bar.h" #include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h" #include "app/ui/editor/editor.h"
#include "app/ui/main_window.h" #include "app/ui/main_window.h"
#include "app/ui/skin/skin_parts.h"
#include "app/ui/skin/skin_theme.h" #include "app/ui/skin/skin_theme.h"
#include "app/ui/timeline.h" #include "app/ui/timeline.h"
#include "app/ui_context.h" #include "app/ui_context.h"

View File

@ -432,8 +432,9 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
int hspan = int_attr(elem, "hspan", 1); int hspan = int_attr(elem, "hspan", 1);
int vspan = int_attr(elem, "vspan", 1); int vspan = int_attr(elem, "vspan", 1);
she::Surface* sur = theme->get_part(std::string(icon)); SkinPartPtr part = theme->getPartById(std::string(icon));
buttonset->addItem(sur, hspan, vspan); if (part)
buttonset->addItem(part, hspan, vspan);
} }
} }
} }

View File

@ -16,6 +16,7 @@ void gen_skin_class(TiXmlDocument* doc, const std::string& inputFn)
{ {
std::vector<std::string> dimensions; std::vector<std::string> dimensions;
std::vector<std::string> colors; std::vector<std::string> colors;
std::vector<std::string> parts;
std::vector<std::string> styles; std::vector<std::string> styles;
TiXmlHandle handle(doc); TiXmlHandle handle(doc);
@ -39,6 +40,17 @@ void gen_skin_class(TiXmlDocument* doc, const std::string& inputFn)
elem = elem->NextSiblingElement(); elem = elem->NextSiblingElement();
} }
elem = handle
.FirstChild("skin")
.FirstChild("parts")
.FirstChild("part").ToElement();
while (elem) {
const char* id = elem->Attribute("id");
if (!strchr(id, ':'))
parts.push_back(id);
elem = elem->NextSiblingElement();
}
elem = handle elem = handle
.FirstChild("skin") .FirstChild("skin")
.FirstChild("stylesheet") .FirstChild("stylesheet")
@ -105,6 +117,26 @@ void gen_skin_class(TiXmlDocument* doc, const std::string& inputFn)
std::cout std::cout
<< " };\n"; << " };\n";
// Parts sub class
std::cout
<< " class Parts {\n"
<< " template<typename> friend class SkinFile;\n"
<< " public:\n";
for (auto part : parts) {
std::string id = convert_xmlid_to_cppid(part, false);
std::cout
<< " const skin::SkinPartPtr& " << id << "() const { return m_" << id << "; }\n";
}
std::cout
<< " private:\n";
for (auto part : parts) {
std::string id = convert_xmlid_to_cppid(part, false);
std::cout
<< " skin::SkinPartPtr m_" << id << ";\n";
}
std::cout
<< " };\n";
// Styles sub class // Styles sub class
std::cout std::cout
<< "\n" << "\n"
@ -130,37 +162,46 @@ void gen_skin_class(TiXmlDocument* doc, const std::string& inputFn)
<< "\n" << "\n"
<< " Dimensions dimensions;\n" << " Dimensions dimensions;\n"
<< " Colors colors;\n" << " Colors colors;\n"
<< " Parts parts;\n"
<< " Styles styles;\n" << " Styles styles;\n"
<< "\n" << "\n"
<< " protected:\n" << " protected:\n"
<< " void updateInternals() {\n"; << " void updateInternals() {\n";
for (auto dimension : dimensions) { for (auto dimension : dimensions) {
std::string id = convert_xmlid_to_cppid(dimension, false); std::string id = convert_xmlid_to_cppid(dimension, false);
std::cout << " dimensions.m_" << id std::cout << " byId(dimensions.m_" << id
<< " = dimensionById(\"" << dimension << "\");\n"; << ", \"" << dimension << "\");\n";
} }
for (auto color : colors) { for (auto color : colors) {
std::string id = convert_xmlid_to_cppid(color, false); std::string id = convert_xmlid_to_cppid(color, false);
std::cout << " colors.m_" << id std::cout << " byId(colors.m_" << id
<< " = colorById(\"" << color << "\");\n"; << ", \"" << color << "\");\n";
}
for (auto part : parts) {
std::string id = convert_xmlid_to_cppid(part, false);
std::cout << " byId(parts.m_" << id
<< ", \"" << part << "\");\n";
} }
for (auto style : styles) { for (auto style : styles) {
std::string id = convert_xmlid_to_cppid(style, false); std::string id = convert_xmlid_to_cppid(style, false);
std::cout << " styles.m_" << id std::cout << " byId(styles.m_" << id
<< " = styleById(\"" << style << "\");\n"; << ", \"" << style << "\");\n";
} }
std::cout std::cout
<< " }\n" << " }\n"
<< "\n" << "\n"
<< " private:\n" << " private:\n"
<< " int dimensionById(const std::string& id) {\n" << " void byId(int& dimension, const std::string& id) {\n"
<< " return static_cast<T*>(this)->getDimensionById(id);\n" << " dimension = static_cast<T*>(this)->getDimensionById(id);\n"
<< " }\n" << " }\n"
<< " gfx::Color colorById(const std::string& id) {\n" << " void byId(gfx::Color& color, const std::string& id) {\n"
<< " return static_cast<T*>(this)->getColorById(id);\n" << " color = static_cast<T*>(this)->getColorById(id);\n"
<< " }\n" << " }\n"
<< " skin::Style* styleById(const std::string& id) {\n" << " void byId(skin::SkinPartPtr& part, const std::string& id) {\n"
<< " return static_cast<T*>(this)->getStyle(id);\n" << " part = static_cast<T*>(this)->getPartById(id);\n"
<< " }\n"
<< " void byId(skin::Style*& style, const std::string& id) {\n"
<< " style = static_cast<T*>(this)->getStyle(id);\n"
<< " }\n"; << " }\n";
std::cout std::cout

View File

@ -274,10 +274,11 @@ bool ButtonBase::onProcessMessage(Message* msg)
void ButtonBase::onPreferredSize(PreferredSizeEvent& ev) void ButtonBase::onPreferredSize(PreferredSizeEvent& ev)
{ {
gfx::Rect box; gfx::Rect box;
gfx::Size iconSize = (m_iconInterface ? m_iconInterface->getSize(): gfx::Size(0, 0));
getTextIconInfo(&box, NULL, NULL, getTextIconInfo(&box, NULL, NULL,
m_iconInterface ? m_iconInterface->getIconAlign(): 0, m_iconInterface ? m_iconInterface->getIconAlign(): 0,
m_iconInterface ? m_iconInterface->getWidth(): 0, iconSize.w,
m_iconInterface ? m_iconInterface->getHeight(): 0); iconSize.h);
ev.setPreferredSize(box.w + border().width(), ev.setPreferredSize(box.w + border().width(),
box.h + border().height()); box.h + border().height());

View File

@ -1,5 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2001-2013 David Capello // Copyright (C) 2001-2013, 2015 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -25,8 +25,7 @@ namespace ui {
public: public:
virtual ~IButtonIcon() { } virtual ~IButtonIcon() { }
virtual void destroy() = 0; virtual void destroy() = 0;
virtual int getWidth() = 0; virtual gfx::Size getSize() = 0;
virtual int getHeight() = 0;
virtual she::Surface* getNormalIcon() = 0; virtual she::Surface* getNormalIcon() = 0;
virtual she::Surface* getSelectedIcon() = 0; virtual she::Surface* getSelectedIcon() = 0;
virtual she::Surface* getDisabledIcon() = 0; virtual she::Surface* getDisabledIcon() = 0;