Convert timeline widget to new styles

And remove the old skin::Style.
This commit is contained in:
David Capello 2017-03-13 18:13:38 -03:00
parent e2311392b8
commit be3c9c1bcc
29 changed files with 272 additions and 1215 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -252,9 +252,8 @@
<part id="colorbar_1" x="16" y="192" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="colorbar_2" x="0" y="208" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="colorbar_3" x="16" y="208" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="colorbar_border_fg" x="0" y="224" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="colorbar_border_bg" x="16" y="224" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="colorbar_border_hotfg" x="32" y="224" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="colorbar_selection_hot" x="0" y="224" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="colorbar_selection" x="16" y="224" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="scrollbar_bg" x="64" y="144" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="scrollbar_thumb" x="64" y="160" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="mini_scrollbar_bg" x="64" y="176" w1="3" w2="2" w3="3" h1="3" h2="2" h3="3" />
@ -409,241 +408,6 @@
<part id="icon_slice" x="248" y="264" w="8" h="8" />
</parts>
<stylesheet>
<!-- timeline -->
<style id="timeline">
<background color="timeline_normal" part="timeline_normal" />
</style>
<!-- timeline_box -->
<style id="timeline_box">
<background color="timeline_normal" part="timeline_normal" />
<text color="timeline_normal_text" align="center" valign="middle" />
</style>
<style id="timeline_box:hover">
<background color="timeline_hover" part="timeline_hover" />
<text color="timeline_hover_text" />
</style>
<style id="timeline_box:active">
<background color="timeline_active" part="timeline_active" />
<text color="timeline_active_text" />
</style>
<style id="timeline_box:active:hover">
<background color="timeline_active_hover" part="timeline_active_hover" />
<text color="timeline_active_hover_text" />
</style>
<style id="timeline_box:clicked">
<background color="timeline_clicked" part="timeline_clicked" />
<text color="timeline_clicked_text" />
</style>
<!-- timeline_eye -->
<style id="timeline_open_eye" base="timeline_box">
<icon part="timeline_open_eye_normal" align="center" valign="middle" />
</style>
<style id="timeline_open_eye:active">
<icon part="timeline_open_eye_active" />
</style>
<style id="timeline_open_eye:disabled">
<icon color="disabled" />
</style>
<style id="timeline_closed_eye" base="timeline_box">
<icon part="timeline_closed_eye_normal" align="center" valign="middle" />
</style>
<style id="timeline_closed_eye:active">
<icon part="timeline_closed_eye_active" />
</style>
<style id="timeline_closed_eye:disabled">
<icon color="disabled" />
</style>
<!-- timeline_padlock -->
<style id="timeline_open_padlock" base="timeline_box">
<icon part="timeline_open_padlock_normal" align="center" valign="middle" />
</style>
<style id="timeline_open_padlock:active">
<icon part="timeline_open_padlock_active" />
</style>
<style id="timeline_open_padlock:disabled">
<icon color="disabled" />
</style>
<style id="timeline_closed_padlock" base="timeline_box">
<icon part="timeline_closed_padlock_normal" align="center" valign="middle" />
</style>
<style id="timeline_closed_padlock:active">
<icon part="timeline_closed_padlock_active" />
</style>
<style id="timeline_closed_padlock:disabled">
<icon color="disabled" />
</style>
<!-- timeline_continuous -->
<style id="timeline_continuous" base="timeline_box">
<icon part="timeline_continuous_normal" align="center" valign="middle" />
</style>
<style id="timeline_continuous:active">
<icon part="timeline_continuous_active" />
</style>
<style id="timeline_discontinuous" base="timeline_box">
<icon part="timeline_discontinuous_normal" align="center" valign="middle" />
</style>
<style id="timeline_discontinuous:active">
<icon part="timeline_discontinuous_active" />
</style>
<!-- timeline_group -->
<style id="timeline_closed_group" base="timeline_box">
<icon part="timeline_closed_group_normal" align="center" valign="middle" />
</style>
<style id="timeline_closed_group:active">
<icon part="timeline_closed_group_active" />
</style>
<style id="timeline_open_group" base="timeline_box">
<icon part="timeline_open_group_normal" align="center" valign="middle" />
</style>
<style id="timeline_open_group:active">
<icon part="timeline_open_group_active" />
</style>
<!-- timeline_layer -->
<style id="timeline_layer" base="timeline_box">
<text align="left" valign="middle" padding-left="4" />
</style>
<style id="timeline_layer_text_only" base="timeline_layer">
<background color="none" part="none" repeat="none" />
</style>
<style id="timeline_layer_text_only:hover" base="timeline_layer">
<background color="none" part="none" repeat="none" />
</style>
<style id="timeline_layer_text_only:active" base="timeline_layer">
<background color="none" part="none" repeat="none" />
</style>
<style id="timeline_layer_text_only:active:hover" base="timeline_layer">
<background color="none" part="none" repeat="none" />
</style>
<!-- timeline_selected_cel -->
<style id="timeline_selected_cel">
<background color="timeline_clicked" part="timeline_clicked" />
<text color="timeline_clicked_text" />
</style>
<!-- timeline_empty_frame -->
<style id="timeline_empty_frame">
<icon part="timeline_empty_frame_normal" align="center" valign="middle" />
</style>
<style id="timeline_empty_frame:active">
<icon part="timeline_empty_frame_active" />
</style>
<!--timeline_keyframe-->
<style id="timeline_keyframe">
<icon part="timeline_keyframe_normal" align="center" valign="middle" />
</style>
<style id="timeline_keyframe:active">
<icon part="timeline_keyframe_active" />
</style>
<style id="timeline_from_left">
<icon part="timeline_from_left_normal" align="center" valign="middle" />
</style>
<style id="timeline_from_left:active">
<icon part="timeline_from_left_active" />
</style>
<style id="timeline_from_right">
<icon part="timeline_from_right_normal" align="center" valign="middle" />
</style>
<style id="timeline_from_right:active">
<icon part="timeline_from_right_active" />
</style>
<style id="timeline_from_both">
<icon part="timeline_from_both_normal" align="center" valign="middle" />
</style>
<style id="timeline_from_both:active">
<icon part="timeline_from_both_active" />
</style>
<style id="timeline_left_link">
<icon part="timeline_left_link_active" align="center" valign="middle" />
</style>
<style id="timeline_right_link">
<icon part="timeline_right_link_active" align="center" valign="middle" />
</style>
<style id="timeline_both_links">
<icon part="timeline_both_links_active" align="center" valign="middle" />
</style>
<!-- timeline_gear -->
<style id="timeline_gear" base="timeline_box">
<icon part="timeline_gear" align="center" valign="middle" />
</style>
<style id="timeline_gear:active">
<icon part="timeline_gear_active" />
</style>
<style id="timeline_gear:clicked">
<icon part="timeline_gear_active" />
</style>
<!-- timeline_onionskin -->
<style id="timeline_onionskin" base="timeline_box">
<icon part="timeline_onionskin" align="center" valign="middle" />
</style>
<style id="timeline_onionskin:active">
<icon part="timeline_onionskin_active" />
</style>
<style id="timeline_onionskin:clicked">
<icon part="timeline_onionskin_active" />
</style>
<!-- timeline_onionskin_range -->
<style id="timeline_onionskin_range">
<background part="timeline_onionskin_range" />
</style>
<!-- paddings -->
<style id="timeline_padding">
<background color="timeline_normal" part="timeline_padding" />
</style>
<style id="timeline_padding_tr">
<background color="timeline_normal" part="timeline_padding_tr" />
</style>
<style id="timeline_padding_bl">
<background color="timeline_normal" part="timeline_padding_bl" />
</style>
<style id="timeline_padding_br">
<background color="timeline_normal" part="timeline_padding_br" />
</style>
<!-- timeline_range_outline -->
<style id="timeline_range_outline">
</style>
<style id="timeline_range_outline:active">
<background part="colorbar_border_hotfg" />
</style>
<style id="timeline_range_outline:hover">
<background part="colorbar_border_fg" />
</style>
<!-- timeline_drop_layer_deco -->
<style id="timeline_drop_layer_deco">
<background part="timeline_drop_layer_deco" />
</style>
<!-- timeline_drop_frame_deco -->
<style id="timeline_drop_frame_deco">
<background part="timeline_drop_frame_deco" />
</style>
<!-- timeline_loop_range -->
<style id="timeline_loop_range">
<background part="timeline_loop_range" />
</style>
</stylesheet>
<styles>
<style id="box" />
@ -983,6 +747,161 @@
<icon part="warning_box" align="center middle" />
</style>
<style id="timeline">
<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" />
</style>
<style id="timeline_open_eye" extends="timeline_box">
<icon part="timeline_open_eye_normal" />
<icon part="timeline_open_eye_active" state="focus" />
<icon part="timeline_open_eye_active" state="selected" />
<icon part="timeline_open_eye_normal" color="disabled" state="disabled" />
</style>
<style id="timeline_closed_eye" extends="timeline_box">
<icon part="timeline_closed_eye_normal" />
<icon part="timeline_closed_eye_active" state="focus" />
<icon part="timeline_closed_eye_active" state="selected" />
<icon part="timeline_closed_eye_normal" color="disabled" state="disabled" />
</style>
<style id="timeline_open_padlock" extends="timeline_box">
<icon part="timeline_open_padlock_normal" />
<icon part="timeline_open_padlock_active" state="focus" />
<icon part="timeline_open_padlock_active" state="selected" />
<icon part="timeline_open_padlock_normal" color="disabled" state="disabled" />
</style>
<style id="timeline_closed_padlock" extends="timeline_box">
<icon part="timeline_closed_padlock_normal" />
<icon part="timeline_closed_padlock_active" state="focus" />
<icon part="timeline_closed_padlock_active" state="selected" />
<icon part="timeline_closed_padlock_normal" color="disabled" state="disabled" />
</style>
<style id="timeline_continuous" extends="timeline_box">
<icon part="timeline_continuous_normal" />
<icon part="timeline_continuous_active" state="focus" />
<icon part="timeline_continuous_active" state="selected" />
</style>
<style id="timeline_discontinuous" extends="timeline_box">
<icon part="timeline_discontinuous_normal" />
<icon part="timeline_discontinuous_active" state="focus" />
<icon part="timeline_discontinuous_active" state="selected" />
</style>
<style id="timeline_closed_group" extends="timeline_box">
<icon part="timeline_closed_group_normal" />
<icon part="timeline_closed_group_active" state="focus" />
<icon part="timeline_closed_group_active" state="selected" />
</style>
<style id="timeline_open_group" extends="timeline_box">
<icon part="timeline_open_group_normal" />
<icon part="timeline_open_group_active" state="focus" />
<icon part="timeline_open_group_active" state="selected" />
</style>
<style id="timeline_layer" extends="timeline_box">
<text color="timeline_normal_text" align="left middle" x="2" />
<text color="timeline_hover_text" align="left middle" x="2" state="mouse" />
<text color="timeline_active_text" align="left middle" x="2" state="focus" />
<text color="timeline_active_hover_text" align="left middle" x="2" state="focus mouse" />
<text color="timeline_clicked_text" align="left middle" x="2" state="selected" />
</style>
<style id="timeline_layer_text_only" extends="timeline_layer">
<background color="none" part="none" repeat="none" />
<background color="none" part="none" repeat="none" state="mouse" />
<background color="none" part="none" repeat="none" state="focus" />
<background color="none" part="none" repeat="none" state="focus mouse" />
</style>
<style id="timeline_header_frame" extends="timeline_box" font="mini">
<text color="timeline_normal_text" />
<text color="timeline_hover_text" state="mouse" />
<text color="timeline_active_text" state="focus" />
<text color="timeline_active_hover_text" state="focus mouse" />
<text color="timeline_clicked_text" state="selected" />
</style>
<style id="timeline_selected_cel">
<background color="timeline_clicked" part="timeline_clicked" />
<text color="timeline_clicked_text" />
</style>
<style id="timeline_empty_frame">
<icon part="timeline_empty_frame_normal" />
<icon part="timeline_empty_frame_active" state="focus" />
</style>
<style id="timeline_keyframe">
<icon part="timeline_keyframe_normal" />
<icon part="timeline_keyframe_active" state="focus" />
</style>
<style id="timeline_from_left">
<icon part="timeline_from_left_normal" />
<icon part="timeline_from_left_active" state="focus" />
</style>
<style id="timeline_from_right">
<icon part="timeline_from_right_normal" />
<icon part="timeline_from_right_active" state="focus" />
</style>
<style id="timeline_from_both">
<icon part="timeline_from_both_normal" />
<icon part="timeline_from_both_active" state="focus" />
</style>
<style id="timeline_left_link">
<icon part="timeline_left_link_active" />
</style>
<style id="timeline_right_link">
<icon part="timeline_right_link_active" />
</style>
<style id="timeline_both_links">
<icon part="timeline_both_links_active" />
</style>
<style id="timeline_gear" extends="timeline_box">
<icon part="timeline_gear" />
<icon part="timeline_gear_active" state="focus" />
<icon part="timeline_gear_active" state="selected" />
</style>
<style id="timeline_onionskin" extends="timeline_box">
<icon part="timeline_onionskin" />
<icon part="timeline_onionskin_active" state="focus" />
<icon part="timeline_onionskin_active" state="selected" />
</style>
<style id="timeline_onionskin_range">
<background part="timeline_onionskin_range" />
</style>
<style id="timeline_padding">
<background color="timeline_normal" part="timeline_padding" />
</style>
<style id="timeline_padding_tr">
<background color="timeline_normal" part="timeline_padding_tr" />
</style>
<style id="timeline_padding_bl">
<background color="timeline_normal" part="timeline_padding_bl" />
</style>
<style id="timeline_padding_br">
<background color="timeline_normal" part="timeline_padding_br" />
</style>
<style id="timeline_range_outline">
<background part="colorbar_selection" state="focus" />
<background part="colorbar_selection_hot" state="focus mouse" />
</style>
<style id="timeline_drop_layer_deco">
<background part="timeline_drop_layer_deco" />
</style>
<style id="timeline_drop_frame_deco">
<background part="timeline_drop_frame_deco" />
</style>
<style id="timeline_loop_range">
<background part="timeline_loop_range" />
</style>
<style id="shade_selection">
<background part="colorbar_selection_hot" />
</style>
<style id="colorbar_selection">
<background part="colorbar_selection" />
<background part="colorbar_selection_hot" state="mouse" />
</style>
</styles>
</theme>

