From 921c5c8ad10cd45dfe7db355d5221ba6b904457f Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 17 Feb 2017 18:00:10 -0300 Subject: [PATCH] Move ui::Separator drawing code to new styles --- data/themes/default/theme.xml | 30 ++++++++- src/app/commands/cmd_keyboard_shortcuts.cpp | 2 +- src/app/ui/browser_view.cpp | 2 +- src/app/ui/data_recovery_view.cpp | 2 +- src/app/ui/skin/skin_theme.cpp | 61 +++++------------ src/app/ui/skin/skin_theme.h | 1 - src/ui/menu.h | 2 +- src/ui/separator.cpp | 7 +- src/ui/separator.h | 6 +- src/ui/style.h | 7 +- src/ui/theme.cpp | 74 ++++++++++++++++++--- src/ui/theme.h | 4 +- 12 files changed, 121 insertions(+), 77 deletions(-) diff --git a/data/themes/default/theme.xml b/data/themes/default/theme.xml index 071e28d0e..bda0c25f9 100644 --- a/data/themes/default/theme.xml +++ b/data/themes/default/theme.xml @@ -832,9 +832,9 @@ + + + + + + + + diff --git a/src/app/commands/cmd_keyboard_shortcuts.cpp b/src/app/commands/cmd_keyboard_shortcuts.cpp index 523aa0897..9a2938f4c 100644 --- a/src/app/commands/cmd_keyboard_shortcuts.cpp +++ b/src/app/commands/cmd_keyboard_shortcuts.cpp @@ -511,7 +511,7 @@ private: if (!group) { group = new Separator( section()->children()[sectionIdx]->text(), HORIZONTAL); - group->setBgColor(SkinTheme::instance()->colors.background()); + group->setStyle(SkinTheme::instance()->newStyles.separatorInView()); searchList()->addChild(group); } diff --git a/src/app/ui/browser_view.cpp b/src/app/ui/browser_view.cpp index 0c81ccc7e..43055c02d 100644 --- a/src/app/ui/browser_view.cpp +++ b/src/app/ui/browser_view.cpp @@ -429,8 +429,8 @@ private: void addSeparator() { auto sep = new Separator("", HORIZONTAL); + sep->setStyle(SkinTheme::instance()->newStyles.separatorInView()); sep->setBorder(gfx::Border(0, font()->height(), 0, font()->height())); - sep->setBgColor(SkinTheme::instance()->colors.textboxFace()); sep->setExpansive(true); addChild(sep); } diff --git a/src/app/ui/data_recovery_view.cpp b/src/app/ui/data_recovery_view.cpp index 72adda460..20d8aa4fd 100644 --- a/src/app/ui/data_recovery_view.cpp +++ b/src/app/ui/data_recovery_view.cpp @@ -116,7 +116,7 @@ void DataRecoveryView::fillList() continue; auto sep = new Separator(session->name(), HORIZONTAL); - sep->setBgColor(SkinTheme::instance()->colors.background()); + sep->setStyle(SkinTheme::instance()->newStyles.separatorInView()); sep->setBorder(sep->border() + gfx::Border(0, 8, 0, 8)*guiscale()); m_listBox.addChild(sep); diff --git a/src/app/ui/skin/skin_theme.cpp b/src/app/ui/skin/skin_theme.cpp index 50c191794..0fe74c055 100644 --- a/src/app/ui/skin/skin_theme.cpp +++ b/src/app/ui/skin/skin_theme.cpp @@ -590,6 +590,16 @@ void SkinTheme::loadXml(const std::string& skinId) } } + // Offset + const char* x = xmlLayer->Attribute("x"); + const char* y = xmlLayer->Attribute("y"); + if (x || y) { + gfx::Point offset(0, 0); + if (x) offset.x = std::strtol(x, nullptr, 10); + if (y) offset.y = std::strtol(y, nullptr, 10); + layer.setOffset(offset); + } + // Sprite sheet const char* partId = xmlLayer->Attribute("part"); if (partId) { @@ -771,18 +781,16 @@ void SkinTheme::initWidget(Widget* widget) break; case kSeparatorWidget: - // Frame - if ((widget->align() & HORIZONTAL) && - (widget->align() & VERTICAL)) { - BORDER(4 * scale); - } // Horizontal bar - else if (widget->align() & HORIZONTAL) { - BORDER4(2 * scale, 4 * scale, 2 * scale, 0); + if (widget->align() & HORIZONTAL) { + if (dynamic_cast(widget)) + widget->setStyle(newStyles.menuSeparator()); + else + widget->setStyle(newStyles.horizontalSeparator()); } // Vertical bar else { - BORDER4(4 * scale, 2 * scale, 1 * scale, 2 * scale); + widget->setStyle(newStyles.verticalSeparator()); } break; @@ -1308,43 +1316,6 @@ void SkinTheme::paintRadioButton(PaintEvent& ev) drawRect(g, bounds, parts.radioFocus().get()); } -void SkinTheme::paintSeparator(ui::PaintEvent& ev) -{ - Graphics* g = ev.graphics(); - Widget* widget = static_cast(ev.getSource()); - gfx::Rect bounds = widget->clientBounds(); - - // background - g->fillRect(BGCOLOR, bounds); - - if (widget->align() & HORIZONTAL) { - int h = parts.separatorHorz()->bitmap(0)->height(); - drawHline(g, gfx::Rect(bounds.x, bounds.y+bounds.h/2-h/2, - bounds.w, h), - parts.separatorHorz().get()); - } - - if (widget->align() & VERTICAL) { - int w = parts.separatorVert()->bitmap(0)->width(); - drawVline(g, gfx::Rect(bounds.x+bounds.w/2-w/2, bounds.y, - w, bounds.h), - parts.separatorVert().get()); - } - - // text - if (widget->hasText()) { - int h = widget->textHeight(); - Rect r( - bounds.x + widget->border().left()/2 + h/2, - bounds.y + bounds.h/2 - h/2, - widget->textWidth(), h); - - drawText(g, nullptr, - colors.separatorLabel(), BGCOLOR, - widget, r, 0, widget->mnemonic()); - } -} - void SkinTheme::paintSlider(PaintEvent& ev) { Graphics* g = ev.graphics(); diff --git a/src/app/ui/skin/skin_theme.h b/src/app/ui/skin/skin_theme.h index fd05e339d..46080ed94 100644 --- a/src/app/ui/skin/skin_theme.h +++ b/src/app/ui/skin/skin_theme.h @@ -64,7 +64,6 @@ namespace app { void paintMenu(ui::PaintEvent& ev) override; void paintMenuItem(ui::PaintEvent& ev) override; void paintRadioButton(ui::PaintEvent& ev) override; - void paintSeparator(ui::PaintEvent& ev) override; void paintSlider(ui::PaintEvent& ev) override; void paintComboBoxEntry(ui::PaintEvent& ev) override; void paintTextBox(ui::PaintEvent& ev) override; diff --git a/src/ui/menu.h b/src/ui/menu.h index eed627d8d..7b36f0edf 100644 --- a/src/ui/menu.h +++ b/src/ui/menu.h @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2001-2016 David Capello +// Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. diff --git a/src/ui/separator.cpp b/src/ui/separator.cpp index 45dd8966a..0fd239e99 100644 --- a/src/ui/separator.cpp +++ b/src/ui/separator.cpp @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2001-2013, 2015 David Capello +// Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -29,11 +29,6 @@ Separator::Separator(const std::string& text, int align) initTheme(); } -void Separator::onPaint(PaintEvent& ev) -{ - theme()->paintSeparator(ev); -} - void Separator::onSizeHint(SizeHintEvent& ev) { Size maxSize(0, 0); diff --git a/src/ui/separator.h b/src/ui/separator.h index 6b3d3176b..93d927a49 100644 --- a/src/ui/separator.h +++ b/src/ui/separator.h @@ -1,5 +1,5 @@ // Aseprite UI Library -// Copyright (C) 2001-2013 David Capello +// Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -12,13 +12,11 @@ namespace ui { - class Separator : public Widget - { + class Separator : public Widget { public: Separator(const std::string& text, int align); protected: - void onPaint(PaintEvent& ev) override; void onSizeHint(SizeHintEvent& ev) override; }; diff --git a/src/ui/style.h b/src/ui/style.h index c2f9f9611..77800f4b9 100644 --- a/src/ui/style.h +++ b/src/ui/style.h @@ -10,6 +10,7 @@ #include "gfx/border.h" #include "gfx/color.h" +#include "gfx/point.h" #include "gfx/rect.h" #include "gfx/size.h" #include "ui/base.h" @@ -50,7 +51,8 @@ namespace ui { , m_align(CENTER | MIDDLE) , m_color(gfx::ColorNone) , m_icon(nullptr) - , m_spriteSheet(nullptr) { + , m_spriteSheet(nullptr) + , m_offset(0, 0) { } Type type() const { return m_type; } @@ -62,6 +64,7 @@ namespace ui { she::Surface* spriteSheet() const { return m_spriteSheet; } const gfx::Rect& spriteBounds() const { return m_spriteBounds; } const gfx::Rect& slicesBounds() const { return m_slicesBounds; } + const gfx::Point& offset() const { return m_offset; } void setType(const Type type) { m_type = type; } void setFlags(const int flags) { m_flags = flags; } @@ -71,6 +74,7 @@ namespace ui { void setSpriteSheet(she::Surface* spriteSheet) { m_spriteSheet = spriteSheet; } void setSpriteBounds(const gfx::Rect& bounds) { m_spriteBounds = bounds; } void setSlicesBounds(const gfx::Rect& bounds) { m_slicesBounds = bounds; } + void setOffset(const gfx::Point& offset) { m_offset = offset; } private: Type m_type; @@ -81,6 +85,7 @@ namespace ui { she::Surface* m_spriteSheet; gfx::Rect m_spriteBounds; gfx::Rect m_slicesBounds; + gfx::Point m_offset; }; typedef std::vector Layers; diff --git a/src/ui/theme.cpp b/src/ui/theme.cpp index 3075b286c..7edf329f4 100644 --- a/src/ui/theme.cpp +++ b/src/ui/theme.cpp @@ -154,10 +154,11 @@ void Theme::paintWidget(Graphics* g, g->fillRect(widget->bgColor(), bounds); gfx::Rect rc = bounds; + gfx::Color bgColor = gfx::ColorNone; for_each_layer( widget, style, - [this, g, widget, &rc](const Style::Layer& layer) { - paintLayer(g, widget, layer, rc); + [this, g, widget, &rc, &bgColor](const Style::Layer& layer) { + paintLayer(g, widget, layer, rc, bgColor); }); } @@ -226,12 +227,14 @@ void Theme::paintTooltip(Graphics* g, void Theme::paintLayer(Graphics* g, const Widget* widget, const Style::Layer& layer, - gfx::Rect& rc) + gfx::Rect& rc, + gfx::Color& bgColor) { switch (layer.type()) { case Style::Layer::Type::kBackground: if (layer.color() != gfx::ColorNone) { + bgColor = layer.color(); g->fillRect(layer.color(), rc); } @@ -247,14 +250,61 @@ void Theme::paintLayer(Graphics* g, rc.w -= layer.spriteBounds().w - layer.slicesBounds().w; rc.h -= layer.spriteBounds().h - layer.slicesBounds().h; } - // Draw background as a solid piece + // Draw background using different methods else { - g->drawRgbaSurface(layer.spriteSheet(), - layer.spriteBounds().x, - layer.spriteBounds().y, - rc.x, rc.y, - layer.spriteBounds().w, - layer.spriteBounds().h); + IntersectClip clip(g, rc); + if (clip) { + switch (layer.align()) { + + // Horizontal line + case MIDDLE: + for (int x=rc.x; xdrawRgbaSurface(layer.spriteSheet(), + layer.spriteBounds().x, + layer.spriteBounds().y, + x, rc.y+rc.h/2-layer.spriteBounds().h/2, + layer.spriteBounds().w, + layer.spriteBounds().h); + } + break; + + // Vertical line + case CENTER: + for (int y=rc.y; ydrawRgbaSurface(layer.spriteSheet(), + layer.spriteBounds().x, + layer.spriteBounds().y, + rc.x+rc.w/2-layer.spriteBounds().w/2, y, + layer.spriteBounds().w, + layer.spriteBounds().h); + } + break; + + // One instance + case CENTER | MIDDLE: + g->drawRgbaSurface(layer.spriteSheet(), + layer.spriteBounds().x, + layer.spriteBounds().y, + rc.x+rc.w/2-layer.spriteBounds().w/2, + rc.y+rc.h/2-layer.spriteBounds().h/2, + layer.spriteBounds().w, + layer.spriteBounds().h); + break; + + // Pattern + case 0: + for (int y=rc.y; ydrawRgbaSurface(layer.spriteSheet(), + layer.spriteBounds().x, + layer.spriteBounds().y, + x, y, + layer.spriteBounds().w, + layer.spriteBounds().h); + } + break; + } + } } } break; @@ -297,9 +347,11 @@ void Theme::paintLayer(Graphics* g, else pt.y = rc.y+rc.h/2-textSize.h/2; + pt += layer.offset(); + g->drawUIText(widget->text(), layer.color(), - gfx::ColorNone, + bgColor, pt, widget->mnemonic()); } break; diff --git a/src/ui/theme.h b/src/ui/theme.h index 1651060f2..e49803d69 100644 --- a/src/ui/theme.h +++ b/src/ui/theme.h @@ -62,7 +62,6 @@ namespace ui { virtual void paintMenu(PaintEvent& ev) = 0; virtual void paintMenuItem(PaintEvent& ev) = 0; virtual void paintRadioButton(PaintEvent& ev) = 0; - virtual void paintSeparator(PaintEvent& ev) = 0; virtual void paintSlider(PaintEvent& ev) = 0; virtual void paintComboBoxEntry(PaintEvent& ev) = 0; virtual void paintTextBox(PaintEvent& ev) = 0; @@ -112,7 +111,8 @@ namespace ui { void paintLayer(Graphics* g, const Widget* widget, const Style::Layer& layer, - gfx::Rect& rc); + gfx::Rect& rc, + gfx::Color& bgColor); void measureLayer(const Widget* widget, const Style::Layer& layer, gfx::Border& borderHint,