diff --git a/src/app/commands/cmd_canvas_size.cpp b/src/app/commands/cmd_canvas_size.cpp index 749a10259..7a22cb648 100644 --- a/src/app/commands/cmd_canvas_size.cpp +++ b/src/app/commands/cmd_canvas_size.cpp @@ -220,37 +220,37 @@ private: int c = 0; for (int v=0; v<3; ++v) { for (int u=0; u<3; ++u) { - const char* iconId = "canvas_empty"; + SkinPartPtr icon = theme->parts.canvasEmpty(); if (c == sel) { - iconId = "canvas_c"; + icon = theme->parts.canvasC(); } 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) { - iconId = "canvas_e"; + icon = theme->parts.canvasE(); } 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) { - iconId = "canvas_s"; + icon = theme->parts.canvasS(); } 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) { - iconId = "canvas_ne"; + icon = theme->parts.canvasNe(); } 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) { - iconId = "canvas_se"; + icon = theme->parts.canvasSe(); } - dir()->getItem(c)->setIcon(theme->get_part(iconId)); + dir()->getItem(c)->setIcon(icon); ++c; } } diff --git a/src/app/commands/filters/filter_target_buttons.cpp b/src/app/commands/filters/filter_target_buttons.cpp index 0c2c4c633..e53334102 100644 --- a/src/app/commands/filters/filter_target_buttons.cpp +++ b/src/app/commands/filters/filter_target_buttons.cpp @@ -13,7 +13,8 @@ #include "app/modules/gfx.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 "doc/image.h" #include "ui/box.h" @@ -25,9 +26,9 @@ namespace app { +using namespace app::skin; using namespace filters; using namespace ui; -using namespace app::skin; FilterTargetButtons::FilterTargetButtons(int imgtype, bool withChannels) : Box(VERTICAL) @@ -91,10 +92,12 @@ FilterTargetButtons::FilterTargetButtons(int imgtype, bool withChannels) withChannels ? 0: 2, withChannels ? 0: 2, 2, 2); setup_mini_look(images); - set_gfxicon_to_button(images, - getTargetNormalIcon(), - getTargetSelectedIcon(), -1, - CENTER | MIDDLE); + + images->setIconInterface( + new ButtonIconImpl(getTargetNormalIcon(), + getTargetSelectedIcon(), + SkinPartPtr(nullptr), + CENTER | MIDDLE)); // Make hierarchy ADD(hbox, r, onChannelChange); @@ -170,39 +173,44 @@ void FilterTargetButtons::onImagesChange(ButtonBase* button) m_target |= TARGET_ALL_FRAMES; } - set_gfxicon_to_button(button, - getTargetNormalIcon(), - getTargetSelectedIcon(), -1, - CENTER | MIDDLE); + button->setIconInterface( + new ButtonIconImpl(getTargetNormalIcon(), + getTargetSelectedIcon(), + SkinPartPtr(nullptr), + CENTER | MIDDLE)); TargetChange(); } -int FilterTargetButtons::getTargetNormalIcon() const +SkinPartPtr FilterTargetButtons::getTargetNormalIcon() const { + SkinTheme* theme = SkinTheme::instance(); + if (m_target & TARGET_ALL_FRAMES) { return (m_target & TARGET_ALL_LAYERS) ? - PART_TARGET_FRAMES_LAYERS: - PART_TARGET_FRAMES; + theme->parts.targetFramesLayers(): + theme->parts.targetFrames(); } else { return (m_target & TARGET_ALL_LAYERS) ? - PART_TARGET_LAYERS: - PART_TARGET_ONE; + theme->parts.targetLayers(): + theme->parts.targetOne(); } } -int FilterTargetButtons::getTargetSelectedIcon() const +SkinPartPtr FilterTargetButtons::getTargetSelectedIcon() const { + SkinTheme* theme = SkinTheme::instance(); + if (m_target & TARGET_ALL_FRAMES) { return (m_target & TARGET_ALL_LAYERS) ? - PART_TARGET_FRAMES_LAYERS_SELECTED: - PART_TARGET_FRAMES_SELECTED; + theme->parts.targetFramesLayersSelected(): + theme->parts.targetFramesSelected(); } else { return (m_target & TARGET_ALL_LAYERS) ? - PART_TARGET_LAYERS_SELECTED: - PART_TARGET_ONE_SELECTED; + theme->parts.targetLayersSelected(): + theme->parts.targetOneSelected(); } } diff --git a/src/app/commands/filters/filter_target_buttons.h b/src/app/commands/filters/filter_target_buttons.h index 64a0eff4b..d810c0a79 100644 --- a/src/app/commands/filters/filter_target_buttons.h +++ b/src/app/commands/filters/filter_target_buttons.h @@ -9,6 +9,7 @@ #define APP_COMMANDS_FILTERS_FILTER_TARGET_BUTTONS_H_INCLUDED #pragma once +#include "app/ui/skin/skin_part.h" #include "base/signal.h" #include "filters/target.h" #include "ui/box.h" @@ -37,8 +38,8 @@ namespace app { private: void selectTargetButton(const char* name, Target specificTarget); - int getTargetNormalIcon() const; - int getTargetSelectedIcon() const; + skin::SkinPartPtr getTargetNormalIcon() const; + skin::SkinPartPtr getTargetSelectedIcon() const; Target m_target; }; diff --git a/src/app/modules/gfx.cpp b/src/app/modules/gfx.cpp index a4f26f593..1ddda47d3 100644 --- a/src/app/modules/gfx.cpp +++ b/src/app/modules/gfx.cpp @@ -100,7 +100,7 @@ void draw_color_button(ui::Graphics* g, const Rect& rc, const app::Color& color, bool hot, bool drag) { - SkinTheme* theme = (SkinTheme*)ui::CurrentTheme::get(); + SkinTheme* theme = SkinTheme::instance(); int scale = ui::guiscale(); // Draw background (the color) @@ -111,25 +111,22 @@ void draw_color_button(ui::Graphics* g, rc.h-2*scale), color); // Draw opaque border - { - int parts[8] = { - PART_COLORBAR_0_NW, - PART_COLORBAR_0_N, - PART_COLORBAR_1_NE, - PART_COLORBAR_1_E, - PART_COLORBAR_3_SE, - PART_COLORBAR_2_S, - PART_COLORBAR_2_SW, - PART_COLORBAR_0_W - }; - theme->draw_bounds_array(g, rc, parts); - } + theme->drawRect( + g, rc, + theme->parts.colorbar0()->getBitmapNW(), + theme->parts.colorbar0()->getBitmapN(), + theme->parts.colorbar1()->getBitmapNE(), + theme->parts.colorbar1()->getBitmapE(), + theme->parts.colorbar3()->getBitmapSE(), + theme->parts.colorbar2()->getBitmapS(), + theme->parts.colorbar2()->getBitmapSW(), + theme->parts.colorbar0()->getBitmapW()); // Draw hot if (hot) { - theme->draw_bounds_nw(g, - gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - 1*scale), - PART_COLORBAR_BORDER_HOTFG_NW); + theme->drawRect( + g, gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - 1*scale), + theme->parts.colorbarBorderHotfg().get()); } } diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index bf5a3e179..334558822 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -28,7 +28,6 @@ #include "app/ui/main_menu_bar.h" #include "app/ui/main_menu_bar.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_theme.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); } -// 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(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 // normal buttons) diff --git a/src/app/modules/gui.h b/src/app/modules/gui.h index 8f6b39948..dc4e2b117 100644 --- a/src/app/modules/gui.h +++ b/src/app/modules/gui.h @@ -45,11 +45,6 @@ namespace app { 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 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); // This function can be used to reinvalidate a specific rectangle if diff --git a/src/app/ui/ani_controls.cpp b/src/app/ui/ani_controls.cpp index e59f75e74..2ca2f1f77 100644 --- a/src/app/ui/ani_controls.cpp +++ b/src/app/ui/ani_controls.cpp @@ -65,11 +65,11 @@ AniControls::AniControls() { SkinTheme* theme = static_cast(this->getTheme()); - addItem(theme->get_part(PART_ANI_FIRST)); - addItem(theme->get_part(PART_ANI_PREVIOUS)); - addItem(theme->get_part(PART_ANI_PLAY)); - addItem(theme->get_part(PART_ANI_NEXT)); - addItem(theme->get_part(PART_ANI_LAST)); + addItem(theme->parts.aniFirst()); + addItem(theme->parts.aniPrevious()); + addItem(theme->parts.aniPlay()); + addItem(theme->parts.aniNext()); + addItem(theme->parts.aniLast()); ItemChange.connect(Bind(&AniControls::onPlayButton, this)); setTriggerOnMouseUp(true); @@ -81,8 +81,9 @@ void AniControls::updateUsingEditor(Editor* editor) { SkinTheme* theme = static_cast(this->getTheme()); getItem(ACTION_PLAY)->setIcon( - theme->get_part( - (editor && editor->isPlaying()) ? PART_ANI_STOP: PART_ANI_PLAY)); + (editor && editor->isPlaying() ? + theme->parts.aniStop(): + theme->parts.aniPlay())); } void AniControls::onPlayButton() diff --git a/src/app/ui/brush_popup.cpp b/src/app/ui/brush_popup.cpp index 0a5042a07..09c71915f 100644 --- a/src/app/ui/brush_popup.cpp +++ b/src/app/ui/brush_popup.cpp @@ -47,11 +47,9 @@ public: , m_delegate(delegate) , m_brush(brush) , m_slot(slot) { - setIcon(BrushPopup::createSurfaceForBrush(brush)); - } - - ~Item() { - icon()->dispose(); + SkinPartPtr icon(new SkinPart); + icon->setBitmap(0, BrushPopup::createSurfaceForBrush(brush)); + setIcon(icon); } const BrushRef& brush() const { diff --git a/src/app/ui/button_set.cpp b/src/app/ui/button_set.cpp index 58da0e618..f285ae8cf 100644 --- a/src/app/ui/button_set.cpp +++ b/src/app/ui/button_set.cpp @@ -48,7 +48,7 @@ ButtonSet::Item::Item() setup_mini_font(this); } -void ButtonSet::Item::setIcon(she::Surface* icon) +void ButtonSet::Item::setIcon(const SkinPartPtr& icon) { m_icon = icon; invalidate(); @@ -65,25 +65,25 @@ void ButtonSet::Item::onPaint(ui::PaintEvent& ev) Graphics* g = ev.getGraphics(); gfx::Rect rc = getClientBounds(); gfx::Color fg, bg; - int nw; + SkinPartPtr nw; if (!gfx::is_transparent(getBgColor())) g->fillRect(getBgColor(), g->getClipBounds()); if (isSelected() || hasMouseOver()) { if (hasCapture()) { - nw = PART_TOOLBUTTON_PUSHED_NW; + nw = theme->parts.toolbuttonPushed(); fg = theme->colors.buttonSelectedText(); bg = theme->colors.buttonSelectedFace(); } else { - nw = PART_TOOLBUTTON_HOT_NW; + nw = theme->parts.toolbuttonHot(); fg = theme->colors.buttonHotText(); bg = theme->colors.buttonHotFace(); } } else { - nw = PART_TOOLBUTTON_LAST_NW; + nw = theme->parts.toolbuttonLast(); fg = theme->colors.buttonNormalText(); 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.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) { - int u = rc.x + rc.w/2 - m_icon->width()/2; - int v = rc.y + rc.h/2 - m_icon->height()/2 - 1*guiscale(); + gfx::Size iconSize = m_icon->getSize(); + 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()) - g->drawColoredRgbaSurface(m_icon, theme->colors.buttonSelectedText(), u, v); + g->drawColoredRgbaSurface(m_icon->getBitmap(0), theme->colors.buttonSelectedText(), u, v); else - g->drawRgbaSurface(m_icon, u, v); + g->drawRgbaSurface(m_icon->getBitmap(0), u, v); } if (!getText().empty()) { @@ -192,7 +193,7 @@ void ButtonSet::addItem(const std::string& text, int hspan, int 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->setIcon(icon); diff --git a/src/app/ui/button_set.h b/src/app/ui/button_set.h index 850582943..9220eaa94 100644 --- a/src/app/ui/button_set.h +++ b/src/app/ui/button_set.h @@ -9,6 +9,7 @@ #define APP_UI_BUTTON_SET_H_INCLUDED #pragma once +#include "app/ui/skin/skin_part.h" #include "base/signal.h" #include "ui/grid.h" @@ -21,21 +22,21 @@ namespace app { class Item : public ui::Widget { public: Item(); - void setIcon(she::Surface* icon); - she::Surface* icon() const { return m_icon; } + void setIcon(const skin::SkinPartPtr& icon); + skin::SkinPartPtr icon() const { return m_icon; } ButtonSet* buttonSet(); protected: void onPaint(ui::PaintEvent& ev) override; bool onProcessMessage(ui::Message* msg) override; void onPreferredSize(ui::PreferredSizeEvent& ev) override; private: - she::Surface* m_icon; + skin::SkinPartPtr m_icon; }; ButtonSet(int columns); 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); Item* getItem(int index); diff --git a/src/app/ui/color_bar.cpp b/src/app/ui/color_bar.cpp index f6c5b7396..9d7e505a4 100644 --- a/src/app/ui/color_bar.cpp +++ b/src/app/ui/color_bar.cpp @@ -100,10 +100,10 @@ protected: ColorBar::ScrollableView::ScrollableView() { SkinTheme* theme = static_cast(getTheme()); - int l = theme->get_part(PART_EDITOR_SELECTED_W)->width(); - int t = theme->get_part(PART_EDITOR_SELECTED_N)->height(); - int r = theme->get_part(PART_EDITOR_SELECTED_E)->width(); - int b = theme->get_part(PART_EDITOR_SELECTED_S)->height(); + int l = theme->parts.editorSelected()->getBitmapW()->width(); + int t = theme->parts.editorSelected()->getBitmapN()->height(); + int r = theme->parts.editorSelected()->getBitmapE()->width(); + int b = theme->parts.editorSelected()->getBitmapS()->height(); setBorder(gfx::Border(l, t, r, b)); } @@ -112,10 +112,11 @@ void ColorBar::ScrollableView::onPaint(ui::PaintEvent& ev) { ui::Graphics* g = ev.getGraphics(); SkinTheme* theme = static_cast(getTheme()); - theme->draw_bounds_nw(g, - getClientBounds(), - hasFocus() ? PART_EDITOR_SELECTED_NW: - PART_EDITOR_NORMAL_NW, + + theme->drawRect( + g, getClientBounds(), + (hasFocus() ? theme->parts.editorSelected().get(): + theme->parts.editorNormal().get()), gfx::ColorNone); } @@ -223,10 +224,10 @@ ColorBar::ColorBar(int align) // Change labels foreground color m_buttons.ItemChange.connect(Bind(&ColorBar::onPaletteButtonClick, this)); - m_buttons.addItem(theme->get_part(PART_PAL_EDIT)); - m_buttons.addItem(theme->get_part(PART_PAL_SORT)); - m_buttons.addItem(theme->get_part(PART_PAL_PRESETS)); - m_buttons.addItem(theme->get_part(PART_PAL_OPTIONS)); + m_buttons.addItem(theme->parts.palEdit()); + m_buttons.addItem(theme->parts.palSort()); + m_buttons.addItem(theme->parts.palPresets()); + m_buttons.addItem(theme->parts.palOptions()); // Tooltips TooltipManager* tooltipManager = new TooltipManager(); diff --git a/src/app/ui/color_spectrum.cpp b/src/app/ui/color_spectrum.cpp index 76e9ea9ef..fa2590812 100644 --- a/src/app/ui/color_spectrum.cpp +++ b/src/app/ui/color_spectrum.cpp @@ -83,8 +83,9 @@ void ColorSpectrum::onPaint(ui::PaintEvent& ev) ui::Graphics* g = ev.getGraphics(); SkinTheme* theme = static_cast(getTheme()); - theme->draw_bounds_nw(g, getClientBounds(), - PART_EDITOR_NORMAL_NW, getBgColor()); + theme->drawRect(g, getClientBounds(), + theme->parts.editorNormal().get(), + getBgColor()); gfx::Rect rc = getClientBounds().shrink(3*ui::guiscale()); if (rc.isEmpty()) diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index 9accdd16a..5dddc1b80 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -63,26 +63,26 @@ public: BrushTypeField(ContextBar* owner) : ButtonSet(1) , m_owner(owner) - , m_bitmap(BrushPopup::createSurfaceForBrush(BrushRef(nullptr))) , 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); } ~BrushTypeField() { closePopup(); - - m_bitmap->dispose(); } void updateBrush(tools::Tool* tool = nullptr) { - if (m_bitmap) - m_bitmap->dispose(); + SkinPartPtr part(new SkinPart); + part->setBitmap( + 0, BrushPopup::createSurfaceForBrush( + m_owner->activeBrush(tool))); - m_bitmap = BrushPopup::createSurfaceForBrush( - m_owner->activeBrush(tool)); - - getItem(0)->setIcon(m_bitmap); + getItem(0)->setIcon(part); } void setupTooltips(TooltipManager* tooltipManager) { @@ -325,21 +325,21 @@ class ContextBar::InkTypeField : public ButtonSet public: InkTypeField(ContextBar* owner) : ButtonSet(1) , m_owner(owner) { - addItem( - static_cast(getTheme())->get_part(PART_INK_DEFAULT)); + SkinTheme* theme = SkinTheme::instance(); + addItem(theme->parts.inkDefault()); } void setInkType(InkType inkType) { - int part = PART_INK_DEFAULT; + SkinTheme* theme = SkinTheme::instance(); + SkinPartPtr part = theme->parts.inkDefault(); switch (inkType) { - case InkType::ALPHA_COMPOSITING: part = PART_INK_DEFAULT; break; - case InkType::COPY_COLOR: part = PART_INK_COPY_COLOR; break; - case InkType::LOCK_ALPHA: part = PART_INK_LOCK_ALPHA; break; + case InkType::ALPHA_COMPOSITING: part = theme->parts.inkDefault(); break; + case InkType::COPY_COLOR: part = theme->parts.inkCopyColor(); break; + case InkType::LOCK_ALPHA: part = theme->parts.inkLockAlpha(); break; } - getItem(0)->setIcon( - static_cast(getTheme())->get_part(part)); + getItem(0)->setIcon(part); } protected: @@ -483,10 +483,12 @@ public: : m_icon(1) , m_maskColor(app::Color::fromMask(), IMAGE_RGB) , m_owner(owner) { + SkinTheme* theme = SkinTheme::instance(); + addChild(&m_icon); addChild(&m_maskColor); - m_icon.addItem(static_cast(getTheme())->get_part(PART_SELECTION_OPAQUE)); + m_icon.addItem(theme->parts.selectionOpaque()); gfx::Size sz = m_icon.getItem(0)->getPreferredSize(); sz.w += 2*guiscale(); m_icon.getItem(0)->setMinSize(sz); @@ -536,9 +538,10 @@ private: void onOpaqueChange() { bool opaque = Preferences::instance().selection.opaque(); - int part = (opaque ? PART_SELECTION_OPAQUE: PART_SELECTION_MASKED); - m_icon.getItem(0)->setIcon( - static_cast(getTheme())->get_part(part)); + SkinTheme* theme = SkinTheme::instance(); + SkinPartPtr part = (opaque ? theme->parts.selectionOpaque(): + theme->parts.selectionMasked()); + m_icon.getItem(0)->setIcon(part); m_maskColor.setVisible(!opaque); if (!opaque) { @@ -559,7 +562,7 @@ class ContextBar::PivotField : public ButtonSet { public: PivotField() : ButtonSet(1) { - addItem(static_cast(getTheme())->get_part(PART_PIVOT_HIDDEN)); + addItem(SkinTheme::instance()->parts.pivotHidden()); ItemChange.connect(Bind(&PivotField::onPopup, this)); @@ -580,15 +583,15 @@ private: CheckBox hidden("Hidden pivot by default"); HBox box; ButtonSet buttonset(3); - buttonset.addItem(theme->get_part(PART_PIVOT_NORTHWEST)); - buttonset.addItem(theme->get_part(PART_PIVOT_NORTH)); - buttonset.addItem(theme->get_part(PART_PIVOT_NORTHEAST)); - buttonset.addItem(theme->get_part(PART_PIVOT_WEST)); - buttonset.addItem(theme->get_part(PART_PIVOT_CENTER)); - buttonset.addItem(theme->get_part(PART_PIVOT_EAST)); - buttonset.addItem(theme->get_part(PART_PIVOT_SOUTHWEST)); - buttonset.addItem(theme->get_part(PART_PIVOT_SOUTH)); - buttonset.addItem(theme->get_part(PART_PIVOT_SOUTHEAST)); + buttonset.addItem(theme->parts.pivotNorthwest()); + buttonset.addItem(theme->parts.pivotNorth()); + buttonset.addItem(theme->parts.pivotNortheast()); + buttonset.addItem(theme->parts.pivotWest()); + buttonset.addItem(theme->parts.pivotCenter()); + buttonset.addItem(theme->parts.pivotEast()); + buttonset.addItem(theme->parts.pivotSouthwest()); + buttonset.addItem(theme->parts.pivotSouth()); + buttonset.addItem(theme->parts.pivotSoutheast()); box.addChild(&buttonset); menu.addChild(&hidden); @@ -618,9 +621,22 @@ private: } void onPivotChange() { - int part = PART_PIVOT_HIDDEN + int(Preferences::instance().selection.pivot()); - getItem(0)->setIcon( - static_cast(getTheme())->get_part(part)); + SkinTheme* theme = SkinTheme::instance(); + SkinPartPtr 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) { - int part = PART_FREEHAND_ALGO_DEFAULT; + SkinTheme* theme = SkinTheme::instance(); + SkinPartPtr part = theme->parts.freehandAlgoDefault(); m_freehandAlgo = algo; switch (m_freehandAlgo) { case kDefaultFreehandAlgorithm: - part = PART_FREEHAND_ALGO_DEFAULT; + part = theme->parts.freehandAlgoDefault(); break; case kPixelPerfectFreehandAlgorithm: - part = PART_FREEHAND_ALGO_PIXEL_PERFECT; + part = theme->parts.freehandAlgoPixelPerfect(); break; case kDotsFreehandAlgorithm: - part = PART_FREEHAND_ALGO_DOTS; + part = theme->parts.freehandAlgoDots(); break; } - m_bitmap = static_cast(getTheme())->get_part(part); + m_bitmap = part; invalidate(); } @@ -717,24 +734,20 @@ public: // ContextBar. } - int getWidth() override { - return m_bitmap->width(); - } - - int getHeight() override { - return m_bitmap->height(); + gfx::Size getSize() override { + return m_bitmap->getSize(); } she::Surface* getNormalIcon() override { - return m_bitmap; + return m_bitmap->getBitmap(0); } she::Surface* getSelectedIcon() override { - return m_bitmap; + return m_bitmap->getBitmap(0); } she::Surface* getDisabledIcon() override { - return m_bitmap; + return m_bitmap->getBitmap(0); } int getIconAlign() override { @@ -771,9 +784,9 @@ private: Region rgn(m_popupWindow->getBounds().createUnion(getBounds())); m_popupWindow->setHotRegion(rgn); m_freehandAlgoButton = new ButtonSet(3); - m_freehandAlgoButton->addItem(theme->get_part(PART_FREEHAND_ALGO_DEFAULT)); - m_freehandAlgoButton->addItem(theme->get_part(PART_FREEHAND_ALGO_PIXEL_PERFECT)); - m_freehandAlgoButton->addItem(theme->get_part(PART_FREEHAND_ALGO_DOTS)); + m_freehandAlgoButton->addItem(theme->parts.freehandAlgoDefault()); + m_freehandAlgoButton->addItem(theme->parts.freehandAlgoPixelPerfect()); + m_freehandAlgoButton->addItem(theme->parts.freehandAlgoDots()); m_freehandAlgoButton->setSelectedItem((int)m_freehandAlgo); m_freehandAlgoButton->ItemChange.connect(&FreehandAlgorithmField::onFreehandAlgoChange, this); m_freehandAlgoButton->setTransparent(true); @@ -804,7 +817,7 @@ private: Preferences::instance().tool(tool).freehandAlgorithm(m_freehandAlgo); } - she::Surface* m_bitmap; + SkinPartPtr m_bitmap; FreehandAlgorithm m_freehandAlgo; PopupWindow* m_popupWindow; ButtonSet* m_freehandAlgoButton; @@ -860,9 +873,9 @@ public: SelectionModeField() : ButtonSet(3) { SkinTheme* theme = static_cast(getTheme()); - addItem(theme->get_part(PART_SELECTION_REPLACE)); - addItem(theme->get_part(PART_SELECTION_ADD)); - addItem(theme->get_part(PART_SELECTION_SUBTRACT)); + addItem(theme->parts.selectionReplace()); + addItem(theme->parts.selectionAdd()); + addItem(theme->parts.selectionSubtract()); setSelectedItem((int)Preferences::instance().selection.mode()); } @@ -893,8 +906,8 @@ public: DropPixelsField() : ButtonSet(2) { SkinTheme* theme = static_cast(getTheme()); - addItem(theme->get_part(PART_DROP_PIXELS_OK)); - addItem(theme->get_part(PART_DROP_PIXELS_CANCEL)); + addItem(theme->parts.dropPixelsOk()); + addItem(theme->parts.dropPixelsCancel()); setOfferCapture(false); } diff --git a/src/app/ui/drop_down_button.cpp b/src/app/ui/drop_down_button.cpp index 12a9f672f..a701ae406 100644 --- a/src/app/ui/drop_down_button.cpp +++ b/src/app/ui/drop_down_button.cpp @@ -27,6 +27,8 @@ DropDownButton::DropDownButton(const char* text) , m_button(new Button(text)) , m_dropDown(new Button("")) { + SkinTheme* theme = SkinTheme::instance(); + setup_look(m_button, LeftButtonLook); setup_look(m_dropDown, RightButtonLook); @@ -41,10 +43,9 @@ DropDownButton::DropDownButton(const char* text) setChildSpacing(0); m_dropDown->setIconInterface - (new ButtonIconImpl(static_cast(m_dropDown->getTheme()), - PART_COMBOBOX_ARROW_DOWN, - PART_COMBOBOX_ARROW_DOWN_SELECTED, - PART_COMBOBOX_ARROW_DOWN_DISABLED, + (new ButtonIconImpl(theme->parts.comboboxArrowDown(), + theme->parts.comboboxArrowDownSelected(), + theme->parts.comboboxArrowDownDisabled(), CENTER | MIDDLE)); } diff --git a/src/app/ui/editor/editor_view.cpp b/src/app/ui/editor/editor_view.cpp index e652b228d..4421cf1e3 100644 --- a/src/app/ui/editor/editor_view.cpp +++ b/src/app/ui/editor/editor_view.cpp @@ -41,10 +41,10 @@ EditorView::EditorView(EditorView::Type type) , m_type(type) { SkinTheme* theme = static_cast(getTheme()); - int l = theme->get_part(PART_EDITOR_SELECTED_W)->width(); - int t = theme->get_part(PART_EDITOR_SELECTED_N)->height(); - int r = theme->get_part(PART_EDITOR_SELECTED_E)->width(); - int b = theme->get_part(PART_EDITOR_SELECTED_S)->height(); + int l = theme->parts.editorSelected()->getBitmapW()->width(); + int t = theme->parts.editorSelected()->getBitmapN()->height(); + int r = theme->parts.editorSelected()->getBitmapE()->width(); + int b = theme->parts.editorSelected()->getBitmapS()->height(); setBorder(gfx::Border(l, t, r, b)); setBgColor(gfx::rgba(0, 0, 0)); @@ -75,9 +75,11 @@ void EditorView::onPaint(PaintEvent& ev) } - theme->draw_bounds_nw(g, getClientBounds(), - selected ? PART_EDITOR_SELECTED_NW: - PART_EDITOR_NORMAL_NW, + theme->drawRect( + g, getClientBounds(), + (selected ? + theme->parts.editorSelected().get(): + theme->parts.editorNormal().get()), getBgColor()); } diff --git a/src/app/ui/editor/transform_handles.cpp b/src/app/ui/editor/transform_handles.cpp index f4a733770..da0cf6b93 100644 --- a/src/app/ui/editor/transform_handles.cpp +++ b/src/app/ui/editor/transform_handles.cpp @@ -55,7 +55,7 @@ static struct HandlesInfo { HandleType TransformHandles::getHandleAtPoint(Editor* editor, const gfx::Point& pt, const gfx::Transformation& transform) { SkinTheme* theme = static_cast(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); gfx::Transformation::Corners corners; @@ -130,7 +130,7 @@ void TransformHandles::drawHandles(Editor* editor, const gfx::Transformation& tr if (visiblePivot(angle)) { gfx::Rect pivotBounds = getPivotHandleBounds(editor, transform, corners); SkinTheme* theme = static_cast(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); } @@ -151,7 +151,7 @@ void TransformHandles::invalidateHandles(Editor* editor, const gfx::Transformati // Invalidate each corner handle. for (size_t c=0; cget_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 v = (screenPoints[handles_info[c].i1].y+screenPoints[handles_info[c].i2].y)/2; @@ -163,11 +163,11 @@ void TransformHandles::invalidateHandles(Editor* editor, const gfx::Transformati // Invalidate area where the pivot is. if (visiblePivot(angle)) { 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( gfx::Rect(pivotBounds.x, pivotBounds.y, - part->width(), part->height())); + part->width(), part->height())); } } @@ -176,17 +176,17 @@ gfx::Rect TransformHandles::getPivotHandleBounds(Editor* editor, const gfx::Transformation::Corners& corners) { SkinTheme* theme = static_cast(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()); screenPivotPos.x += editor->zoom().apply(1) / 2; screenPivotPos.y += editor->zoom().apply(1) / 2; return gfx::Rect( - screenPivotPos.x-part->width()/2, - screenPivotPos.y-part->height()/2, - part->width(), - part->height()); + screenPivotPos.x-partSize.w/2, + screenPivotPos.y-partSize.h/2, + partSize.w, + partSize.h); } 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) { SkinTheme* theme = static_cast(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); diff --git a/src/app/ui/file_selector.cpp b/src/app/ui/file_selector.cpp index 5a06b02ff..4c82deabc 100644 --- a/src/app/ui/file_selector.cpp +++ b/src/app/ui/file_selector.cpp @@ -21,7 +21,8 @@ #include "app/modules/gui.h" #include "app/recent_files.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 "base/bind.h" #include "base/convert_to.h" @@ -239,6 +240,7 @@ FileSelector::FileSelector(FileSelectorType type, FileSelectorDelegate* delegate , m_delegate(delegate) , m_navigationLocked(false) { + SkinTheme* theme = SkinTheme::instance(); bool withResizeOptions = (delegate && delegate->hasResizeCombobox()); addChild(new ArrowNavigator(this)); @@ -252,26 +254,26 @@ FileSelector::FileSelector(FileSelectorType type, FileSelectorDelegate* delegate goUpButton()->setFocusStop(false); newFolderButton()->setFocusStop(false); - set_gfxicon_to_button(goBackButton(), - PART_COMBOBOX_ARROW_LEFT, - PART_COMBOBOX_ARROW_LEFT_SELECTED, - PART_COMBOBOX_ARROW_LEFT_DISABLED, - CENTER | MIDDLE); - set_gfxicon_to_button(goForwardButton(), - PART_COMBOBOX_ARROW_RIGHT, - PART_COMBOBOX_ARROW_RIGHT_SELECTED, - PART_COMBOBOX_ARROW_RIGHT_DISABLED, - CENTER | MIDDLE); - set_gfxicon_to_button(goUpButton(), - PART_COMBOBOX_ARROW_UP, - PART_COMBOBOX_ARROW_UP_SELECTED, - PART_COMBOBOX_ARROW_UP_DISABLED, - CENTER | MIDDLE); - set_gfxicon_to_button(newFolderButton(), - PART_NEWFOLDER, - PART_NEWFOLDER_SELECTED, - PART_NEWFOLDER, - CENTER | MIDDLE); + goBackButton()->setIconInterface( + new ButtonIconImpl(theme->parts.comboboxArrowLeft(), + theme->parts.comboboxArrowLeftSelected(), + theme->parts.comboboxArrowLeftDisabled(), + CENTER | MIDDLE)); + goForwardButton()->setIconInterface( + new ButtonIconImpl(theme->parts.comboboxArrowRight(), + theme->parts.comboboxArrowRightSelected(), + theme->parts.comboboxArrowRightDisabled(), + CENTER | MIDDLE)); + goUpButton()->setIconInterface( + new ButtonIconImpl(theme->parts.comboboxArrowUp(), + theme->parts.comboboxArrowUpSelected(), + theme->parts.comboboxArrowUpDisabled(), + CENTER | MIDDLE)); + newFolderButton()->setIconInterface( + new ButtonIconImpl(theme->parts.newfolder(), + theme->parts.newfolderSelected(), + theme->parts.newfolder(), + CENTER | MIDDLE)); setup_mini_look(goBackButton()); setup_mini_look(goForwardButton()); diff --git a/src/app/ui/popup_window_pin.cpp b/src/app/ui/popup_window_pin.cpp index 6bd740adc..8f822b495 100644 --- a/src/app/ui/popup_window_pin.cpp +++ b/src/app/ui/popup_window_pin.cpp @@ -13,6 +13,7 @@ #include "app/modules/gfx.h" #include "app/modules/gui.h" +#include "app/ui/skin/button_icon_impl.h" #include "app/ui/skin/skin_theme.h" #include "base/bind.h" #include "gfx/border.h" @@ -30,14 +31,18 @@ PopupWindowPin::PopupWindowPin(const std::string& text, ClickBehavior clickBehav : PopupWindow(text, clickBehavior) , m_pin("") { + SkinTheme* theme = SkinTheme::instance(); + // Configure the micro check-box look without borders, only the "pin" icon is shown. setup_look(&m_pin, WithoutBordersLook); m_pin.setChildSpacing(0); m_pin.setBorder(gfx::Border(0)); - m_pin.Click.connect(&PopupWindowPin::onPinClick, this); - - set_gfxicon_to_button(&m_pin, PART_UNPINNED, PART_PINNED, PART_UNPINNED, CENTER | MIDDLE); + m_pin.setIconInterface( + new ButtonIconImpl(theme->parts.unpinned(), + theme->parts.pinned(), + theme->parts.unpinned(), + CENTER | MIDDLE)); } void PopupWindowPin::onPinClick(Event& ev) diff --git a/src/app/ui/preview_editor.cpp b/src/app/ui/preview_editor.cpp index 53c921cb3..3dd2f85c7 100644 --- a/src/app/ui/preview_editor.cpp +++ b/src/app/ui/preview_editor.cpp @@ -46,9 +46,9 @@ class MiniCenterButton : public SkinButton { public: MiniCenterButton() : SkinButton( - PART_WINDOW_CENTER_BUTTON_NORMAL, - PART_WINDOW_CENTER_BUTTON_HOT, - PART_WINDOW_CENTER_BUTTON_SELECTED) + SkinTheme::instance()->parts.windowCenterButtonNormal(), + SkinTheme::instance()->parts.windowCenterButtonHot(), + SkinTheme::instance()->parts.windowCenterButtonSelected()) { setup_bevels(this, 0, 0, 0, 0); setDecorative(true); @@ -56,13 +56,12 @@ public: } protected: - void onSetDecorativeWidgetBounds() override - { + void onSetDecorativeWidgetBounds() override { SkinTheme* theme = static_cast(getTheme()); Widget* window = getParent(); gfx::Rect rect(0, 0, 0, 0); - gfx::Size iconSize = theme->get_part_size(PART_WINDOW_PLAY_BUTTON_NORMAL); - gfx::Size closeSize = theme->get_part_size(PART_WINDOW_CLOSE_BUTTON_NORMAL); + gfx::Size iconSize = theme->parts.windowPlayButtonNormal()->getSize(); + gfx::Size closeSize = theme->parts.windowCloseButtonNormal()->getSize(); rect.w = iconSize.w; rect.h = iconSize.h; @@ -91,11 +90,11 @@ protected: class MiniPlayButton : public SkinButton