View File

@ -482,10 +482,7 @@ add_library(app-lib
ui/skin/skin_part.cpp
ui/skin/skin_property.cpp
ui/skin/skin_slider_property.cpp
ui/skin/skin_style_property.cpp
ui/skin/skin_theme.cpp
ui/skin/style.cpp
ui/skin/style_sheet.cpp
ui/slice_window.cpp
ui/status_bar.cpp
ui/tabs.cpp

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -141,7 +141,7 @@ void draw_color_button(ui::Graphics* g,
if (hot) {
theme->drawRect(
g, gfx::Rect(rc.x, rc.y, rc.w, rc.h-1 - 1*scale),
theme->parts.colorbarBorderHotfg().get());
theme->parts.colorbarSelection().get());
}
}

View File

@ -13,7 +13,6 @@
#include "app/resource_finder.h"
#include "app/ui/browser_view.h"
#include "app/ui/main_window.h"
#include "app/ui/skin/skin_style_property.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/workspace.h"
#include "base/file_handle.h"

View File

@ -23,7 +23,6 @@
#include "app/transaction.h"
#include "app/ui/palette_view.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "app/ui_context.h"
#include "base/bind.h"
#include "base/scoped_value.h"

View File

@ -36,7 +36,6 @@
#include "app/ui/icon_button.h"
#include "app/ui/skin/button_icon_impl.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "app/ui_context.h"
#include "base/bind.h"
#include "base/scoped_value.h"
@ -663,8 +662,6 @@ class ContextBar::InkShadesField : public HBox {
bounds.w = w;
}
skin::Style::State state;
if (hasMouseOver()) state += Style::hover();
theme->paintWidget(g, this, theme->newStyles.view(), bounds);
bounds.shrink(3*guiscale());
@ -707,10 +704,9 @@ class ContextBar::InkShadesField : public HBox {
if (!hotBounds.isEmpty() && m_click == DragAndDrop) {
hotBounds.enlarge(3*guiscale());
Style::State state = Style::active();
state += Style::hover();
theme->styles.timelineRangeOutline()->paint(
g, hotBounds, NULL, state);
PaintWidgetPartInfo info;
theme->paintWidgetPart(
g, theme->newStyles.shadeSelection(), hotBounds, info);
}
}
else {

View File

@ -15,7 +15,6 @@
#include "app/crash/session.h"
#include "app/modules/gui.h"
#include "app/ui/drop_down_button.h"
#include "app/ui/skin/skin_style_property.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/workspace.h"
#include "base/bind.h"

View File

@ -15,7 +15,6 @@
#include "app/ui/devconsole_view.h"
#include "app/app_menus.h"
#include "app/ui/skin/skin_style_property.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/workspace.h"
#include "ui/entry.h"

View File

@ -18,7 +18,6 @@
#include "app/ui/main_window.h"
#include "app/ui/news_listbox.h"
#include "app/ui/recent_listbox.h"
#include "app/ui/skin/skin_style_property.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/workspace.h"
#include "app/ui/workspace_tabs.h"

View File

@ -12,7 +12,6 @@
#include "app/notification_delegate.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "base/launcher.h"
#include "ui/menu.h"
#include "ui/paint_event.h"

View File

@ -19,7 +19,6 @@
#include "app/ui/editor/editor.h"
#include "app/ui/palette_view.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "app/ui/status_bar.h"
#include "app/util/clipboard.h"
#include "base/convert_to.h"
@ -515,8 +514,9 @@ void PaletteView::onPaint(ui::PaintEvent& ev)
// Draw selected entries
Style::State state = Style::active();
if (m_hot.part == Hit::OUTLINE) state += Style::hover();
PaintWidgetPartInfo info;
if (m_hot.part == Hit::OUTLINE)
info.styleFlags |= ui::Style::Layer::kMouse;
PalettePicks dragPicks;
int j = 0;
@ -551,9 +551,9 @@ void PaletteView::onPaint(ui::PaintEvent& ev)
box2.y + box2.h/2 - minifont->height()/2));
}
// Draw outlines
theme->styles.timelineRangeOutline()->paint(
g, box, NULL, state);
// Draw the selection
theme->paintWidgetPart(
g, theme->newStyles.colorbarSelection(), box, info);
}
++j;

