SkinTheme: paint windows using styles

This commit is contained in:
David Capello 2014-03-21 00:28:01 -03:00
parent 5f4f1ff029
commit 04a0845a62
5 changed files with 32 additions and 29 deletions

View File

@ -314,6 +314,24 @@
<stylesheet>
<!-- window -->
<style id="window">
<background color="window_face" part="window" />
</style>
<style id="window_title">
<background color="window_titlebar_face" />
<text color="window_titlebar_text" align="left" valign="middle" />
</style>
<style id="menubox">
<background color="window_face" part="menu" />
</style>
<style id="desktop">
<background color="desktop" />
</style>
<!-- scrollbar -->
<style id="scrollbar">
<background color="scrollbar_bg_face" part="scrollbar_bg" />

View File

@ -57,8 +57,6 @@ namespace app {
SKIN_PART_NESW(PART_SUNKEN2_FOCUSED),
SKIN_PART_NESW(PART_SUNKEN_MINI_NORMAL),
SKIN_PART_NESW(PART_SUNKEN_MINI_FOCUSED),
SKIN_PART_NESW(PART_WINDOW),
SKIN_PART_NESW(PART_MENU),
PART_WINDOW_CLOSE_BUTTON_NORMAL,
PART_WINDOW_CLOSE_BUTTON_HOT,

View File

@ -63,6 +63,8 @@ static std::map<std::string, ThemeColor::Type> color_mapping;
const char* SkinTheme::kThemeCloseButtonId = "theme_close_button";
const char* kWindowFaceColorId = "window_face";
// Controls the "X" button in a window to close it.
class WindowCloseButton : public Button {
public:
@ -168,8 +170,6 @@ SkinTheme::SkinTheme()
sheet_mapping["sunken2_focused"] = PART_SUNKEN2_FOCUSED_NW;
sheet_mapping["sunken_mini_normal"] = PART_SUNKEN_MINI_NORMAL_NW;
sheet_mapping["sunken_mini_focused"] = PART_SUNKEN_MINI_FOCUSED_NW;
sheet_mapping["window"] = PART_WINDOW_NW;
sheet_mapping["menu"] = PART_MENU_NW;
sheet_mapping["window_close_button_normal"] = PART_WINDOW_CLOSE_BUTTON_NORMAL;
sheet_mapping["window_close_button_hot"] = PART_WINDOW_CLOSE_BUTTON_HOT;
sheet_mapping["window_close_button_selected"] = PART_WINDOW_CLOSE_BUTTON_SELECTED;
@ -291,7 +291,6 @@ SkinTheme::SkinTheme()
color_mapping["hot_face"] = ThemeColor::HotFace;
color_mapping["selected"] = ThemeColor::Selected;
color_mapping["background"] = ThemeColor::Background;
color_mapping["desktop"] = ThemeColor::Desktop;
color_mapping["textbox_text"] = ThemeColor::TextBoxText;
color_mapping["textbox_face"] = ThemeColor::TextBoxFace;
color_mapping["entry_suffix"] = ThemeColor::EntrySuffix;
@ -312,9 +311,6 @@ SkinTheme::SkinTheme()
color_mapping["menuitem_hot_face"] = ThemeColor::MenuItemHotFace;
color_mapping["menuitem_highlight_text"] = ThemeColor::MenuItemHighlightText;
color_mapping["menuitem_highlight_face"] = ThemeColor::MenuItemHighlightFace;
color_mapping["window_face"] = ThemeColor::WindowFace;
color_mapping["window_titlebar_text"] = ThemeColor::WindowTitlebarText;
color_mapping["window_titlebar_face"] = ThemeColor::WindowTitlebarFace;
color_mapping["editor_face"] = ThemeColor::EditorFace;
color_mapping["editor_sprite_border"] = ThemeColor::EditorSpriteBorder;
color_mapping["editor_sprite_bottom_border"] = ThemeColor::EditorSpriteBottomBorder;
@ -886,8 +882,8 @@ void SkinTheme::initWidget(Widget* widget)
else {
BORDER(0);
}
widget->child_spacing = 4 * scale;
widget->setBgColor(getColor(ThemeColor::WindowFace));
widget->child_spacing = 4 * scale; // TODO this hard-coded 4 should be configurable in skin.xml
widget->setBgColor(getColorById(kWindowFaceColorId));
break;
default:
@ -1779,27 +1775,20 @@ void SkinTheme::paintWindow(PaintEvent& ev)
if (!window->isDesktop()) {
// window frame
if (window->hasText()) {
draw_bounds_nw(g, pos, PART_WINDOW_NW,
getColor(ThemeColor::WindowFace));
pos.h = cpos.y - pos.y;
// titlebar
g->setFont(window->getFont());
g->drawString(window->getText(), ThemeColor::Background, ColorNone,
false,
gfx::Point(cpos.x,
pos.y + pos.h/2 - text_height(window->getFont())/2));
get_style("window")->paint(g, pos, NULL, Style::State());
get_style("window_title")->paint(g,
gfx::Rect(cpos.x, pos.y+5*jguiscale(), cpos.w, // TODO this hard-coded 5 should be configurable in skin.xml
jwidget_get_text_height(window)),
window->getText().c_str(), Style::State());
}
// menubox
else {
draw_bounds_nw(g, pos, PART_MENU_NW,
getColor(ThemeColor::WindowFace));
get_style("menubox")->paint(g, pos, NULL, Style::State());
}
}
// desktop
else {
g->fillRect(ThemeColor::Desktop, pos);
get_style("desktop")->paint(g, pos, NULL, Style::State());
}
}

View File

@ -51,7 +51,6 @@ namespace app {
HotFace,
Selected,
Background,
Desktop,
TextBoxText,
TextBoxFace,
EntrySuffix,
@ -72,9 +71,6 @@ namespace app {
MenuItemHotFace,
MenuItemHighlightText,
MenuItemHighlightFace,
WindowFace,
WindowTitlebarText,
WindowTitlebarFace,
EditorFace,
EditorSpriteBorder,
EditorSpriteBottomBorder,
@ -108,6 +104,8 @@ namespace app {
};
}
extern const char* kWindowFaceColorId;
// This is the GUI theme used by Aseprite (which use images from
// data/skins directory).
class SkinTheme : public ui::Theme {

View File

@ -361,7 +361,7 @@ void Tabs::onPaint(PaintEvent& ev)
2*jguiscale(),
theme->get_part(PART_TAB_FILLER)->h);
g->fillRect(theme->getColor(ThemeColor::WindowFace), g->getClipBounds());
g->fillRect(theme->getColorById(kWindowFaceColorId), g->getClipBounds());
theme->draw_part_as_hline(g, box, PART_TAB_FILLER);
theme->draw_part_as_hline(g, gfx::Rect(box.x, box.y2(), box.w, rect.y2()-box.y2()), PART_TAB_BOTTOM_NORMAL);