Move painting code for checkbox & radio button to theme styles

This commit is contained in:
David Capello 2017-03-17 15:43:42 -03:00
parent b5e7ed2836
commit bc01f16a4e
9 changed files with 90 additions and 162 deletions

View File

@ -445,6 +445,7 @@
<text color="text" align="left" />
<text color="disabled" align="left" state="disabled" />
</style>
<style id="mini_label" extends="label" font="mini" />
<style id="link">
<text color="link_text" align="left" />
<text color="link_hover" align="left" state="mouse" />
@ -457,14 +458,14 @@
<text color="workspace_link" align="left" />
<text color="workspace_link_hover" align="left" state="mouse" />
</style>
<style id="workspace_update_link" padding-right="16">
<background part="button_normal" />
<background part="button_hot" state="mouse" />
<background part="button_selected" state="selected" />
<style id="workspace_update_link">
<background-border part="button_normal" />
<background-border part="button_hot" state="mouse" />
<background-border part="button_selected" state="selected" />
<icon part="warning_box" align="right" />
<text color="button_normal_text" />
<text color="button_hot_text" state="mouse" />
<text color="button_selected_text" state="selected" />
<text color="button_normal_text" align="left" />
<text color="button_hot_text" align="left" state="mouse" />
<text color="button_selected_text" align="left" state="selected" />
</style>
<style id="view" border="3" border-top="4">
<background color="window_face" />
@ -485,39 +486,63 @@
<border part="editor_selected" state="focus" />
</style>
<style id="button">
<background part="button_normal" />
<background part="button_hot" state="mouse" />
<background part="button_focused" state="focus" />
<background part="button_selected" state="selected" />
<background-border part="button_normal" />
<background-border part="button_hot" state="mouse" />
<background-border part="button_focused" state="focus" />
<background-border part="button_selected" state="selected" />
<text color="button_normal_text" />
<text color="button_hot_text" state="mouse" />
<text color="button_selected_text" state="selected" />
<text color="background" x="1" y="1" state="disabled" />
<newlayer />
<text color="disabled" state="disabled" />
</style>
<style id="check_box" border="2">
<background part="check_focus" color="check_hot_face" state="mouse focus" />
<background part="check_focus" color="check_focus_face" state="focus" />
<background color="check_hot_face" state="mouse" />
<text color="text" align="left middle" x="14" />
<text color="disabled" align="left middle" x="14" state="disabled" />
<icon part="check_normal" align="left middle" x="2" />
<icon part="check_selected" align="left middle" x="2" state="selected" />
<icon part="check_disabled" align="left middle" x="2" state="disabled" />
</style>
<style id="radio_button" border="2">
<background part="radio_focus" color="radio_hot_face" state="mouse focus" />
<background part="radio_focus" color="radio_focus_face" state="focus" />
<background color="radio_hot_face" state="mouse" />
<text color="text" align="left middle" x="14" />
<text color="disabled" align="left middle" x="14" state="disabled" />
<icon part="radio_normal" align="left middle" x="2" />
<icon part="radio_selected" align="left middle" x="2" state="selected" />
<icon part="radio_disabled" align="left middle" x="2" state="disabled" />
</style>
<style id="mini_button">
<background part="toolbutton_last" />
<background part="toolbutton_hot" state="mouse" />
<background part="toolbutton_hot" state="focus" />
<background part="toolbutton_pushed" state="selected" />
<background-border part="toolbutton_last" />
<background-border part="toolbutton_hot" state="mouse" />
<background-border part="toolbutton_hot" state="focus" />
<background-border part="toolbutton_pushed" state="selected" />
<text color="button_normal_text" />
<text color="button_hot_text" state="mouse" />
<text color="button_selected_text" state="selected" />
</style>
<style id="mini_check_box" extends="check_box" font="mini" />
<style id="combobox_button" extends="mini_button">
<icon part="combobox_arrow_down" />
<icon part="combobox_arrow_down_selected" state="selected" />
<icon part="combobox_arrow_down_disabled" state="disabled" />
</style>
<style id="drop_down_button" extends="button">
<background part="drop_down_button_left_normal" />
<background part="drop_down_button_left_selected" state="selected" />
<background part="drop_down_button_left_hot" state="mouse" />
<background part="drop_down_button_left_focused" state="focus" />
<background-border part="drop_down_button_left_normal" />
<background-border part="drop_down_button_left_selected" state="selected" />
<background-border part="drop_down_button_left_hot" state="mouse" />
<background-border part="drop_down_button_left_focused" state="focus" />
</style>
<style id="drop_down_expand_button" extends="button">
<background part="drop_down_button_right_normal" />
<background part="drop_down_button_right_selected" state="selected" />
<background part="drop_down_button_right_hot" state="mouse" />
<background part="drop_down_button_right_focused" state="focus" />
<background-border part="drop_down_button_right_normal" />
<background-border part="drop_down_button_right_selected" state="selected" />
<background-border part="drop_down_button_right_hot" state="mouse" />
<background-border part="drop_down_button_right_focused" state="focus" />
<icon part="combobox_arrow_down" />
<icon part="combobox_arrow_down_selected" state="selected" />
<icon part="combobox_arrow_down_disabled" state="disabled" />
@ -557,15 +582,15 @@
<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" />
<background-border 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 id="separator_in_view" extends="horizontal_separator">
<background part="separator_horz" color="background" align="middle" />
<background-border 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" />
<background-border part="separator_vert" align="center" />
</style>
<style id="recent_item" />
<style id="recent_file" border="2">
@ -666,11 +691,11 @@
<background color="timeline_normal" part="timeline_normal" />
</style>
<style id="timeline_box">
<background color="timeline_normal" part="timeline_normal" />
<background color="timeline_hover" part="timeline_hover" state="mouse" />
<background color="timeline_active" part="timeline_active" state="focus" />
<background color="timeline_active_hover" part="timeline_active_hover" state="focus mouse" />
<background color="timeline_clicked" part="timeline_clicked" state="selected" />
<background-border color="timeline_normal" part="timeline_normal" />
<background-border color="timeline_hover" part="timeline_hover" state="mouse" />
<background-border color="timeline_active" part="timeline_active" state="focus" />
<background-border color="timeline_active_hover" part="timeline_active_hover" state="focus mouse" />
<background-border color="timeline_clicked" part="timeline_clicked" state="selected" />
</style>
<style id="timeline_open_eye" extends="timeline_box">
<icon part="timeline_open_eye_normal" />