View File

@ -1,30 +0,0 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/ui/skin/skin_style_property.h"
namespace app {
namespace skin {
const char* SkinStyleProperty::Name = "SkinStyleProperty";
SkinStyleProperty::SkinStyleProperty(Style* style)
: Property(Name)
, m_style(style)
{
}
Style* SkinStyleProperty::getStyle() const
{
return m_style;
}
} // namespace skin
} // namespace app

View File

@ -1,36 +0,0 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_UI_SKIN_SKIN_STYLE_PROPERTY_H_INCLUDED
#define APP_UI_SKIN_SKIN_STYLE_PROPERTY_H_INCLUDED
#pragma once
#include "app/ui/skin/skin_property.h"
#include "app/ui/skin/style.h"
#include "base/shared_ptr.h"
namespace app {
namespace skin {
class Style;
class SkinStyleProperty : public ui::Property {
public:
static const char* Name;
SkinStyleProperty(Style* style);
skin::Style* getStyle() const;
private:
skin::Style* m_style;
};
typedef base::SharedPtr<SkinStyleProperty> SkinStylePropertyPtr;
} // namespace skin
} // namespace app
#endif

View File

@ -19,10 +19,7 @@
#include "app/ui/skin/font_data.h"
#include "app/ui/skin/skin_property.h"
#include "app/ui/skin/skin_slider_property.h"
#include "app/ui/skin/skin_style_property.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "app/ui/skin/style_sheet.h"
#include "app/xml_document.h"
#include "app/xml_exception.h"
#include "base/bind.h"
@ -88,14 +85,6 @@ static const char* cursor_names[kCursorTypes] = {
"magnifier" // kMagnifierCursor
};
static css::Value value_or_none(const char* valueStr)
{
if (strcmp(valueStr, "none") == 0)
return css::Value();
else
return css::Value(valueStr);
}
static FontData* load_font(std::map<std::string, FontData*>& fonts,
const TiXmlElement* xmlFont,
const std::string& xmlFilename)
@ -512,93 +501,7 @@ void SkinTheme::loadXml(const std::string& skinId)
}
}
// Load old stylesheet
{
TiXmlElement* xmlStyle = handle
.FirstChild("theme")
.FirstChild("stylesheet")
.FirstChild("style").ToElement();
while (xmlStyle) {
const char* style_id = xmlStyle->Attribute("id");
const char* base_id = xmlStyle->Attribute("base");
const css::Style* base = NULL;
if (base_id)
base = m_stylesheet.getCssStyle(base_id);
css::Style* style = new css::Style(style_id, base);
m_stylesheet.addCssStyle(style);
TiXmlElement* xmlRule = xmlStyle->FirstChildElement();
while (xmlRule) {
const std::string ruleName = xmlRule->Value();
LOG(VERBOSE) << "THEME: Rule " << ruleName
<< " for " << style_id << "\n";
// TODO This code design to read styles could be improved.
const char* part_id = xmlRule->Attribute("part");
const char* color_id = xmlRule->Attribute("color");
// Style align
int align = 0;
const char* halign = xmlRule->Attribute("align");
const char* valign = xmlRule->Attribute("valign");
const char* wordwrap = xmlRule->Attribute("wordwrap");
if (halign) {
if (strcmp(halign, "left") == 0) align |= LEFT;
else if (strcmp(halign, "right") == 0) align |= RIGHT;
else if (strcmp(halign, "center") == 0) align |= CENTER;
}
if (valign) {
if (strcmp(valign, "top") == 0) align |= TOP;
else if (strcmp(valign, "bottom") == 0) align |= BOTTOM;
else if (strcmp(valign, "middle") == 0) align |= MIDDLE;
}
if (wordwrap && strcmp(wordwrap, "true") == 0)
align |= WORDWRAP;
if (ruleName == "background") {
const char* repeat_id = xmlRule->Attribute("repeat");
if (color_id) (*style)[StyleSheet::backgroundColorRule()] = value_or_none(color_id);
if (part_id) (*style)[StyleSheet::backgroundPartRule()] = value_or_none(part_id);
if (repeat_id) (*style)[StyleSheet::backgroundRepeatRule()] = value_or_none(repeat_id);
}
else if (ruleName == "icon") {
if (align) (*style)[StyleSheet::iconAlignRule()] = css::Value(align);
if (part_id) (*style)[StyleSheet::iconPartRule()] = css::Value(part_id);
if (color_id) (*style)[StyleSheet::iconColorRule()] = value_or_none(color_id);
const char* x = xmlRule->Attribute("x");
const char* y = xmlRule->Attribute("y");
if (x) (*style)[StyleSheet::iconXRule()] = css::Value(strtol(x, NULL, 10));
if (y) (*style)[StyleSheet::iconYRule()] = css::Value(strtol(y, NULL, 10));
}
else if (ruleName == "text") {
if (color_id) (*style)[StyleSheet::textColorRule()] = css::Value(color_id);
if (align) (*style)[StyleSheet::textAlignRule()] = css::Value(align);
const char* l = xmlRule->Attribute("padding-left");
const char* t = xmlRule->Attribute("padding-top");
const char* r = xmlRule->Attribute("padding-right");
const char* b = xmlRule->Attribute("padding-bottom");
if (l) (*style)[StyleSheet::paddingLeftRule()] = css::Value(strtol(l, NULL, 10));
if (t) (*style)[StyleSheet::paddingTopRule()] = css::Value(strtol(t, NULL, 10));
if (r) (*style)[StyleSheet::paddingRightRule()] = css::Value(strtol(r, NULL, 10));
if (b) (*style)[StyleSheet::paddingBottomRule()] = css::Value(strtol(b, NULL, 10));
}
xmlRule = xmlRule->NextSiblingElement();
}
xmlStyle = xmlStyle->NextSiblingElement();
}
}
// Load new styles
// Load styles
{
TiXmlElement* xmlStyle = handle
.FirstChild("theme")
@ -738,6 +641,9 @@ void SkinTheme::loadXml(const std::string& skinId)
auto it = m_colors_by_id.find(colorId);
if (it != m_colors_by_id.end())
layer.setColor(it->second);
else if (std::strcmp(colorId, "none") == 0) {
layer.setColor(gfx::ColorNone);
}
else {
throw base::Exception("Color <%s color='%s' ...> was not found in '%s'\n",
layerName.c_str(), colorId,
@ -771,6 +677,12 @@ void SkinTheme::loadXml(const std::string& skinId)
}
}
}
else if (std::strcmp(partId, "none") == 0) {
layer.setIcon(nullptr);
layer.setSpriteSheet(nullptr);
layer.setSpriteBounds(gfx::Rect(0, 0, 0, 0));
layer.setSlicesBounds(gfx::Rect(0, 0, 0, 0));
}
else {
throw base::Exception("Part <%s part='%s' ...> was not found in '%s'\n",
layerName.c_str(), partId,

View File

@ -9,7 +9,6 @@
#pragma once
#include "app/ui/skin/skin_part.h"
#include "app/ui/skin/style_sheet.h"
#include "gfx/color.h"
#include "gfx/fwd.h"
#include "ui/manager.h"
@ -84,10 +83,6 @@ namespace app {
void drawVline(ui::Graphics* g, const gfx::Rect& rc, SkinPart* skinPart);
void paintProgressBar(ui::Graphics* g, const gfx::Rect& rc, double progress);
Style* getStyle(const std::string& id) {
return m_stylesheet.getStyle(id);
}
ui::Style* getNewStyle(const std::string& id) {
return m_styles[id];
}
@ -136,7 +131,6 @@ namespace app {
std::map<std::string, gfx::Color> m_colors_by_id;
std::map<std::string, int> m_dimensions_by_id;
std::vector<ui::Cursor*> m_cursors;
StyleSheet m_stylesheet;
std::map<std::string, ui::Style*> m_styles;
std::map<std::string, FontData*> m_fonts;
std::map<std::string, she::Font*> m_themeFonts;

View File

@ -1,268 +0,0 @@
// Aseprite
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/ui/skin/style.h"
#include "app/ui/skin/skin_theme.h"
#include "css/sheet.h"
#include "she/surface.h"
#include "ui/graphics.h"
#include "ui/theme.h"
namespace app {
namespace skin {
css::State Style::m_hoverState("hover");
css::State Style::m_activeState("active");
css::State Style::m_clickedState("clicked");
css::State Style::m_disabledState("disabled");
Rule::~Rule()
{
}
void Rule::paint(ui::Graphics* g,
const gfx::Rect& bounds,
const char* text)
{
onPaint(g, bounds, text);
}
void BackgroundRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text)
{
SkinTheme* theme = SkinTheme::instance();
if (m_part && m_part->countBitmaps() > 0) {
if (!gfx::is_transparent(m_color))
g->fillRect(m_color, bounds);
if (m_part->countBitmaps() == 1) {
she::Surface* bmp = m_part->bitmap(0);
if (m_repeat == BackgroundRepeat::NO_REPEAT) {
g->drawRgbaSurface(bmp, bounds.x, bounds.y);
}
else {
ui::IntersectClip clip(g, bounds);
if (!clip)
return;
for (int y=bounds.y; y<bounds.y2(); y+=bmp->height()) {
for (int x=bounds.x; x<bounds.x2(); x+=bmp->width()) {
g->drawRgbaSurface(bmp, x, y);
if (m_repeat == BackgroundRepeat::REPEAT_Y)
break;
}
if (m_repeat == BackgroundRepeat::REPEAT_X)
break;
}
}
}
else if (m_part->countBitmaps() == 8) {
theme->drawRect(
g, bounds, m_part.get(),
// This is a hack (we could use a new property but anyway we
// have plans to change the whole theme structure). If
// "repeat" is REPEAT, the center will be filled with the
// center slice of the part.
m_repeat == BackgroundRepeat::REPEAT);
}
}
else if (!gfx::is_transparent(m_color)) {
g->fillRect(m_color, bounds);
}
}
void TextRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text)
{
SkinTheme* theme = SkinTheme::instance();
if (text) {
g->drawAlignedUIText(text,
(gfx::is_transparent(m_color) ?
theme->colors.text():
m_color),
gfx::ColorNone,
gfx::Rect(bounds).shrink(m_padding), m_align);
}
}
void IconRule::onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text)
{
she::Surface* bmp = m_part->bitmap(0);
int x, y;
if (m_align & ui::RIGHT)
x = bounds.x2() - bmp->width();
else if (m_align & ui::CENTER)
x = bounds.x + bounds.w/2 - bmp->width()/2;
else
x = bounds.x;
if (m_align & ui::BOTTOM)
y = bounds.y2() - bmp->height();
else if (m_align & ui::MIDDLE)
y = bounds.y + bounds.h/2 - bmp->height()/2;
else
y = bounds.y;
x += m_x;
y += m_y;
if (m_color == gfx::ColorNone)
g->drawRgbaSurface(bmp, x, y);
else
g->drawColoredRgbaSurface(bmp, m_color, x, y);
}
Rules::Rules(const css::Query& query) :
m_background(NULL),
m_text(NULL),
m_icon(NULL)
{
css::Value backgroundColor = query[StyleSheet::backgroundColorRule()];
css::Value backgroundPart = query[StyleSheet::backgroundPartRule()];
css::Value backgroundRepeat = query[StyleSheet::backgroundRepeatRule()];
css::Value iconAlign = query[StyleSheet::iconAlignRule()];
css::Value iconPart = query[StyleSheet::iconPartRule()];
css::Value iconX = query[StyleSheet::iconXRule()];
css::Value iconY = query[StyleSheet::iconYRule()];
css::Value iconColor = query[StyleSheet::iconColorRule()];
css::Value textAlign = query[StyleSheet::textAlignRule()];
css::Value textColor = query[StyleSheet::textColorRule()];
css::Value paddingLeft = query[StyleSheet::paddingLeftRule()];
css::Value paddingTop = query[StyleSheet::paddingTopRule()];
css::Value paddingRight = query[StyleSheet::paddingRightRule()];
css::Value paddingBottom = query[StyleSheet::paddingBottomRule()];
css::Value none;
if (backgroundColor != none
|| backgroundPart != none
|| backgroundRepeat != none) {
m_background = new BackgroundRule();
m_background->setColor(StyleSheet::convertColor(backgroundColor));
m_background->setPart(StyleSheet::convertPart(backgroundPart));
m_background->setRepeat(StyleSheet::convertRepeat(backgroundRepeat));
}
if (iconAlign != none
|| iconPart != none
|| iconX != none
|| iconY != none
|| iconColor != none) {
m_icon = new IconRule();
m_icon->setAlign((int)iconAlign.number());
m_icon->setPart(StyleSheet::convertPart(iconPart));
m_icon->setX((int)iconX.number()*ui::guiscale());
m_icon->setY((int)iconY.number()*ui::guiscale());
m_icon->setColor(StyleSheet::convertColor(iconColor));
}
if (textAlign != none
|| textColor != none
|| paddingLeft != none
|| paddingTop != none
|| paddingRight != none
|| paddingBottom != none) {
m_text = new TextRule();
m_text->setAlign((int)textAlign.number());
m_text->setColor(StyleSheet::convertColor(textColor));
m_text->setPadding(gfx::Border(
int(paddingLeft.number()),
int(paddingTop.number()),
int(paddingRight.number()),
int(paddingBottom.number()))*ui::guiscale());
}
}
Rules::~Rules()
{
delete m_background;
delete m_text;
delete m_icon;
}
void Rules::paint(ui::Graphics* g,
const gfx::Rect& bounds,
const char* text)
{
if (m_background) m_background->paint(g, bounds, text);
if (m_icon) m_icon->paint(g, bounds, text);
if (m_text) m_text->paint(g, bounds, text);
}
gfx::Size Rules::sizeHint(const char* text, int maxWidth)
{
gfx::Size sz(0, 0);
if (m_icon) {
sz.w += m_icon->getPart()->bitmap(0)->width();
sz.h = m_icon->getPart()->bitmap(0)->height();
}
if (m_text && text) {
ui::ScreenGraphics g;
gfx::Size textSize = g.fitString(text, maxWidth, m_text->align());
if (sz.w > 0) sz.w += 2*ui::guiscale(); // TODO text separation
sz.w += textSize.w;
sz.h = MAX(sz.h, textSize.h);
sz.w += m_text->padding().left() + m_text->padding().right();
sz.h += m_text->padding().top() + m_text->padding().bottom();
}
return sz;
}
Style::Style(css::Sheet& sheet, const std::string& id)
: m_id(id)
, m_compoundStyle(sheet.compoundStyle(id))
{
}
Style::~Style()
{
for (RulesMap::iterator it = m_rules.begin(), end = m_rules.end();
it != end; ++it) {
delete it->second;
}
}
Rules* Style::getRulesFromState(const State& state)
{
Rules* rules = NULL;
RulesMap::iterator it = m_rules.find(state);
if (it != m_rules.end()) {
rules = it->second;
}
else {
rules = new Rules(m_compoundStyle[state]);
m_rules[state] = rules;
}
return rules;
}
void Style::paint(ui::Graphics* g,
const gfx::Rect& bounds,
const char* text,
const State& state)
{
getRulesFromState(state)->paint(g, bounds, text);
}
gfx::Size Style::sizeHint(
const char* text,
const State& state,
int maxWidth)
{
return getRulesFromState(state)->sizeHint(text, maxWidth);
}
} // namespace skin
} // namespace app

View File

@ -1,168 +0,0 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_UI_SKIN_STYLE_H_INCLUDED
#define APP_UI_SKIN_STYLE_H_INCLUDED
#pragma once
#include "app/ui/skin/background_repeat.h"
#include "app/ui/skin/skin_part.h"
#include "base/disable_copying.h"
#include "css/compound_style.h"
#include "css/state.h"
#include "css/stateful_style.h"
#include "gfx/border.h"
#include "gfx/color.h"
#include "gfx/fwd.h"
#include <map>
#include <string>
#include <vector>
namespace ui {
class Graphics;
}
namespace app {
namespace skin {
class Rule {
public:
Rule() { }
virtual ~Rule();
void paint(ui::Graphics* g,
const gfx::Rect& bounds,
const char* text);
protected:
virtual void onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text) = 0;
};
class BackgroundRule : public Rule {
public:
BackgroundRule() : m_color(gfx::ColorNone)
, m_repeat(BackgroundRepeat::NO_REPEAT) { }
void setColor(gfx::Color color) { m_color = color; }
void setPart(const SkinPartPtr& part) { m_part = part; }
void setRepeat(BackgroundRepeat repeat) { m_repeat = repeat; }
protected:
void onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text) override;
private:
gfx::Color m_color;
SkinPartPtr m_part;
BackgroundRepeat m_repeat;
};
class TextRule : public Rule {
public:
explicit TextRule() : m_align(0),
m_color(gfx::ColorNone) { }
void setAlign(int align) { m_align = align; }
void setColor(gfx::Color color) { m_color = color; }
void setPadding(const gfx::Border& padding) { m_padding = padding; }
int align() const { return m_align; }
gfx::Border padding() const { return m_padding; }
protected:
void onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text) override;
private:
int m_align;
gfx::Color m_color;
gfx::Border m_padding;
};
class IconRule : public Rule {
public:
explicit IconRule() : m_align(0),
m_color(gfx::ColorNone) { }
void setAlign(int align) { m_align = align; }
void setPart(const SkinPartPtr& part) { m_part = part; }
void setX(int x) { m_x = x; }
void setY(int y) { m_y = y; }
void setColor(gfx::Color color) { m_color = color; }
SkinPartPtr getPart() { return m_part; }
protected:
void onPaint(ui::Graphics* g, const gfx::Rect& bounds, const char* text) override;
private:
int m_align;
SkinPartPtr m_part;
int m_x, m_y;
gfx::Color m_color;
};
class Rules {
public:
Rules(const css::Query& query);
~Rules();
void paint(ui::Graphics* g,
const gfx::Rect& bounds,
const char* text);
gfx::Size sizeHint(const char* text, int maxWidth);
private:
BackgroundRule* m_background;
TextRule* m_text;
IconRule* m_icon;
DISABLE_COPYING(Rules);
};
class Style {
public:
typedef css::States State;
static const css::State& hover() { return m_hoverState; }
static const css::State& active() { return m_activeState; }
static const css::State& clicked() { return m_clickedState; }
static const css::State& disabled() { return m_disabledState; }
Style(css::Sheet& sheet, const std::string& id);
~Style();
void paint(ui::Graphics* g,
const gfx::Rect& bounds,
const char* text,
const State& state);
gfx::Size sizeHint(
const char* text,
const State& state,
int maxWidth = 0);
const std::string& id() const { return m_id; }
private:
typedef std::map<State, Rules*> RulesMap;
Rules* getRulesFromState(const State& state);
std::string m_id;
css::CompoundStyle m_compoundStyle;
RulesMap m_rules;
static css::State m_hoverState;
static css::State m_activeState;
static css::State m_clickedState;
static css::State m_disabledState;
};
} // namespace skin
} // namespace app
#endif

