mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-26 17:37:07 +00:00
Move ui::Separator drawing code to new styles
This commit is contained in:
parent
86f138a714
commit
921c5c8ad1
@ -832,9 +832,9 @@
|
||||
</style>
|
||||
|
||||
<style id="window_close_button" margin-top="3" margin-right="3">
|
||||
<background part="window_button_normal" />
|
||||
<background part="window_button_hot" state="mouse" />
|
||||
<background part="window_button_selected" state="selected" />
|
||||
<background part="window_button_normal" align="center middle" />
|
||||
<background part="window_button_hot" state="mouse" align="center middle" />
|
||||
<background part="window_button_selected" state="selected" align="center middle" />
|
||||
<icon part="window_close_icon" color="button_normal_text" />
|
||||
<icon part="window_close_icon" color="button_hot_text" state="mouse" />
|
||||
<icon part="window_close_icon" color="button_selected_text" state="selected" />
|
||||
@ -1021,6 +1021,30 @@
|
||||
<background color="workspace" />
|
||||
</style>
|
||||
|
||||
<style id="horizontal_separator"
|
||||
border-left="2"
|
||||
border-top="4"
|
||||
border-right="2"
|
||||
border-bottom="0">
|
||||
<background part="separator_horz" color="window_face" align="middle" />
|
||||
<text color="separator_label" x="4" align="left middle" />
|
||||
</style>
|
||||
|
||||
<style id="menu_separator" extends="horizontal_separator">
|
||||
</style>
|
||||
|
||||
<style id="separator_in_view" extends="horizontal_separator">
|
||||
<background part="separator_horz" color="background" align="middle" />
|
||||
</style>
|
||||
|
||||
<style id="vertical_separator"
|
||||
border-left="4"
|
||||
border-top="2"
|
||||
border-right="1"
|
||||
border-bottom="2">
|
||||
<background part="separator_vert" align="center" />
|
||||
</style>
|
||||
|
||||
</styles>
|
||||
|
||||
</theme>
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<MenuSeparator*>(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<Widget*>(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();
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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<Layer> Layers;
|
||||
|
@ -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; x<rc.x2(); x+=layer.spriteBounds().w) {
|
||||
g->drawRgbaSurface(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; y<rc.y2(); y+=layer.spriteBounds().h) {
|
||||
g->drawRgbaSurface(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; y<rc.y2(); y+=layer.spriteBounds().h) {
|
||||
for (int x=rc.x; x<rc.x2(); x+=layer.spriteBounds().w)
|
||||
g->drawRgbaSurface(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;
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user