diff --git a/data/skins/default/sheet.png b/data/skins/default/sheet.png index f56045fe0..46c72d3fe 100644 Binary files a/data/skins/default/sheet.png and b/data/skins/default/sheet.png differ diff --git a/data/skins/default/skin.xml b/data/skins/default/skin.xml index 31d97c42c..bd893fd57 100644 --- a/data/skins/default/skin.xml +++ b/data/skins/default/skin.xml @@ -128,9 +128,9 @@ - - - + + + @@ -151,6 +151,12 @@ + + + + + + diff --git a/src/skin/skin_button.h b/src/skin/skin_button.h new file mode 100644 index 000000000..fc48a340c --- /dev/null +++ b/src/skin/skin_button.h @@ -0,0 +1,74 @@ +/* ASEPRITE + * Copyright (C) 2001-2012 David Capello + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SKIN_BUTTON_H_INCLUDED +#define SKIN_BUTTON_H_INCLUDED + +#include "skin/skin_parts.h" +#include "skin/skin_theme.h" +#include "ui/button.h" +#include "ui/graphics.h" +#include "ui/paint_event.h" + +template +class SkinButton : public Base +{ +public: + SkinButton(SkinPart partNormal, + SkinPart partHot, + SkinPart partSelected) + : Base("") + , m_partNormal(partNormal) + , m_partHot(partHot) + , m_partSelected(partSelected) + { + } + + void setParts(SkinPart partNormal, + SkinPart partHot, + SkinPart partSelected) { + m_partNormal = partNormal; + m_partHot = partHot; + m_partSelected = partSelected; + invalidate(); + } + +protected: + void onPaint(ui::PaintEvent& ev) OVERRIDE { + gfx::Rect bounds(getClientBounds()); + Graphics* g = ev.getGraphics(); + SkinTheme* theme = static_cast(getTheme()); + SkinPart part; + + if (isSelected()) + part = m_partSelected; + else if (hasMouseOver()) + part = m_partHot; + else + part = m_partNormal; + + g->drawAlphaBitmap(theme->get_part(part), bounds.x, bounds.y); + } + +private: + SkinPart m_partNormal; + SkinPart m_partHot; + SkinPart m_partSelected; +}; + +#endif diff --git a/src/skin/skin_parts.h b/src/skin/skin_parts.h index 605d8bb1b..a1687123b 100644 --- a/src/skin/skin_parts.h +++ b/src/skin/skin_parts.h @@ -20,7 +20,7 @@ #define SKIN_PARTS_H_INCLUDED // Available parts in the skin sheet -enum { +enum SkinPart { PART_RADIO_NORMAL, PART_RADIO_SELECTED, @@ -160,6 +160,14 @@ enum { 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_SLIDER_FULL_NW, PART_SLIDER_FULL_N, PART_SLIDER_FULL_NE, diff --git a/src/skin/skin_theme.cpp b/src/skin/skin_theme.cpp index b91d0032c..7342af1d9 100644 --- a/src/skin/skin_theme.cpp +++ b/src/skin/skin_theme.cpp @@ -165,6 +165,12 @@ SkinTheme::SkinTheme() 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["slider_full"] = PART_SLIDER_FULL_NW; sheet_mapping["slider_empty"] = PART_SLIDER_EMPTY_NW; sheet_mapping["slider_full_focused"] = PART_SLIDER_FULL_FOCUSED_NW; @@ -394,6 +400,12 @@ void SkinTheme::reload_fonts() m_minifont = loadFont("UserMiniFont", "skins/" + m_selected_skin + "/minifont.png"); } +gfx::Size SkinTheme::get_part_size(int part_i) const +{ + BITMAP* bmp = get_part(part_i); + return gfx::Size(bmp->w, bmp->h); +} + void SkinTheme::onRegenerate() { scrollbar_size = 12 * jguiscale(); @@ -787,7 +799,7 @@ void SkinTheme::getWindowMask(Widget* widget, Region& region) region = widget->getBounds(); } -void SkinTheme::mapDecorativeWidget(Widget* widget) +void SkinTheme::setDecorativeWidgetBounds(Widget* widget) { if (widget->getId() == kThemeCloseButtonId) { Widget* window = widget->getParent(); @@ -797,8 +809,8 @@ void SkinTheme::mapDecorativeWidget(Widget* widget) rect->y2 = m_part[PART_WINDOW_CLOSE_BUTTON_NORMAL]->h; jrect_displace(rect, - window->rc->x2 - 3 - jrect_w(rect), - window->rc->y1 + 3); + window->rc->x2 - 3*jguiscale() - jrect_w(rect), + window->rc->y1 + 3*jguiscale()); jwidget_set_rect(widget, rect); jrect_free(rect); diff --git a/src/skin/skin_theme.h b/src/skin/skin_theme.h index 7e0af12a4..0343e2435 100644 --- a/src/skin/skin_theme.h +++ b/src/skin/skin_theme.h @@ -19,7 +19,7 @@ #ifndef SKIN_THEME_H_INCLUDED #define SKIN_THEME_H_INCLUDED -#include "gfx/rect.h" +#include "gfx/fwd.h" #include "skin/skin_parts.h" #include "ui/color.h" #include "ui/rect.h" @@ -122,7 +122,7 @@ public: ui::Cursor* getCursor(ui::CursorType type); void initWidget(ui::Widget* widget); void getWindowMask(ui::Widget* widget, gfx::Region& region); - void mapDecorativeWidget(ui::Widget* widget); + void setDecorativeWidgetBounds(ui::Widget* widget); void paintDesktop(ui::PaintEvent& ev); void paintBox(ui::PaintEvent& ev); @@ -155,6 +155,7 @@ public: BITMAP* get_part(int part_i) const { return m_part[part_i]; } BITMAP* 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 void draw_bounds_array(BITMAP* bmp, int x1, int y1, int x2, int y2, int parts[8]); diff --git a/src/ui/theme.h b/src/ui/theme.h index 42fe682e0..56a49eaee 100644 --- a/src/ui/theme.h +++ b/src/ui/theme.h @@ -43,7 +43,7 @@ namespace ui { virtual Cursor* getCursor(CursorType type) = 0; virtual void initWidget(Widget* widget) = 0; virtual void getWindowMask(ui::Widget* widget, gfx::Region& region) = 0; - virtual void mapDecorativeWidget(ui::Widget* widget) = 0; + virtual void setDecorativeWidgetBounds(ui::Widget* widget) = 0; virtual void paintDesktop(PaintEvent& ev) = 0; virtual void paintBox(PaintEvent& ev) = 0; diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 4d35aa794..789e8e663 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -557,6 +557,11 @@ void Widget::saveLayout() (*it)->saveLayout(); } +void Widget::setDecorativeWidgetBounds() +{ + onSetDecorativeWidgetBounds(); +} + /**********************************************************************/ /* position and geometry */ @@ -1364,6 +1369,13 @@ void Widget::onInitTheme(InitThemeEvent& ev) } } +void Widget::onSetDecorativeWidgetBounds() +{ + if (m_theme) { + m_theme->setDecorativeWidgetBounds(this); + } +} + void Widget::onEnable() { // Do nothing diff --git a/src/ui/widget.h b/src/ui/widget.h index 66108bc77..b3558a443 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -235,6 +235,8 @@ namespace ui { void loadLayout(); void saveLayout(); + void setDecorativeWidgetBounds(); + // =============================================================== // POSITION & GEOMETRY // =============================================================== @@ -327,6 +329,7 @@ namespace ui { virtual void onPaint(PaintEvent& ev); virtual void onBroadcastMouseMessage(WidgetsList& targets); virtual void onInitTheme(InitThemeEvent& ev); + virtual void onSetDecorativeWidgetBounds(); virtual void onEnable(); virtual void onDisable(); virtual void onSelect(); diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 74671935d..09484ed23 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -517,12 +517,12 @@ void Window::windowSetPosition(JRect rect) jrect_copy(this->rc, rect); Rect cpos = getChildrenBounds(); - /* set all the children to the same "child_pos" */ + // Set all the children to the same "cpos" UI_FOREACH_WIDGET(getChildren(), it) { Widget* child = *it; if (child->isDecorative()) - child->getTheme()->mapDecorativeWidget(child); + child->setDecorativeWidgetBounds(); else child->setBounds(cpos); } diff --git a/src/widgets/mini_editor.cpp b/src/widgets/mini_editor.cpp index 477e79185..26a5f5f1b 100644 --- a/src/widgets/mini_editor.cpp +++ b/src/widgets/mini_editor.cpp @@ -20,14 +20,17 @@ #include "widgets/mini_editor.h" +#include "base/bind.h" #include "gfx/rect.h" #include "ini_file.h" #include "modules/editors.h" #include "modules/gui.h" +#include "skin/skin_button.h" #include "skin/skin_theme.h" #include "ui/base.h" #include "ui/button.h" #include "ui/close_event.h" +#include "ui/message.h" #include "ui/rect.h" #include "ui/system.h" #include "widgets/editor/editor.h" @@ -38,9 +41,78 @@ using namespace ui; namespace widgets { +class MiniPlayButton : public SkinButton