View File

@ -1,145 +0,0 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/ui/skin/style_sheet.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "base/exception.h"
#include "css/sheet.h"
#include "tinyxml.h"
namespace app {
namespace skin {
css::Rule StyleSheet::m_backgroundColorRule("background-color");
css::Rule StyleSheet::m_backgroundPartRule("background-part");
css::Rule StyleSheet::m_backgroundRepeatRule("background-repeat");
css::Rule StyleSheet::m_iconAlignRule("icon-align");
css::Rule StyleSheet::m_iconPartRule("icon-part");
css::Rule StyleSheet::m_iconXRule("icon-x");
css::Rule StyleSheet::m_iconYRule("icon-y");
css::Rule StyleSheet::m_iconColorRule("icon-color");
css::Rule StyleSheet::m_textAlignRule("text-align");
css::Rule StyleSheet::m_textColorRule("text-color");
css::Rule StyleSheet::m_paddingLeftRule("padding-left");
css::Rule StyleSheet::m_paddingTopRule("padding-top");
css::Rule StyleSheet::m_paddingRightRule("padding-right");
css::Rule StyleSheet::m_paddingBottomRule("padding-bottom");
StyleSheet::StyleSheet()
{
m_sheet = new css::Sheet;
m_sheet->addRule(&m_backgroundColorRule);
m_sheet->addRule(&m_backgroundPartRule);
m_sheet->addRule(&m_backgroundRepeatRule);
m_sheet->addRule(&m_iconAlignRule);
m_sheet->addRule(&m_iconPartRule);
m_sheet->addRule(&m_iconXRule);
m_sheet->addRule(&m_iconYRule);
m_sheet->addRule(&m_iconColorRule);
m_sheet->addRule(&m_textAlignRule);
m_sheet->addRule(&m_textColorRule);
m_sheet->addRule(&m_paddingLeftRule);
m_sheet->addRule(&m_paddingTopRule);
m_sheet->addRule(&m_paddingRightRule);
m_sheet->addRule(&m_paddingBottomRule);
}
StyleSheet::~StyleSheet()
{
// Destroy skin::Styles
for (StyleMap::iterator it = m_styles.begin(), end = m_styles.end();
it != end; ++it)
delete it->second;
// Destroy css::Styles
for (std::vector<css::Style*>::iterator it = m_cssStyles.begin(), end = m_cssStyles.end();
it != end; ++it)
delete *it;
delete m_sheet;
}
void StyleSheet::addCssStyle(css::Style* style)
{
m_sheet->addStyle(style);
m_cssStyles.push_back(style);
}
const css::Style* StyleSheet::getCssStyle(const std::string& id)
{
return m_sheet->getStyle(id);
}
Style* StyleSheet::getStyle(const std::string& id)
{
Style* style = NULL;
StyleMap::iterator it = m_styles.find(id);
if (it != m_styles.end())
style = it->second;
else {
style = new Style(*m_sheet, id);
m_styles[id] = style;
}
return style;
}
// static
SkinPartPtr StyleSheet::convertPart(const css::Value& value)
{
SkinPartPtr part;
if (value.type() == css::Value::String) {
const std::string& part_id = value.string();
part = get_part_by_id(part_id);
if (!part)
throw base::Exception("Unknown part '%s'\n", part_id.c_str());
}
return part;
}
// static
gfx::Color StyleSheet::convertColor(const css::Value& value)
{
gfx::Color color = gfx::ColorNone;
if (value.type() == css::Value::String) {
const std::string& color_id = value.string();
color = get_color_by_id(color_id);
if (color == gfx::ColorNone)
throw base::Exception("Unknown color '%s'\n", color_id.c_str());
}
return color;
}
// static
BackgroundRepeat StyleSheet::convertRepeat(const css::Value& value)
{
BackgroundRepeat repeat = BackgroundRepeat::NO_REPEAT;
if (value.type() == css::Value::String) {
const std::string& id = value.string();
if (id == "repeat")
repeat = BackgroundRepeat::REPEAT;
else if (id == "repeat-x")
repeat = BackgroundRepeat::REPEAT_X;
else if (id == "repeat-y")
repeat = BackgroundRepeat::REPEAT_Y;
else if (id == "no_repeat")
repeat = BackgroundRepeat::NO_REPEAT;
else
throw base::Exception("Unknown repeat value '%s'\n", id.c_str());
}
return repeat;
}
} // namespace skin
} // namespace app

