2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2018-01-30 01:09:22 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-03-08 00:21:24 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2010-03-08 00:21:24 +08:00
|
|
|
|
2017-06-11 02:02:39 +08:00
|
|
|
#include "app/ui/skin/skin_theme.h"
|
|
|
|
|
|
|
|
#include "app/app.h"
|
2016-10-27 21:44:31 +08:00
|
|
|
#include "app/console.h"
|
2017-06-11 02:02:39 +08:00
|
|
|
#include "app/extensions.h"
|
2017-02-25 04:56:57 +08:00
|
|
|
#include "app/font_path.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/gui.h"
|
2015-09-18 22:56:45 +08:00
|
|
|
#include "app/pref/preferences.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/resource_finder.h"
|
2014-10-29 22:58:03 +08:00
|
|
|
#include "app/ui/app_menuitem.h"
|
|
|
|
#include "app/ui/keyboard_shortcuts.h"
|
2017-02-25 04:56:57 +08:00
|
|
|
#include "app/ui/skin/font_data.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/skin/skin_property.h"
|
|
|
|
#include "app/ui/skin/skin_slider_property.h"
|
2013-10-15 06:58:11 +08:00
|
|
|
#include "app/xml_document.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/xml_exception.h"
|
2010-09-26 04:20:59 +08:00
|
|
|
#include "base/bind.h"
|
2013-10-15 06:58:11 +08:00
|
|
|
#include "base/fs.h"
|
2017-08-23 01:54:08 +08:00
|
|
|
#include "base/log.h"
|
2010-09-30 04:14:11 +08:00
|
|
|
#include "base/shared_ptr.h"
|
2014-09-21 22:59:39 +08:00
|
|
|
#include "base/string.h"
|
2011-02-05 23:03:22 +08:00
|
|
|
#include "gfx/border.h"
|
|
|
|
#include "gfx/point.h"
|
2011-01-24 11:03:38 +08:00
|
|
|
#include "gfx/rect.h"
|
2011-02-05 23:03:22 +08:00
|
|
|
#include "gfx/size.h"
|
2017-02-07 04:58:55 +08:00
|
|
|
#include "she/draw_text.h"
|
2014-06-23 05:53:14 +08:00
|
|
|
#include "she/font.h"
|
|
|
|
#include "she/surface.h"
|
2012-08-11 10:14:54 +08:00
|
|
|
#include "she/system.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/intern.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2009-11-22 04:02:31 +08:00
|
|
|
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
#include "tinyxml.h"
|
|
|
|
|
2017-03-16 02:13:23 +08:00
|
|
|
#include <cstring>
|
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
#define BGCOLOR (getWidgetBgColor(widget))
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
namespace skin {
|
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
using namespace ui;
|
|
|
|
|
2017-06-11 02:02:39 +08:00
|
|
|
// TODO For backward compatibility, in future versions we should remove this (extensions are preferred)
|
2017-02-10 00:18:44 +08:00
|
|
|
const char* SkinTheme::kThemesFolderName = "themes";
|
2012-06-16 10:37:59 +08:00
|
|
|
|
2017-03-15 06:00:24 +08:00
|
|
|
static const char* g_cursor_names[kCursorTypes] = {
|
2012-08-11 10:14:54 +08:00
|
|
|
"null", // kNoCursor
|
|
|
|
"normal", // kArrowCursor
|
|
|
|
"normal_add", // kArrowPlusCursor
|
2016-08-31 22:22:08 +08:00
|
|
|
"crosshair", // kCrosshairCursor
|
2012-08-11 10:14:54 +08:00
|
|
|
"forbidden", // kForbiddenCursor
|
|
|
|
"hand", // kHandCursor
|
|
|
|
"scroll", // kScrollCursor
|
|
|
|
"move", // kMoveCursor
|
2014-08-11 06:51:14 +08:00
|
|
|
"size_ns", // kSizeNSCursor
|
|
|
|
"size_we", // kSizeWECursor
|
|
|
|
"size_n", // kSizeNCursor
|
|
|
|
"size_ne", // kSizeNECursor
|
|
|
|
"size_e", // kSizeECursor
|
|
|
|
"size_se", // kSizeSECursor
|
|
|
|
"size_s", // kSizeSCursor
|
|
|
|
"size_sw", // kSizeSWCursor
|
|
|
|
"size_w", // kSizeWCursor
|
|
|
|
"size_nw", // kSizeNWCursor
|
2009-11-22 04:02:31 +08:00
|
|
|
};
|
|
|
|
|
2017-02-25 04:56:57 +08:00
|
|
|
static FontData* load_font(std::map<std::string, FontData*>& fonts,
|
|
|
|
const TiXmlElement* xmlFont,
|
|
|
|
const std::string& xmlFilename)
|
|
|
|
{
|
|
|
|
const char* fontRef = xmlFont->Attribute("font");
|
|
|
|
if (fontRef) {
|
|
|
|
auto it = fonts.find(fontRef);
|
|
|
|
if (it == fonts.end())
|
|
|
|
throw base::Exception("Font named '%s' not found\n", fontRef);
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* nameStr = xmlFont->Attribute("name");
|
|
|
|
if (!nameStr)
|
|
|
|
throw base::Exception("No \"name\" or \"font\" attributes specified on <font>");
|
|
|
|
|
|
|
|
std::string name(nameStr);
|
2017-08-23 01:54:08 +08:00
|
|
|
|
|
|
|
// Use cached font data
|
|
|
|
auto it = fonts.find(name);
|
|
|
|
if (it != fonts.end())
|
|
|
|
return it->second;
|
|
|
|
|
2017-03-09 06:25:03 +08:00
|
|
|
LOG(VERBOSE) << "THEME: Loading font '" << name << "'\n";
|
2017-02-25 04:56:57 +08:00
|
|
|
|
|
|
|
const char* typeStr = xmlFont->Attribute("type");
|
|
|
|
if (!typeStr)
|
|
|
|
throw base::Exception("<font> without 'type' attribute in '%s'\n",
|
|
|
|
xmlFilename.c_str());
|
|
|
|
|
|
|
|
std::string type(typeStr);
|
2017-10-09 22:55:20 +08:00
|
|
|
std::string xmlDir(base::get_file_path(xmlFilename));
|
2017-02-25 04:56:57 +08:00
|
|
|
base::UniquePtr<FontData> font(nullptr);
|
|
|
|
|
|
|
|
if (type == "spritesheet") {
|
|
|
|
const char* fileStr = xmlFont->Attribute("file");
|
|
|
|
if (fileStr) {
|
|
|
|
font.reset(new FontData(she::FontType::kSpriteSheet));
|
2017-10-09 22:55:20 +08:00
|
|
|
font->setFilename(base::join_path(xmlDir, fileStr));
|
2017-02-25 04:56:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == "truetype") {
|
|
|
|
const char* platformFileAttrName =
|
|
|
|
#ifdef _WIN32
|
|
|
|
"file_win"
|
|
|
|
#elif defined __APPLE__
|
|
|
|
"file_mac"
|
|
|
|
#else
|
|
|
|
"file_linux"
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
const char* platformFileStr = xmlFont->Attribute(platformFileAttrName);
|
|
|
|
const char* fileStr = xmlFont->Attribute("file");
|
|
|
|
bool antialias = true;
|
|
|
|
if (xmlFont->Attribute("antialias"))
|
|
|
|
antialias = bool_attr_is_true(xmlFont, "antialias");
|
|
|
|
|
|
|
|
std::string fontFilename;
|
|
|
|
if (platformFileStr)
|
2017-10-09 22:55:20 +08:00
|
|
|
fontFilename = app::find_font(xmlDir, platformFileStr);
|
2017-02-25 04:56:57 +08:00
|
|
|
if (fileStr && fontFilename.empty())
|
2017-10-09 22:55:20 +08:00
|
|
|
fontFilename = app::find_font(xmlDir, fileStr);
|
2017-02-25 04:56:57 +08:00
|
|
|
|
2017-03-08 01:53:40 +08:00
|
|
|
// The filename can be empty if the font was not found, anyway we
|
|
|
|
// want to keep the font information (e.g. to use the fallback
|
|
|
|
// information of this font).
|
|
|
|
font.reset(new FontData(she::FontType::kTrueType));
|
|
|
|
font->setFilename(fontFilename);
|
|
|
|
font->setAntialias(antialias);
|
|
|
|
|
|
|
|
if (!fontFilename.empty())
|
2017-03-09 06:25:03 +08:00
|
|
|
LOG(VERBOSE) << "THEME: Font file '" << fontFilename << "' not found\n";
|
2017-02-25 04:56:57 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw base::Exception("Invalid type=\"%s\" in '%s' for <font name=\"%s\" ...>\n",
|
|
|
|
type.c_str(), xmlFilename.c_str(), name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
FontData* result = nullptr;
|
|
|
|
if (font) {
|
|
|
|
fonts[name] = result = font.get();
|
|
|
|
font.release();
|
|
|
|
|
|
|
|
// Fallback font
|
|
|
|
const TiXmlElement* xmlFallback =
|
|
|
|
(const TiXmlElement*)xmlFont->FirstChild("fallback");
|
|
|
|
if (xmlFallback) {
|
|
|
|
FontData* fallback = load_font(fonts, xmlFallback, xmlFilename);
|
|
|
|
if (fallback) {
|
|
|
|
int size = 10;
|
|
|
|
const char* sizeStr = xmlFont->Attribute("size");
|
|
|
|
if (sizeStr)
|
|
|
|
size = std::strtol(sizeStr, nullptr, 10);
|
|
|
|
|
|
|
|
result->setFallback(fallback, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-02-17 22:43:25 +08:00
|
|
|
// static
|
|
|
|
SkinTheme* SkinTheme::instance()
|
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
return static_cast<SkinTheme*>(ui::Manager::getDefault()->theme());
|
2015-02-17 22:43:25 +08:00
|
|
|
}
|
|
|
|
|
2011-01-22 04:29:45 +08:00
|
|
|
SkinTheme::SkinTheme()
|
2017-02-25 04:56:57 +08:00
|
|
|
: m_sheet(nullptr)
|
2017-04-07 05:41:18 +08:00
|
|
|
, m_standardCursors(ui::kCursorTypes, nullptr)
|
2017-02-25 04:56:57 +08:00
|
|
|
, m_defaultFont(nullptr)
|
|
|
|
, m_miniFont(nullptr)
|
2017-08-19 06:23:23 +08:00
|
|
|
, m_preferredScreenScaling(-1)
|
|
|
|
, m_preferredUIScaling(-1)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
2010-04-24 06:03:09 +08:00
|
|
|
}
|
|
|
|
|
2011-01-22 04:29:45 +08:00
|
|
|
SkinTheme::~SkinTheme()
|
2010-04-24 06:03:09 +08:00
|
|
|
{
|
2012-08-11 10:14:54 +08:00
|
|
|
// Delete all cursors.
|
2017-09-29 02:27:27 +08:00
|
|
|
for (auto& it : m_cursors)
|
2017-04-07 05:41:18 +08:00
|
|
|
delete it.second; // Delete cursor
|
2010-04-24 06:03:09 +08:00
|
|
|
|
2014-06-23 05:53:14 +08:00
|
|
|
if (m_sheet)
|
|
|
|
m_sheet->dispose();
|
2014-05-03 10:07:11 +08:00
|
|
|
|
|
|
|
m_parts_by_id.clear();
|
2011-04-02 22:45:43 +08:00
|
|
|
|
2015-05-21 03:58:23 +08:00
|
|
|
// Destroy fonts
|
2017-09-29 02:27:27 +08:00
|
|
|
for (auto& kv : m_fonts)
|
2017-02-25 04:56:57 +08:00
|
|
|
delete kv.second; // Delete all FontDatas
|
2017-08-23 01:54:08 +08:00
|
|
|
m_fonts.clear();
|
2010-04-24 06:03:09 +08:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:39:06 +08:00
|
|
|
void SkinTheme::onRegenerateTheme()
|
2010-04-24 06:03:09 +08:00
|
|
|
{
|
2015-09-19 00:05:52 +08:00
|
|
|
Preferences& pref = Preferences::instance();
|
|
|
|
|
|
|
|
// First we load the skin from default theme, which is more proper
|
|
|
|
// to have every single needed skin part/color/dimension.
|
|
|
|
loadAll(pref.theme.selected.defaultValue());
|
|
|
|
|
|
|
|
// Then we load the selected theme to redefine default theme parts.
|
2016-10-27 21:44:31 +08:00
|
|
|
if (pref.theme.selected.defaultValue() != pref.theme.selected()) {
|
|
|
|
try {
|
|
|
|
loadAll(pref.theme.selected());
|
|
|
|
}
|
|
|
|
catch (const std::exception& e) {
|
2017-03-09 06:25:03 +08:00
|
|
|
LOG("THEME: Error loading user-theme: %s\n", e.what());
|
2016-10-27 21:44:31 +08:00
|
|
|
|
2017-06-30 02:26:18 +08:00
|
|
|
// Load default theme again
|
|
|
|
loadAll(pref.theme.selected.defaultValue());
|
|
|
|
|
2016-12-12 20:48:58 +08:00
|
|
|
if (ui::get_theme())
|
2016-10-27 21:44:31 +08:00
|
|
|
Console::showException(e);
|
|
|
|
|
|
|
|
// We can continue, as we've already loaded the default theme
|
2016-10-28 22:25:46 +08:00
|
|
|
// anyway. Here we restore the setting to its default value.
|
|
|
|
pref.theme.selected(pref.theme.selected.defaultValue());
|
2016-10-27 21:44:31 +08:00
|
|
|
}
|
|
|
|
}
|
2015-09-19 00:05:52 +08:00
|
|
|
}
|
|
|
|
|
2017-02-25 04:56:57 +08:00
|
|
|
void SkinTheme::loadFontData()
|
|
|
|
{
|
2017-03-09 06:25:03 +08:00
|
|
|
LOG("THEME: Loading fonts\n");
|
2017-02-25 04:56:57 +08:00
|
|
|
|
|
|
|
std::string fonstFilename("fonts/fonts.xml");
|
|
|
|
|
|
|
|
ResourceFinder rf;
|
|
|
|
rf.includeDataDir(fonstFilename.c_str());
|
|
|
|
if (!rf.findFirst())
|
|
|
|
throw base::Exception("File %s not found", fonstFilename.c_str());
|
|
|
|
|
|
|
|
XmlDocumentRef doc = open_xml(rf.filename());
|
|
|
|
TiXmlHandle handle(doc.get());
|
|
|
|
|
|
|
|
TiXmlElement* xmlFont = handle
|
|
|
|
.FirstChild("fonts")
|
|
|
|
.FirstChild("font").ToElement();
|
|
|
|
while (xmlFont) {
|
|
|
|
load_font(m_fonts, xmlFont, rf.filename());
|
|
|
|
xmlFont = xmlFont->NextSiblingElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 02:02:39 +08:00
|
|
|
void SkinTheme::loadAll(const std::string& themeId)
|
2015-09-19 00:05:52 +08:00
|
|
|
{
|
2017-06-11 02:02:39 +08:00
|
|
|
LOG("THEME: Loading theme %s\n", themeId.c_str());
|
2016-10-27 21:44:31 +08:00
|
|
|
|
2017-02-25 04:56:57 +08:00
|
|
|
if (m_fonts.empty())
|
|
|
|
loadFontData();
|
|
|
|
|
2017-06-13 22:51:49 +08:00
|
|
|
m_path = findThemePath(themeId);
|
2017-06-11 02:02:39 +08:00
|
|
|
if (m_path.empty())
|
|
|
|
throw base::Exception("Theme %s not found", themeId.c_str());
|
|
|
|
|
|
|
|
loadSheet();
|
|
|
|
loadXml();
|
2015-09-19 00:05:52 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 02:02:39 +08:00
|
|
|
void SkinTheme::loadSheet()
|
2015-09-19 00:05:52 +08:00
|
|
|
{
|
2010-03-07 22:03:47 +08:00
|
|
|
// Load the skin sheet
|
2017-06-11 02:02:39 +08:00
|
|
|
std::string sheet_filename(base::join_path(m_path, "sheet.png"));
|
2017-06-30 02:26:18 +08:00
|
|
|
she::Surface* newSheet = nullptr;
|
2014-06-23 05:53:14 +08:00
|
|
|
try {
|
2017-06-30 02:26:18 +08:00
|
|
|
newSheet = she::instance()->loadRgbaSurface(sheet_filename.c_str());
|
2014-06-23 05:53:14 +08:00
|
|
|
}
|
|
|
|
catch (...) {
|
2018-06-26 01:05:57 +08:00
|
|
|
// Ignore the error, newSheet is nullptr and we will throw our own
|
|
|
|
// exception.
|
2014-06-23 05:53:14 +08:00
|
|
|
}
|
2018-06-26 01:05:57 +08:00
|
|
|
if (!newSheet)
|
|
|
|
throw base::Exception("Error loading %s file", sheet_filename.c_str());
|
2017-06-30 02:26:18 +08:00
|
|
|
|
|
|
|
// Replace the sprite sheet
|
|
|
|
if (m_sheet) {
|
|
|
|
m_sheet->dispose();
|
|
|
|
m_sheet = nullptr;
|
|
|
|
}
|
|
|
|
m_sheet = newSheet;
|
|
|
|
if (m_sheet)
|
|
|
|
m_sheet->applyScale(guiscale());
|
|
|
|
|
2017-09-29 02:27:27 +08:00
|
|
|
// Reset sprite sheet and font of all layer styles (to avoid
|
|
|
|
// dangling pointers to she::Surface or she::Font).
|
|
|
|
for (auto& it : m_styles) {
|
|
|
|
for (auto& layer : it.second->layers()) {
|
|
|
|
layer.setIcon(nullptr);
|
|
|
|
layer.setSpriteSheet(nullptr);
|
2017-06-30 02:26:18 +08:00
|
|
|
}
|
2017-09-29 02:27:27 +08:00
|
|
|
it.second->setFont(nullptr);
|
2017-06-30 02:26:18 +08:00
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 02:02:39 +08:00
|
|
|
void SkinTheme::loadXml()
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
2017-04-15 19:13:20 +08:00
|
|
|
const int scale = guiscale();
|
|
|
|
|
2010-03-25 08:35:44 +08:00
|
|
|
// Load the skin XML
|
2017-06-11 02:02:39 +08:00
|
|
|
std::string xml_filename(base::join_path(m_path, "theme.xml"));
|
2013-01-07 01:45:43 +08:00
|
|
|
|
2017-06-11 02:02:39 +08:00
|
|
|
XmlDocumentRef doc = open_xml(xml_filename);
|
2015-04-03 07:42:43 +08:00
|
|
|
TiXmlHandle handle(doc.get());
|
2013-12-11 11:34:16 +08:00
|
|
|
|
2017-08-19 06:23:23 +08:00
|
|
|
// Load Preferred scaling
|
|
|
|
m_preferredScreenScaling = -1;
|
|
|
|
m_preferredUIScaling = -1;
|
|
|
|
{
|
|
|
|
TiXmlElement* xmlTheme = handle
|
|
|
|
.FirstChild("theme").ToElement();
|
|
|
|
if (xmlTheme) {
|
|
|
|
const char* screenScaling = xmlTheme->Attribute("screenscaling");
|
|
|
|
const char* uiScaling = xmlTheme->Attribute("uiscaling");
|
|
|
|
if (screenScaling)
|
|
|
|
m_preferredScreenScaling = std::strtol(screenScaling, nullptr, 10);
|
|
|
|
if (uiScaling)
|
|
|
|
m_preferredUIScaling = std::strtol(uiScaling, nullptr, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-25 04:56:57 +08:00
|
|
|
// Load fonts
|
|
|
|
{
|
|
|
|
TiXmlElement* xmlFont = handle
|
|
|
|
.FirstChild("theme")
|
|
|
|
.FirstChild("fonts")
|
|
|
|
.FirstChild("font").ToElement();
|
|
|
|
while (xmlFont) {
|
|
|
|
const char* idStr = xmlFont->Attribute("id");
|
2017-06-11 02:02:39 +08:00
|
|
|
FontData* fontData = load_font(m_fonts, xmlFont, xml_filename);
|
2017-02-25 04:56:57 +08:00
|
|
|
if (idStr && fontData) {
|
|
|
|
std::string id(idStr);
|
2017-03-09 06:25:03 +08:00
|
|
|
LOG(VERBOSE) << "THEME: Loading theme font '" << id << "\n";
|
2017-02-25 04:56:57 +08:00
|
|
|
|
|
|
|
int size = 10;
|
|
|
|
const char* sizeStr = xmlFont->Attribute("size");
|
|
|
|
if (sizeStr)
|
|
|
|
size = std::strtol(sizeStr, nullptr, 10);
|
|
|
|
|
2017-03-09 05:53:36 +08:00
|
|
|
she::Font* font = fontData->getFont(size);
|
|
|
|
m_themeFonts[idStr] = font;
|
|
|
|
|
|
|
|
if (id == "default")
|
|
|
|
m_defaultFont = font;
|
|
|
|
else if (id == "mini")
|
|
|
|
m_miniFont = font;
|
2017-02-25 04:56:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
xmlFont = xmlFont->NextSiblingElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No available font to run the program
|
|
|
|
if (!m_defaultFont)
|
|
|
|
throw base::Exception("There is no default font");
|
|
|
|
if (!m_miniFont)
|
|
|
|
m_miniFont = m_defaultFont;
|
|
|
|
|
2015-02-17 23:22:46 +08:00
|
|
|
// Load dimension
|
|
|
|
{
|
|
|
|
TiXmlElement* xmlDim = handle
|
2017-02-10 00:18:44 +08:00
|
|
|
.FirstChild("theme")
|
2015-02-17 23:22:46 +08:00
|
|
|
.FirstChild("dimensions")
|
|
|
|
.FirstChild("dim").ToElement();
|
|
|
|
while (xmlDim) {
|
|
|
|
std::string id = xmlDim->Attribute("id");
|
|
|
|
uint32_t value = strtol(xmlDim->Attribute("value"), NULL, 10);
|
|
|
|
|
2017-03-09 06:25:03 +08:00
|
|
|
LOG(VERBOSE) << "THEME: Loading dimension '" << id << "\n";
|
2015-02-17 23:22:46 +08:00
|
|
|
|
|
|
|
m_dimensions_by_id[id] = value;
|
|
|
|
xmlDim = xmlDim->NextSiblingElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-11 11:34:16 +08:00
|
|
|
// Load colors
|
|
|
|
{
|
|
|
|
TiXmlElement* xmlColor = handle
|
2017-02-10 00:18:44 +08:00
|
|
|
.FirstChild("theme")
|
2013-12-11 11:34:16 +08:00
|
|
|
.FirstChild("colors")
|
|
|
|
.FirstChild("color").ToElement();
|
|
|
|
while (xmlColor) {
|
|
|
|
std::string id = xmlColor->Attribute("id");
|
|
|
|
uint32_t value = strtol(xmlColor->Attribute("value")+1, NULL, 16);
|
2014-06-29 03:10:39 +08:00
|
|
|
gfx::Color color = gfx::rgba(
|
|
|
|
(value & 0xff0000) >> 16,
|
|
|
|
(value & 0xff00) >> 8,
|
|
|
|
(value & 0xff));
|
2013-12-11 11:34:16 +08:00
|
|
|
|
2017-03-09 06:25:03 +08:00
|
|
|
LOG(VERBOSE) << "THEME: Loading color " << id << "\n";
|
2013-12-11 11:34:16 +08:00
|
|
|
|
|
|
|
m_colors_by_id[id] = color;
|
|
|
|
xmlColor = xmlColor->NextSiblingElement();
|
|
|
|
}
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-12-11 11:34:16 +08:00
|
|
|
// Load parts
|
|
|
|
{
|
|
|
|
TiXmlElement* xmlPart = handle
|
2017-02-10 00:18:44 +08:00
|
|
|
.FirstChild("theme")
|
2013-12-11 11:34:16 +08:00
|
|
|
.FirstChild("parts")
|
|
|
|
.FirstChild("part").ToElement();
|
|
|
|
while (xmlPart) {
|
|
|
|
// Get the tool-icon rectangle
|
|
|
|
const char* part_id = xmlPart->Attribute("id");
|
2017-04-15 19:13:20 +08:00
|
|
|
int x = scale*strtol(xmlPart->Attribute("x"), nullptr, 10);
|
|
|
|
int y = scale*strtol(xmlPart->Attribute("y"), nullptr, 10);
|
|
|
|
int w = (xmlPart->Attribute("w") ? scale*strtol(xmlPart->Attribute("w"), nullptr, 10): 0);
|
|
|
|
int h = (xmlPart->Attribute("h") ? scale*strtol(xmlPart->Attribute("h"), nullptr, 10): 0);
|
2013-12-11 11:34:16 +08:00
|
|
|
|
2017-03-09 06:25:03 +08:00
|
|
|
LOG(VERBOSE) << "THEME: Loading part " << part_id << "\n";
|
2013-12-11 11:34:16 +08:00
|
|
|
|
|
|
|
SkinPartPtr part = m_parts_by_id[part_id];
|
2015-04-03 07:42:43 +08:00
|
|
|
if (!part)
|
2013-12-11 11:34:16 +08:00
|
|
|
part = m_parts_by_id[part_id] = SkinPartPtr(new SkinPart);
|
|
|
|
|
|
|
|
if (w > 0 && h > 0) {
|
2017-02-10 03:51:52 +08:00
|
|
|
part->setSpriteBounds(gfx::Rect(x, y, w, h));
|
2017-04-15 19:13:20 +08:00
|
|
|
part->setBitmap(0, sliceSheet(part->bitmap(0), gfx::Rect(x, y, w, h)));
|
2013-12-11 11:34:16 +08:00
|
|
|
}
|
|
|
|
else if (xmlPart->Attribute("w1")) { // 3x3-1 part (NW, N, NE, E, SE, S, SW, W)
|
2017-04-15 19:13:20 +08:00
|
|
|
int w1 = scale*strtol(xmlPart->Attribute("w1"), nullptr, 10);
|
|
|
|
int w2 = scale*strtol(xmlPart->Attribute("w2"), nullptr, 10);
|
|
|
|
int w3 = scale*strtol(xmlPart->Attribute("w3"), nullptr, 10);
|
|
|
|
int h1 = scale*strtol(xmlPart->Attribute("h1"), nullptr, 10);
|
|
|
|
int h2 = scale*strtol(xmlPart->Attribute("h2"), nullptr, 10);
|
|
|
|
int h3 = scale*strtol(xmlPart->Attribute("h3"), nullptr, 10);
|
2013-12-11 11:34:16 +08:00
|
|
|
|
2017-02-10 03:51:52 +08:00
|
|
|
part->setSpriteBounds(gfx::Rect(x, y, w1+w2+w3, h1+h2+h3));
|
|
|
|
part->setSlicesBounds(gfx::Rect(w1, h1, w2, h2));
|
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
part->setBitmap(0, sliceSheet(part->bitmap(0), gfx::Rect(x, y, w1, h1))); // NW
|
|
|
|
part->setBitmap(1, sliceSheet(part->bitmap(1), gfx::Rect(x+w1, y, w2, h1))); // N
|
|
|
|
part->setBitmap(2, sliceSheet(part->bitmap(2), gfx::Rect(x+w1+w2, y, w3, h1))); // NE
|
|
|
|
part->setBitmap(3, sliceSheet(part->bitmap(3), gfx::Rect(x+w1+w2, y+h1, w3, h2))); // E
|
|
|
|
part->setBitmap(4, sliceSheet(part->bitmap(4), gfx::Rect(x+w1+w2, y+h1+h2, w3, h3))); // SE
|
|
|
|
part->setBitmap(5, sliceSheet(part->bitmap(5), gfx::Rect(x+w1, y+h1+h2, w2, h3))); // S
|
|
|
|
part->setBitmap(6, sliceSheet(part->bitmap(6), gfx::Rect(x, y+h1+h2, w1, h3))); // SW
|
|
|
|
part->setBitmap(7, sliceSheet(part->bitmap(7), gfx::Rect(x, y+h1, w1, h2))); // W
|
2013-12-11 11:34:16 +08:00
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2017-03-15 06:00:24 +08:00
|
|
|
// Is it a mouse cursor?
|
|
|
|
if (std::strncmp(part_id, "cursor_", 7) == 0) {
|
|
|
|
std::string cursorName = std::string(part_id).substr(7);
|
2017-04-15 19:13:20 +08:00
|
|
|
int focusx = scale*std::strtol(xmlPart->Attribute("focusx"), NULL, 10);
|
|
|
|
int focusy = scale*std::strtol(xmlPart->Attribute("focusy"), NULL, 10);
|
2017-03-15 06:00:24 +08:00
|
|
|
|
2017-04-07 05:41:18 +08:00
|
|
|
LOG(VERBOSE) << "THEME: Loading cursor '" << cursorName << "'\n";
|
2017-03-15 06:00:24 +08:00
|
|
|
|
2017-04-07 05:41:18 +08:00
|
|
|
auto it = m_cursors.find(cursorName);
|
|
|
|
if (it != m_cursors.end() && it->second != nullptr) {
|
|
|
|
delete it->second;
|
|
|
|
it->second = nullptr;
|
|
|
|
}
|
2017-03-15 06:00:24 +08:00
|
|
|
|
2017-04-07 05:41:18 +08:00
|
|
|
// TODO share the Surface with the SkinPart
|
|
|
|
she::Surface* slice = sliceSheet(nullptr, gfx::Rect(x, y, w, h));
|
|
|
|
Cursor* cursor =
|
2017-04-15 19:13:20 +08:00
|
|
|
new Cursor(slice, gfx::Point(focusx, focusy));
|
2017-04-07 05:41:18 +08:00
|
|
|
m_cursors[cursorName] = cursor;
|
2017-03-15 06:00:24 +08:00
|
|
|
|
2017-04-07 05:41:18 +08:00
|
|
|
for (int c=0; c<kCursorTypes; ++c) {
|
|
|
|
if (cursorName == g_cursor_names[c]) {
|
|
|
|
m_standardCursors[c] = cursor;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-15 06:00:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-11 11:34:16 +08:00
|
|
|
xmlPart = xmlPart->NextSiblingElement();
|
|
|
|
}
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2017-03-14 05:13:38 +08:00
|
|
|
// Load styles
|
2017-02-14 05:34:23 +08:00
|
|
|
{
|
|
|
|
TiXmlElement* xmlStyle = handle
|
|
|
|
.FirstChild("theme")
|
|
|
|
.FirstChild("styles")
|
|
|
|
.FirstChild("style").ToElement();
|
2017-06-30 02:26:18 +08:00
|
|
|
|
|
|
|
if (!xmlStyle) // Without styles?
|
|
|
|
throw base::Exception("There are no styles");
|
|
|
|
|
2017-02-14 05:34:23 +08:00
|
|
|
while (xmlStyle) {
|
|
|
|
const char* style_id = xmlStyle->Attribute("id");
|
|
|
|
if (!style_id) {
|
|
|
|
throw base::Exception("<style> without 'id' attribute in '%s'\n",
|
|
|
|
xml_filename.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* extends_id = xmlStyle->Attribute("extends");
|
|
|
|
const ui::Style* base = nullptr;
|
|
|
|
if (extends_id)
|
|
|
|
base = m_styles[extends_id];
|
|
|
|
|
|
|
|
ui::Style* style = m_styles[style_id];
|
|
|
|
if (!style) {
|
|
|
|
m_styles[style_id] = style = new ui::Style(base);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*style = ui::Style(base);
|
|
|
|
}
|
2017-09-29 02:27:27 +08:00
|
|
|
style->setId(style_id);
|
2017-02-14 05:34:23 +08:00
|
|
|
|
2017-02-18 01:18:47 +08:00
|
|
|
// Margin
|
|
|
|
{
|
|
|
|
const char* m = xmlStyle->Attribute("margin");
|
|
|
|
const char* l = xmlStyle->Attribute("margin-left");
|
|
|
|
const char* t = xmlStyle->Attribute("margin-top");
|
|
|
|
const char* r = xmlStyle->Attribute("margin-right");
|
|
|
|
const char* b = xmlStyle->Attribute("margin-bottom");
|
|
|
|
gfx::Border margin = ui::Style::UndefinedBorder();
|
2017-04-15 19:13:20 +08:00
|
|
|
if (m || l) margin.left(scale*std::strtol(l ? l: m, nullptr, 10));
|
|
|
|
if (m || t) margin.top(scale*std::strtol(t ? t: m, nullptr, 10));
|
|
|
|
if (m || r) margin.right(scale*std::strtol(r ? r: m, nullptr, 10));
|
|
|
|
if (m || b) margin.bottom(scale*std::strtol(b ? b: m, nullptr, 10));
|
|
|
|
style->setMargin(margin);
|
2017-02-18 01:18:47 +08:00
|
|
|
}
|
|
|
|
|
2017-02-14 05:34:23 +08:00
|
|
|
// Border
|
|
|
|
{
|
|
|
|
const char* m = xmlStyle->Attribute("border");
|
|
|
|
const char* l = xmlStyle->Attribute("border-left");
|
|
|
|
const char* t = xmlStyle->Attribute("border-top");
|
|
|
|
const char* r = xmlStyle->Attribute("border-right");
|
|
|
|
const char* b = xmlStyle->Attribute("border-bottom");
|
2017-02-18 01:18:47 +08:00
|
|
|
gfx::Border border = ui::Style::UndefinedBorder();
|
2017-04-15 19:13:20 +08:00
|
|
|
if (m || l) border.left(scale*std::strtol(l ? l: m, nullptr, 10));
|
|
|
|
if (m || t) border.top(scale*std::strtol(t ? t: m, nullptr, 10));
|
|
|
|
if (m || r) border.right(scale*std::strtol(r ? r: m, nullptr, 10));
|
|
|
|
if (m || b) border.bottom(scale*std::strtol(b ? b: m, nullptr, 10));
|
|
|
|
style->setBorder(border);
|
2017-02-14 05:34:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Padding
|
|
|
|
{
|
|
|
|
const char* m = xmlStyle->Attribute("padding");
|
|
|
|
const char* l = xmlStyle->Attribute("padding-left");
|
|
|
|
const char* t = xmlStyle->Attribute("padding-top");
|
|
|
|
const char* r = xmlStyle->Attribute("padding-right");
|
|
|
|
const char* b = xmlStyle->Attribute("padding-bottom");
|
2017-02-18 01:18:47 +08:00
|
|
|
gfx::Border padding = ui::Style::UndefinedBorder();
|
2017-04-15 19:13:20 +08:00
|
|
|
if (m || l) padding.left(scale*std::strtol(l ? l: m, nullptr, 10));
|
|
|
|
if (m || t) padding.top(scale*std::strtol(t ? t: m, nullptr, 10));
|
|
|
|
if (m || r) padding.right(scale*std::strtol(r ? r: m, nullptr, 10));
|
|
|
|
if (m || b) padding.bottom(scale*std::strtol(b ? b: m, nullptr, 10));
|
|
|
|
style->setPadding(padding);
|
2017-02-14 05:34:23 +08:00
|
|
|
}
|
|
|
|
|
2017-03-09 05:53:36 +08:00
|
|
|
// Font
|
|
|
|
{
|
|
|
|
const char* fontId = xmlStyle->Attribute("font");
|
|
|
|
if (fontId) {
|
|
|
|
she::Font* font = m_themeFonts[fontId];
|
|
|
|
style->setFont(font);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-14 05:34:23 +08:00
|
|
|
TiXmlElement* xmlLayer = xmlStyle->FirstChildElement();
|
|
|
|
while (xmlLayer) {
|
|
|
|
const std::string layerName = xmlLayer->Value();
|
|
|
|
|
2017-03-09 06:25:03 +08:00
|
|
|
LOG(VERBOSE) << "THEME: Layer " << layerName
|
2017-02-14 05:34:23 +08:00
|
|
|
<< " for " << style_id << "\n";
|
|
|
|
|
|
|
|
ui::Style::Layer layer;
|
|
|
|
|
|
|
|
// Layer type
|
|
|
|
if (layerName == "background") {
|
|
|
|
layer.setType(ui::Style::Layer::Type::kBackground);
|
|
|
|
}
|
2017-03-18 02:43:42 +08:00
|
|
|
else if (layerName == "background-border") {
|
|
|
|
layer.setType(ui::Style::Layer::Type::kBackgroundBorder);
|
|
|
|
}
|
2017-02-14 05:34:23 +08:00
|
|
|
else if (layerName == "border") {
|
|
|
|
layer.setType(ui::Style::Layer::Type::kBorder);
|
|
|
|
}
|
|
|
|
else if (layerName == "icon") {
|
|
|
|
layer.setType(ui::Style::Layer::Type::kIcon);
|
|
|
|
}
|
|
|
|
else if (layerName == "text") {
|
|
|
|
layer.setType(ui::Style::Layer::Type::kText);
|
|
|
|
}
|
|
|
|
else if (layerName == "newlayer") {
|
|
|
|
layer.setType(ui::Style::Layer::Type::kNewLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse state condition
|
|
|
|
const char* stateValue = xmlLayer->Attribute("state");
|
|
|
|
if (stateValue) {
|
|
|
|
std::string state(stateValue);
|
|
|
|
int flags = 0;
|
|
|
|
if (state.find("disabled") != std::string::npos) flags |= ui::Style::Layer::kDisabled;
|
|
|
|
if (state.find("selected") != std::string::npos) flags |= ui::Style::Layer::kSelected;
|
|
|
|
if (state.find("focus") != std::string::npos) flags |= ui::Style::Layer::kFocus;
|
|
|
|
if (state.find("mouse") != std::string::npos) flags |= ui::Style::Layer::kMouse;
|
|
|
|
layer.setFlags(flags);
|
|
|
|
}
|
|
|
|
|
2017-02-15 01:55:45 +08:00
|
|
|
// Align
|
|
|
|
const char* alignValue = xmlLayer->Attribute("align");
|
|
|
|
if (alignValue) {
|
|
|
|
std::string alignString(alignValue);
|
|
|
|
int align = 0;
|
|
|
|
if (alignString.find("left") != std::string::npos) align |= LEFT;
|
|
|
|
if (alignString.find("center") != std::string::npos) align |= CENTER;
|
|
|
|
if (alignString.find("right") != std::string::npos) align |= RIGHT;
|
|
|
|
if (alignString.find("top") != std::string::npos) align |= TOP;
|
|
|
|
if (alignString.find("middle") != std::string::npos) align |= MIDDLE;
|
|
|
|
if (alignString.find("bottom") != std::string::npos) align |= BOTTOM;
|
|
|
|
if (alignString.find("wordwrap") != std::string::npos) align |= WORDWRAP;
|
|
|
|
layer.setAlign(align);
|
|
|
|
}
|
|
|
|
|
2017-02-14 05:34:23 +08:00
|
|
|
// Color
|
|
|
|
const char* colorId = xmlLayer->Attribute("color");
|
|
|
|
if (colorId) {
|
2017-02-15 01:55:45 +08:00
|
|
|
auto it = m_colors_by_id.find(colorId);
|
|
|
|
if (it != m_colors_by_id.end())
|
|
|
|
layer.setColor(it->second);
|
2017-03-14 05:13:38 +08:00
|
|
|
else if (std::strcmp(colorId, "none") == 0) {
|
|
|
|
layer.setColor(gfx::ColorNone);
|
|
|
|
}
|
2017-02-15 01:55:45 +08:00
|
|
|
else {
|
|
|
|
throw base::Exception("Color <%s color='%s' ...> was not found in '%s'\n",
|
|
|
|
layerName.c_str(), colorId,
|
|
|
|
xml_filename.c_str());
|
|
|
|
}
|
2017-02-14 05:34:23 +08:00
|
|
|
}
|
|
|
|
|
2017-02-18 05:00:10 +08:00
|
|
|
// Offset
|
|
|
|
const char* x = xmlLayer->Attribute("x");
|
|
|
|
const char* y = xmlLayer->Attribute("y");
|
|
|
|
if (x || y) {
|
|
|
|
gfx::Point offset(0, 0);
|
|
|
|
if (x) offset.x = std::strtol(x, nullptr, 10);
|
|
|
|
if (y) offset.y = std::strtol(y, nullptr, 10);
|
2017-04-15 19:13:20 +08:00
|
|
|
layer.setOffset(offset*scale);
|
2017-02-18 05:00:10 +08:00
|
|
|
}
|
|
|
|
|
2017-02-14 05:34:23 +08:00
|
|
|
// Sprite sheet
|
|
|
|
const char* partId = xmlLayer->Attribute("part");
|
|
|
|
if (partId) {
|
|
|
|
auto it = m_parts_by_id.find(partId);
|
|
|
|
if (it != m_parts_by_id.end()) {
|
|
|
|
SkinPartPtr part = it->second;
|
|
|
|
if (part) {
|
|
|
|
if (layer.type() == ui::Style::Layer::Type::kIcon)
|
|
|
|
layer.setIcon(part->bitmap(0));
|
|
|
|
else {
|
|
|
|
layer.setSpriteSheet(m_sheet);
|
|
|
|
layer.setSpriteBounds(part->spriteBounds());
|
|
|
|
layer.setSlicesBounds(part->slicesBounds());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-14 05:13:38 +08:00
|
|
|
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));
|
|
|
|
}
|
2017-02-14 05:34:23 +08:00
|
|
|
else {
|
|
|
|
throw base::Exception("Part <%s part='%s' ...> was not found in '%s'\n",
|
|
|
|
layerName.c_str(), partId,
|
|
|
|
xml_filename.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layer.type() != ui::Style::Layer::Type::kNone)
|
|
|
|
style->addLayer(layer);
|
|
|
|
|
|
|
|
xmlLayer = xmlLayer->NextSiblingElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlStyle = xmlStyle->NextSiblingElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 00:18:44 +08:00
|
|
|
ThemeFile<SkinTheme>::updateInternals();
|
2010-03-25 08:35:44 +08:00
|
|
|
}
|
|
|
|
|
2014-06-23 05:53:14 +08:00
|
|
|
she::Surface* SkinTheme::sliceSheet(she::Surface* sur, const gfx::Rect& bounds)
|
2010-03-25 08:35:44 +08:00
|
|
|
{
|
2014-06-23 05:53:14 +08:00
|
|
|
if (sur && (sur->width() != bounds.w ||
|
|
|
|
sur->height() != bounds.h)) {
|
|
|
|
sur->dispose();
|
2017-08-12 02:53:04 +08:00
|
|
|
sur = nullptr;
|
2010-03-25 08:35:44 +08:00
|
|
|
}
|
|
|
|
|
2017-08-12 02:53:04 +08:00
|
|
|
if (!bounds.isEmpty()) {
|
|
|
|
if (!sur)
|
|
|
|
sur = she::instance()->createRgbaSurface(bounds.w, bounds.h);
|
2014-06-23 05:53:14 +08:00
|
|
|
|
2016-03-09 22:00:17 +08:00
|
|
|
she::SurfaceLock lockSrc(m_sheet);
|
|
|
|
she::SurfaceLock lockDst(sur);
|
|
|
|
m_sheet->blitTo(sur, bounds.x, bounds.y, 0, 0, bounds.w, bounds.h);
|
2014-06-23 05:53:14 +08:00
|
|
|
}
|
2017-08-12 02:53:04 +08:00
|
|
|
else {
|
|
|
|
ASSERT(!sur);
|
|
|
|
}
|
2010-03-25 08:35:44 +08:00
|
|
|
|
2014-06-23 05:53:14 +08:00
|
|
|
return sur;
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2015-05-06 06:14:33 +08:00
|
|
|
she::Font* SkinTheme::getWidgetFont(const Widget* widget) const
|
|
|
|
{
|
|
|
|
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
|
|
|
|
if (skinPropery && skinPropery->hasMiniFont())
|
|
|
|
return getMiniFont();
|
|
|
|
else
|
|
|
|
return getDefaultFont();
|
|
|
|
}
|
|
|
|
|
2017-04-07 05:41:18 +08:00
|
|
|
Cursor* SkinTheme::getStandardCursor(CursorType type)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
2017-04-07 05:41:18 +08:00
|
|
|
if (type >= kFirstCursorType && type <= kLastCursorType)
|
|
|
|
return m_standardCursors[type];
|
|
|
|
else
|
|
|
|
return nullptr;
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2013-01-14 09:39:44 +08:00
|
|
|
void SkinTheme::initWidget(Widget* widget)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
2015-06-24 06:20:49 +08:00
|
|
|
#define BORDER(n) \
|
|
|
|
widget->setBorder(gfx::Border(n))
|
|
|
|
|
|
|
|
#define BORDER4(L,T,R,B) \
|
|
|
|
widget->setBorder(gfx::Border((L), (T), (R), (B)))
|
2010-03-08 00:21:24 +08:00
|
|
|
|
2017-04-15 19:13:20 +08:00
|
|
|
const int scale = guiscale();
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2015-06-24 01:37:22 +08:00
|
|
|
switch (widget->type()) {
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kBoxWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.box());
|
2009-11-22 04:02:31 +08:00
|
|
|
BORDER(0);
|
2015-06-24 06:20:49 +08:00
|
|
|
widget->setChildSpacing(4 * scale);
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kButtonWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.button());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kCheckWidget:
|
2017-03-18 02:43:42 +08:00
|
|
|
widget->setStyle(styles.checkBox());
|
|
|
|
break;
|
2011-03-07 03:15:05 +08:00
|
|
|
|
2017-03-18 02:43:42 +08:00
|
|
|
case kRadioWidget:
|
|
|
|
widget->setStyle(styles.radioButton());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kEntryWidget:
|
2014-06-23 05:53:14 +08:00
|
|
|
BORDER4(
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
parts.sunkenNormal()->bitmapW()->width(),
|
|
|
|
parts.sunkenNormal()->bitmapN()->height(),
|
|
|
|
parts.sunkenNormal()->bitmapE()->width(),
|
|
|
|
parts.sunkenNormal()->bitmapS()->height());
|
2015-12-01 02:08:18 +08:00
|
|
|
widget->setChildSpacing(3 * scale);
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kGridWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.grid());
|
2009-11-22 04:02:31 +08:00
|
|
|
BORDER(0);
|
2015-06-24 06:20:49 +08:00
|
|
|
widget->setChildSpacing(4 * scale);
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kLabelWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.label());
|
2017-02-15 01:55:45 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case kLinkLabelWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.link());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kListBoxWidget:
|
2009-11-22 04:02:31 +08:00
|
|
|
BORDER(0);
|
2015-06-24 06:20:49 +08:00
|
|
|
widget->setChildSpacing(0);
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kListItemWidget:
|
2017-06-12 23:38:53 +08:00
|
|
|
widget->setStyle(styles.listItem());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2017-02-14 05:34:23 +08:00
|
|
|
case kComboBoxWidget: {
|
|
|
|
ComboBox* combobox = static_cast<ComboBox*>(widget);
|
|
|
|
Button* button = combobox->getButtonWidget();
|
2017-08-15 21:39:06 +08:00
|
|
|
combobox->setChildSpacing(0);
|
2017-03-14 09:31:57 +08:00
|
|
|
button->setStyle(styles.comboboxButton());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
2017-02-14 05:34:23 +08:00
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kMenuWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.menu());
|
2017-02-18 01:18:47 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kMenuBarWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.menubar());
|
2017-02-18 01:18:47 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kMenuBoxWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.menubox());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kMenuItemWidget:
|
2010-03-09 10:42:31 +08:00
|
|
|
BORDER(2 * scale);
|
2015-06-24 06:20:49 +08:00
|
|
|
widget->setChildSpacing(18 * scale);
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kSplitterWidget:
|
2015-06-24 06:20:49 +08:00
|
|
|
widget->setChildSpacing(3 * scale);
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.splitter());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kSeparatorWidget:
|
2015-05-21 23:28:21 +08:00
|
|
|
// Horizontal bar
|
2017-02-18 05:00:10 +08:00
|
|
|
if (widget->align() & HORIZONTAL) {
|
2017-08-15 21:39:06 +08:00
|
|
|
if (dynamic_cast<MenuSeparator*>(widget)) {
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.menuSeparator());
|
2017-08-15 21:39:06 +08:00
|
|
|
BORDER(2 * scale);
|
|
|
|
}
|
2017-02-18 05:00:10 +08:00
|
|
|
else
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.horizontalSeparator());
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
2015-05-21 23:28:21 +08:00
|
|
|
// Vertical bar
|
2009-11-22 04:02:31 +08:00
|
|
|
else {
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.verticalSeparator());
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kSliderWidget:
|
2014-06-23 05:53:14 +08:00
|
|
|
BORDER4(
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
parts.sliderEmpty()->bitmapW()->width()-1*scale,
|
|
|
|
parts.sliderEmpty()->bitmapN()->height(),
|
|
|
|
parts.sliderEmpty()->bitmapE()->width()-1*scale,
|
|
|
|
parts.sliderEmpty()->bitmapS()->height()-1*scale);
|
|
|
|
widget->setChildSpacing(widget->textHeight());
|
2015-06-24 01:00:00 +08:00
|
|
|
widget->setAlign(CENTER | MIDDLE);
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kTextBoxWidget:
|
2016-12-07 08:30:46 +08:00
|
|
|
BORDER(4*guiscale());
|
2015-06-24 06:20:49 +08:00
|
|
|
widget->setChildSpacing(0);
|
2016-12-07 08:30:46 +08:00
|
|
|
widget->setBgColor(colors.textboxFace());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kViewWidget:
|
2015-06-24 06:20:49 +08:00
|
|
|
widget->setChildSpacing(0);
|
2015-02-16 02:29:16 +08:00
|
|
|
widget->setBgColor(colors.windowFace());
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.view());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kViewScrollbarWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.scrollbar());
|
|
|
|
static_cast<ScrollBar*>(widget)->setThumbStyle(styles.scrollbarThumb());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kViewViewportWidget:
|
2009-11-22 04:02:31 +08:00
|
|
|
BORDER(0);
|
2015-06-24 06:20:49 +08:00
|
|
|
widget->setChildSpacing(0);
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
2017-02-18 01:37:58 +08:00
|
|
|
case kManagerWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.desktop());
|
2017-02-18 01:37:58 +08:00
|
|
|
break;
|
|
|
|
|
2013-04-04 09:07:24 +08:00
|
|
|
case kWindowWidget:
|
2017-02-18 01:18:47 +08:00
|
|
|
if (TipWindow* window = dynamic_cast<TipWindow*>(widget)) {
|
2017-03-14 09:31:57 +08:00
|
|
|
window->setStyle(styles.tooltipWindow());
|
|
|
|
window->setArrowStyle(styles.tooltipWindowArrow());
|
|
|
|
window->textBox()->setStyle(SkinTheme::instance()->styles.tooltipText());
|
2017-02-18 01:18:47 +08:00
|
|
|
}
|
|
|
|
else if (dynamic_cast<TransparentPopupWindow*>(widget)) {
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.transparentPopupWindow());
|
2017-02-18 01:18:47 +08:00
|
|
|
}
|
|
|
|
else if (dynamic_cast<PopupWindow*>(widget)) {
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.popupWindow());
|
2017-02-18 01:18:47 +08:00
|
|
|
}
|
|
|
|
else if (static_cast<Window*>(widget)->isDesktop()) {
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.desktop());
|
2017-02-18 01:18:47 +08:00
|
|
|
}
|
|
|
|
else {
|
2012-01-06 06:45:03 +08:00
|
|
|
if (widget->hasText()) {
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.windowWithTitle());
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
else {
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(styles.windowWithoutTitle());
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
2017-02-18 01:18:47 +08:00
|
|
|
break;
|
2015-12-11 03:46:01 +08:00
|
|
|
|
2017-02-18 01:18:47 +08:00
|
|
|
case kWindowTitleLabelWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(SkinTheme::instance()->styles.windowTitleLabel());
|
2017-02-18 01:18:47 +08:00
|
|
|
break;
|
2015-12-11 03:46:01 +08:00
|
|
|
|
2017-02-18 01:18:47 +08:00
|
|
|
case kWindowCloseButtonWidget:
|
2017-03-14 09:31:57 +08:00
|
|
|
widget->setStyle(SkinTheme::instance()->styles.windowCloseButton());
|
2009-11-22 04:02:31 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-14 09:39:44 +08:00
|
|
|
void SkinTheme::getWindowMask(Widget* widget, Region& region)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
region = widget->bounds();
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2015-08-13 03:48:40 +08:00
|
|
|
int SkinTheme::getScrollbarSize()
|
|
|
|
{
|
2015-08-13 03:56:19 +08:00
|
|
|
return dimensions.scrollbarSize();
|
2015-08-13 03:48:40 +08:00
|
|
|
}
|
|
|
|
|
2017-02-08 06:05:47 +08:00
|
|
|
gfx::Size SkinTheme::getEntryCaretSize(Widget* widget)
|
|
|
|
{
|
|
|
|
if (widget->font()->type() == she::FontType::kTrueType)
|
|
|
|
return gfx::Size(2*guiscale(), widget->textHeight());
|
|
|
|
else
|
|
|
|
return gfx::Size(2*guiscale(), widget->textHeight()+2*guiscale());
|
|
|
|
}
|
|
|
|
|
2011-02-12 20:32:57 +08:00
|
|
|
void SkinTheme::paintEntry(PaintEvent& ev)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2011-02-12 20:32:57 +08:00
|
|
|
Entry* widget = static_cast<Entry*>(ev.getSource());
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Rect bounds = widget->clientBounds();
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2013-03-31 00:27:38 +08:00
|
|
|
// Outside borders
|
2014-04-20 02:18:16 +08:00
|
|
|
g->fillRect(BGCOLOR, bounds);
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2012-01-10 08:18:32 +08:00
|
|
|
bool isMiniLook = false;
|
2013-12-05 12:19:46 +08:00
|
|
|
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
|
2015-04-03 07:42:43 +08:00
|
|
|
if (skinPropery)
|
2012-01-10 08:18:32 +08:00
|
|
|
isMiniLook = (skinPropery->getLook() == MiniLook);
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
drawRect(g, bounds,
|
2014-04-20 02:18:16 +08:00
|
|
|
(widget->hasFocus() ?
|
2015-08-05 06:38:52 +08:00
|
|
|
(isMiniLook ? parts.sunkenMiniFocused().get(): parts.sunkenFocused().get()):
|
2017-02-11 04:49:37 +08:00
|
|
|
(isMiniLook ? parts.sunkenMiniNormal().get() : parts.sunkenNormal().get())));
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
drawEntryText(g, widget);
|
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
namespace {
|
2015-04-06 22:53:14 +08:00
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
class DrawEntryTextDelegate : public she::DrawTextDelegate {
|
|
|
|
public:
|
|
|
|
DrawEntryTextDelegate(Entry* widget, Graphics* graphics,
|
|
|
|
const gfx::Point& pos, const int h)
|
|
|
|
: m_widget(widget)
|
|
|
|
, m_graphics(graphics)
|
|
|
|
, m_caretDrawn(false)
|
|
|
|
// m_lastX is an absolute position on screen
|
|
|
|
, m_lastX(pos.x+m_widget->bounds().x)
|
|
|
|
, m_y(pos.y)
|
|
|
|
, m_h(h)
|
|
|
|
{
|
|
|
|
m_widget->getEntryThemeInfo(&m_index, &m_caret, &m_state, &m_selbeg, &m_selend);
|
|
|
|
}
|
|
|
|
|
|
|
|
int index() const { return m_index; }
|
|
|
|
bool caretDrawn() const { return m_caretDrawn; }
|
|
|
|
const gfx::Rect& textBounds() const { return m_textBounds; }
|
|
|
|
|
2017-02-22 05:05:23 +08:00
|
|
|
void preProcessChar(const int index,
|
|
|
|
const int codepoint,
|
2017-02-07 04:58:55 +08:00
|
|
|
gfx::Color& fg,
|
2017-02-21 04:14:41 +08:00
|
|
|
gfx::Color& bg) override {
|
2013-01-07 01:45:43 +08:00
|
|
|
// Normal text
|
2017-02-07 04:58:55 +08:00
|
|
|
auto& colors = SkinTheme::instance()->colors;
|
2013-01-07 01:45:43 +08:00
|
|
|
bg = ColorNone;
|
2017-02-07 04:58:55 +08:00
|
|
|
fg = colors.text();
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
// Selected
|
2017-02-07 04:58:55 +08:00
|
|
|
if ((m_index >= m_selbeg) &&
|
|
|
|
(m_index <= m_selend)) {
|
|
|
|
if (m_widget->hasFocus())
|
2015-02-16 02:29:16 +08:00
|
|
|
bg = colors.selected();
|
2009-11-22 04:02:31 +08:00
|
|
|
else
|
2015-02-16 02:29:16 +08:00
|
|
|
bg = colors.disabled();
|
2018-01-30 01:09:22 +08:00
|
|
|
fg = colors.selectedText();
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
// Disabled
|
2017-02-07 04:58:55 +08:00
|
|
|
if (!m_widget->isEnabled()) {
|
2013-03-30 03:27:08 +08:00
|
|
|
bg = ColorNone;
|
2015-02-16 02:29:16 +08:00
|
|
|
fg = colors.disabled();
|
2013-03-30 03:27:08 +08:00
|
|
|
}
|
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
m_bg = bg;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool preDrawChar(const gfx::Rect& charBounds) override {
|
2017-02-08 06:05:47 +08:00
|
|
|
m_textBounds |= charBounds;
|
|
|
|
m_charStartX = charBounds.x;
|
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
if (charBounds.x2()-m_widget->bounds().x < m_widget->clientBounds().x2()) {
|
|
|
|
if (m_bg != ColorNone) {
|
|
|
|
// Fill background e.g. needed for selected/highlighted
|
|
|
|
// regions with TTF fonts where the char is smaller than the
|
|
|
|
// text bounds [m_y,m_y+m_h)
|
|
|
|
gfx::Rect fillThisRect(m_lastX-m_widget->bounds().x,
|
|
|
|
m_y, charBounds.x2()-m_lastX, m_h);
|
|
|
|
if (charBounds != fillThisRect)
|
|
|
|
m_graphics->fillRect(m_bg, fillThisRect);
|
|
|
|
}
|
|
|
|
m_lastX = charBounds.x2();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
void postDrawChar(const gfx::Rect& charBounds) override {
|
2013-01-07 01:45:43 +08:00
|
|
|
// Caret
|
2017-02-07 04:58:55 +08:00
|
|
|
if (m_state &&
|
|
|
|
m_index == m_caret &&
|
|
|
|
m_widget->hasFocus() &&
|
|
|
|
m_widget->isEnabled()) {
|
|
|
|
SkinTheme::instance()->drawEntryCaret(
|
|
|
|
m_graphics, m_widget,
|
2017-02-08 06:05:47 +08:00
|
|
|
m_charStartX-m_widget->bounds().x, m_y);
|
2017-02-07 04:58:55 +08:00
|
|
|
m_caretDrawn = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
++m_index;
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
private:
|
|
|
|
Entry* m_widget;
|
|
|
|
Graphics* m_graphics;
|
|
|
|
int m_index;
|
|
|
|
int m_caret;
|
|
|
|
int m_state;
|
|
|
|
int m_selbeg;
|
|
|
|
int m_selend;
|
|
|
|
gfx::Rect m_textBounds;
|
|
|
|
bool m_caretDrawn;
|
|
|
|
gfx::Color m_bg;
|
2017-02-08 06:05:47 +08:00
|
|
|
int m_lastX; // Last position used to fill the background
|
2017-02-07 04:58:55 +08:00
|
|
|
int m_y, m_h;
|
2017-02-08 06:05:47 +08:00
|
|
|
int m_charStartX;
|
2017-02-07 04:58:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void SkinTheme::drawEntryText(ui::Graphics* g, ui::Entry* widget)
|
|
|
|
{
|
|
|
|
// Draw the text
|
|
|
|
gfx::Rect bounds = widget->getEntryTextBounds();
|
|
|
|
|
|
|
|
DrawEntryTextDelegate delegate(widget, g, bounds.origin(), widget->textHeight());
|
|
|
|
int scroll = delegate.index();
|
|
|
|
|
|
|
|
const std::string& textString = widget->text();
|
|
|
|
base::utf8_const_iterator utf8_it((textString.begin()));
|
|
|
|
int textlen = base::utf8_length(textString);
|
2017-02-08 06:05:47 +08:00
|
|
|
scroll = MIN(scroll, textlen);
|
|
|
|
if (scroll)
|
2017-02-07 04:58:55 +08:00
|
|
|
utf8_it += scroll;
|
|
|
|
|
|
|
|
g->drawText(utf8_it,
|
|
|
|
base::utf8_const_iterator(textString.end()),
|
|
|
|
colors.text(), ColorNone,
|
|
|
|
bounds.origin(), &delegate);
|
|
|
|
|
|
|
|
bounds.x += delegate.textBounds().w;
|
|
|
|
|
2015-11-25 06:54:10 +08:00
|
|
|
// Draw suffix if there is enough space
|
|
|
|
if (!widget->getSuffix().empty()) {
|
2017-02-07 04:58:55 +08:00
|
|
|
Rect sufBounds(bounds.x, bounds.y,
|
|
|
|
bounds.x2()-widget->childSpacing()*guiscale()-bounds.x,
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
widget->textHeight());
|
2017-02-08 06:05:47 +08:00
|
|
|
IntersectClip clip(g, sufBounds & widget->clientChildrenBounds());
|
2015-11-25 06:54:10 +08:00
|
|
|
if (clip) {
|
2017-02-07 04:58:55 +08:00
|
|
|
drawText(
|
2015-11-25 06:54:10 +08:00
|
|
|
g, widget->getSuffix().c_str(),
|
|
|
|
colors.entrySuffix(), ColorNone,
|
2017-02-15 01:16:37 +08:00
|
|
|
widget, sufBounds, 0, 0);
|
2015-11-25 06:54:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
// Draw caret at the end of the text
|
|
|
|
if (!delegate.caretDrawn()) {
|
2017-02-08 06:05:47 +08:00
|
|
|
gfx::Rect charBounds(bounds.x+widget->bounds().x,
|
|
|
|
bounds.y+widget->bounds().y, 0, widget->textHeight());
|
|
|
|
delegate.preDrawChar(charBounds);
|
|
|
|
delegate.postDrawChar(charBounds);
|
2013-01-07 01:45:43 +08:00
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:40:18 +08:00
|
|
|
void SkinTheme::paintListBox(PaintEvent& ev)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2013-05-21 07:40:18 +08:00
|
|
|
|
2015-02-16 02:29:16 +08:00
|
|
|
g->fillRect(colors.background(), g->getClipBounds());
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:40:18 +08:00
|
|
|
void SkinTheme::paintMenu(PaintEvent& ev)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
2013-05-21 07:40:18 +08:00
|
|
|
Widget* widget = static_cast<Widget*>(ev.getSource());
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2013-05-21 07:40:18 +08:00
|
|
|
|
|
|
|
g->fillRect(BGCOLOR, g->getClipBounds());
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:40:18 +08:00
|
|
|
void SkinTheme::paintMenuItem(ui::PaintEvent& ev)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
2014-11-26 09:33:45 +08:00
|
|
|
int scale = guiscale();
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2014-11-07 05:41:18 +08:00
|
|
|
MenuItem* widget = static_cast<MenuItem*>(ev.getSource());
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Rect bounds = widget->clientBounds();
|
2014-06-29 03:10:39 +08:00
|
|
|
gfx::Color fg, bg;
|
2013-01-07 01:45:43 +08:00
|
|
|
int c, bar;
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
// TODO ASSERT?
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
if (!widget->parent()->parent())
|
2009-11-22 04:02:31 +08:00
|
|
|
return;
|
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
bar = (widget->parent()->parent()->type() == kMenuBarWidget);
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
// Colors
|
2010-07-04 02:26:27 +08:00
|
|
|
if (!widget->isEnabled()) {
|
2013-01-07 01:45:43 +08:00
|
|
|
fg = ColorNone;
|
2015-02-16 02:29:16 +08:00
|
|
|
bg = colors.menuitemNormalFace();
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
else {
|
2011-04-23 10:00:35 +08:00
|
|
|
if (widget->isHighlighted()) {
|
2015-02-16 02:29:16 +08:00
|
|
|
fg = colors.menuitemHighlightText();
|
|
|
|
bg = colors.menuitemHighlightFace();
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
2014-04-25 19:59:00 +08:00
|
|
|
else if (widget->hasMouse()) {
|
2015-02-16 02:29:16 +08:00
|
|
|
fg = colors.menuitemHotText();
|
|
|
|
bg = colors.menuitemHotFace();
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
else {
|
2015-02-16 02:29:16 +08:00
|
|
|
fg = colors.menuitemNormalText();
|
|
|
|
bg = colors.menuitemNormalFace();
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-20 02:18:16 +08:00
|
|
|
// Background
|
|
|
|
g->fillRect(bg, bounds);
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2014-04-20 02:18:16 +08:00
|
|
|
// Draw an indicator for selected items
|
2010-07-04 02:03:26 +08:00
|
|
|
if (widget->isSelected()) {
|
2014-06-23 05:53:14 +08:00
|
|
|
she::Surface* icon =
|
2015-08-05 06:38:52 +08:00
|
|
|
(widget->isEnabled() ?
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
parts.checkSelected()->bitmap(0):
|
|
|
|
parts.checkDisabled()->bitmap(0));
|
2014-06-23 05:53:14 +08:00
|
|
|
|
|
|
|
int x = bounds.x+4*scale-icon->width()/2;
|
|
|
|
int y = bounds.y+bounds.h/2-icon->height()/2;
|
|
|
|
g->drawRgbaSurface(icon, x, y);
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2014-04-20 02:18:16 +08:00
|
|
|
// Text
|
2009-11-22 04:02:31 +08:00
|
|
|
if (bar)
|
2015-06-24 01:00:00 +08:00
|
|
|
widget->setAlign(CENTER | MIDDLE);
|
2009-11-22 04:02:31 +08:00
|
|
|
else
|
2015-06-24 01:00:00 +08:00
|
|
|
widget->setAlign(LEFT | MIDDLE);
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2014-04-20 02:18:16 +08:00
|
|
|
Rect pos = bounds;
|
2009-11-22 04:02:31 +08:00
|
|
|
if (!bar)
|
2015-06-24 06:20:49 +08:00
|
|
|
pos.offset(widget->childSpacing()/2, 0);
|
2017-02-15 01:16:37 +08:00
|
|
|
drawText(g, nullptr, fg, ColorNone, widget, pos, 0,
|
|
|
|
widget->mnemonic());
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2013-05-21 07:40:18 +08:00
|
|
|
// For menu-box
|
2009-11-22 04:02:31 +08:00
|
|
|
if (!bar) {
|
2013-05-21 07:40:18 +08:00
|
|
|
// Draw the arrown (to indicate which this menu has a sub-menu)
|
2011-04-23 10:00:35 +08:00
|
|
|
if (widget->getSubmenu()) {
|
2013-05-21 07:40:18 +08:00
|
|
|
// Enabled
|
2010-07-04 02:26:27 +08:00
|
|
|
if (widget->isEnabled()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
for (c=0; c<3*scale; c++)
|
2014-04-20 02:18:16 +08:00
|
|
|
g->drawVLine(fg,
|
|
|
|
bounds.x2()-3*scale-c,
|
|
|
|
bounds.y+bounds.h/2-c, 2*c+1);
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
2013-05-21 07:40:18 +08:00
|
|
|
// Disabled
|
2009-11-22 04:02:31 +08:00
|
|
|
else {
|
2012-01-06 06:45:03 +08:00
|
|
|
for (c=0; c<3*scale; c++)
|
2015-02-16 02:29:16 +08:00
|
|
|
g->drawVLine(colors.background(),
|
2014-04-20 02:18:16 +08:00
|
|
|
bounds.x2()-3*scale-c+1,
|
|
|
|
bounds.y+bounds.h/2-c+1, 2*c+1);
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
for (c=0; c<3*scale; c++)
|
2015-02-16 02:29:16 +08:00
|
|
|
g->drawVLine(colors.disabled(),
|
2014-04-20 02:18:16 +08:00
|
|
|
bounds.x2()-3*scale-c,
|
|
|
|
bounds.y+bounds.h/2-c, 2*c+1);
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
}
|
2012-07-18 08:42:02 +08:00
|
|
|
// Draw the keyboard shortcut
|
2014-11-07 05:41:18 +08:00
|
|
|
else if (AppMenuItem* appMenuItem = dynamic_cast<AppMenuItem*>(widget)) {
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
if (appMenuItem->key() && !appMenuItem->key()->accels().empty()) {
|
|
|
|
int old_align = appMenuItem->align();
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2014-11-07 05:41:18 +08:00
|
|
|
pos = bounds;
|
2015-06-24 06:20:49 +08:00
|
|
|
pos.w -= widget->childSpacing()/4;
|
2009-11-22 04:02:31 +08:00
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
std::string buf = appMenuItem->key()->accels().front().toString();
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2015-06-24 01:00:00 +08:00
|
|
|
widget->setAlign(RIGHT | MIDDLE);
|
2017-02-15 01:16:37 +08:00
|
|
|
drawText(g, buf.c_str(), fg, ColorNone, widget, pos, 0, 0);
|
2014-11-07 05:41:18 +08:00
|
|
|
widget->setAlign(old_align);
|
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-05 23:03:22 +08:00
|
|
|
void SkinTheme::paintSlider(PaintEvent& ev)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2014-04-20 02:18:16 +08:00
|
|
|
Slider* widget = static_cast<Slider*>(ev.getSource());
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Rect bounds = widget->clientBounds();
|
2009-11-22 04:02:31 +08:00
|
|
|
int min, max, value;
|
|
|
|
|
2013-04-04 08:17:12 +08:00
|
|
|
// Outside borders
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Color bgcolor = widget->bgColor();
|
2013-04-04 08:17:12 +08:00
|
|
|
if (!is_transparent(bgcolor))
|
2014-04-20 02:18:16 +08:00
|
|
|
g->fillRect(bgcolor, bounds);
|
2013-04-04 08:17:12 +08:00
|
|
|
|
2010-12-05 03:13:21 +08:00
|
|
|
widget->getSliderThemeInfo(&min, &max, &value);
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2015-06-24 06:20:49 +08:00
|
|
|
Rect rc(Rect(bounds).shrink(widget->border()));
|
2011-02-05 23:03:22 +08:00
|
|
|
int x;
|
2009-11-22 04:02:31 +08:00
|
|
|
if (min != max)
|
2011-02-05 23:03:22 +08:00
|
|
|
x = rc.x + rc.w * (value-min) / (max-min);
|
2009-11-22 04:02:31 +08:00
|
|
|
else
|
2011-02-05 23:03:22 +08:00
|
|
|
x = rc.x;
|
2009-11-22 04:02:31 +08:00
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
rc = widget->clientBounds();
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2011-01-24 11:03:38 +08:00
|
|
|
// The mini-look is used for sliders with tiny borders.
|
|
|
|
bool isMiniLook = false;
|
|
|
|
|
|
|
|
// The BG painter is used for sliders without a number-indicator and
|
|
|
|
// customized background (e.g. RGB sliders)
|
|
|
|
ISliderBgPainter* bgPainter = NULL;
|
|
|
|
|
2013-12-05 12:19:46 +08:00
|
|
|
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
|
2015-04-03 07:42:43 +08:00
|
|
|
if (skinPropery)
|
2011-03-30 08:07:37 +08:00
|
|
|
isMiniLook = (skinPropery->getLook() == MiniLook);
|
2011-01-24 11:03:38 +08:00
|
|
|
|
2013-12-05 12:19:46 +08:00
|
|
|
SkinSliderPropertyPtr skinSliderPropery = widget->getProperty(SkinSliderProperty::Name);
|
2015-04-03 07:42:43 +08:00
|
|
|
if (skinSliderPropery)
|
2013-12-05 12:19:46 +08:00
|
|
|
bgPainter = skinSliderPropery->getBgPainter();
|
2011-01-24 11:03:38 +08:00
|
|
|
|
|
|
|
// Draw customized background
|
|
|
|
if (bgPainter) {
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinPartPtr nw = parts.miniSliderEmpty();
|
2014-06-23 05:53:14 +08:00
|
|
|
she::Surface* thumb =
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
(widget->hasFocus() ? parts.miniSliderThumbFocused()->bitmap(0):
|
|
|
|
parts.miniSliderThumb()->bitmap(0));
|
2011-01-24 11:03:38 +08:00
|
|
|
|
|
|
|
// Draw background
|
2011-02-05 23:03:22 +08:00
|
|
|
g->fillRect(BGCOLOR, rc);
|
2011-01-24 11:03:38 +08:00
|
|
|
|
|
|
|
// Draw thumb
|
2016-09-13 04:53:01 +08:00
|
|
|
int thumb_y = rc.y;
|
|
|
|
if (rc.h > thumb->height()*3)
|
|
|
|
rc.shrink(Border(0, thumb->height(), 0, 0));
|
2011-01-24 11:03:38 +08:00
|
|
|
|
|
|
|
// Draw borders
|
2016-09-13 04:53:01 +08:00
|
|
|
if (rc.h > 4*guiscale()) {
|
|
|
|
rc.shrink(Border(3, 0, 3, 1) * guiscale());
|
2017-02-11 04:49:37 +08:00
|
|
|
drawRect(g, rc, nw.get());
|
2016-09-13 04:53:01 +08:00
|
|
|
}
|
2010-03-22 08:28:32 +08:00
|
|
|
|
2011-02-05 23:03:22 +08:00
|
|
|
// Draw background (using the customized ISliderBgPainter implementation)
|
2014-11-26 09:33:45 +08:00
|
|
|
rc.shrink(Border(1, 1, 1, 2) * guiscale());
|
2011-02-05 23:03:22 +08:00
|
|
|
if (!rc.isEmpty())
|
|
|
|
bgPainter->paint(widget, g, rc);
|
2016-09-13 04:53:01 +08:00
|
|
|
|
|
|
|
g->drawRgbaSurface(thumb, x-thumb->width()/2, thumb_y);
|
2010-03-22 08:28:32 +08:00
|
|
|
}
|
|
|
|
else {
|
2011-01-24 11:03:38 +08:00
|
|
|
// Draw borders
|
2015-08-05 06:38:52 +08:00
|
|
|
SkinPartPtr full_part;
|
|
|
|
SkinPartPtr empty_part;
|
2011-01-24 11:03:38 +08:00
|
|
|
|
|
|
|
if (isMiniLook) {
|
2015-08-05 06:38:52 +08:00
|
|
|
full_part = widget->hasMouseOver() ? parts.miniSliderFullFocused():
|
|
|
|
parts.miniSliderFull();
|
|
|
|
empty_part = widget->hasMouseOver() ? parts.miniSliderEmptyFocused():
|
|
|
|
parts.miniSliderEmpty();
|
2011-01-24 11:03:38 +08:00
|
|
|
}
|
|
|
|
else {
|
2015-08-05 06:38:52 +08:00
|
|
|
full_part = widget->hasFocus() ? parts.sliderFullFocused():
|
|
|
|
parts.sliderFull();
|
|
|
|
empty_part = widget->hasFocus() ? parts.sliderEmptyFocused():
|
|
|
|
parts.sliderEmpty();
|
2011-01-24 11:03:38 +08:00
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2011-01-24 11:03:38 +08:00
|
|
|
if (value == min)
|
2017-02-11 04:49:37 +08:00
|
|
|
drawRect(g, rc, empty_part.get());
|
2011-01-24 11:03:38 +08:00
|
|
|
else if (value == max)
|
2017-02-11 04:49:37 +08:00
|
|
|
drawRect(g, rc, full_part.get());
|
2011-01-24 11:03:38 +08:00
|
|
|
else
|
2015-08-05 06:38:52 +08:00
|
|
|
drawRect2(g, rc, x,
|
2017-02-11 04:49:37 +08:00
|
|
|
full_part.get(), empty_part.get());
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2011-01-24 11:03:38 +08:00
|
|
|
// Draw text
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
std::string old_text = widget->text();
|
2015-08-15 06:46:48 +08:00
|
|
|
widget->setTextQuiet(widget->convertValueToText(value));
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-05-05 08:51:52 +08:00
|
|
|
{
|
|
|
|
IntersectClip clip(g, Rect(rc.x, rc.y, x-rc.x, rc.h));
|
|
|
|
if (clip) {
|
2017-02-15 01:16:37 +08:00
|
|
|
drawText(g, nullptr,
|
|
|
|
colors.sliderFullText(), ColorNone,
|
|
|
|
widget, rc, 0, widget->mnemonic());
|
2014-05-05 08:51:52 +08:00
|
|
|
}
|
2011-02-05 23:03:22 +08:00
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2014-05-05 08:51:52 +08:00
|
|
|
{
|
|
|
|
IntersectClip clip(g, Rect(x+1, rc.y, rc.w-(x-rc.x+1), rc.h));
|
|
|
|
if (clip) {
|
2017-02-15 01:16:37 +08:00
|
|
|
drawText(g, nullptr,
|
|
|
|
colors.sliderEmptyText(),
|
|
|
|
ColorNone, widget, rc, 0, widget->mnemonic());
|
2014-05-05 08:51:52 +08:00
|
|
|
}
|
2011-02-05 23:03:22 +08:00
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2010-01-26 08:38:05 +08:00
|
|
|
widget->setTextQuiet(old_text.c_str());
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:40:18 +08:00
|
|
|
void SkinTheme::paintComboBoxEntry(ui::PaintEvent& ev)
|
2009-11-22 08:26:58 +08:00
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2013-05-21 07:40:18 +08:00
|
|
|
Entry* widget = static_cast<Entry*>(ev.getSource());
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Rect bounds = widget->clientBounds();
|
2009-11-22 08:26:58 +08:00
|
|
|
|
2013-03-31 00:27:38 +08:00
|
|
|
// Outside borders
|
2014-04-20 02:18:16 +08:00
|
|
|
g->fillRect(BGCOLOR, bounds);
|
2009-11-22 08:26:58 +08:00
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
drawRect(g, bounds,
|
|
|
|
(widget->hasFocus() ?
|
|
|
|
parts.sunken2Focused().get():
|
2017-02-11 04:49:37 +08:00
|
|
|
parts.sunken2Normal().get()));
|
2009-11-22 08:26:58 +08:00
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
drawEntryText(g, widget);
|
2009-11-22 08:26:58 +08:00
|
|
|
}
|
|
|
|
|
2013-05-21 07:40:18 +08:00
|
|
|
void SkinTheme::paintTextBox(ui::PaintEvent& ev)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2013-05-21 07:40:18 +08:00
|
|
|
Widget* widget = static_cast<Widget*>(ev.getSource());
|
2014-04-20 02:18:16 +08:00
|
|
|
|
2016-12-15 21:50:47 +08:00
|
|
|
Theme::drawTextBox(g, widget, nullptr, nullptr,
|
|
|
|
BGCOLOR, colors.textboxText());
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
void SkinTheme::paintViewViewport(PaintEvent& ev)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
2013-01-07 01:45:43 +08:00
|
|
|
Viewport* widget = static_cast<Viewport*>(ev.getSource());
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2014-06-29 03:10:39 +08:00
|
|
|
gfx::Color bg = BGCOLOR;
|
2013-01-07 01:45:43 +08:00
|
|
|
|
2014-04-20 05:51:42 +08:00
|
|
|
if (!is_transparent(bg))
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
g->fillRect(bg, widget->clientBounds());
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2014-06-29 03:10:39 +08:00
|
|
|
gfx::Color SkinTheme::getWidgetBgColor(Widget* widget)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
gfx::Color c = widget->bgColor();
|
2012-04-06 06:00:19 +08:00
|
|
|
bool decorative = widget->isDecorative();
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2017-08-15 21:39:06 +08:00
|
|
|
if (!is_transparent(c) ||
|
|
|
|
widget->type() == kWindowWidget)
|
|
|
|
return (widget->isTransparent() ? gfx::ColorNone: c);
|
2014-04-20 05:51:42 +08:00
|
|
|
else if (decorative)
|
2015-02-16 02:29:16 +08:00
|
|
|
return colors.selected();
|
2014-04-20 05:51:42 +08:00
|
|
|
else
|
2015-02-16 02:29:16 +08:00
|
|
|
return colors.face();
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
void SkinTheme::drawText(Graphics* g, const char *t, gfx::Color fg_color, gfx::Color bg_color,
|
|
|
|
Widget* widget, const Rect& rc,
|
2017-02-15 01:16:37 +08:00
|
|
|
int selected_offset, int mnemonic)
|
2011-02-05 23:03:22 +08:00
|
|
|
{
|
|
|
|
if (t || widget->hasText()) {
|
2012-06-18 09:02:54 +08:00
|
|
|
Rect textrc;
|
2011-02-05 23:03:22 +08:00
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
g->setFont(widget->font());
|
2011-02-05 23:03:22 +08:00
|
|
|
|
|
|
|
if (!t)
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
t = widget->text().c_str();
|
2011-02-05 23:03:22 +08:00
|
|
|
|
2017-02-07 04:58:55 +08:00
|
|
|
textrc.setSize(g->measureUIText(t));
|
2011-02-05 23:03:22 +08:00
|
|
|
|
|
|
|
// Horizontally text alignment
|
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
if (widget->align() & RIGHT)
|
2011-02-05 23:03:22 +08:00
|
|
|
textrc.x = rc.x + rc.w - textrc.w - 1;
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
else if (widget->align() & CENTER)
|
|
|
|
textrc.x = rc.center().x - textrc.w/2;
|
2011-02-05 23:03:22 +08:00
|
|
|
else
|
|
|
|
textrc.x = rc.x;
|
|
|
|
|
|
|
|
// Vertically text alignment
|
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
if (widget->align() & BOTTOM)
|
2011-02-05 23:03:22 +08:00
|
|
|
textrc.y = rc.y + rc.h - textrc.h - 1;
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
else if (widget->align() & MIDDLE)
|
|
|
|
textrc.y = rc.center().y - textrc.h/2;
|
2011-02-05 23:03:22 +08:00
|
|
|
else
|
|
|
|
textrc.y = rc.y;
|
|
|
|
|
|
|
|
if (widget->isSelected()) {
|
|
|
|
textrc.x += selected_offset;
|
|
|
|
textrc.y += selected_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Background
|
2013-01-07 01:45:43 +08:00
|
|
|
if (!is_transparent(bg_color)) {
|
2011-02-05 23:03:22 +08:00
|
|
|
if (!widget->isEnabled())
|
2014-11-26 09:33:45 +08:00
|
|
|
g->fillRect(bg_color, Rect(textrc).inflate(guiscale(), guiscale()));
|
2011-02-05 23:03:22 +08:00
|
|
|
else
|
2012-01-06 06:45:03 +08:00
|
|
|
g->fillRect(bg_color, textrc);
|
2011-02-05 23:03:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Text
|
2015-06-10 03:22:47 +08:00
|
|
|
Rect textWrap = textrc.createIntersection(
|
2014-04-20 02:18:16 +08:00
|
|
|
// TODO add ui::Widget::getPadding() property
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
// Rect(widget->clientBounds()).shrink(widget->border()));
|
|
|
|
widget->clientBounds()).inflate(0, 1*guiscale());
|
2011-02-05 23:03:22 +08:00
|
|
|
|
2014-05-05 08:51:52 +08:00
|
|
|
IntersectClip clip(g, textWrap);
|
|
|
|
if (clip) {
|
2014-04-18 03:24:04 +08:00
|
|
|
if (!widget->isEnabled()) {
|
|
|
|
// Draw white part
|
2017-02-15 01:16:37 +08:00
|
|
|
g->drawUIText(
|
|
|
|
t,
|
2015-02-16 02:29:16 +08:00
|
|
|
colors.background(),
|
2014-06-29 03:10:39 +08:00
|
|
|
gfx::ColorNone,
|
2017-02-15 01:16:37 +08:00
|
|
|
textrc.origin() + Point(guiscale(), guiscale()),
|
|
|
|
mnemonic);
|
2014-04-18 03:24:04 +08:00
|
|
|
}
|
|
|
|
|
2017-02-15 01:16:37 +08:00
|
|
|
g->drawUIText(
|
|
|
|
t,
|
2014-04-18 03:24:04 +08:00
|
|
|
(!widget->isEnabled() ?
|
2017-02-15 01:16:37 +08:00
|
|
|
colors.disabled():
|
|
|
|
(gfx::geta(fg_color) > 0 ? fg_color :
|
|
|
|
colors.text())),
|
|
|
|
bg_color, textrc.origin(),
|
|
|
|
mnemonic);
|
2014-04-18 03:24:04 +08:00
|
|
|
}
|
2011-02-05 23:03:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-20 02:18:16 +08:00
|
|
|
void SkinTheme::drawEntryCaret(ui::Graphics* g, Entry* widget, int x, int y)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
2015-02-16 02:29:16 +08:00
|
|
|
gfx::Color color = colors.text();
|
2017-02-08 06:05:47 +08:00
|
|
|
int textHeight = widget->textHeight();
|
|
|
|
gfx::Size caretSize = getEntryCaretSize(widget);
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2017-02-08 06:05:47 +08:00
|
|
|
for (int u=x; u<x+caretSize.w; ++u)
|
|
|
|
g->drawVLine(color, u, y+textHeight/2-caretSize.h/2, caretSize.h);
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:39:06 +08:00
|
|
|
SkinPartPtr SkinTheme::getToolPart(const char* toolId) const
|
|
|
|
{
|
|
|
|
return getPartById(std::string("tool_") + toolId);
|
|
|
|
}
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
she::Surface* SkinTheme::getToolIcon(const char* toolId) const
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
{
|
2017-08-15 21:39:06 +08:00
|
|
|
SkinPartPtr part = getToolPart(toolId);
|
2017-03-14 09:55:52 +08:00
|
|
|
if (part)
|
|
|
|
return part->bitmap(0);
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
else
|
2017-03-14 09:55:52 +08:00
|
|
|
return nullptr;
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
}
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
void SkinTheme::drawRect(Graphics* g, const Rect& rc,
|
|
|
|
she::Surface* nw, she::Surface* n, she::Surface* ne,
|
|
|
|
she::Surface* e, she::Surface* se, she::Surface* s,
|
|
|
|
she::Surface* sw, she::Surface* w)
|
2011-02-05 23:03:22 +08:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
// Top
|
|
|
|
|
2014-06-23 05:53:14 +08:00
|
|
|
g->drawRgbaSurface(nw, rc.x, rc.y);
|
2014-05-05 08:51:52 +08:00
|
|
|
{
|
2014-06-23 05:53:14 +08:00
|
|
|
IntersectClip clip(g, Rect(rc.x+nw->width(), rc.y,
|
|
|
|
rc.w-nw->width()-ne->width(), rc.h));
|
2014-05-05 08:51:52 +08:00
|
|
|
if (clip) {
|
2014-06-23 05:53:14 +08:00
|
|
|
for (x = rc.x+nw->width();
|
|
|
|
x < rc.x+rc.w-ne->width();
|
|
|
|
x += n->width()) {
|
|
|
|
g->drawRgbaSurface(n, x, rc.y);
|
2014-05-05 08:51:52 +08:00
|
|
|
}
|
2011-02-05 23:03:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 05:53:14 +08:00
|
|
|
g->drawRgbaSurface(ne, rc.x+rc.w-ne->width(), rc.y);
|
2011-02-05 23:03:22 +08:00
|
|
|
|
|
|
|
// Bottom
|
|
|
|
|
2014-06-23 05:53:14 +08:00
|
|
|
g->drawRgbaSurface(sw, rc.x, rc.y+rc.h-sw->height());
|
2014-05-05 08:51:52 +08:00
|
|
|
{
|
2014-06-23 05:53:14 +08:00
|
|
|
IntersectClip clip(g, Rect(rc.x+sw->width(), rc.y,
|
|
|
|
rc.w-sw->width()-se->width(), rc.h));
|
2014-05-05 08:51:52 +08:00
|
|
|
if (clip) {
|
2014-06-23 05:53:14 +08:00
|
|
|
for (x = rc.x+sw->width();
|
|
|
|
x < rc.x+rc.w-se->width();
|
|
|
|
x += s->width()) {
|
|
|
|
g->drawRgbaSurface(s, x, rc.y+rc.h-s->height());
|
2014-05-05 08:51:52 +08:00
|
|
|
}
|
2011-02-05 23:03:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 05:53:14 +08:00
|
|
|
g->drawRgbaSurface(se, rc.x+rc.w-se->width(), rc.y+rc.h-se->height());
|
2014-05-05 08:51:52 +08:00
|
|
|
{
|
2014-06-23 05:53:14 +08:00
|
|
|
IntersectClip clip(g, Rect(rc.x, rc.y+nw->height(),
|
|
|
|
rc.w, rc.h-nw->height()-sw->height()));
|
2014-05-05 08:51:52 +08:00
|
|
|
if (clip) {
|
|
|
|
// Left
|
2014-06-23 05:53:14 +08:00
|
|
|
for (y = rc.y+nw->height();
|
|
|
|
y < rc.y+rc.h-sw->height();
|
|
|
|
y += w->height()) {
|
|
|
|
g->drawRgbaSurface(w, rc.x, y);
|
2014-05-05 08:51:52 +08:00
|
|
|
}
|
2011-02-05 23:03:22 +08:00
|
|
|
|
2014-05-05 08:51:52 +08:00
|
|
|
// Right
|
2014-06-23 05:53:14 +08:00
|
|
|
for (y = rc.y+ne->height();
|
|
|
|
y < rc.y+rc.h-se->height();
|
|
|
|
y += e->height()) {
|
|
|
|
g->drawRgbaSurface(e, rc.x+rc.w-e->width(), y);
|
2014-05-05 08:51:52 +08:00
|
|
|
}
|
2011-02-05 23:03:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-11 04:49:37 +08:00
|
|
|
void SkinTheme::drawRect(ui::Graphics* g, const gfx::Rect& rc,
|
|
|
|
SkinPart* skinPart, const bool drawCenter)
|
2009-11-22 04:02:31 +08:00
|
|
|
{
|
2017-02-11 04:49:37 +08:00
|
|
|
Theme::drawSlices(g, m_sheet, rc,
|
|
|
|
skinPart->spriteBounds(),
|
2017-03-27 23:32:39 +08:00
|
|
|
skinPart->slicesBounds(),
|
|
|
|
gfx::ColorNone,
|
|
|
|
drawCenter);
|
2013-12-11 11:34:16 +08:00
|
|
|
}
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
void SkinTheme::drawRect2(Graphics* g, const Rect& rc, int x_mid,
|
2017-02-11 04:49:37 +08:00
|
|
|
SkinPart* nw1, SkinPart* nw2)
|
2011-02-05 23:03:22 +08:00
|
|
|
{
|
2012-06-18 09:02:54 +08:00
|
|
|
Rect rc2(rc.x, rc.y, x_mid-rc.x+1, rc.h);
|
2014-05-05 08:51:52 +08:00
|
|
|
{
|
|
|
|
IntersectClip clip(g, rc2);
|
|
|
|
if (clip)
|
2017-02-11 04:49:37 +08:00
|
|
|
drawRect(g, rc, nw1);
|
2014-05-05 08:51:52 +08:00
|
|
|
}
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2011-02-05 23:03:22 +08:00
|
|
|
rc2.x += rc2.w;
|
|
|
|
rc2.w = rc.w - rc2.w;
|
2009-11-22 04:02:31 +08:00
|
|
|
|
2014-05-05 08:51:52 +08:00
|
|
|
IntersectClip clip(g, rc2);
|
|
|
|
if (clip)
|
2017-02-11 04:49:37 +08:00
|
|
|
drawRect(g, rc, nw2);
|
2009-11-22 04:02:31 +08:00
|
|
|
}
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
void SkinTheme::drawHline(ui::Graphics* g, const gfx::Rect& rc, SkinPart* part)
|
2013-05-21 07:40:18 +08:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
|
|
|
for (x = rc.x;
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
x < rc.x2()-part->size().w;
|
|
|
|
x += part->size().w) {
|
|
|
|
g->drawRgbaSurface(part->bitmap(0), x, rc.y);
|
2013-05-21 07:40:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x < rc.x2()) {
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Rect rc2(x, rc.y, rc.w-(x-rc.x), part->size().h);
|
2014-05-05 08:51:52 +08:00
|
|
|
IntersectClip clip(g, rc2);
|
|
|
|
if (clip)
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
g->drawRgbaSurface(part->bitmap(0), x, rc.y);
|
2013-05-21 07:40:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-05 06:38:52 +08:00
|
|
|
void SkinTheme::drawVline(ui::Graphics* g, const gfx::Rect& rc, SkinPart* part)
|
2013-05-21 07:40:18 +08:00
|
|
|
{
|
|
|
|
int y;
|
|
|
|
|
|
|
|
for (y = rc.y;
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
y < rc.y2()-part->size().h;
|
|
|
|
y += part->size().h) {
|
|
|
|
g->drawRgbaSurface(part->bitmap(0), rc.x, y);
|
2013-05-21 07:40:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (y < rc.y2()) {
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Rect rc2(rc.x, y, part->size().w, rc.h-(y-rc.y));
|
2014-05-05 08:51:52 +08:00
|
|
|
IntersectClip clip(g, rc2);
|
|
|
|
if (clip)
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
g->drawRgbaSurface(part->bitmap(0), rc.x, y);
|
2013-05-21 07:40:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-15 09:37:56 +08:00
|
|
|
void SkinTheme::paintProgressBar(ui::Graphics* g, const gfx::Rect& rc0, double progress)
|
2013-12-30 08:12:23 +08:00
|
|
|
{
|
2015-02-16 02:29:16 +08:00
|
|
|
g->drawRect(colors.text(), rc0);
|
2013-12-30 08:12:23 +08:00
|
|
|
|
|
|
|
gfx::Rect rc = rc0;
|
|
|
|
rc.shrink(1);
|
|
|
|
|
2015-02-15 09:37:56 +08:00
|
|
|
int u = (int)((double)rc.w*progress);
|
2013-12-30 08:12:23 +08:00
|
|
|
u = MID(0, u, rc.w);
|
|
|
|
|
|
|
|
if (u > 0)
|
2015-02-16 02:29:16 +08:00
|
|
|
g->fillRect(colors.selected(), gfx::Rect(rc.x, rc.y, u, rc.h));
|
2013-12-30 08:12:23 +08:00
|
|
|
|
|
|
|
if (1+u < rc.w)
|
2015-02-16 02:29:16 +08:00
|
|
|
g->fillRect(colors.background(), gfx::Rect(rc.x+u, rc.y, rc.w-u, rc.h));
|
2013-12-30 08:12:23 +08:00
|
|
|
}
|
|
|
|
|
2017-06-13 22:51:49 +08:00
|
|
|
std::string SkinTheme::findThemePath(const std::string& themeId) const
|
2017-02-10 00:18:44 +08:00
|
|
|
{
|
2017-06-11 02:02:39 +08:00
|
|
|
// First we try to find the theme on an extensions
|
|
|
|
std::string path = App::instance()->extensions().themePath(themeId);
|
|
|
|
if (path.empty()) {
|
|
|
|
// Then we try a theme in the old themes/ folder
|
|
|
|
path = base::join_path(SkinTheme::kThemesFolderName, themeId);
|
|
|
|
path = base::join_path(path, "theme.xml");
|
|
|
|
|
|
|
|
ResourceFinder rf;
|
|
|
|
rf.includeDataDir(path.c_str());
|
|
|
|
if (!rf.findFirst())
|
|
|
|
return std::string();
|
|
|
|
|
|
|
|
path = base::get_file_path(rf.filename());
|
|
|
|
}
|
2017-06-13 22:51:49 +08:00
|
|
|
return base::normalize_path(path);
|
2017-02-10 00:18:44 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace skin
|
|
|
|
} // namespace app
|