Redraw editor when onionskin preferences are changed

We have added a Before/AfterChange signals to preference Sections.
This commit is contained in:
David Capello 2015-03-10 19:05:20 -03:00
parent 1780a13ed4
commit 4588579e25
6 changed files with 59 additions and 48 deletions

View File

@ -13,10 +13,22 @@
namespace app {
class Section {
public:
Section(const std::string& name) : m_name(name) { }
const char* name() const { return m_name.c_str(); }
Signal0<void> BeforeChange;
Signal0<void> AfterChange;
private:
std::string m_name;
};
template<typename T>
class Option {
public:
Option(const char* section, const char* id, const T& defaultValue = T())
Option(Section* section, const char* id, const T& defaultValue = T())
: m_section(section)
, m_id(id)
, m_default(defaultValue)
@ -24,20 +36,12 @@ namespace app {
, m_dirty(false) {
}
Option(const Option& opt)
: m_section(opt.m_section)
, m_id(opt.m_id)
, m_default(opt.m_default)
, m_value(opt.m_value)
, m_dirty(false) {
}
Option& operator=(const Option& opt) {
operator()(opt.m_value());
operator()(opt.m_value);
return *this;
}
const char* section() const { return m_section; }
const char* section() const { return m_section->name(); }
const char* id() const { return m_id; }
const T& defaultValue() const { return m_default; }
@ -54,12 +58,17 @@ namespace app {
return m_value;
BeforeChange(*this, newValue);
if (m_section)
m_section->BeforeChange();
T oldValue = m_value;
m_value = newValue;
m_dirty = true;
AfterChange(*this, oldValue);
if (m_section)
m_section->AfterChange();
return m_value;
}
@ -67,13 +76,14 @@ namespace app {
Signal2<void, Option&, const T&> AfterChange;
private:
const char* m_section;
Section* m_section;
const char* m_id;
T m_default;
T m_value;
bool m_dirty;
Option();
Option(const Option& opt);
};
} // namespace app

View File

@ -61,9 +61,7 @@ ToolPreferences& Preferences::tool(tools::Tool* tool)
return *it->second;
}
else {
std::string section = "tool.";
section += tool->getId();
std::string section = std::string("tool.") + tool->getId();
ToolPreferences* toolPref = new ToolPreferences(section);
m_tools[tool->getId()] = toolPref;
toolPref->load();
@ -79,8 +77,10 @@ DocumentPreferences& Preferences::document(app::Document* document)
}
else {
DocumentPreferences* docPref;
if (document)
docPref = new DocumentPreferences(this->document(nullptr));
if (document) {
docPref = new DocumentPreferences("");
*docPref = this->document(nullptr);
}
else
docPref = new DocumentPreferences("");

View File

@ -170,12 +170,11 @@ Editor::Editor(Document* document, EditorFlags flags)
DocumentPreferences& docPref = App::instance()
->preferences().document(m_document);
m_tiledModeConn = docPref.tiled.mode.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_gridVisibleConn = docPref.grid.visible.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_gridBoundsConn = docPref.grid.bounds.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_gridColorConn = docPref.grid.color.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_pixelGridVisibleConn = docPref.pixelGrid.visible.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_pixelGridColorConn = docPref.pixelGrid.visible.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_tiledConn = docPref.tiled.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_gridConn = docPref.grid.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_pixelGridConn = docPref.pixelGrid.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_onionskinConn = docPref.onionskin.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_document->addObserver(this);

View File

@ -284,12 +284,10 @@ namespace app {
ScopedConnection m_fgColorChangeConn;
// Slots listeing document preferences.
ScopedConnection m_tiledModeConn;
ScopedConnection m_gridVisibleConn;
ScopedConnection m_gridBoundsConn;
ScopedConnection m_gridColorConn;
ScopedConnection m_pixelGridVisibleConn;
ScopedConnection m_pixelGridColorConn;
ScopedConnection m_tiledConn;
ScopedConnection m_gridConn;
ScopedConnection m_pixelGridConn;
ScopedConnection m_onionskinConn;
EditorObservers m_observers;

View File

@ -1,5 +1,5 @@
// Aseprite Base Library
// Copyright (c) 2001-2014 David Capello
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -9,7 +9,6 @@
#pragma once
#include "base/connection.h"
#include "base/disable_copying.h"
#include "base/remove_from_container.h"
#include "base/slot.h"
@ -33,6 +32,11 @@ public:
Signal0_base() { }
~Signal0_base() { }
Signal0_base(const Signal0_base&) { }
Signal0_base operator=(const Signal0_base&) {
return *this;
}
Connection addSlot(SlotType* slot) {
m_slots.push_back(slot);
return Connection(this, slot);
@ -54,9 +58,6 @@ public:
protected:
SlotList m_slots;
private:
DISABLE_COPYING(Signal0_base);
};
// Signal0<R>
@ -128,6 +129,11 @@ public:
Signal1_base() { }
~Signal1_base() { }
Signal1_base(const Signal1_base&) { }
Signal1_base operator=(const Signal1_base&) {
return *this;
}
Connection addSlot(SlotType* slot) {
m_slots.push_back(slot);
return Connection(this, slot);
@ -149,9 +155,6 @@ public:
protected:
SlotList m_slots;
private:
DISABLE_COPYING(Signal1_base);
};
// Signal1<R, A1>
@ -224,6 +227,11 @@ public:
Signal2_base() { }
~Signal2_base() { }
Signal2_base(const Signal2_base&) { }
Signal2_base operator=(const Signal2_base&) {
return *this;
}
Connection addSlot(SlotType* slot) {
m_slots.push_back(slot);
return Connection(this, slot);
@ -245,9 +253,6 @@ public:
protected:
SlotList m_slots;
private:
DISABLE_COPYING(Signal2_base);
};
// Signal2<R, A1>

View File

@ -23,10 +23,9 @@ static void print_pref_class_def(TiXmlElement* elem, const std::string& classNam
std::string indent(indentSpaces, ' ');
std::cout
<< "\n"
<< indent << "class " << className << " {\n"
<< indent << " std::string m_section;\n"
<< indent << "class " << className << " : public Section {\n"
<< indent << "public:\n"
<< indent << " " << className << "(const std::string& section);\n";
<< indent << " " << className << "(const std::string& name);\n";
std::cout
<< indent << " void load();\n"
@ -65,12 +64,12 @@ static void print_pref_class_impl(TiXmlElement* elem, const std::string& prefix,
{
std::cout
<< "\n"
<< prefix << className << "::" << className << "(const std::string& section)\n";
<< prefix << className << "::" << className << "(const std::string& name)\n";
if (section)
std::cout << " : m_section((!section.empty() ? section + \".\": section) + \"" << section << "\")\n";
std::cout << " : Section(std::string(!name.empty() ? name + \".\": \"\") + \"" << section << "\")\n";
else
std::cout << " : m_section(section)\n";
std::cout << " : Section(name)\n";
TiXmlElement* child = (elem->FirstChild() ? elem->FirstChild()->ToElement(): NULL);
while (child) {
@ -83,7 +82,7 @@ static void print_pref_class_impl(TiXmlElement* elem, const std::string& prefix,
if (!childId) throw std::runtime_error("missing 'id' attr in <option>");
std::string memberName = convert_xmlid_to_cppid(childId, false);
std::cout << " , "
<< memberName << "(m_section.c_str(), \"" << childId << "\"";
<< memberName << "(this, \"" << childId << "\"";
if (child->Attribute("default"))
std::cout << ", " << child->Attribute("default");
std::cout << ")\n";
@ -91,7 +90,7 @@ static void print_pref_class_impl(TiXmlElement* elem, const std::string& prefix,
else if (name == "section") {
if (!childId) throw std::runtime_error("missing 'id' attr in <option>");
std::string memberName = convert_xmlid_to_cppid(childId, false);
std::cout << " , " << memberName << "(m_section)\n";
std::cout << " , " << memberName << "(name)\n";
}
}
child = child->NextSiblingElement();