View File

@ -1,88 +0,0 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_UI_SKIN_STYLE_SHEET_H_INCLUDED
#define APP_UI_SKIN_STYLE_SHEET_H_INCLUDED
#pragma once
#include "app/ui/skin/background_repeat.h"
#include "app/ui/skin/skin_part.h"
#include "css/rule.h"
#include "css/state.h"
#include "gfx/color.h"
#include <map>
#include <string>
class TiXmlElement;
namespace css {
class Sheet;
class Style;
class Value;
}
namespace app {
namespace skin {
class Style;
class StyleSheet {
public:
StyleSheet();
~StyleSheet();
static css::Rule& backgroundColorRule() { return m_backgroundColorRule; }
static css::Rule& backgroundPartRule() { return m_backgroundPartRule; }
static css::Rule& backgroundRepeatRule() { return m_backgroundRepeatRule; }
static css::Rule& iconAlignRule() { return m_iconAlignRule; }
static css::Rule& iconPartRule() { return m_iconPartRule; }
static css::Rule& iconXRule() { return m_iconXRule; }
static css::Rule& iconYRule() { return m_iconYRule; }
static css::Rule& iconColorRule() { return m_iconColorRule; }
static css::Rule& textAlignRule() { return m_textAlignRule; }
static css::Rule& textColorRule() { return m_textColorRule; }
static css::Rule& paddingLeftRule() { return m_paddingLeftRule; }
static css::Rule& paddingTopRule() { return m_paddingTopRule; }
static css::Rule& paddingRightRule() { return m_paddingRightRule; }
static css::Rule& paddingBottomRule() { return m_paddingBottomRule; }
void addCssStyle(css::Style* style);
const css::Style* getCssStyle(const std::string& id);
Style* getStyle(const std::string& id);
static SkinPartPtr convertPart(const css::Value& value);
static gfx::Color convertColor(const css::Value& value);
static BackgroundRepeat convertRepeat(const css::Value& value);
private:
typedef std::map<std::string, Style*> StyleMap;
static css::Rule m_backgroundColorRule;
static css::Rule m_backgroundPartRule;
static css::Rule m_backgroundRepeatRule;
static css::Rule m_iconAlignRule;
static css::Rule m_iconPartRule;
static css::Rule m_iconXRule;
static css::Rule m_iconYRule;
static css::Rule m_iconColorRule;
static css::Rule m_textAlignRule;
static css::Rule m_textColorRule;
static css::Rule m_paddingLeftRule;
static css::Rule m_paddingTopRule;
static css::Rule m_paddingRightRule;
static css::Rule m_paddingBottomRule;
css::Sheet* m_sheet;
std::vector<css::Style*> m_cssStyles;
StyleMap m_styles;
};
} // namespace skin
} // namespace app
#endif