View File

@ -18,7 +18,6 @@
#include "app/document.h"
#include "app/ini_file.h"
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/pref/preferences.h"
#include "app/shade.h"
@ -309,7 +308,7 @@ class ContextBar::ContiguousField : public CheckBox
{
public:
ContiguousField() : CheckBox("Contiguous") {
setup_mini_font(this);
setStyle(SkinTheme::instance()->styles.miniCheckBox());
}
protected:
@ -1142,7 +1141,7 @@ class ContextBar::FreehandAlgorithmField : public CheckBox
{
public:
FreehandAlgorithmField() : CheckBox("Pixel-perfect") {
setup_mini_font(this);
setStyle(SkinTheme::instance()->styles.miniCheckBox());
}
void setupTooltips(TooltipManager* tooltipManager) {
@ -1292,7 +1291,7 @@ class ContextBar::AutoSelectLayerField : public CheckBox
{
public:
AutoSelectLayerField() : CheckBox("Auto Select Layer") {
setup_mini_font(this);
setStyle(SkinTheme::instance()->styles.miniCheckBox());
}
protected:
@ -1397,17 +1396,17 @@ ContextBar::ContextBar()
addChild(m_selectBoxHelp = new Label(""));
setup_mini_font(m_sprayLabel);
m_sprayLabel->setStyle(theme->styles.miniLabel());
addChild(m_freehandBox = new HBox());
#if 0 // TODO for v1.1
m_freehandBox->addChild(m_freehandLabel = new Label("Freehand:"));
setup_mini_font(m_freehandLabel);
m_freehandLabel->setStyle(theme->styles.miniLabel());
#endif
m_freehandBox->addChild(m_freehandAlgo = new FreehandAlgorithmField());
setup_mini_font(m_toleranceLabel);
setup_mini_font(m_inkOpacityLabel);
m_toleranceLabel->setStyle(theme->styles.miniLabel());
m_inkOpacityLabel->setStyle(theme->styles.miniLabel());
addChild(m_symmetry = new SymmetryField());
m_symmetry->setVisible(Preferences::instance().symmetryMode.enabled());

View File

@ -546,6 +546,9 @@ void SkinTheme::loadXml(const std::string& skinId)
if (layerName == "background") {
layer.setType(ui::Style::Layer::Type::kBackground);
}
else if (layerName == "background-border") {
layer.setType(ui::Style::Layer::Type::kBackgroundBorder);
}
else if (layerName == "border") {
layer.setType(ui::Style::Layer::Type::kBorder);
}
@ -718,14 +721,11 @@ void SkinTheme::initWidget(Widget* widget)
break;
case kCheckWidget:
BORDER(2 * scale);
widget->setChildSpacing(4 * scale);
widget->setStyle(styles.checkBox());
break;
static_cast<ButtonBase*>(widget)->setIconInterface
(new ButtonIconImpl(parts.checkNormal(),
parts.checkSelected(),
parts.checkDisabled(),
LEFT | MIDDLE));
case kRadioWidget:
widget->setStyle(styles.radioButton());
break;
case kEntryWidget:
@ -789,17 +789,6 @@ void SkinTheme::initWidget(Widget* widget)
widget->setStyle(styles.splitter());
break;
case kRadioWidget:
BORDER(2 * scale);
widget->setChildSpacing(4 * scale);
static_cast<ButtonBase*>(widget)->setIconInterface
(new ButtonIconImpl(parts.radioNormal(),
parts.radioSelected(),
parts.radioDisabled(),
LEFT | MIDDLE));
break;
case kSeparatorWidget:
// Horizontal bar
if (widget->align() & HORIZONTAL) {
@ -906,54 +895,6 @@ gfx::Size SkinTheme::getEntryCaretSize(Widget* widget)
return gfx::Size(2*guiscale(), widget->textHeight()+2*guiscale());
}
void SkinTheme::paintCheckBox(PaintEvent& ev)
{
Graphics* g = ev.graphics();
ButtonBase* widget = static_cast<ButtonBase*>(ev.getSource());
gfx::Rect bounds = widget->clientBounds();
IButtonIcon* iconInterface = widget->iconInterface();
gfx::Rect box, text, icon;
gfx::Color bg;
widget->getTextIconInfo(&box, &text, &icon,
iconInterface ? iconInterface->iconAlign(): 0,
iconInterface ? iconInterface->size().w: 0,
iconInterface ? iconInterface->size().h: 0);
// Check box look
LookType look = NormalLook;
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
if (skinPropery)
look = skinPropery->getLook();
// Background
g->fillRect(bg = BGCOLOR, bounds);
// Mouse
if (widget->isEnabled()) {
if (widget->hasMouseOver())
g->fillRect(bg = colors.checkHotFace(), bounds);
else if (widget->hasFocus())
g->fillRect(bg = colors.checkFocusFace(), bounds);
}
// Text
drawText(g, nullptr, ColorNone, ColorNone, widget, text, 0,
widget->mnemonic());
// Paint the icon
if (iconInterface)
paintIcon(widget, g, iconInterface, icon.x, icon.y);
// Draw focus
if (look != WithoutBordersLook &&
(widget->hasFocus() || (iconInterface &&
widget->text().empty() &&
widget->hasMouseOver()))) {
drawRect(g, bounds, parts.checkFocus().get());
}
}
void SkinTheme::paintEntry(PaintEvent& ev)
{
Graphics* g = ev.graphics();
@ -1271,43 +1212,6 @@ void SkinTheme::paintMenuItem(ui::PaintEvent& ev)
}
}
void SkinTheme::paintRadioButton(PaintEvent& ev)
{
Graphics* g = ev.graphics();
ButtonBase* widget = static_cast<ButtonBase*>(ev.getSource());
gfx::Rect bounds = widget->clientBounds();
IButtonIcon* iconInterface = widget->iconInterface();
gfx::Color bg = BGCOLOR;
gfx::Rect box, text, icon;
widget->getTextIconInfo(&box, &text, &icon,
iconInterface ? iconInterface->iconAlign(): 0,
iconInterface ? iconInterface->size().w: 0,
iconInterface ? iconInterface->size().h: 0);
// Background
g->fillRect(bg, g->getClipBounds());
// Mouse
if (widget->isEnabled()) {
if (widget->hasMouseOver())
g->fillRect(bg = colors.radioHotFace(), bounds);
else if (widget->hasFocus())
g->fillRect(bg = colors.radioFocusFace(), bounds);
}
// Text
drawText(g, nullptr, ColorNone, ColorNone, widget, text, 0, widget->mnemonic());
// Icon
if (iconInterface)
paintIcon(widget, g, iconInterface, icon.x, icon.y);
// Focus
if (widget->hasFocus())
drawRect(g, bounds, parts.radioFocus().get());
}
void SkinTheme::paintSlider(PaintEvent& ev)
{
Graphics* g = ev.graphics();

View File

@ -56,13 +56,11 @@ namespace app {
int getScrollbarSize() override;
gfx::Size getEntryCaretSize(ui::Widget* widget) override;
void paintCheckBox(ui::PaintEvent& ev) override;
void paintEntry(ui::PaintEvent& ev) override;
void paintListBox(ui::PaintEvent& ev) override;
void paintListItem(ui::PaintEvent& ev) override;
void paintMenu(ui::PaintEvent& ev) override;
void paintMenuItem(ui::PaintEvent& ev) override;
void paintRadioButton(ui::PaintEvent& ev) override;
void paintSlider(ui::PaintEvent& ev) override;
void paintComboBoxEntry(ui::PaintEvent& ev) override;
void paintTextBox(ui::PaintEvent& ev) override;

View File

@ -295,11 +295,7 @@ void ButtonBase::onPaint(PaintEvent& ev)
if (style())
return Widget::onPaint(ev);
switch (m_drawType) {
case kButtonWidget: ASSERT(false); break;
case kCheckWidget: theme()->paintCheckBox(ev); break;
case kRadioWidget: theme()->paintRadioButton(ev); break;
}
ASSERT(false);
}
void ButtonBase::generateButtonSelectSignal()

View File

@ -32,6 +32,7 @@ namespace ui {
enum class Type {
kNone,
kBackground,
kBackgroundBorder,
kBorder,
kIcon,
kText,

View File

@ -295,6 +295,7 @@ void Theme::paintLayer(Graphics* g,
switch (layer.type()) {
case Style::Layer::Type::kBackground:
case Style::Layer::Type::kBackgroundBorder:
if (layer.color() != gfx::ColorNone) {
bgColor = layer.color();
g->fillRect(layer.color(), rc);
@ -307,10 +308,12 @@ void Theme::paintLayer(Graphics* g,
layer.spriteBounds(),
layer.slicesBounds(), true);
rc.x += layer.slicesBounds().x;
rc.y += layer.slicesBounds().y;
rc.w -= layer.spriteBounds().w - layer.slicesBounds().w;
rc.h -= layer.spriteBounds().h - layer.slicesBounds().h;
if (layer.type() == Style::Layer::Type::kBackgroundBorder) {
rc.x += layer.slicesBounds().x;
rc.y += layer.slicesBounds().y;
rc.w -= layer.spriteBounds().w - layer.slicesBounds().w;
rc.h -= layer.spriteBounds().h - layer.slicesBounds().h;
}
}
// Draw background using different methods
else {
@ -488,6 +491,7 @@ void Theme::measureLayer(const Widget* widget,
switch (layer.type()) {
case Style::Layer::Type::kBackground:
case Style::Layer::Type::kBackgroundBorder:
case Style::Layer::Type::kBorder:
if (layer.spriteSheet() &&
!layer.spriteBounds().isEmpty()) {
@ -509,8 +513,9 @@ void Theme::measureLayer(const Widget* widget,
she::Font* font = (style->font() ? style->font(): widget->font());
gfx::Size textSize(Graphics::measureUITextLength(widget->text(), font),
font->height());
textHint.w = std::max(textHint.w, textSize.w);
textHint.h = std::max(textHint.h, textSize.h);
textHint.w = std::max(textHint.w, textSize.w+ABS(layer.offset().x));
textHint.h = std::max(textHint.h, textSize.h+ABS(layer.offset().y));
textAlign = layer.align();
}
break;
@ -518,8 +523,8 @@ void Theme::measureLayer(const Widget* widget,
case Style::Layer::Type::kIcon: {
she::Surface* icon = layer.icon();
if (icon) {
iconHint.w = std::max(iconHint.w, icon->width());
iconHint.h = std::max(iconHint.h, icon->height());
iconHint.w = std::max(iconHint.w, icon->width()+ABS(layer.offset().x));
iconHint.h = std::max(iconHint.h, icon->height()+ABS(layer.offset().y));
iconAlign = layer.align();
}
break;
@ -577,7 +582,8 @@ gfx::Color Theme::calcBgColor(const Widget* widget,
widget, style,
[&bgColor]
(const Style::Layer& layer) {
if (layer.type() == Style::Layer::Type::kBackground)
if (layer.type() == Style::Layer::Type::kBackground ||
layer.type() == Style::Layer::Type::kBackgroundBorder)
bgColor = layer.color();
});
@ -601,7 +607,8 @@ void Theme::calcWidgetMetrics(const Widget* widget,
for_each_layer(
widget, style,
[this, widget, style, &borderHint, &textHint, &textAlign, &iconHint, &iconAlign]
[this, widget, style, &borderHint,
&textHint, &textAlign, &iconHint, &iconAlign]
(const Style::Layer& layer) {
measureLayer(widget, style, layer,
borderHint,

View File

@ -65,13 +65,11 @@ namespace ui {
virtual int getScrollbarSize() = 0;
virtual gfx::Size getEntryCaretSize(Widget* widget) = 0;
virtual void paintCheckBox(PaintEvent& ev) = 0;
virtual void paintEntry(PaintEvent& ev) = 0;
virtual void paintListBox(PaintEvent& ev) = 0;
virtual void paintListItem(PaintEvent& ev) = 0;
virtual void paintMenu(PaintEvent& ev) = 0;
virtual void paintMenuItem(PaintEvent& ev) = 0;
virtual void paintRadioButton(PaintEvent& ev) = 0;
virtual void paintSlider(PaintEvent& ev) = 0;
virtual void paintComboBoxEntry(PaintEvent& ev) = 0;
virtual void paintTextBox(PaintEvent& ev) = 0;

View File

@ -182,7 +182,7 @@ void Widget::setStyle(Style* style)
{
m_style = style;
m_border = m_theme->calcBorder(this, style);
m_bgColor = m_theme->calcBgColor(this, m_style);
m_bgColor = m_theme->calcBgColor(this, style);
if (style->font())
m_font = style->font();
}