mirror of https://github.com/aseprite/aseprite.git
Add widgets to HomeView (icon, new file, open file, and list boxes)
* Add widgets/home_view.xml * Add possibility to specify style="..." and border="..." in XML widgets * Add SkinStyleProperty * Remove Label::get/setTextColor() (replaced with styles) * Add <image> widget in WidgetLoader * Paint labels, link labels, and views with styles
This commit is contained in:
parent
c396f271c8
commit
8eb8122bc0
|
@ -24,7 +24,8 @@
|
|||
<color id="textbox_text" value="#000000" />
|
||||
<color id="textbox_face" value="#ffffff" />
|
||||
<color id="entry_suffix" value="#c6c6c6" />
|
||||
<color id="link_text" value="#0000ff" />
|
||||
<color id="link_text" value="#2c4c91" />
|
||||
<color id="link_hover" value="#ff5555" />
|
||||
<color id="button_normal_text" value="#000000" />
|
||||
<color id="button_normal_face" value="#c6c6c6" />
|
||||
<color id="button_hot_text" value="#000000" />
|
||||
|
@ -73,7 +74,9 @@
|
|||
<color id="filelist_selected_row_face" value="#ff5555" />
|
||||
<color id="filelist_disabled_row_text" value="#ffc8c8" />
|
||||
<color id="workspace" value="#7d929e" />
|
||||
<color id="workspace_text" value="#ffffff" />
|
||||
<color id="workspace_text" value="#655561" />
|
||||
<color id="workspace_link" value="#655561" />
|
||||
<color id="workspace_link_hover" value="#ffff7d" />
|
||||
<color id="timeline_normal" value="#c6c6c6" />
|
||||
<color id="timeline_normal_text" value="#000000" />
|
||||
<color id="timeline_hover" value="#d9d9d9" />
|
||||
|
@ -373,6 +376,27 @@
|
|||
|
||||
<stylesheet>
|
||||
|
||||
<!-- label -->
|
||||
<style id="label">
|
||||
<text color="text" />
|
||||
</style>
|
||||
|
||||
<!-- link -->
|
||||
<style id="link">
|
||||
<text color="link_text" />
|
||||
</style>
|
||||
<style id="link:hover">
|
||||
<text color="link_hover" />
|
||||
</style>
|
||||
|
||||
<!-- view -->
|
||||
<style id="view">
|
||||
<background part="sunken_normal" />
|
||||
</style>
|
||||
<style id="view:active">
|
||||
<background part="sunken_focused" />
|
||||
</style>
|
||||
|
||||
<!-- window -->
|
||||
<style id="window">
|
||||
<background color="window_face" part="window" />
|
||||
|
@ -698,6 +722,27 @@
|
|||
<icon part="tab_home_icon_active" />
|
||||
</style>
|
||||
|
||||
<!-- workspace_label -->
|
||||
<style id="workspace_label">
|
||||
<text color="workspace_text" />
|
||||
</style>
|
||||
|
||||
<!-- workspace_link -->
|
||||
<style id="workspace_link">
|
||||
<text color="workspace_link" />
|
||||
</style>
|
||||
<style id="workspace_link:hover">
|
||||
<text color="workspace_link_hover" />
|
||||
</style>
|
||||
|
||||
<!-- workspace_view -->
|
||||
<style id="workspace_view">
|
||||
<background part="editor_normal" />
|
||||
</style>
|
||||
<style id="workspace_view:active">
|
||||
<background part="editor_selected" />
|
||||
</style>
|
||||
|
||||
</stylesheet>
|
||||
|
||||
</skin>
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<!-- Aseprite -->
|
||||
<!-- Copyright (C) 2001-2015 by David Capello -->
|
||||
<gui>
|
||||
<vbox noborders="true" id="home_view" childspacing="8" expansive="true">
|
||||
<hbox noborders="true">
|
||||
<image file="icons/ase48.png" align="center" />
|
||||
<vbox cell_vspan="2" border="4" childspacing="4">
|
||||
<link id="new_file" text="New File..." style="workspace_link" />
|
||||
<link id="open_file" text="Open File..." style="workspace_link" />
|
||||
</vbox>
|
||||
</hbox>
|
||||
<hbox noborders="true" expansive="true" homogeneous="true">
|
||||
<vbox noborders="true">
|
||||
<label text="Recent files:" style="workspace_label" />
|
||||
<view expansive="true" style="workspace_view">
|
||||
<listbox id="recent_files" />
|
||||
</view>
|
||||
<label text="Recent folders:" style="workspace_label" />
|
||||
<view expansive="true" style="workspace_view">
|
||||
<listbox id="recent_folders" />
|
||||
</view>
|
||||
</vbox>
|
||||
<vbox noborders="true">
|
||||
<label text="News:" style="workspace_label" />
|
||||
<view expansive="true" style="workspace_view">
|
||||
<listbox id="news" />
|
||||
</view>
|
||||
</vbox>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</gui>
|
|
@ -319,6 +319,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
|
||||
|
|
|
@ -12,8 +12,12 @@
|
|||
#include "app/ui/home_view.h"
|
||||
|
||||
#include "app/app_menus.h"
|
||||
#include "app/commands/commands.h"
|
||||
#include "app/ui/skin/skin_theme.h"
|
||||
#include "app/ui/workspace.h"
|
||||
#include "app/ui_context.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/exception.h"
|
||||
#include "ui/label.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/textbox.h"
|
||||
|
@ -25,16 +29,14 @@ using namespace ui;
|
|||
using namespace skin;
|
||||
|
||||
HomeView::HomeView()
|
||||
: Box(JI_VERTICAL)
|
||||
{
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(getTheme());
|
||||
setBgColor(theme->colors.workspace());
|
||||
|
||||
child_spacing = 8 * guiscale();
|
||||
|
||||
Label* label = new Label("Welcome to " PACKAGE " v" VERSION);
|
||||
label->setTextColor(theme->colors.workspaceText());
|
||||
addChild(label);
|
||||
newFile()->Click.connect(Bind(&HomeView::onNewFile, this));
|
||||
openFile()->Click.connect(Bind(&HomeView::onOpenFile, this));
|
||||
}
|
||||
|
||||
HomeView::~HomeView()
|
||||
|
@ -80,4 +82,16 @@ void HomeView::onWorkspaceViewSelected()
|
|||
{
|
||||
}
|
||||
|
||||
void HomeView::onNewFile()
|
||||
{
|
||||
Command* command = CommandsModule::instance()->getCommandByName(CommandId::NewFile);
|
||||
UIContext::instance()->executeCommand(command, nullptr);
|
||||
}
|
||||
|
||||
void HomeView::onOpenFile()
|
||||
{
|
||||
Command* command = CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
|
||||
UIContext::instance()->executeCommand(command, nullptr);
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
|
|
@ -13,12 +13,14 @@
|
|||
#include "app/ui/workspace_view.h"
|
||||
#include "ui/box.h"
|
||||
|
||||
#include "generated_home_view.h"
|
||||
|
||||
namespace ui {
|
||||
class View;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
class HomeView : public ui::Box
|
||||
class HomeView : public app::gen::HomeView
|
||||
, public TabView
|
||||
, public WorkspaceView {
|
||||
public:
|
||||
|
@ -36,6 +38,10 @@ namespace app {
|
|||
bool onCloseView(Workspace* workspace) override;
|
||||
void onTabPopup(Workspace* workspace) override;
|
||||
void onWorkspaceViewSelected() override;
|
||||
|
||||
private:
|
||||
void onNewFile();
|
||||
void onOpenFile();
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
|
||||
#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
|
|
@ -0,0 +1,37 @@
|
|||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
|
||||
#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 SharedPtr<SkinStyleProperty> SkinStylePropertyPtr;
|
||||
|
||||
} // namespace skin
|
||||
} // namespace app
|
||||
|
||||
#endif
|
|
@ -17,6 +17,7 @@
|
|||
#include "app/ui/skin/button_icon_impl.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"
|
||||
|
@ -706,7 +707,6 @@ void SkinTheme::initWidget(Widget* widget)
|
|||
|
||||
case kLabelWidget:
|
||||
BORDER(1 * scale);
|
||||
static_cast<Label*>(widget)->setTextColor(colors.text());
|
||||
break;
|
||||
|
||||
case kListBoxWidget:
|
||||
|
@ -1112,36 +1112,41 @@ void SkinTheme::paintLabel(PaintEvent& ev)
|
|||
{
|
||||
Graphics* g = ev.getGraphics();
|
||||
Label* widget = static_cast<Label*>(ev.getSource());
|
||||
Style* style = styles.label();
|
||||
gfx::Color bg = BGCOLOR;
|
||||
gfx::Color fg = widget->getTextColor();
|
||||
Rect text, rc = widget->getClientBounds();
|
||||
|
||||
SkinStylePropertyPtr styleProp = widget->getProperty(SkinStyleProperty::Name);
|
||||
if (styleProp)
|
||||
style = styleProp->getStyle();
|
||||
|
||||
if (!is_transparent(bg))
|
||||
g->fillRect(bg, rc);
|
||||
|
||||
rc.shrink(widget->getBorder());
|
||||
|
||||
widget->getTextIconInfo(NULL, &text);
|
||||
g->drawUIString(widget->getText(), fg, ColorNone, text.getOrigin());
|
||||
style->paint(g, text, widget->getText().c_str(), Style::State());
|
||||
}
|
||||
|
||||
void SkinTheme::paintLinkLabel(PaintEvent& ev)
|
||||
{
|
||||
Graphics* g = ev.getGraphics();
|
||||
Widget* widget = static_cast<Widget*>(ev.getSource());
|
||||
Style* style = styles.link();
|
||||
gfx::Rect bounds = widget->getClientBounds();
|
||||
gfx::Color fg = colors.linkText();
|
||||
gfx::Color bg = BGCOLOR;
|
||||
|
||||
g->fillRect(bg, bounds);
|
||||
drawTextString(g, NULL, fg, ColorNone, widget, bounds, 0);
|
||||
SkinStylePropertyPtr styleProp = widget->getProperty(SkinStyleProperty::Name);
|
||||
if (styleProp)
|
||||
style = styleProp->getStyle();
|
||||
|
||||
// Underline style
|
||||
if (widget->hasMouseOver()) {
|
||||
int w = widget->getTextWidth();
|
||||
for (int v=0; v<guiscale(); ++v)
|
||||
g->drawHLine(fg, bounds.x, bounds.y2()-1-v, w);
|
||||
}
|
||||
Style::State state;
|
||||
if (widget->hasMouseOver()) state += Style::hover();
|
||||
if (widget->isSelected()) state += Style::clicked();
|
||||
|
||||
g->fillRect(bg, bounds);
|
||||
style->paint(g, bounds, widget->getText().c_str(), state);
|
||||
}
|
||||
|
||||
void SkinTheme::paintListBox(PaintEvent& ev)
|
||||
|
@ -1620,15 +1625,19 @@ void SkinTheme::paintView(PaintEvent& ev)
|
|||
View* widget = static_cast<View*>(ev.getSource());
|
||||
gfx::Rect bounds = widget->getClientBounds();
|
||||
gfx::Color bg = BGCOLOR;
|
||||
Style* style = styles.view();
|
||||
|
||||
SkinStylePropertyPtr styleProp = widget->getProperty(SkinStyleProperty::Name);
|
||||
if (styleProp)
|
||||
style = styleProp->getStyle();
|
||||
|
||||
Style::State state;
|
||||
if (widget->hasMouseOver()) state += Style::hover();
|
||||
|
||||
if (!is_transparent(bg))
|
||||
g->fillRect(bg, bounds);
|
||||
|
||||
draw_bounds_nw(g, bounds,
|
||||
(widget->hasFocus() ?
|
||||
PART_SUNKEN_FOCUSED_NW:
|
||||
PART_SUNKEN_NORMAL_NW),
|
||||
BGCOLOR);
|
||||
style->paint(g, bounds, nullptr, state);
|
||||
}
|
||||
|
||||
void SkinTheme::paintViewScrollbar(PaintEvent& ev)
|
||||
|
|
|
@ -113,6 +113,7 @@ namespace app {
|
|||
}
|
||||
|
||||
gfx::Color getColorById(const std::string& id) {
|
||||
ASSERT(m_colors_by_id.find(id) != m_colors_by_id.end());
|
||||
return m_colors_by_id[id];
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "app/resource_finder.h"
|
||||
#include "app/ui/button_set.h"
|
||||
#include "app/ui/color_button.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"
|
||||
|
@ -23,6 +24,7 @@
|
|||
#include "base/bind.h"
|
||||
#include "base/fs.h"
|
||||
#include "base/memory.h"
|
||||
#include "she/system.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
#include "tinyxml.h"
|
||||
|
@ -429,6 +431,27 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (elem_name == "image") {
|
||||
if (!widget) {
|
||||
const char* file = elem->Attribute("file");
|
||||
|
||||
// Load image
|
||||
std::string icon(file);
|
||||
|
||||
ResourceFinder rf;
|
||||
rf.includeDataDir(file);
|
||||
if (!rf.findFirst())
|
||||
throw base::Exception("File %s not found", file);
|
||||
|
||||
try {
|
||||
she::Surface* sur = she::instance()->loadRgbaSurface(rf.filename().c_str());
|
||||
widget = new ImageView(sur, 0);
|
||||
}
|
||||
catch (...) {
|
||||
throw base::Exception("Error loading %s file", file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Was the widget created?
|
||||
if (widget)
|
||||
|
@ -454,6 +477,8 @@ void WidgetLoader::fillWidgetWithXmlElementAttributes(const TiXmlElement* elem,
|
|||
const char* minheight = elem->Attribute("minheight");
|
||||
const char* maxwidth = elem->Attribute("maxwidth");
|
||||
const char* maxheight = elem->Attribute("maxheight");
|
||||
const char* border = elem->Attribute("border");
|
||||
const char* styleid = elem->Attribute("style");
|
||||
const char* childspacing = elem->Attribute("childspacing");
|
||||
|
||||
if (width) {
|
||||
|
@ -498,8 +523,11 @@ void WidgetLoader::fillWidgetWithXmlElementAttributes(const TiXmlElement* elem,
|
|||
if (noborders)
|
||||
widget->noBorderNoChildSpacing();
|
||||
|
||||
if (border)
|
||||
widget->setBorder(gfx::Border(strtol(childspacing, NULL, 10)*guiscale()));
|
||||
|
||||
if (childspacing)
|
||||
widget->child_spacing = strtol(childspacing, NULL, 10);
|
||||
widget->child_spacing = strtol(childspacing, NULL, 10)*guiscale();
|
||||
|
||||
gfx::Size reqSize = widget->getPreferredSize();
|
||||
|
||||
|
@ -515,6 +543,14 @@ void WidgetLoader::fillWidgetWithXmlElementAttributes(const TiXmlElement* elem,
|
|||
widget->setMaxSize(gfx::Size(w, h));
|
||||
}
|
||||
|
||||
if (styleid) {
|
||||
SkinTheme* theme = static_cast<SkinTheme*>(root->getTheme());
|
||||
skin::Style* style = theme->getStyle(styleid);
|
||||
ASSERT(style);
|
||||
SkinStylePropertyPtr prop(new SkinStyleProperty(style));
|
||||
widget->setProperty(prop);
|
||||
}
|
||||
|
||||
if (!root)
|
||||
root = widget;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2013 David Capello
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
@ -23,16 +23,6 @@ Label::Label(const std::string& text)
|
|||
initTheme();
|
||||
}
|
||||
|
||||
gfx::Color Label::getTextColor() const
|
||||
{
|
||||
return m_textColor;
|
||||
}
|
||||
|
||||
void Label::setTextColor(gfx::Color color)
|
||||
{
|
||||
m_textColor = color;
|
||||
}
|
||||
|
||||
void Label::onPreferredSize(PreferredSizeEvent& ev)
|
||||
{
|
||||
gfx::Size sz(0, 0);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2013 David Capello
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
@ -13,20 +13,13 @@
|
|||
|
||||
namespace ui {
|
||||
|
||||
class Label : public Widget
|
||||
{
|
||||
class Label : public Widget {
|
||||
public:
|
||||
Label(const std::string& text);
|
||||
|
||||
gfx::Color getTextColor() const;
|
||||
void setTextColor(gfx::Color color);
|
||||
|
||||
protected:
|
||||
void onPreferredSize(PreferredSizeEvent& ev) override;
|
||||
void onPaint(PaintEvent& ev) override;
|
||||
|
||||
private:
|
||||
gfx::Color m_textColor;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
|
Loading…
Reference in New Issue