View File

@ -26,7 +26,6 @@
#include "app/ui/editor/editor.h"
#include "app/ui/keyboard_shortcuts.h"
#include "app/ui/main_window.h"
#include "app/ui/skin/skin_style_property.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h"
#include "app/ui/timeline.h"

View File

@ -14,7 +14,6 @@
#include "app/modules/gui.h"
#include "app/ui/editor/editor_view.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "she/font.h"
#include "she/surface.h"
#include "she/system.h"

View File

@ -34,7 +34,6 @@
#include "app/ui/editor/editor.h"
#include "app/ui/input_chain.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/skin/style.h"
#include "app/ui/status_bar.h"
#include "app/ui/workspace.h"
#include "app/ui_context.h"
@ -1177,8 +1176,9 @@ void Timeline::onPaint(ui::PaintEvent& ev)
// Draw onionskin indicators.
gfx::Rect bounds = getOnionskinFramesBounds();
if (!bounds.isEmpty()) {
drawPart(g, bounds,
NULL, skinTheme()->styles.timelineOnionskinRange(),
drawPart(
g, bounds, nullptr,
skinTheme()->newStyles.timelineOnionskinRange(),
false, false, false);
}
}
@ -1289,8 +1289,9 @@ void Timeline::onPaint(ui::PaintEvent& ev)
paintNoDoc:;
if (noDoc)
drawPart(g, clientBounds(), NULL,
skinTheme()->styles.timelinePadding());
drawPart(
g, clientBounds(), nullptr,
skinTheme()->newStyles.timelinePadding());
}
void Timeline::onAfterCommandExecution(CommandExecutionEvent& ev)
@ -1503,23 +1504,25 @@ void Timeline::getDrawableFrames(ui::Graphics* g, frame_t* firstFrame, frame_t*
}
void Timeline::drawPart(ui::Graphics* g, const gfx::Rect& bounds,
const char* text, Style* style,
bool is_active,
bool is_hover,
bool is_clicked,
bool is_disabled)
const std::string* text, ui::Style* style,
const bool is_active,
const bool is_hover,
const bool is_clicked,
const bool is_disabled)
{
IntersectClip clip(g, bounds);
if (!clip)
return;
Style::State state;
if (is_active) state += Style::active();
if (is_hover) state += Style::hover();
if (is_clicked) state += Style::clicked();
if (is_disabled) state += Style::disabled();
PaintWidgetPartInfo info;
info.text = text;
info.styleFlags =
(is_active ? ui::Style::Layer::kFocus: 0) |
(is_hover ? ui::Style::Layer::kMouse: 0) |
(is_clicked ? ui::Style::Layer::kSelected: 0) |
(is_disabled ? ui::Style::Layer::kDisabled: 0);
style->paint(g, bounds, text, state);
theme()->paintWidgetPart(g, style, bounds, info);
}
void Timeline::drawClipboardRange(ui::Graphics* g)
@ -1549,34 +1552,35 @@ void Timeline::drawTop(ui::Graphics* g)
void Timeline::drawHeader(ui::Graphics* g)
{
SkinTheme::Styles& styles = skinTheme()->styles;
auto& styles = skinTheme()->newStyles;
bool allInvisible = allLayersInvisible();
bool allLocked = allLayersLocked();
bool allContinuous = allLayersContinuous();
drawPart(g, getPartBounds(Hit(PART_HEADER_EYE)),
NULL,
nullptr,
allInvisible ? styles.timelineClosedEye(): styles.timelineOpenEye(),
m_clk.part == PART_HEADER_EYE,
m_hot.part == PART_HEADER_EYE,
m_clk.part == PART_HEADER_EYE);
drawPart(g, getPartBounds(Hit(PART_HEADER_PADLOCK)),
NULL,
nullptr,
allLocked ? styles.timelineClosedPadlock(): styles.timelineOpenPadlock(),
m_clk.part == PART_HEADER_PADLOCK,
m_hot.part == PART_HEADER_PADLOCK,
m_clk.part == PART_HEADER_PADLOCK);
drawPart(g, getPartBounds(Hit(PART_HEADER_CONTINUOUS)),
NULL,
nullptr,
allContinuous ? styles.timelineContinuous(): styles.timelineDiscontinuous(),
m_clk.part == PART_HEADER_CONTINUOUS,
m_hot.part == PART_HEADER_CONTINUOUS,
m_clk.part == PART_HEADER_CONTINUOUS);
drawPart(g, getPartBounds(Hit(PART_HEADER_GEAR)),
NULL, styles.timelineGear(),
nullptr,
styles.timelineGear(),
false,
m_hot.part == PART_HEADER_GEAR,
m_clk.part == PART_HEADER_GEAR);
@ -1603,21 +1607,17 @@ void Timeline::drawHeaderFrame(ui::Graphics* g, frame_t frame)
return;
// Draw the header for the layers.
char buf[4];
std::snprintf(
buf, sizeof(buf), "%d",
// Draw only the first two digits
std::string text = base::convert_to<std::string, int>(
(docPref().timeline.firstFrame()+frame) % 100);
she::Font* oldFont = g->font();
g->setFont(skinTheme()->getMiniFont());
drawPart(g, bounds, buf, skinTheme()->styles.timelineBox(), is_active, is_hover, is_clicked);
g->setFont(oldFont);
drawPart(g, bounds, &text,
skinTheme()->newStyles.timelineHeaderFrame(),
is_active, is_hover, is_clicked);
}
void Timeline::drawLayer(ui::Graphics* g, int layerIdx)
{
SkinTheme::Styles& styles = skinTheme()->styles;
auto& styles = skinTheme()->newStyles;
Layer* layer = m_layers[layerIdx].layer;
bool is_active = isLayerActive(layerIdx);
bool hotlayer = (m_hot.layer == layerIdx);
@ -1652,7 +1652,7 @@ void Timeline::drawLayer(ui::Graphics* g, int layerIdx)
// Draw the continuous flag/group icon.
bounds = getPartBounds(Hit(PART_LAYER_CONTINUOUS_ICON, layerIdx));
if (layer->isImage()) {
drawPart(g, bounds, NULL,
drawPart(g, bounds, nullptr,
layer->isContinuous() ? styles.timelineContinuous():
styles.timelineDiscontinuous(),
is_active,
@ -1660,7 +1660,7 @@ void Timeline::drawLayer(ui::Graphics* g, int layerIdx)
(clklayer && m_clk.part == PART_LAYER_CONTINUOUS_ICON));
}
else if (layer->isGroup()) {
drawPart(g, bounds, NULL,
drawPart(g, bounds, nullptr,
layer->isCollapsed() ? styles.timelineClosedGroup():
styles.timelineOpenGroup(),
is_active,
@ -1695,13 +1695,17 @@ void Timeline::drawLayer(ui::Graphics* g, int layerIdx)
doc::rgba_geta(layerColor)),
b2);
drawPart(g, textBounds, layer->name().c_str(), styles.timelineLayerTextOnly(),
drawPart(g, textBounds,
&layer->name(),
styles.timelineLayerTextOnly(),
is_active,
(hotlayer && m_hot.part == PART_LAYER_TEXT),
(clklayer && m_clk.part == PART_LAYER_TEXT));
}
else {
drawPart(g, textBounds, layer->name().c_str(), styles.timelineLayer(),
drawPart(g, textBounds,
&layer->name(),
styles.timelineLayer(),
is_active,
(hotlayer && m_hot.part == PART_LAYER_TEXT),
(clklayer && m_clk.part == PART_LAYER_TEXT));
@ -1741,7 +1745,7 @@ void Timeline::drawLayer(ui::Graphics* g, int layerIdx)
void Timeline::drawCel(ui::Graphics* g, layer_t layerIndex, frame_t frame, Cel* cel, DrawCelData* data)
{
SkinTheme::Styles& styles = skinTheme()->styles;
auto& styles = skinTheme()->newStyles;
Layer* layer = m_layers[layerIndex].layer;
Image* image = (cel ? cel->image(): nullptr);
bool is_hover = (m_hot.part == PART_CEL &&
@ -1757,9 +1761,9 @@ void Timeline::drawCel(ui::Graphics* g, layer_t layerIndex, frame_t frame, Cel*
return;
if (layer == m_layer && frame == m_frame)
drawPart(g, bounds, NULL, styles.timelineSelectedCel(), false, false, true);
drawPart(g, bounds, nullptr, styles.timelineSelectedCel(), false, false, true);
else
drawPart(g, bounds, NULL, styles.timelineBox(), is_active, is_hover);
drawPart(g, bounds, nullptr, styles.timelineBox(), is_active, is_hover);
if ((docPref().thumbnails.enabled() || m_zoom > 1) && image) {
gfx::Rect thumb_bounds = gfx::Rect(bounds).shrink(guiscale()).inflate(guiscale(), guiscale());
@ -1794,7 +1798,7 @@ void Timeline::drawCel(ui::Graphics* g, layer_t layerIndex, frame_t frame, Cel*
bounds.w = headerBoxWidth();
skin::Style* style;
ui::Style* style = nullptr;
bool fromLeft = false;
bool fromRight = false;
if (is_empty || !data) {
@ -1822,14 +1826,14 @@ void Timeline::drawCel(ui::Graphics* g, layer_t layerIndex, frame_t frame, Cel*
else
style = styles.timelineKeyframe();
}
drawPart(g, bounds, NULL, style, is_active, is_hover);
drawPart(g, bounds, nullptr, style, is_active, is_hover);
if (m_zoom > 1) {
if (style == styles.timelineFromBoth() ||
style == styles.timelineFromRight()) {
style = styles.timelineFromBoth();
while ((bounds.x += bounds.w) < full_bounds.x + full_bounds.w) {
drawPart(g, bounds, NULL, style, is_active, is_hover);
drawPart(g, bounds, nullptr, style, is_active, is_hover);
}
}
}
@ -1950,11 +1954,11 @@ void Timeline::drawCelLinkDecorators(ui::Graphics* g, const gfx::Rect& full_boun
Cel* cel, frame_t frame, bool is_active, bool is_hover,
DrawCelData* data)
{
SkinTheme::Styles& styles = skinTheme()->styles;
auto& styles = skinTheme()->newStyles;
ObjectId imageId = (*data->activeIt)->image()->id();
gfx::Rect bounds = gfx::Rect(full_bounds).setSize(gfx::Size(headerBoxWidth(), headerBoxHeight()));
skin::Style* style = NULL;
ui::Style* style = NULL;
// Links at the left or right side
bool left = (data->firstLink != data->end ? frame > (*data->firstLink)->frame(): false);
@ -1978,12 +1982,12 @@ void Timeline::drawCelLinkDecorators(ui::Graphics* g, const gfx::Rect& full_boun
}
if (style) {
drawPart(g, bounds, NULL, style, is_active, is_hover);
drawPart(g, bounds, nullptr, style, is_active, is_hover);
if (m_zoom > 1 && (style == styles.timelineBothLinks() || style == styles.timelineRightLink())) {
style = styles.timelineBothLinks();
while ((bounds.x += bounds.w) < full_bounds.x + full_bounds.w) {
drawPart(g, bounds, NULL, style, is_active, is_hover);
drawPart(g, bounds, nullptr, style, is_active, is_hover);
}
}
}
@ -1996,7 +2000,7 @@ void Timeline::drawFrameTags(ui::Graphics* g)
return;
SkinTheme* theme = skinTheme();
SkinTheme::Styles& styles = theme->styles;
auto& styles = theme->newStyles;
g->fillRect(theme->colors.workspace(),
gfx::Rect(
@ -2013,7 +2017,7 @@ void Timeline::drawFrameTags(ui::Graphics* g)
{
IntersectClip clip(g, bounds);
if (clip)
drawPart(g, bounds, NULL, styles.timelineLoopRange());
drawPart(g, bounds, nullptr, styles.timelineLoopRange());
}
{
@ -2048,7 +2052,7 @@ void Timeline::drawFrameTags(ui::Graphics* g)
void Timeline::drawRangeOutline(ui::Graphics* g)
{
SkinTheme::Styles& styles = skinTheme()->styles;
auto& styles = skinTheme()->newStyles;
gfx::Rect clipBounds;
switch (m_range.type()) {
@ -2060,12 +2064,14 @@ void Timeline::drawRangeOutline(ui::Graphics* g)
if (!clip)
return;
Style::State state;
if (m_range.enabled()) state += Style::active();
if (m_hot.part == PART_RANGE_OUTLINE) state += Style::hover();
PaintWidgetPartInfo info;
info.styleFlags =
(m_range.enabled() ? ui::Style::Layer::kFocus: 0) |
(m_hot.part == PART_RANGE_OUTLINE ? ui::Style::Layer::kMouse: 0);
gfx::Rect bounds = getPartBounds(Hit(PART_RANGE_OUTLINE));
styles.timelineRangeOutline()->paint(g, bounds, NULL, state);
theme()->paintWidgetPart(
g, styles.timelineRangeOutline(), bounds, info);
Range drop = m_dropRange;
gfx::Rect dropBounds = getRangeBounds(drop);
@ -2074,7 +2080,9 @@ void Timeline::drawRangeOutline(ui::Graphics* g)
case Range::kCels: {
dropBounds = dropBounds.enlarge(outlineWidth());
styles.timelineRangeOutline()->paint(g, dropBounds, NULL, Style::active());
info.styleFlags = ui::Style::Layer::kFocus;
theme()->paintWidgetPart(
g, styles.timelineRangeOutline(), dropBounds, info);
break;
}
@ -2090,7 +2098,9 @@ void Timeline::drawRangeOutline(ui::Graphics* g)
dropBounds.w = w;
styles.timelineDropFrameDeco()->paint(g, dropBounds, NULL, Style::State());
info.styleFlags = 0;
theme()->paintWidgetPart(
g, styles.timelineDropFrameDeco(), dropBounds, info);
break;
}
@ -2106,7 +2116,8 @@ void Timeline::drawRangeOutline(ui::Graphics* g)
dropBounds.h = h;
styles.timelineDropLayerDeco()->paint(g, dropBounds, NULL, Style::State());
theme()->paintWidgetPart(
g, styles.timelineDropLayerDeco(), dropBounds, info);
break;
}
}
@ -2114,7 +2125,7 @@ void Timeline::drawRangeOutline(ui::Graphics* g)
void Timeline::drawPaddings(ui::Graphics* g)
{
SkinTheme::Styles& styles = skinTheme()->styles;
auto& styles = skinTheme()->newStyles;
gfx::Rect client = clientBounds();
gfx::Rect bottomLayer;

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -40,7 +40,6 @@ namespace ui {
namespace app {
namespace skin {
class Style;
class SkinTheme;
}
@ -240,9 +239,12 @@ namespace app {
void getDrawableLayers(ui::Graphics* g, layer_t* firstLayer, layer_t* lastLayer);
void getDrawableFrames(ui::Graphics* g, frame_t* firstFrame, frame_t* lastFrame);
void drawPart(ui::Graphics* g, const gfx::Rect& bounds,
const char* text, skin::Style* style,
bool is_active = false, bool is_hover = false,
bool is_clicked = false, bool is_disabled = false);
const std::string* text,
ui::Style* style,
const bool is_active = false,
const bool is_hover = false,
const bool is_clicked = false,
const bool is_disabled = false);
void drawTop(ui::Graphics* g);
void drawHeader(ui::Graphics* g);
void drawHeaderFrame(ui::Graphics* g, frame_t frame);

View File

@ -19,7 +19,6 @@
#include "app/ui/drop_down_button.h"
#include "app/ui/icon_button.h"
#include "app/ui/search_entry.h"
#include "app/ui/skin/skin_style_property.h"
#include "app/ui/skin/skin_theme.h"
#include "app/widget_not_found.h"
#include "app/xml_document.h"

View File

@ -1,5 +1,5 @@
// Aseprite Document 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.
@ -51,7 +51,7 @@ namespace doc {
virtual int getMemSize() const override;
std::string name() const { return m_name; }
const std::string& name() const { return m_name; }
void setName(const std::string& name) { m_name = name; }
Sprite* sprite() const { return m_sprite; }

View File

@ -17,7 +17,6 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
std::vector<std::string> dimensions;
std::vector<std::string> colors;
std::vector<std::string> parts;
std::vector<std::string> styles;
std::vector<std::string> newStyles;
TiXmlHandle handle(doc);
@ -52,17 +51,6 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
elem = elem->NextSiblingElement();
}
elem = handle
.FirstChild("theme")
.FirstChild("stylesheet")
.FirstChild("style").ToElement();
while (elem) {
const char* id = elem->Attribute("id");
if (!strchr(id, ':'))
styles.push_back(id);
elem = elem->NextSiblingElement();
}
elem = handle
.FirstChild("theme")
.FirstChild("styles")
@ -148,27 +136,6 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
std::cout
<< " };\n";
// Styles sub class
std::cout
<< "\n"
<< " class Styles {\n"
<< " template<typename> friend class ThemeFile;\n"
<< " public:\n";
for (auto style : styles) {
std::string id = convert_xmlid_to_cppid(style, false);
std::cout
<< " skin::Style* " << id << "() const { return m_" << id << "; }\n";
}
std::cout
<< " private:\n";
for (auto style : styles) {
std::string id = convert_xmlid_to_cppid(style, false);
std::cout
<< " skin::Style* m_" << id << ";\n";
}
std::cout
<< " };\n";
// New styles sub class
std::cout
<< "\n"
@ -195,7 +162,6 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
<< " Dimensions dimensions;\n"
<< " Colors colors;\n"
<< " Parts parts;\n"
<< " Styles styles;\n"
<< " NewStyles newStyles;\n"
<< "\n"
<< " protected:\n"
@ -215,11 +181,6 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
std::cout << " byId(parts.m_" << id
<< ", \"" << part << "\");\n";
}
for (auto style : styles) {
std::string id = convert_xmlid_to_cppid(style, false);
std::cout << " byId(styles.m_" << id
<< ", \"" << style << "\");\n";
}
for (auto newStyle : newStyles) {
std::string id = convert_xmlid_to_cppid(newStyle, false);
std::cout << " byId(newStyles.m_" << id
@ -238,9 +199,6 @@ void gen_theme_class(TiXmlDocument* doc, const std::string& inputFn)
<< " void byId(skin::SkinPartPtr& part, const std::string& id) {\n"
<< " part = static_cast<T*>(this)->getPartById(id);\n"
<< " }\n"
<< " void byId(skin::Style*& style, const std::string& id) {\n"
<< " style = static_cast<T*>(this)->getStyle(id);\n"
<< " }\n"
<< " void byId(ui::Style*& style, const std::string& id) {\n"
<< " style = static_cast<T*>(this)->getNewStyle(id);\n"
<< " }\n";

View File

@ -187,8 +187,9 @@ void Theme::paintWidgetPart(Graphics* g,
gfx::Color outBgColor = gfx::ColorNone;
for_each_layer(
info.styleFlags, style,
[this, g, &info, &rc, &outBgColor](const Style::Layer& layer) {
paintLayer(g, layer,
[this, g, style, &info, &rc, &outBgColor]
(const Style::Layer& layer) {
paintLayer(g, style, layer,
(info.text ? *info.text: std::string()),
info.mnemonic, rc, outBgColor);
});
@ -284,6 +285,7 @@ void Theme::paintTooltip(Graphics* g,
}
void Theme::paintLayer(Graphics* g,
const Style* style,
const Style::Layer& layer,
const std::string& text,
const int mnemonic,
@ -390,6 +392,10 @@ void Theme::paintLayer(Graphics* g,
case Style::Layer::Type::kText:
if (layer.color() != gfx::ColorNone) {
she::Font* oldFont = g->font();
if (style->font())
g->setFont(style->font());
if (layer.align() & WORDWRAP) {
gfx::Rect textBounds = rc;
textBounds.offset(layer.offset());
@ -424,6 +430,9 @@ void Theme::paintLayer(Graphics* g,
bgColor,
pt, mnemonic);
}
if (style->font())
g->setFont(oldFont);
}
break;
@ -470,6 +479,7 @@ gfx::Size Theme::calcSizeHint(const Widget* widget,
}
void Theme::measureLayer(const Widget* widget,
const Style* style,
const Style::Layer& layer,
gfx::Border& borderHint,
gfx::Size& textHint, int& textAlign,
@ -496,9 +506,9 @@ void Theme::measureLayer(const Widget* widget,
case Style::Layer::Type::kText:
if (layer.color() != gfx::ColorNone) {
gfx::Size textSize(Graphics::measureUITextLength(widget->text(),
widget->font()),
widget->font()->height());
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);
textAlign = layer.align();
@ -591,9 +601,9 @@ void Theme::calcWidgetMetrics(const Widget* widget,
for_each_layer(
widget, style,
[this, widget, &borderHint, &textHint, &textAlign, &iconHint, &iconAlign]
[this, widget, style, &borderHint, &textHint, &textAlign, &iconHint, &iconAlign]
(const Style::Layer& layer) {
measureLayer(widget, layer,
measureLayer(widget, style, layer,
borderHint,
textHint, textAlign,
iconHint, iconAlign);

View File

@ -130,12 +130,14 @@ namespace ui {
private:
void paintLayer(Graphics* g,
const Style* style,
const Style::Layer& layer,
const std::string& text,
const int mnemonic,
gfx::Rect& rc,
gfx::Color& bgColor);
void measureLayer(const Widget* widget,
const Style* style,
const Style::Layer& layer,
gfx::Border& borderHint,
gfx::Size& textHint, int& textAlign,