Replace ISettings with Preferences

Changes:
* Move FreehandAlgorithm/InkType/RotationAlgorithm/SelectionMode to
  app::tools namespace
* Removed ISettings, IToolSettings, IBrushSettings, ISelectionSettings,
  and IColorSwatchesStore (and implementations from UISettingsImpl)
* Added app::tools::PreferenceGlue to do some adjustments that
  UIToolSettingsImpl was doing
* Remove signals from App related to brush size/angle changes, and current
  tool change (there events can be observed directly from Preferences)
* Remove ColorBar::FgColor/BgColor, these options can be observed from
  Preferences::colorBar.fg/bgColor
This commit is contained in:
David Capello 2015-05-18 16:53:25 -03:00
parent 026972a7b9
commit f6be0c3be6
82 changed files with 615 additions and 1448 deletions

View File

@ -4,11 +4,6 @@
<preferences>
<types>
<enum id="InkType">
<value id="DEFAULT" value="0" />
<value id="SET_ALPHA" value="1" />
<value id="LOCK_ALPHA" value="2" />
</enum>
<enum id="RightClickMode">
<value id="DEFAULT" value="0" />
<value id="PAINT_BGCOLOR" value="0" />
@ -19,25 +14,11 @@
<value id="MERGE" value="0" />
<value id="RED_BLUE_TINT" value="1" />
</enum>
<enum id="FreehandAlgorithm">
<value id="REGULAR" value="0" />
<value id="PIXEL_PERFECT" value="1" />
<value id="DOTS" value="2" />
</enum>
<enum id="BrushType">
<value id="CIRCLE" value="0" />
<value id="SQUARE" value="1" />
<value id="LINE" value="2" />
</enum>
<enum id="SelectionMode">
<value id="DEFAULT" value="0" />
<value id="ADD" value="1" />
<value id="SUBTRACT" value="2" />
</enum>
<enum id="RotationAlgorithm">
<value id="FAST" value="0" />
<value id="ROTSPRITE" value="1" />
</enum>
<enum id="BgType">
<value id="CHECKED_16x16" value="0" />
<value id="CHECKED_8x8" value="1" />
@ -74,9 +55,6 @@
<option id="right_click_mode" type="RightClickMode" default="RightClickMode::PAINT_BGCOLOR" migrate="Options.RightClickMode" />
<option id="grab_alpha" type="bool" default="false" migrate="Options.GrabAlpha" />
<option id="auto_select_layer" type="bool" default="false" migrate="Options.AutoSelectLayer" />
<option id="fg_color" type="app::Color" />
<option id="bg_color" type="app::Color" />
<option id="current_tool" type="std::string" default="&quot;pencil&quot;" />
</section>
<section id="experimental" text="Experimental">
<option id="ui_scale" type="int" default="1" />
@ -89,6 +67,11 @@
</section>
<section id="color_bar">
<option id="box_size" type="int" default="11" />
<option id="fg_color" type="app::Color" />
<option id="bg_color" type="app::Color" />
</section>
<section id="tool_box">
<option id="active_tool" type="std::string" default="&quot;pencil&quot;" />
</section>
<section id="updater">
<option id="inits" type="int" default="0" migrate="Updater.Inits" />
@ -103,6 +86,11 @@
<section id="brush">
<option id="pattern" type="doc::BrushPattern" default="doc::BrushPattern::DEFAULT" />
</section>
<section id="selection">
<option id="mode" type="app::tools::SelectionMode" default="app::tools::SelectionMode::DEFAULT" />
<option id="transparent_color" type="app::Color" />
<option id="rotation_algorithm" type="app::tools::RotationAlgorithm" default="app::tools::RotationAlgorithm::DEFAULT" />
</section>
</global>
<tool>
@ -111,8 +99,8 @@
<option id="contiguous" type="bool" default="true" />
<option id="filled" type="bool" default="false" />
<option id="filled_preview" type="bool" default="false" />
<option id="ink" type="InkType" />
<option id="freehand_algorithm" type="FreehandAlgorithm" />
<option id="ink" type="app::tools::InkType" default="app::tools::InkType::DEFAULT" />
<option id="freehand_algorithm" type="app::tools::FreehandAlgorithm" default="app::tools::FreehandAlgorithm::DEFAULT" />
<section id="brush">
<option id="type" type="BrushType" default="BrushType::CIRCLE" />
<option id="size" type="int" default="1" />
@ -122,11 +110,6 @@
<option id="width" type="int" default="16" />
<option id="speed" type="int" default="32" />
</section>
<section id="selection">
<option id="mode" type="SelectionMode" />
<option id="transparent_color" type="app::Color" />
<option id="rotation_algorithm" type="RotationAlgorithm" />
</section>
</tool>
<document>

View File

@ -286,7 +286,6 @@ add_library(app-lib
res/resources_loader.cpp
resource_finder.cpp
send_crash.cpp
settings/ui_settings_impl.cpp
shell.cpp
snap_to_grid.cpp
thumbnail_generator.cpp

View File

@ -40,7 +40,6 @@
#include "app/recent_files.h"
#include "app/resource_finder.h"
#include "app/send_crash.h"
#include "app/settings/settings.h"
#include "app/shell.h"
#include "app/tools/tool_box.h"
#include "app/ui/color_bar.h"
@ -657,6 +656,11 @@ tools::ToolBox* App::getToolBox() const
return &m_modules->m_toolbox;
}
tools::Tool* App::activeTool() const
{
return getToolBox()->getToolById(preferences().toolBox.activeTool());
}
RecentFiles* App::getRecentFiles() const
{
ASSERT(m_modules != NULL);

View File

@ -39,6 +39,7 @@ namespace app {
class RecentFiles;
namespace tools {
class Tool;
class ToolBox;
}
@ -64,6 +65,7 @@ namespace app {
void run();
tools::ToolBox* getToolBox() const;
tools::Tool* activeTool() const;
RecentFiles* getRecentFiles() const;
MainWindow* getMainWindow() const { return m_mainWindow; }
Preferences& preferences() const;
@ -76,11 +78,6 @@ namespace app {
// App Signals
Signal0<void> Exit;
Signal0<void> PaletteChange;
Signal0<void> BrushSizeBeforeChange;
Signal0<void> BrushSizeAfterChange;
Signal0<void> BrushAngleBeforeChange;
Signal0<void> BrushAngleAfterChange;
Signal0<void> CurrentToolChange;
private:
typedef std::vector<std::string> FileList;

View File

@ -11,7 +11,6 @@
#include "app/app_render.h"
#include "app/app.h"
#include "app/color_utils.h"
#include "app/pref/preferences.h"
#include "render/render.h"
@ -29,7 +28,7 @@ AppRender::AppRender(app::Document* doc, doc::PixelFormat pixelFormat)
void AppRender::setupBackground(app::Document* doc, doc::PixelFormat pixelFormat)
{
DocumentPreferences& docPref = App::instance()->preferences().document(doc);
DocumentPreferences& docPref = Preferences::instance().document(doc);
render::BgType bgType;
gfx::Size tile;

View File

@ -78,7 +78,7 @@ private:
CheckUpdateThreadLauncher::CheckUpdateThreadLauncher(CheckUpdateDelegate* delegate)
: m_delegate(delegate)
, m_preferences(delegate->getPreferences())
, m_preferences(Preferences::instance())
, m_doCheck(true)
, m_received(false)
, m_inits(m_preferences.updater.inits())

View File

@ -15,15 +15,12 @@
namespace app {
class Preferences;
class CheckUpdateDelegate {
public:
virtual ~CheckUpdateDelegate() { }
virtual void onCheckingUpdates() = 0;
virtual void onUpToDate() = 0;
virtual void onNewUpdate(const std::string& url, const std::string& version) = 0;
virtual Preferences& getPreferences() = 0;
};
} // namespace app

View File

@ -13,7 +13,6 @@
#include "app/context_access.h"
#include "app/document_api.h"
#include "app/modules/gui.h"
#include "app/settings/settings.h"
#include "app/ui/color_bar.h"
#include "app/transaction.h"
#include "doc/layer.h"

View File

@ -16,7 +16,6 @@
#include "app/load_widget.h"
#include "app/modules/editors.h"
#include "app/modules/gui.h"
#include "app/settings/settings.h"
#include "app/ui/button_set.h"
#include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h"

View File

@ -15,7 +15,7 @@
#include "app/commands/command.h"
#include "app/commands/params.h"
#include "app/context.h"
#include "app/settings/settings.h"
#include "app/pref/preferences.h"
#include "app/tools/tool.h"
#include "app/ui/context_bar.h"
#include "app/ui/main_window.h"
@ -73,29 +73,29 @@ void ChangeBrushCommand::onLoadParams(const Params& params)
void ChangeBrushCommand::onExecute(Context* context)
{
tools::Tool* current_tool = context->settings()->getCurrentTool();
IToolSettings* tool_settings = context->settings()->getToolSettings(current_tool);
IBrushSettings* brush = tool_settings->getBrush();
tools::Tool* tool = App::instance()->activeTool();
ToolPreferences::Brush& brush =
Preferences::instance().tool(tool).brush;
switch (m_change) {
case None:
// Do nothing
break;
case IncrementSize:
if (brush->getSize() < doc::Brush::kMaxBrushSize)
brush->setSize(brush->getSize()+1);
if (brush.size() < doc::Brush::kMaxBrushSize)
brush.size(brush.size()+1);
break;
case DecrementSize:
if (brush->getSize() > doc::Brush::kMinBrushSize)
brush->setSize(brush->getSize()-1);
if (brush.size() > doc::Brush::kMinBrushSize)
brush.size(brush.size()-1);
break;
case IncrementAngle:
if (brush->getAngle() < 180)
brush->setAngle(brush->getAngle()+1);
if (brush.angle() < 180)
brush.angle(brush.angle()+1);
break;
case DecrementAngle:
if (brush->getAngle() > 0)
brush->setAngle(brush->getAngle()-1);
if (brush.angle() > 0)
brush.angle(brush.angle()-1);
break;
case CustomBrush:
App::instance()->getMainWindow()->getContextBar()

View File

@ -19,7 +19,6 @@
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
#include "app/pref/preferences.h"
#include "app/settings/settings.h"
#include "app/ui/color_button.h"
#include "app/ui/editor/editor.h"
#include "app/ui/status_bar.h"
@ -68,13 +67,8 @@ public:
}
private:
ISettings* settings() {
ASSERT(m_ctx);
return m_ctx->settings();
}
Preferences& preferences() {
return App::instance()->preferences();
return Preferences::instance();
}
DocumentPreferences& docPref() {

View File

@ -13,7 +13,6 @@
#include "app/commands/command.h"
#include "app/commands/commands.h"
#include "app/context_access.h"
#include "app/settings/settings.h"
#include "app/tools/tool_box.h"
#include "app/ui/context_bar.h"
#include "app/ui/main_window.h"

View File

@ -422,7 +422,7 @@ void ExportSpriteSheetCommand::onExecute(Context* context)
{
Document* document(context->activeDocument());
Sprite* sprite = document->sprite();
DocumentPreferences& docPref(App::instance()->preferences().document(document));
DocumentPreferences& docPref(Preferences::instance().document(document));
if (m_useUI && context->isUiAvailable()) {
ExportSpriteSheetWindow window(document, sprite, docPref);

View File

@ -17,7 +17,6 @@
#include "app/commands/params.h"
#include "app/modules/editors.h"
#include "app/pref/preferences.h"
#include "app/settings/settings.h"
#include "app/tools/tool.h"
#include "app/tools/tool_box.h"
#include "app/ui/color_bar.h"
@ -84,8 +83,8 @@ void EyedropperCommand::onExecute(Context* context)
gfx::Point pixelPos = editor->screenToEditor(ui::get_mouse_position());
// Check if we've to grab alpha channel or the merged color.
ISettings* settings = UIContext::instance()->settings();
bool grabAlpha = App::instance()->preferences().editor.grabAlpha();
Preferences& pref = Preferences::instance();
bool grabAlpha = pref.editor.grabAlpha();
ColorPicker picker;
picker.pickColor(editor->getSite(),
@ -96,15 +95,14 @@ void EyedropperCommand::onExecute(Context* context)
if (grabAlpha) {
tools::ToolBox* toolBox = App::instance()->getToolBox();
for (tools::ToolIterator it=toolBox->begin(), end=toolBox->end(); it!=end; ++it) {
settings->getToolSettings(*it)->setOpacity(picker.alpha());
}
for (auto tool : *toolBox)
pref.tool(tool).opacity(picker.alpha());
}
if (m_background)
settings->setBgColor(picker.color());
pref.colorBar.bgColor(picker.color());
else
settings->setFgColor(picker.color());
pref.colorBar.fgColor(picker.color());
}
Command* CommandFactory::createEyedropperCommand()

View File

@ -59,7 +59,7 @@ public:
// will call other sub-commands (e.g. previous frame, next frame,
// etc.).
View* view = View::getView(editor);
DocumentPreferences& docPref = App::instance()->preferences().document(m_doc);
DocumentPreferences& docPref = Preferences::instance().document(m_doc);
m_tiled = (filters::TiledMode)docPref.tiled.mode();
// Free mouse

View File

@ -38,12 +38,12 @@ public:
protected:
bool onChecked(Context* ctx) {
DocumentPreferences& docPref = App::instance()->preferences().document(ctx->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
return docPref.grid.visible();
}
void onExecute(Context* ctx) {
DocumentPreferences& docPref = App::instance()->preferences().document(ctx->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
docPref.grid.visible(!docPref.grid.visible());
}
};
@ -60,12 +60,12 @@ public:
protected:
bool onChecked(Context* ctx) {
DocumentPreferences& docPref = App::instance()->preferences().document(ctx->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
return docPref.pixelGrid.visible();
}
void onExecute(Context* ctx) {
DocumentPreferences& docPref = App::instance()->preferences().document(ctx->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
docPref.pixelGrid.visible(!docPref.pixelGrid.visible());
}
};
@ -82,12 +82,12 @@ public:
protected:
bool onChecked(Context* ctx) {
DocumentPreferences& docPref = App::instance()->preferences().document(ctx->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
return docPref.grid.snap();
}
void onExecute(Context* ctx) {
DocumentPreferences& docPref = App::instance()->preferences().document(ctx->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(ctx->activeDocument());
docPref.grid.snap(!docPref.grid.snap());
char buf[512];
@ -129,7 +129,7 @@ void GridSettingsCommand::onExecute(Context* context)
Widget* grid_w = app::find_widget<Widget>(window, "grid_w");
Widget* grid_h = app::find_widget<Widget>(window, "grid_h");
DocumentPreferences& docPref = App::instance()->preferences().document(context->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(context->activeDocument());
Rect bounds = docPref.grid.bounds();
grid_x->setTextf("%d", bounds.x);

View File

@ -181,7 +181,7 @@ private:
captureEditor();
if (m_document) {
m_docPref = &App::instance()->preferences().document(m_document);
m_docPref = &Preferences::instance().document(m_document);
onChangeRectangle(m_docPref->importSpriteSheet.bounds());
onEntriesChange();

View File

@ -68,7 +68,7 @@ bool MoveMaskCommand::onEnabled(Context* context)
void MoveMaskCommand::onExecute(Context* context)
{
DocumentPreferences& docPref = App::instance()->preferences().document(context->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(context->activeDocument());
ui::View* view = ui::View::getView(current_editor);
gfx::Rect vp = view->getViewportBounds();
gfx::Rect gridBounds = docPref.grid.bounds();

View File

@ -16,7 +16,6 @@
#include "app/console.h"
#include "app/context_access.h"
#include "app/modules/editors.h"
#include "app/settings/settings.h"
#include "app/tools/ink.h"
#include "app/tools/tool_box.h"
#include "app/transaction.h"
@ -170,12 +169,8 @@ void NewBrushCommand::createBrush(const Mask* mask)
void NewBrushCommand::selectPencilTool()
{
ISettings* settings = UIContext::instance()->settings();
if (settings->getCurrentTool()->getInk(0)->isSelection()) {
tools::Tool* pencil = App::instance()->getToolBox()
->getToolById(tools::WellKnownTools::Pencil);
settings->setCurrentTool(pencil);
}
if (App::instance()->activeTool()->getInk(0)->isSelection())
Preferences::instance().toolBox.activeTool(tools::WellKnownTools::Pencil);
}
Command* CommandFactory::createNewBrushCommand()

View File

@ -33,13 +33,13 @@ public:
protected:
bool onChecked(Context* context)
{
DocumentPreferences& docPref = App::instance()->preferences().document(context->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(context->activeDocument());
return docPref.onionskin.active();
}
void onExecute(Context* context)
{
DocumentPreferences& docPref = App::instance()->preferences().document(context->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(context->activeDocument());
docPref.onionskin.active(!docPref.onionskin.active());
}
};

View File

@ -21,7 +21,6 @@
#include "app/pref/preferences.h"
#include "app/resource_finder.h"
#include "app/send_crash.h"
#include "app/settings/settings.h"
#include "app/ui/color_button.h"
#include "app/ui/editor/editor.h"
#include "base/bind.h"
@ -41,8 +40,7 @@ using namespace ui;
class OptionsWindow : public app::gen::Options {
public:
OptionsWindow(Context* context, int& curSection)
: m_settings(context->settings())
, m_preferences(App::instance()->preferences())
: m_preferences(Preferences::instance())
, m_globPref(m_preferences.document(nullptr))
, m_docPref(m_preferences.document(context->activeDocument()))
, m_curPref(&m_docPref)
@ -266,7 +264,7 @@ private:
}
void onReset() {
// Reset global settings (use default values specified in pref.xml)
// Reset global preferences (use default values specified in pref.xml)
if (m_curPref == &m_globPref) {
DocumentPreferences& pref = m_globPref;
@ -283,7 +281,7 @@ private:
m_checked_bg_color1->setColor(pref.bg.color1.defaultValue());
m_checked_bg_color2->setColor(pref.bg.color2.defaultValue());
}
// Reset document settings with global settings
// Reset document preferences with global settings
else {
DocumentPreferences& pref = m_globPref;
@ -310,7 +308,6 @@ private:
app::launcher::open_folder(app::main_config_filename());
}
ISettings* m_settings;
Preferences& m_preferences;
DocumentPreferences& m_globPref;
DocumentPreferences& m_docPref;
@ -337,7 +334,7 @@ OptionsCommand::OptionsCommand()
"Options",
CmdUIOnlyFlag)
{
Preferences& preferences = App::instance()->preferences();
Preferences& preferences = Preferences::instance();
ui::MenuBar::setExpandOnMouseover(
preferences.general.expandMenubarOnMouseover());

View File

@ -10,8 +10,8 @@
#endif
#include "app/app.h"
#include "app/cmd_sequence.h"
#include "app/cmd/set_palette.h"
#include "app/cmd_sequence.h"
#include "app/color.h"
#include "app/color_utils.h"
#include "app/commands/command.h"
@ -24,8 +24,7 @@
#include "app/modules/editors.h"
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/settings/settings.h"
#include "app/settings/settings.h"
#include "app/pref/preferences.h"
#include "app/transaction.h"
#include "app/ui/color_bar.h"
#include "app/ui/color_sliders.h"
@ -68,7 +67,7 @@ protected:
void onExit();
void onCloseWindow();
void onFgBgColorChange(const app::Color& color);
void onFgBgColorChange(const app::Color& _color);
void onColorSlidersChange(ColorSlidersChangeEvent& ev);
void onColorHexEntryChange(const app::Color& color);
void onColorTypeButtonClick(Event& ev);
@ -216,8 +215,8 @@ void PaletteEditorCommand::onExecute(Context* context)
// Show the specified target color
{
app::Color color =
(m_background ? context->settings()->getBgColor():
context->settings()->getFgColor());
(m_background ? Preferences::instance().colorBar.bgColor():
Preferences::instance().colorBar.fgColor());
g_window->setColor(color);
}
@ -293,8 +292,10 @@ PaletteEntryEditor::PaletteEntryEditor()
selectColorType(app::Color::RgbType);
// We hook fg/bg color changes (by eyedropper mainly) to update the selected entry color
ColorBar::instance()->FgColorChange.connect(&PaletteEntryEditor::onFgBgColorChange, this);
ColorBar::instance()->BgColorChange.connect(&PaletteEntryEditor::onFgBgColorChange, this);
Preferences::instance().colorBar.fgColor.AfterChange.connect(
&PaletteEntryEditor::onFgBgColorChange, this);
Preferences::instance().colorBar.bgColor.AfterChange.connect(
&PaletteEntryEditor::onFgBgColorChange, this);
// We hook the Window::Close event to save the frame position before closing it.
this->Close.connect(Bind<void>(&PaletteEntryEditor::onCloseWindow, this));

View File

@ -50,7 +50,7 @@ void RepeatLastExportCommand::onExecute(Context* context)
const ContextReader reader(context);
const Document* document(reader.document());
DocumentPreferences& docPref =
App::instance()->preferences().document(document);
Preferences::instance().document(document);
params.set("ui",
(docPref.spriteSheet.type() == app::gen::SpriteSheetType::NONE ? "1": "0"));

View File

@ -87,7 +87,7 @@ bool ScrollCommand::onEnabled(Context* context)
void ScrollCommand::onExecute(Context* context)
{
DocumentPreferences& docPref = App::instance()->preferences().document(context->activeDocument());
DocumentPreferences& docPref = Preferences::instance().document(context->activeDocument());
ui::View* view = ui::View::getView(current_editor);
gfx::Rect vp = view->getViewportBounds();
gfx::Point scroll = view->getViewScroll();

View File

@ -67,7 +67,7 @@ void UndoCommand::onExecute(Context* context)
Sprite* sprite = document->sprite();
SpritePosition spritePosition;
const bool gotoModified =
App::instance()->preferences().undo.gotoModified();
Preferences::instance().undo.gotoModified();
if (gotoModified) {
SpritePosition currentPosition(writer.site()->layerIndex(),

View File

@ -93,7 +93,7 @@ void ZoomCommand::onExecute(Context* context)
break;
}
bool center = App::instance()->preferences().editor.zoomFromCenterWithKeys();
bool center = Preferences::instance().editor.zoomFromCenterWithKeys();
editor->setZoomAndCenterInMouse(
zoom, mousePos,

View File

@ -176,8 +176,8 @@ void ConvolutionMatrixCommand::onExecute(Context* context)
m_stock.getByName(get_config_string(ConfigSection, "Selected", ""));
// Create the filter and setup initial settings
DocumentPreferences& docPref = App::instance()
->preferences().document(context->activeDocument());
DocumentPreferences& docPref = Preferences::instance()
.document(context->activeDocument());
ConvolutionMatrixFilter filter;
filter.setTiledMode(docPref.tiled.mode());

View File

@ -106,7 +106,8 @@ bool DespeckleCommand::onEnabled(Context* context)
void DespeckleCommand::onExecute(Context* context)
{
DocumentPreferences& docPref = App::instance()->preferences().document(context->activeDocument());
DocumentPreferences& docPref = Preferences::instance()
.document(context->activeDocument());
MedianFilter filter;
filter.setTiledMode((filters::TiledMode)docPref.tiled.mode());

View File

@ -16,7 +16,6 @@
#include "app/commands/commands.h"
#include "app/console.h"
#include "app/document.h"
#include "app/settings/settings.h"
#include <algorithm>
#include <stdexcept>
@ -24,21 +23,9 @@
namespace app {
Context::Context()
: m_settings(NULL)
{
}
Context::Context(ISettings* settings)
: m_settings(settings)
{
}
Context::~Context()
{
delete m_settings;
m_settings = NULL;
}
void Context::sendDocumentToTop(doc::Document* document)
{
ASSERT(document != NULL);

View File

@ -21,7 +21,6 @@
namespace app {
class Command;
class Document;
class ISettings;
class CommandPreconditionException : public base::Exception {
public:
@ -32,17 +31,12 @@ namespace app {
class Context : public doc::Context {
public:
Context();
// The "settings" are deleted automatically in the ~Context destructor
Context(ISettings* settings);
virtual ~Context();
virtual bool isUiAvailable() const { return false; }
virtual bool isRecordingMacro() const { return false; }
virtual bool isExecutingMacro() const { return false; }
virtual bool isExecutingScript() const { return false; }
app::ISettings* settings() { return m_settings; }
bool checkFlags(uint32_t flags) const { return m_flags.check(flags); }
void updateFlags() { m_flags.update(this); }
@ -60,9 +54,6 @@ namespace app {
virtual void onCreateDocument(doc::CreateDocumentArgs* args) override;
private:
// Settings in this context.
ISettings* m_settings;
// Last updated flags.
ContextFlags m_flags;

View File

@ -65,7 +65,7 @@ void BackupObserver::onRemoveDocument(doc::Document* document)
void BackupObserver::backgroundThread()
{
int normalPeriod = 60*App::instance()->preferences().general.dataRecoveryPeriod();
int normalPeriod = 60*Preferences::instance().general.dataRecoveryPeriod();
int lockedPeriod = 10;
#if 0 // Just for testing purposes
normalPeriod = 5;

View File

@ -11,6 +11,7 @@
#include "app/document.h"
#include "app/app.h"
#include "app/color_target.h"
#include "app/color_utils.h"
#include "app/context.h"
@ -18,7 +19,7 @@
#include "app/document_undo.h"
#include "app/file/format_options.h"
#include "app/flatten.h"
#include "app/settings/settings.h"
#include "app/pref/preferences.h"
#include "app/util/boundary.h"
#include "base/memory.h"
#include "base/mutex.h"
@ -94,26 +95,18 @@ DocumentApi Document::getApi(Transaction& transaction)
color_t Document::bgColor() const
{
app::ISettings* appSettings = nullptr;
if (app::Context* ctx = dynamic_cast<app::Context*>(context()))
appSettings = ctx->settings();
return color_utils::color_for_target(
(appSettings ? appSettings->getBgColor(): Color::fromMask()),
Preferences::instance().colorBar.bgColor(),
ColorTarget(ColorTarget::BackgroundLayer,
sprite()->pixelFormat(),
sprite()->transparentColor()));
sprite()->pixelFormat(),
sprite()->transparentColor()));
}
color_t Document::bgColor(Layer* layer) const
{
app::ISettings* appSettings = nullptr;
if (app::Context* ctx = dynamic_cast<app::Context*>(context()))
appSettings = ctx->settings();
if (layer->isBackground())
return color_utils::color_for_layer(
appSettings ? appSettings->getBgColor(): Color::fromMask(),
Preferences::instance().colorBar.bgColor(),
layer);
else
return layer->sprite()->transparentColor();

View File

@ -45,7 +45,6 @@
#include "app/color_utils.h"
#include "app/document.h"
#include "app/document_undo.h"
#include "app/settings/settings.h"
#include "app/transaction.h"
#include "base/unique_ptr.h"
#include "doc/algorithm/flip_image.h"

View File

@ -26,7 +26,7 @@ std::string show_file_selector(const std::string& title,
const std::string& showExtensions,
FileSelectorType type)
{
if (App::instance()->preferences().experimental.useNativeFileDialog() &&
if (Preferences::instance().experimental.useNativeFileDialog() &&
she::instance()->nativeDialogs()) {
she::FileDialog* dlg =
she::instance()->nativeDialogs()->createFileDialog();

View File

@ -21,7 +21,6 @@
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/pref/preferences.h"
#include "app/settings/settings.h"
#include "app/tools/ink.h"
#include "app/tools/tool_box.h"
#include "app/ui/editor/editor.h"
@ -96,7 +95,7 @@ static void save_gui_config();
static int get_screen_scale()
{
int scale = App::instance()->preferences().general.screenScale();
int scale = Preferences::instance().general.screenScale();
scale = MID(1, scale, 4);
return scale;
}
@ -126,7 +125,7 @@ int init_module_gui()
try_resolutions[c].scale);
scale = try_resolutions[c].scale;
App::instance()->preferences().general.screenScale(scale);
Preferences::instance().general.screenScale(scale);
break;
}
catch (const she::DisplayCreationException&) {
@ -149,7 +148,7 @@ int init_module_gui()
// Setup the GUI theme for all widgets
gui_theme = new SkinTheme();
gui_theme->setScale(App::instance()->preferences().experimental.uiScale());
gui_theme->setScale(Preferences::instance().experimental.uiScale());
CurrentTheme::set(gui_theme);
if (maximized)
@ -427,7 +426,7 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
switch (key->type()) {
case KeyType::Tool: {
tools::Tool* current_tool = UIContext::instance()->settings()->getCurrentTool();
tools::Tool* current_tool = App::instance()->activeTool();
tools::Tool* select_this_tool = key->tool();
tools::ToolBox* toolbox = App::instance()->getToolBox();
std::vector<tools::Tool*> possibles;

View File

@ -58,7 +58,7 @@ namespace app {
if (m_value == newValue)
return m_value;
BeforeChange(*this, newValue);
BeforeChange(newValue);
if (m_section)
m_section->BeforeChange();
@ -66,15 +66,15 @@ namespace app {
m_value = newValue;
m_dirty = true;
AfterChange(*this, oldValue);
AfterChange(oldValue);
if (m_section)
m_section->AfterChange();
return m_value;
}
Signal2<void, Option&, const T&> BeforeChange;
Signal2<void, Option&, const T&> AfterChange;
Signal1<void, const T&> BeforeChange;
Signal1<void, const T&> AfterChange;
private:
Section* m_section;

View File

@ -17,9 +17,21 @@
namespace app {
static Preferences* singleton = nullptr;
// static
Preferences& Preferences::instance()
{
ASSERT(singleton);
return *singleton;
}
Preferences::Preferences()
: app::gen::GlobalPref("")
{
ASSERT(!singleton);
singleton = this;
load();
}
@ -32,6 +44,9 @@ Preferences::~Preferences()
for (auto& pair : m_docs)
delete pair.second;
ASSERT(singleton == this);
singleton = nullptr;
}
void Preferences::load()

View File

@ -9,8 +9,18 @@
#define APP_PREF_PREFERENCES_H_INCLUDED
#pragma once
#include "app/color.h"
#include "app/pref/option.h"
#include "app/tools/freehand_algorithm.h"
#include "app/tools/ink_type.h"
#include "app/tools/rotation_algorithm.h"
#include "app/tools/selection_mode.h"
#include "doc/anidir.h"
#include "doc/brush_pattern.h"
#include "doc/documents_observer.h"
#include "doc/frame.h"
#include "filters/tiled_mode.h"
#include "gfx/rect.h"
#include "generated_pref_types.h"
@ -31,6 +41,8 @@ namespace app {
class Preferences : public app::gen::GlobalPref
, public doc::DocumentsObserver {
public:
static Preferences& instance();
Preferences();
~Preferences();

View File

@ -1,35 +0,0 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_SETTINGS_INK_TYPE_H_INCLUDED
#define APP_SETTINGS_INK_TYPE_H_INCLUDED
#pragma once
namespace app {
// If you change this enumeration, you should update the
// ContextBar::InkTypeField() UI widget. Also, remember that these
// indexes are loaded/saved from/to the user configuration file, so
// you shouldn't change them.
enum InkType {
kDefaultInk,
kOpaqueInk,
kSetAlphaInk,
kLockAlphaInk,
kMergeInk,
kShadingInk,
kReplaceInk,
kEraseInk,
kSelectionInk,
kBlurInk,
kJumbleInk,
kMaxInks
};
} // namespace app
#endif // APP_SETTINGS_INK_TYPE_H_INCLUDED

View File

@ -1,138 +0,0 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_SETTINGS_SETTINGS_H_INCLUDED
#define APP_SETTINGS_SETTINGS_H_INCLUDED
#pragma once
#include "app/color.h"
#include "app/settings/freehand_algorithm.h"
#include "app/settings/ink_type.h"
#include "app/settings/rotation_algorithm.h"
#include "app/settings/selection_mode.h"
#include "gfx/point.h"
#include "gfx/rect.h"
#include "doc/brush_type.h"
namespace doc {
class Document;
}
namespace app {
class ColorSwatches;
class IColorSwatchesStore;
class IBrushSettings;
class BrushSettingsObserver;
class IToolSettings;
class ToolSettingsObserver;
class ISelectionSettings;
class SelectionSettingsObserver;
namespace tools {
class Tool;
}
class ISettings {
public:
virtual ~ISettings() { }
// General settings
virtual app::Color getFgColor() = 0;
virtual app::Color getBgColor() = 0;
virtual tools::Tool* getCurrentTool() = 0;
virtual app::ColorSwatches* getColorSwatches() = 0;
virtual void setFgColor(const app::Color& color) = 0;
virtual void setBgColor(const app::Color& color) = 0;
virtual void setCurrentTool(tools::Tool* tool) = 0;
virtual void setColorSwatches(app::ColorSwatches* colorSwatches) = 0;
// Specific configuration for the given tool.
virtual IToolSettings* getToolSettings(tools::Tool* tool) = 0;
// Specific configuration for the current selection
virtual ISelectionSettings* selection() = 0;
virtual IColorSwatchesStore* getColorSwatchesStore() = 0;
};
// Tool's settings
class IToolSettings {
public:
virtual ~IToolSettings() { }
virtual IBrushSettings* getBrush() = 0;
virtual int getOpacity() = 0;
virtual int getTolerance() = 0;
virtual bool getContiguous() = 0;
virtual bool getFilled() = 0;
virtual bool getPreviewFilled() = 0;
virtual int getSprayWidth() = 0;
virtual int getSpraySpeed() = 0;
virtual InkType getInkType() = 0;
virtual FreehandAlgorithm getFreehandAlgorithm() = 0;
virtual void setOpacity(int opacity) = 0;
virtual void setTolerance(int tolerance) = 0;
virtual void setContiguous(bool state) = 0;
virtual void setFilled(bool state) = 0;
virtual void setPreviewFilled(bool state) = 0;
virtual void setSprayWidth(int width) = 0;
virtual void setSpraySpeed(int speed) = 0;
virtual void setInkType(InkType inkType) = 0;
virtual void setFreehandAlgorithm(FreehandAlgorithm algorithm) = 0;
virtual void addObserver(ToolSettingsObserver* observer) = 0;
virtual void removeObserver(ToolSettingsObserver* observer) = 0;
};
// Settings for a tool's brush
class IBrushSettings {
public:
virtual ~IBrushSettings() { }
virtual doc::BrushType getType() = 0;
virtual int getSize() = 0;
virtual int getAngle() = 0;
virtual void setType(BrushType type) = 0;
virtual void setSize(int size) = 0;
virtual void setAngle(int angle) = 0;
virtual void addObserver(BrushSettingsObserver* observer) = 0;
virtual void removeObserver(BrushSettingsObserver* observer) = 0;
};
class ISelectionSettings {
public:
virtual ~ISelectionSettings() {}
// Mask color used during a move operation
virtual SelectionMode getSelectionMode() = 0;
virtual app::Color getMoveTransparentColor() = 0;
virtual RotationAlgorithm getRotationAlgorithm() = 0;
virtual void setSelectionMode(SelectionMode mode) = 0;
virtual void setMoveTransparentColor(app::Color color) = 0;
virtual void setRotationAlgorithm(RotationAlgorithm algorithm) = 0;
virtual void addObserver(SelectionSettingsObserver* observer) = 0;
virtual void removeObserver(SelectionSettingsObserver* observer) = 0;
};
class IColorSwatchesStore {
public:
virtual ~IColorSwatchesStore() { }
virtual void addColorSwatches(app::ColorSwatches* colorSwatches) = 0;
virtual void removeColorSwatches(app::ColorSwatches* colorSwatches) = 0;
};
} // namespace app
#endif

View File

@ -1,63 +0,0 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_SETTINGS_SETTINGS_OBSERVERS_H_INCLUDED
#define APP_SETTINGS_SETTINGS_OBSERVERS_H_INCLUDED
#pragma once
#include "app/color.h"
#include "app/settings/freehand_algorithm.h"
#include "app/settings/ink_type.h"
#include "app/settings/rotation_algorithm.h"
#include "app/settings/selection_mode.h"
#include "filters/tiled_mode.h"
#include "gfx/fwd.h"
#include "doc/brush_type.h"
namespace app {
class Color;
namespace tools {
class Tool;
}
class ColorSwatches;
class BrushSettingsObserver {
public:
virtual ~BrushSettingsObserver() {}
virtual void onSetBrushSize(int newSize) {}
virtual void onSetBrushType(doc::BrushType newType) {}
virtual void onSetBrushAngle(int newAngle) {}
};
class ToolSettingsObserver {
public:
virtual ~ToolSettingsObserver() {}
virtual void onSetOpacity(int newOpacity) {}
virtual void onSetTolerance(int newTolerance) {}
virtual void onSetFilled(bool filled) {}
virtual void onSetPreviewFilled(bool previewFilled) {}
virtual void onSetSprayWidth(int newSprayWidth) {}
virtual void onSetSpraySpeed(int newSpraySpeed) {}
virtual void onSetInkType(InkType newInkType) {}
virtual void onSetFreehandAlgorithm(FreehandAlgorithm algorithm) {}
};
class SelectionSettingsObserver {
public:
virtual ~SelectionSettingsObserver() {}
virtual void onSetSelectionMode(SelectionMode mode) {}
virtual void onSetMoveTransparentColor(app::Color newColor) {}
virtual void onSetRotationAlgorithm(RotationAlgorithm algorithm) {}
};
} // namespace app
#endif // APP_SETTINGS_SETTINGS_OBSERVERS_H_INCLUDED

View File

@ -1,498 +0,0 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/settings/ui_settings_impl.h"
#include "app/app.h"
#include "app/color_swatches.h"
#include "app/document.h"
#include "app/ini_file.h"
#include "app/resource_finder.h"
#include "app/tools/controller.h"
#include "app/tools/ink.h"
#include "app/tools/point_shape.h"
#include "app/tools/tool.h"
#include "app/tools/tool_box.h"
#include "app/ui/color_bar.h"
#include "app/ui_context.h"
#include "base/observable.h"
#include "doc/brush.h"
#include "doc/context.h"
#include "doc/documents_observer.h"
#include "ui/manager.h"
#include "ui/system.h"
#include <algorithm>
#include <string>
#define DEFAULT_ONIONSKIN_TYPE Onionskin_Merge
#define DEFAULT_ONIONSKIN_OPACITY_BASE 68
#define DEFAULT_ONIONSKIN_OPACITY_STEP 28
namespace app {
using namespace gfx;
using namespace doc;
using namespace filters;
namespace {
class UISelectionSettingsImpl
: public ISelectionSettings
, public base::Observable<SelectionSettingsObserver> {
public:
UISelectionSettingsImpl();
virtual ~UISelectionSettingsImpl();
SelectionMode getSelectionMode();
app::Color getMoveTransparentColor();
RotationAlgorithm getRotationAlgorithm();
void setSelectionMode(SelectionMode mode);
void setMoveTransparentColor(app::Color color);
void setRotationAlgorithm(RotationAlgorithm algorithm);
void addObserver(SelectionSettingsObserver* observer);
void removeObserver(SelectionSettingsObserver* observer);
private:
SelectionMode m_selectionMode;
app::Color m_moveTransparentColor;
RotationAlgorithm m_rotationAlgorithm;
};
} // anonymous namespace
//////////////////////////////////////////////////////////////////////
// UISettingsImpl
UISettingsImpl::UISettingsImpl()
: m_currentTool(NULL)
, m_colorSwatches(NULL)
, m_selectionSettings(new UISelectionSettingsImpl)
{
m_colorSwatches = new app::ColorSwatches("Default");
for (size_t i=0; i<16; ++i)
m_colorSwatches->addColor(app::Color::fromIndex(i));
addColorSwatches(m_colorSwatches);
}
UISettingsImpl::~UISettingsImpl()
{
for (auto it : m_toolSettings)
delete it.second;
for (auto it : m_colorSwatchesStore)
delete it;
}
//////////////////////////////////////////////////////////////////////
// General settings
app::Color UISettingsImpl::getFgColor()
{
ColorBar* colorbar = ColorBar::instance();
return colorbar ? colorbar->getFgColor(): app::Color::fromMask();
}
app::Color UISettingsImpl::getBgColor()
{
ColorBar* colorbar = ColorBar::instance();
return colorbar ? colorbar->getBgColor(): app::Color::fromMask();
}
tools::Tool* UISettingsImpl::getCurrentTool()
{
if (!m_currentTool)
m_currentTool = App::instance()->getToolBox()->getToolById("pencil");
return m_currentTool;
}
app::ColorSwatches* UISettingsImpl::getColorSwatches()
{
return m_colorSwatches;
}
void UISettingsImpl::setFgColor(const app::Color& color)
{
ColorBar::instance()->setFgColor(color);
}
void UISettingsImpl::setBgColor(const app::Color& color)
{
ColorBar::instance()->setBgColor(color);
}
void UISettingsImpl::setCurrentTool(tools::Tool* tool)
{
if (m_currentTool != tool) {
// Fire signals (maybe the new selected tool has a different brush size)
App::instance()->BrushSizeBeforeChange();
App::instance()->BrushAngleBeforeChange();
// Change the tool
m_currentTool = tool;
App::instance()->CurrentToolChange(); // Fire CurrentToolChange signal
App::instance()->BrushSizeAfterChange(); // Fire BrushSizeAfterChange signal
App::instance()->BrushAngleAfterChange(); // Fire BrushAngleAfterChange signal
}
}
void UISettingsImpl::setColorSwatches(app::ColorSwatches* colorSwatches)
{
m_colorSwatches = colorSwatches;
}
IColorSwatchesStore* UISettingsImpl::getColorSwatchesStore()
{
return this;
}
void UISettingsImpl::addColorSwatches(app::ColorSwatches* colorSwatches)
{
m_colorSwatchesStore.push_back(colorSwatches);
}
void UISettingsImpl::removeColorSwatches(app::ColorSwatches* colorSwatches)
{
std::vector<app::ColorSwatches*>::iterator it =
std::find(m_colorSwatchesStore.begin(),
m_colorSwatchesStore.end(),
colorSwatches);
ASSERT(it != m_colorSwatchesStore.end());
if (it != m_colorSwatchesStore.end())
m_colorSwatchesStore.erase(it);
}
ISelectionSettings* UISettingsImpl::selection()
{
return m_selectionSettings;
}
//////////////////////////////////////////////////////////////////////
// Tools & brush settings
class UIBrushSettingsImpl
: public IBrushSettings
, public base::Observable<BrushSettingsObserver> {
private:
BrushType m_type;
int m_size;
int m_angle;
bool m_fireSignals;
public:
UIBrushSettingsImpl()
{
m_type = kFirstBrushType;
m_size = 1;
m_angle = 0;
m_fireSignals = true;
}
~UIBrushSettingsImpl()
{
}
BrushType getType() { return m_type; }
int getSize() { return m_size; }
int getAngle() { return m_angle; }
void setType(BrushType type)
{
m_type = MID(kFirstBrushType, type, kLastBrushType);
notifyObservers<BrushType>(&BrushSettingsObserver::onSetBrushType, m_type);
}
void setSize(int size)
{
// Trigger BrushSizeBeforeChange signal
if (m_fireSignals)
App::instance()->BrushSizeBeforeChange();
// Change the size of the brushcil
m_size = MID(doc::Brush::kMinBrushSize, size, doc::Brush::kMaxBrushSize);
// Trigger BrushSizeAfterChange signal
if (m_fireSignals)
App::instance()->BrushSizeAfterChange();
notifyObservers<int>(&BrushSettingsObserver::onSetBrushSize, m_size);
}
void setAngle(int angle)
{
// Trigger BrushAngleBeforeChange signal
if (m_fireSignals)
App::instance()->BrushAngleBeforeChange();
m_angle = MID(0, angle, 360);
// Trigger BrushAngleAfterChange signal
if (m_fireSignals)
App::instance()->BrushAngleAfterChange();
}
void enableSignals(bool state)
{
m_fireSignals = state;
}
void addObserver(BrushSettingsObserver* observer) override{
base::Observable<BrushSettingsObserver>::addObserver(observer);
}
void removeObserver(BrushSettingsObserver* observer) override{
base::Observable<BrushSettingsObserver>::removeObserver(observer);
}
};
class UIToolSettingsImpl
: public IToolSettings
, base::Observable<ToolSettingsObserver> {
tools::Tool* m_tool;
UIBrushSettingsImpl m_brush;
int m_opacity;
int m_tolerance;
bool m_contiguous;
bool m_filled;
bool m_previewFilled;
int m_spray_width;
int m_spray_speed;
InkType m_inkType;
FreehandAlgorithm m_freehandAlgorithm;
public:
UIToolSettingsImpl(tools::Tool* tool)
: m_tool(tool)
{
std::string cfg_section(getCfgSection());
m_opacity = get_config_int(cfg_section.c_str(), "Opacity", 255);
m_opacity = MID(0, m_opacity, 255);
m_tolerance = get_config_int(cfg_section.c_str(), "Tolerance", 0);
m_tolerance = MID(0, m_tolerance, 255);
m_contiguous = get_config_bool(cfg_section.c_str(), "Contiguous", true);
m_filled = false;
m_previewFilled = get_config_bool(cfg_section.c_str(), "PreviewFilled", false);
m_spray_width = 16;
m_spray_speed = 32;
m_inkType = (InkType)get_config_int(cfg_section.c_str(), "InkType", (int)kDefaultInk);
m_freehandAlgorithm = kDefaultFreehandAlgorithm;
// Reset invalid configurations for inks.
if (m_inkType != kDefaultInk &&
m_inkType != kSetAlphaInk &&
m_inkType != kLockAlphaInk)
m_inkType = kDefaultInk;
m_brush.enableSignals(false);
m_brush.setType((BrushType)get_config_int(cfg_section.c_str(), "BrushType", (int)kCircleBrushType));
m_brush.setSize(get_config_int(cfg_section.c_str(), "BrushSize", m_tool->getDefaultBrushSize()));
m_brush.setAngle(get_config_int(cfg_section.c_str(), "BrushAngle", 0));
m_brush.enableSignals(true);
if (m_tool->getPointShape(0)->isSpray() ||
m_tool->getPointShape(1)->isSpray()) {
m_spray_width = get_config_int(cfg_section.c_str(), "SprayWidth", m_spray_width);
m_spray_speed = get_config_int(cfg_section.c_str(), "SpraySpeed", m_spray_speed);
}
if (m_tool->getController(0)->isFreehand() ||
m_tool->getController(1)->isFreehand()) {
m_freehandAlgorithm = (FreehandAlgorithm)get_config_int(cfg_section.c_str(), "FreehandAlgorithm", (int)kDefaultFreehandAlgorithm);
setFreehandAlgorithm(m_freehandAlgorithm);
}
}
~UIToolSettingsImpl()
{
std::string cfg_section(getCfgSection());
set_config_int(cfg_section.c_str(), "Opacity", m_opacity);
set_config_int(cfg_section.c_str(), "Tolerance", m_tolerance);
set_config_bool(cfg_section.c_str(), "Contiguous", m_contiguous);
set_config_int(cfg_section.c_str(), "BrushType", m_brush.getType());
set_config_int(cfg_section.c_str(), "BrushSize", m_brush.getSize());
set_config_int(cfg_section.c_str(), "BrushAngle", m_brush.getAngle());
set_config_int(cfg_section.c_str(), "BrushAngle", m_brush.getAngle());
set_config_int(cfg_section.c_str(), "InkType", m_inkType);
set_config_bool(cfg_section.c_str(), "PreviewFilled", m_previewFilled);
if (m_tool->getPointShape(0)->isSpray() ||
m_tool->getPointShape(1)->isSpray()) {
set_config_int(cfg_section.c_str(), "SprayWidth", m_spray_width);
set_config_int(cfg_section.c_str(), "SpraySpeed", m_spray_speed);
}
if (m_tool->getController(0)->isFreehand() ||
m_tool->getController(1)->isFreehand()) {
set_config_int(cfg_section.c_str(), "FreehandAlgorithm", m_freehandAlgorithm);
}
}
IBrushSettings* getBrush() { return &m_brush; }
int getOpacity() override { return m_opacity; }
int getTolerance() override { return m_tolerance; }
bool getContiguous() override { return m_contiguous; }
bool getFilled() override { return m_filled; }
bool getPreviewFilled() override { return m_previewFilled; }
int getSprayWidth() override { return m_spray_width; }
int getSpraySpeed() override { return m_spray_speed; }
InkType getInkType() override { return m_inkType; }
FreehandAlgorithm getFreehandAlgorithm() override { return m_freehandAlgorithm; }
void setOpacity(int opacity) override { m_opacity = opacity; }
void setTolerance(int tolerance) override { m_tolerance = tolerance; }
void setContiguous(bool state) override { m_contiguous = state; }
void setFilled(bool state) override { m_filled = state; }
void setPreviewFilled(bool state) override { m_previewFilled = state; }
void setSprayWidth(int width) override { m_spray_width = width; }
void setSpraySpeed(int speed) override { m_spray_speed = speed; }
void setInkType(InkType inkType) override { m_inkType = inkType; }
void setFreehandAlgorithm(FreehandAlgorithm algorithm) override {
m_freehandAlgorithm = algorithm;
tools::ToolBox* toolBox = App::instance()->getToolBox();
for (int i=0; i<2; ++i) {
if (m_tool->getTracePolicy(i) != tools::TracePolicy::Accumulate &&
m_tool->getTracePolicy(i) != tools::TracePolicy::AccumulateUpdateLast) {
continue;
}
switch (algorithm) {
case kDefaultFreehandAlgorithm:
m_tool->setIntertwine(i, toolBox->getIntertwinerById(tools::WellKnownIntertwiners::AsLines));
m_tool->setTracePolicy(i, tools::TracePolicy::Accumulate);
break;
case kPixelPerfectFreehandAlgorithm:
m_tool->setIntertwine(i, toolBox->getIntertwinerById(tools::WellKnownIntertwiners::AsPixelPerfect));
m_tool->setTracePolicy(i, tools::TracePolicy::AccumulateUpdateLast);
break;
case kDotsFreehandAlgorithm:
m_tool->setIntertwine(i, toolBox->getIntertwinerById(tools::WellKnownIntertwiners::None));
m_tool->setTracePolicy(i, tools::TracePolicy::Accumulate);
break;
}
}
}
void addObserver(ToolSettingsObserver* observer) override {
base::Observable<ToolSettingsObserver>::addObserver(observer);
}
void removeObserver(ToolSettingsObserver* observer) override{
base::Observable<ToolSettingsObserver>::removeObserver(observer);
}
private:
std::string getCfgSection() const {
return std::string("Tool:") + m_tool->getId();
}
};
IToolSettings* UISettingsImpl::getToolSettings(tools::Tool* tool)
{
ASSERT(tool != NULL);
std::map<std::string, IToolSettings*>::iterator
it = m_toolSettings.find(tool->getId());
if (it != m_toolSettings.end()) {
return it->second;
}
else {
IToolSettings* tool_settings = new UIToolSettingsImpl(tool);
m_toolSettings[tool->getId()] = tool_settings;
return tool_settings;
}
}
//////////////////////////////////////////////////////////////////////
// Selection Settings
namespace {
UISelectionSettingsImpl::UISelectionSettingsImpl() :
m_selectionMode(kDefaultSelectionMode),
m_moveTransparentColor(app::Color::fromMask()),
m_rotationAlgorithm(kFastRotationAlgorithm)
{
m_selectionMode = (SelectionMode)get_config_int("Tools", "SelectionMode", m_selectionMode);
m_selectionMode = MID(
kFirstSelectionMode,
m_selectionMode,
kLastSelectionMode);
m_rotationAlgorithm = (RotationAlgorithm)get_config_int("Tools", "RotAlgorithm", m_rotationAlgorithm);
m_rotationAlgorithm = MID(
kFirstRotationAlgorithm,
m_rotationAlgorithm,
kLastRotationAlgorithm);
}
UISelectionSettingsImpl::~UISelectionSettingsImpl()
{
set_config_int("Tools", "SelectionMode", (int)m_selectionMode);
set_config_int("Tools", "RotAlgorithm", (int)m_rotationAlgorithm);
}
SelectionMode UISelectionSettingsImpl::getSelectionMode()
{
return m_selectionMode;
}
app::Color UISelectionSettingsImpl::getMoveTransparentColor()
{
return m_moveTransparentColor;
}
RotationAlgorithm UISelectionSettingsImpl::getRotationAlgorithm()
{
return m_rotationAlgorithm;
}
void UISelectionSettingsImpl::setSelectionMode(SelectionMode mode)
{
m_selectionMode = mode;
notifyObservers(&SelectionSettingsObserver::onSetSelectionMode, mode);
}
void UISelectionSettingsImpl::setMoveTransparentColor(app::Color color)
{
m_moveTransparentColor = color;
notifyObservers(&SelectionSettingsObserver::onSetMoveTransparentColor, color);
}
void UISelectionSettingsImpl::setRotationAlgorithm(RotationAlgorithm algorithm)
{
m_rotationAlgorithm = algorithm;
notifyObservers(&SelectionSettingsObserver::onSetRotationAlgorithm, algorithm);
}
void UISelectionSettingsImpl::addObserver(SelectionSettingsObserver* observer)
{
base::Observable<SelectionSettingsObserver>::addObserver(observer);
}
void UISelectionSettingsImpl::removeObserver(SelectionSettingsObserver* observer)
{
base::Observable<SelectionSettingsObserver>::removeObserver(observer);
}
} // anonymous namespace
} // namespace app

View File

@ -1,63 +0,0 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_SETTINGS_UI_SETTINGS_H_INCLUDED
#define APP_SETTINGS_UI_SETTINGS_H_INCLUDED
#pragma once
#include <map>
#include <string>
#include <vector>
#include "app/settings/settings.h"
#include "app/settings/settings_observers.h"
#include "base/observable.h"
#include "base/unique_ptr.h"
#include "doc/object_id.h"
namespace app {
class UISettingsImpl
: public ISettings
, public IColorSwatchesStore {
public:
UISettingsImpl();
~UISettingsImpl();
// ISettings implementation
app::Color getFgColor() override;
app::Color getBgColor() override;
tools::Tool* getCurrentTool() override;
app::ColorSwatches* getColorSwatches() override;
void setFgColor(const app::Color& color) override;
void setBgColor(const app::Color& color) override;
void setCurrentTool(tools::Tool* tool) override;
void setColorSwatches(app::ColorSwatches* colorSwatches) override;
IToolSettings* getToolSettings(tools::Tool* tool) override;
IColorSwatchesStore* getColorSwatchesStore() override;
ISelectionSettings* selection() override;
// IColorSwatchesStore implementation
void addColorSwatches(app::ColorSwatches* colorSwatches) override;
void removeColorSwatches(app::ColorSwatches* colorSwatches) override;
private:
tools::Tool* m_currentTool;
std::map<std::string, IToolSettings*> m_toolSettings;
app::ColorSwatches* m_colorSwatches;
std::vector<app::ColorSwatches*> m_colorSwatchesStore;
base::UniquePtr<ISelectionSettings> m_selectionSettings;
bool m_grabAlpha;
};
} // namespace app
#endif

View File

@ -5,18 +5,21 @@
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_SETTINGS_FREEHAND_ALGORITHM_H_INCLUDED
#define APP_SETTINGS_FREEHAND_ALGORITHM_H_INCLUDED
#ifndef APP_TOOLS_FREEHAND_ALGORITHM_H_INCLUDED
#define APP_TOOLS_FREEHAND_ALGORITHM_H_INCLUDED
#pragma once
namespace app {
namespace tools {
enum FreehandAlgorithm {
kDefaultFreehandAlgorithm,
kPixelPerfectFreehandAlgorithm,
kDotsFreehandAlgorithm,
enum class FreehandAlgorithm {
DEFAULT = 0,
REGULAR = 0,
PIXEL_PERFECT = 1,
DOTS = 2,
};
} // namespace tools
} // namespace app
#endif // APP_SETTINGS_FREEHAND_ALGORITHM_H_INCLUDED
#endif

24
src/app/tools/ink_type.h Normal file
View File

@ -0,0 +1,24 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_TOOLS_INK_TYPE_H_INCLUDED
#define APP_TOOLS_INK_TYPE_H_INCLUDED
#pragma once
namespace app {
namespace tools {
enum class InkType {
DEFAULT = 0,
SET_ALPHA = 1,
LOCK_ALPHA = 2,
};
} // namespace tools
} // namespace app
#endif

View File

@ -12,7 +12,6 @@
#include "app/context.h"
#include "app/document.h"
#include "app/document_undo.h"
#include "app/settings/settings.h"
#include "app/tools/pick_ink.h"
#include "doc/mask.h"
#include "gfx/region.h"
@ -46,10 +45,8 @@ public:
case WithFg:
case WithBg:
{
int color = color_utils::color_for_layer(m_type == WithFg ?
loop->settings()->getFgColor():
loop->settings()->getBgColor(),
loop->getLayer());
int color = (m_type == WithFg ? loop->getFgColor():
loop->getBgColor());
loop->setPrimaryColor(color);
loop->setSecondaryColor(color);
}
@ -177,19 +174,15 @@ public:
case ReplaceFgWithBg:
m_proc = ink_processing[INK_REPLACE][MID(0, loop->sprite()->pixelFormat(), 2)];
loop->setPrimaryColor(color_utils::color_for_layer(loop->settings()->getFgColor(),
loop->getLayer()));
loop->setSecondaryColor(color_utils::color_for_layer(loop->settings()->getBgColor(),
loop->getLayer()));
loop->setPrimaryColor(loop->getFgColor());
loop->setSecondaryColor(loop->getBgColor());
break;
case ReplaceBgWithFg:
m_proc = ink_processing[INK_REPLACE][MID(0, loop->sprite()->pixelFormat(), 2)];
loop->setPrimaryColor(color_utils::color_for_layer(loop->settings()->getBgColor(),
loop->getLayer()));
loop->setSecondaryColor(color_utils::color_for_layer(loop->settings()->getFgColor(),
loop->getLayer()));
loop->setPrimaryColor(loop->getBgColor());
loop->setSecondaryColor(loop->getFgColor());
break;
}
}
@ -273,11 +266,11 @@ public:
Point offset = loop->getOffset();
switch (loop->getSelectionMode()) {
case kDefaultSelectionMode:
case kAddSelectionMode:
case SelectionMode::DEFAULT:
case SelectionMode::ADD:
m_mask.add(gfx::Rect(x1-offset.x, y-offset.y, x2-x1+1, 1));
break;
case kSubtractSelectionMode:
case SelectionMode::SUBTRACT:
m_mask.subtract(gfx::Rect(x1-offset.x, y-offset.y, x2-x1+1, 1));
break;
}

View File

@ -5,20 +5,20 @@
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_SETTINGS_ROTATION_ALGORITHM_H_INCLUDED
#define APP_SETTINGS_ROTATION_ALGORITHM_H_INCLUDED
#ifndef APP_TOOLS_ROTATION_ALGORITHM_H_INCLUDED
#define APP_TOOLS_ROTATION_ALGORITHM_H_INCLUDED
#pragma once
namespace app {
namespace tools {
enum RotationAlgorithm {
kFastRotationAlgorithm,
kRotSpriteRotationAlgorithm,
kFirstRotationAlgorithm = kFastRotationAlgorithm,
kLastRotationAlgorithm = kRotSpriteRotationAlgorithm
enum class RotationAlgorithm {
DEFAULT = 0,
FAST = 0,
ROTSPRITE = 1,
};
} // namespace tools
} // namespace app
#endif

View File

@ -5,21 +5,20 @@
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_SETTINGS_SELECTION_MODE_H_INCLUDED
#define APP_SETTINGS_SELECTION_MODE_H_INCLUDED
#ifndef APP_TOOLS_SELECTION_MODE_H_INCLUDED
#define APP_TOOLS_SELECTION_MODE_H_INCLUDED
#pragma once
namespace app {
namespace tools {
enum SelectionMode {
kDefaultSelectionMode,
kAddSelectionMode,
kSubtractSelectionMode,
kFirstSelectionMode = kDefaultSelectionMode,
kLastSelectionMode = kSubtractSelectionMode
enum class SelectionMode {
DEFAULT = 0,
ADD = 1,
SUBTRACT = 2,
};
} // namespace tools
} // namespace app
#endif

View File

@ -12,12 +12,14 @@
#include "app/tools/tool_box.h"
#include "app/gui_xml.h"
#include "app/pref/preferences.h"
#include "app/tools/controller.h"
#include "app/tools/ink.h"
#include "app/tools/intertwine.h"
#include "app/tools/point_shape.h"
#include "app/tools/tool_group.h"
#include "app/tools/tool_loop.h"
#include "base/bind.h"
#include "base/exception.h"
#include "doc/algo.h"
#include "doc/algorithm/floodfill.h"
@ -78,7 +80,50 @@ const char* WellKnownPointShapes::Brush = "brush";
const char* WellKnownPointShapes::FloodFill = "floodfill";
const char* WellKnownPointShapes::Spray = "spray";
// Observes changes in the freehand algorithm of each tool to adjust
// the intertwiner and trace policy of each tool depending on the
// selected value.
class PreferencesGlue {
public:
PreferencesGlue(ToolBox* toolBox) : m_toolBox(toolBox) {
for (Tool* tool : *m_toolBox)
Preferences::instance().tool(tool).freehandAlgorithm.AfterChange.connect(
Bind<void>(&PreferencesGlue::onFreehandAlgorithmChange, this, tool));
}
private:
void onFreehandAlgorithmChange(Tool* tool) {
FreehandAlgorithm algorithm = Preferences::instance().tool(tool).freehandAlgorithm();
for (int i=0; i<2; ++i) {
if (tool->getTracePolicy(i) != TracePolicy::Accumulate &&
tool->getTracePolicy(i) != TracePolicy::AccumulateUpdateLast) {
continue;
}
switch (algorithm) {
case FreehandAlgorithm::DEFAULT:
tool->setIntertwine(i, m_toolBox->getIntertwinerById(WellKnownIntertwiners::AsLines));
tool->setTracePolicy(i, TracePolicy::Accumulate);
break;
case FreehandAlgorithm::PIXEL_PERFECT:
tool->setIntertwine(i, m_toolBox->getIntertwinerById(WellKnownIntertwiners::AsPixelPerfect));
tool->setTracePolicy(i, TracePolicy::AccumulateUpdateLast);
break;
case FreehandAlgorithm::DOTS:
tool->setIntertwine(i, m_toolBox->getIntertwinerById(WellKnownIntertwiners::None));
tool->setTracePolicy(i, TracePolicy::Accumulate);
break;
}
}
}
private:
ToolBox* m_toolBox;
};
ToolBox::ToolBox()
: m_preferencesGlue(nullptr)
{
PRINTF("Toolbox module: installing\n");
@ -123,6 +168,8 @@ ToolBox::ToolBox()
loadTools();
m_preferencesGlue.reset(new PreferencesGlue(this));
PRINTF("Toolbox module: installed\n");
}

View File

@ -14,6 +14,7 @@
#include <string>
#include "app/tools/tool.h"
#include "base/unique_ptr.h"
class TiXmlElement;
@ -72,6 +73,8 @@ namespace app {
typedef std::list<ToolGroup*> ToolGroupList;
class PreferencesGlue;
// Loads and maintains the group of tools specified in the gui.xml file
class ToolBox {
public:
@ -103,6 +106,7 @@ namespace app {
ToolGroupList m_groups;
ToolList m_tools;
base::UniquePtr<PreferencesGlue> m_preferencesGlue;
};
} // namespace tools

View File

@ -9,8 +9,9 @@
#define APP_TOOLS_TOOL_LOOP_H_INCLUDED
#pragma once
#include "app/settings/selection_mode.h"
#include "app/tools/selection_mode.h"
#include "app/tools/trace_policy.h"
#include "doc/color.h"
#include "doc/frame.h"
#include "filters/tiled_mode.h"
#include "gfx/point.h"
@ -35,7 +36,6 @@ namespace render {
namespace app {
class Context;
class Document;
class ISettings;
namespace tools {
class Controller;
@ -130,17 +130,23 @@ namespace app {
// tools).
virtual Button getMouseButton() = 0;
// Returns active foreground/background color (certain tools
// needs to know the exact foreground/background color, they
// cannot used the primary/secondary).
virtual doc::color_t getFgColor() = 0;
virtual doc::color_t getBgColor() = 0;
// Primary color to draw (e.g. foreground if the user start drawing
// with the left button, or background color if he used the right
// button)
virtual int getPrimaryColor() = 0;
virtual void setPrimaryColor(int color) = 0;
virtual doc::color_t getPrimaryColor() = 0;
virtual void setPrimaryColor(doc::color_t color) = 0;
// Secondary color to draw (e.g. background if the user start drawing
// with the left button, or foreground color if he used the right
// button)
virtual int getSecondaryColor() = 0;
virtual void setSecondaryColor(int color) = 0;
virtual doc::color_t getSecondaryColor() = 0;
virtual void setSecondaryColor(doc::color_t color) = 0;
// Returns the opacity to be used by the ink (Ink).
virtual int getOpacity() = 0;
@ -153,13 +159,7 @@ namespace app {
virtual bool getContiguous() = 0;
// Returns the selection mode (if the ink is of selection type).
virtual SelectionMode getSelectionMode() = 0;
// Returns the current settings. Used to know current
// foreground/background color (certain tools needs to know the
// exact foreground/background color, they cannot used the
// primary/secondary).
virtual ISettings* settings() = 0;
virtual tools::SelectionMode getSelectionMode() = 0;
// Returns the preferred "tiled" mode of the document.
// See the method PointShape::doInkHline to check how this member is

View File

@ -19,7 +19,6 @@
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/settings/settings.h"
#include "app/tools/tool.h"
#include "app/ui/button_set.h"
#include "app/ui/color_button.h"

View File

@ -35,6 +35,7 @@
#include "app/ui_context.h"
#include "app/util/clipboard.h"
#include "base/bind.h"
#include "base/scoped_value.h"
#include "doc/image.h"
#include "doc/palette.h"
#include "doc/remap.h"
@ -99,11 +100,12 @@ ColorBar::ColorBar(int align)
: Box(align)
, m_buttons(int(PalButton::MAX))
, m_paletteView(true, PaletteView::FgBgColors, this,
App::instance()->preferences().colorBar.boxSize() * guiscale())
Preferences::instance().colorBar.boxSize() * guiscale())
, m_remapButton("Remap")
, m_fgColor(app::Color::fromRgb(255, 255, 255), IMAGE_RGB)
, m_bgColor(app::Color::fromRgb(0, 0, 0), IMAGE_RGB)
, m_lock(false)
, m_syncingWithPref(false)
, m_remap(nullptr)
, m_lastDocument(nullptr)
, m_ascending(true)
@ -157,13 +159,13 @@ ColorBar::ColorBar(int align)
spectrum->ColorChange.connect(&ColorBar::onPickSpectrum, this);
// Set background color reading its value from the configuration.
setBgColor(get_config_color("ColorBar", "BG", getBgColor()));
setBgColor(Preferences::instance().colorBar.bgColor());
// Clear the selection of the BG color in the palette.
m_paletteView.deselect();
// Set foreground color reading its value from the configuration.
setFgColor(get_config_color("ColorBar", "FG", getFgColor()));
setFgColor(Preferences::instance().colorBar.fgColor());
// Change color-bar background color (not ColorBar::setBgColor)
Widget::setBgColor(theme->colors.tabActiveFace());
@ -190,15 +192,14 @@ ColorBar::ColorBar(int align)
UIContext::instance()->addObserver(this);
m_conn = UIContext::instance()->BeforeCommandExecution.connect(&ColorBar::onBeforeExecuteCommand, this);
m_fgConn = Preferences::instance().colorBar.fgColor.AfterChange.connect(Bind<void>(&ColorBar::onFgColorChangeFromPreferences, this));
m_bgConn = Preferences::instance().colorBar.bgColor.AfterChange.connect(Bind<void>(&ColorBar::onBgColorChangeFromPreferences, this));
m_paletteView.FocusEnter.connect(&ColorBar::onFocusPaletteView, this);
}
ColorBar::~ColorBar()
{
UIContext::instance()->removeObserver(this);
set_config_color("ColorBar", "FG", getFgColor());
set_config_color("ColorBar", "BG", getBgColor());
}
void ColorBar::setPixelFormat(PixelFormat pixelFormat)
@ -223,8 +224,6 @@ void ColorBar::setFgColor(const app::Color& color)
if (!m_lock)
onColorButtonChange(color);
FgColorChange(color);
}
void ColorBar::setBgColor(const app::Color& color)
@ -233,8 +232,6 @@ void ColorBar::setBgColor(const app::Color& color)
if (!m_lock)
onColorButtonChange(color);
BgColorChange(color);
}
PaletteView* ColorBar::getPaletteView()
@ -426,7 +423,7 @@ void ColorBar::setPalette(const doc::Palette* newPalette, const std::string& act
void ColorBar::onPaletteViewChangeSize(int boxsize)
{
App::instance()->preferences().colorBar.boxSize(boxsize);
Preferences::instance().colorBar.boxSize(boxsize);
}
void ColorBar::onPaletteViewPasteColors(
@ -469,6 +466,24 @@ void ColorBar::onPaletteViewPasteColors(
setPalette(&newPalette, "Paste Colors");
}
void ColorBar::onFgColorChangeFromPreferences()
{
if (m_syncingWithPref)
return;
base::ScopedValue<bool> sync(m_syncingWithPref, true, false);
setFgColor(Preferences::instance().colorBar.fgColor());
}
void ColorBar::onBgColorChangeFromPreferences()
{
if (m_syncingWithPref)
return;
base::ScopedValue<bool> sync(m_syncingWithPref, true, false);
setBgColor(Preferences::instance().colorBar.bgColor());
}
void ColorBar::onFgColorButtonChange(const app::Color& color)
{
if (!m_lock) {
@ -476,8 +491,12 @@ void ColorBar::onFgColorButtonChange(const app::Color& color)
m_paletteView.invalidate();
}
if (!m_syncingWithPref) {
base::ScopedValue<bool> sync(m_syncingWithPref, true, false);
Preferences::instance().colorBar.fgColor(color);
}
onColorButtonChange(color);
FgColorChange(color);
}
void ColorBar::onBgColorButtonChange(const app::Color& color)
@ -487,8 +506,12 @@ void ColorBar::onBgColorButtonChange(const app::Color& color)
m_paletteView.invalidate();
}
if (!m_syncingWithPref) {
base::ScopedValue<bool> sync(m_syncingWithPref, true, false);
Preferences::instance().colorBar.bgColor(color);
}
onColorButtonChange(color);
BgColorChange(color);
}
void ColorBar::onColorButtonChange(const app::Color& color)

View File

@ -70,16 +70,14 @@ namespace app {
bool onClear(Context* ctx) override;
void onCancel(Context* ctx) override;
// Signals
Signal1<void, const app::Color&> FgColorChange;
Signal1<void, const app::Color&> BgColorChange;
protected:
void onFocusPaletteView();
void onBeforeExecuteCommand(Command* command);
void onPaletteButtonClick();
void onRemapButtonClick();
void onPaletteIndexChange(PaletteIndexChangeEvent& ev);
void onFgColorChangeFromPreferences();
void onBgColorChangeFromPreferences();
void onFgColorButtonChange(const app::Color& color);
void onBgColorButtonChange(const app::Color& color);
void onColorButtonChange(const app::Color& color);
@ -115,10 +113,13 @@ namespace app {
ColorButton m_fgColor;
ColorButton m_bgColor;
bool m_lock;
bool m_syncingWithPref;
doc::Remap* m_remap;
const doc::Document* m_lastDocument;
bool m_ascending;
ScopedConnection m_conn;
ScopedConnection m_fgConn;
ScopedConnection m_bgConn;
};
} // namespace app

View File

@ -19,7 +19,6 @@
#include "app/find_widget.h"
#include "app/load_widget.h"
#include "app/loop_tag.h"
#include "app/settings/settings.h"
#include "app/transaction.h"
#include "app/ui/main_window.h"
#include "app/ui/timeline.h"
@ -62,7 +61,7 @@ app::Document* ConfigureTimelinePopup::doc()
DocumentPreferences& ConfigureTimelinePopup::docPref()
{
return App::instance()->preferences().document(doc());
return Preferences::instance().document(doc());
}
void ConfigureTimelinePopup::updateWidgetsFromCurrentSettings()

View File

@ -16,13 +16,11 @@
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/pref/preferences.h"
#include "app/settings/ink_type.h"
#include "app/settings/selection_mode.h"
#include "app/settings/settings.h"
#include "app/settings/settings_observers.h"
#include "app/tools/controller.h"
#include "app/tools/ink.h"
#include "app/tools/ink_type.h"
#include "app/tools/point_shape.h"
#include "app/tools/selection_mode.h"
#include "app/tools/tool.h"
#include "app/tools/tool_box.h"
#include "app/ui/brush_popup.h"
@ -56,7 +54,7 @@ using namespace gfx;
using namespace ui;
using namespace tools;
static bool g_updatingFromTool = false;
static bool g_updatingFromCode = false;
class ContextBar::BrushTypeField : public ButtonSet
, public BrushPopupDelegate {
@ -136,8 +134,6 @@ private:
}
void openPopup() {
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
doc::BrushRef brush = m_owner->activeBrush();
m_popupWindow.regenerate(getPopupBox(), m_owner->getBrushes());
@ -157,13 +153,13 @@ private:
if (brush->type() == kImageBrushType)
m_owner->setActiveBrush(brush);
else {
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
IBrushSettings* brushSettings = settings->getToolSettings(currentTool)->getBrush();
brushSettings->setType(brush->type());
Tool* tool = App::instance()->activeTool();
ToolPreferences::Brush& brushPref = Preferences::instance().tool(tool).brush;
brushPref.type(static_cast<app::gen::BrushType>(brush->type()));
m_owner->setActiveBrush(
ContextBar::createBrushFromSettings(brushSettings));
ContextBar::createBrushFromPreferences(&brushPref));
}
}
@ -181,15 +177,14 @@ public:
private:
void onValueChange() override {
IntEntry::onValueChange();
if (g_updatingFromTool)
if (g_updatingFromCode)
return;
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->getBrush()
->setSize(getValue());
IntEntry::onValueChange();
base::ScopedValue<bool> lockFlag(g_updatingFromCode, true, g_updatingFromCode);
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).brush.size(getValue());
}
};
@ -204,15 +199,14 @@ public:
protected:
void onValueChange() override {
IntEntry::onValueChange();
if (g_updatingFromTool)
if (g_updatingFromCode)
return;
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->getBrush()
->setAngle(getValue());
IntEntry::onValueChange();
base::ScopedValue<bool> lockFlag(g_updatingFromCode, true, g_updatingFromCode);
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).brush.angle(getValue());
m_brushType->updateBrush();
}
@ -259,7 +253,7 @@ protected:
case 2: type = BrushPattern::PAINT_BRUSH; break;
}
App::instance()->preferences().brush.pattern(type);
Preferences::instance().brush.pattern(type);
}
bool m_lock;
@ -273,14 +267,13 @@ public:
protected:
void onValueChange() override {
IntEntry::onValueChange();
if (g_updatingFromTool)
if (g_updatingFromCode)
return;
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setTolerance(getValue());
IntEntry::onValueChange();
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).tolerance(getValue());
}
};
@ -299,10 +292,8 @@ protected:
void onClick(Event& ev) override {
CheckBox::onClick(ev);
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setContiguous(isSelected());
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).contiguous(isSelected());
releaseFocus();
}
@ -334,9 +325,9 @@ public:
int index = 0;
switch (inkType) {
case kDefaultInk: index = 0; break;
case kSetAlphaInk: index = 1; break;
case kLockAlphaInk: index = 2; break;
case InkType::DEFAULT: index = 0; break;
case InkType::SET_ALPHA: index = 1; break;
case InkType::LOCK_ALPHA: index = 2; break;
}
m_lock = true;
@ -351,17 +342,16 @@ protected:
if (m_lock)
return;
InkType inkType = kDefaultInk;
InkType inkType = InkType::DEFAULT;
switch (getSelectedItemIndex()) {
case 0: inkType = kDefaultInk; break;
case 1: inkType = kSetAlphaInk; break;
case 2: inkType = kLockAlphaInk; break;
case 0: inkType = InkType::DEFAULT; break;
case 1: inkType = InkType::SET_ALPHA; break;
case 2: inkType = InkType::LOCK_ALPHA; break;
}
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)->setInkType(inkType);
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).ink(inkType);
}
void onCloseListBox() override {
@ -379,14 +369,15 @@ public:
protected:
void onValueChange() override {
IntEntry::onValueChange();
if (g_updatingFromTool)
if (g_updatingFromCode)
return;
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setOpacity(getValue());
IntEntry::onValueChange();
base::ScopedValue<bool> lockFlag(g_updatingFromCode, true, g_updatingFromCode);
int newValue = getValue();
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).opacity(newValue);
}
};
@ -399,13 +390,11 @@ public:
protected:
void onValueChange() override {
IntEntry::onValueChange();
if (g_updatingFromTool)
if (g_updatingFromCode)
return;
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setSprayWidth(getValue());
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).spray.width(getValue());
}
};
@ -417,14 +406,13 @@ public:
protected:
void onValueChange() override {
IntEntry::onValueChange();
if (g_updatingFromTool)
if (g_updatingFromCode)
return;
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setSpraySpeed(getValue());
IntEntry::onValueChange();
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).spray.speed(getValue());
}
};
@ -438,7 +426,7 @@ public:
protected:
void onChange() {
UIContext::instance()->settings()->selection()->setMoveTransparentColor(getColor());
Preferences::instance().selection.transparentColor(getColor());
}
};
@ -450,12 +438,11 @@ public:
// algorithm when we call ComboBox::addItem() (because the first
// addItem() generates an onChange() event).
m_lockChange = true;
addItem(new Item("Fast Rotation", kFastRotationAlgorithm));
addItem(new Item("RotSprite", kRotSpriteRotationAlgorithm));
addItem(new Item("Fast Rotation", tools::RotationAlgorithm::FAST));
addItem(new Item("RotSprite", tools::RotationAlgorithm::ROTSPRITE));
m_lockChange = false;
setSelectedItemIndex((int)UIContext::instance()->settings()
->selection()->getRotationAlgorithm());
setSelectedItemIndex((int)Preferences::instance().selection.rotationAlgorithm());
}
protected:
@ -463,8 +450,8 @@ protected:
if (m_lockChange)
return;
UIContext::instance()->settings()->selection()
->setRotationAlgorithm(static_cast<Item*>(getSelectedItem())->algo());
Preferences::instance().selection.rotationAlgorithm(
static_cast<Item*>(getSelectedItem())->algo());
}
void onCloseListBox() override {
@ -474,15 +461,15 @@ protected:
private:
class Item : public ListItem {
public:
Item(const std::string& text, RotationAlgorithm algo) :
Item(const std::string& text, tools::RotationAlgorithm algo) :
ListItem(text),
m_algo(algo) {
}
RotationAlgorithm algo() const { return m_algo; }
tools::RotationAlgorithm algo() const { return m_algo; }
private:
RotationAlgorithm m_algo;
tools::RotationAlgorithm m_algo;
};
bool m_lockChange;
@ -619,10 +606,8 @@ private:
setFreehandAlgorithm(
(FreehandAlgorithm)m_freehandAlgoButton->getSelectedItem());
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setFreehandAlgorithm(m_freehandAlgo);
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).freehandAlgorithm(m_freehandAlgo);
}
she::Surface* m_bitmap;
@ -645,15 +630,15 @@ public:
// Do nothing
}
void setFreehandAlgorithm(FreehandAlgorithm algo) {
void setFreehandAlgorithm(tools::FreehandAlgorithm algo) {
switch (algo) {
case kDefaultFreehandAlgorithm:
case tools::FreehandAlgorithm::DEFAULT:
setSelected(false);
break;
case kPixelPerfectFreehandAlgorithm:
case tools::FreehandAlgorithm::PIXEL_PERFECT:
setSelected(true);
break;
case kDotsFreehandAlgorithm:
case tools::FreehandAlgorithm::DOTS:
// Not available
break;
}
@ -663,12 +648,11 @@ protected:
void onClick(Event& ev) override {
CheckBox::onClick(ev);
ISettings* settings = UIContext::instance()->settings();
Tool* currentTool = settings->getCurrentTool();
settings->getToolSettings(currentTool)
->setFreehandAlgorithm(isSelected() ?
kPixelPerfectFreehandAlgorithm:
kDefaultFreehandAlgorithm);
Tool* tool = App::instance()->activeTool();
Preferences::instance().tool(tool).freehandAlgorithm(
isSelected() ?
tools::FreehandAlgorithm::PIXEL_PERFECT:
tools::FreehandAlgorithm::DEFAULT);
releaseFocus();
}
@ -686,9 +670,7 @@ public:
addItem(theme->get_part(PART_SELECTION_ADD));
addItem(theme->get_part(PART_SELECTION_SUBTRACT));
setSelectedItem(
(int)UIContext::instance()->settings()
->selection()->getSelectionMode());
setSelectedItem((int)Preferences::instance().selection.mode());
}
void setupTooltips(TooltipManager* tooltipManager) {
@ -706,8 +688,8 @@ protected:
void onItemChange() override {
ButtonSet::onItemChange();
UIContext::instance()->settings()->selection()
->setSelectionMode((SelectionMode)selectedItem());
Preferences::instance().selection.mode(
(tools::SelectionMode)selectedItem());
}
};
@ -751,7 +733,7 @@ protected:
void onClick(Event& ev) override {
CheckBox::onClick(ev);
App::instance()->preferences().editor.grabAlpha(isSelected());
Preferences::instance().editor.grabAlpha(isSelected());
releaseFocus();
}
@ -768,7 +750,7 @@ protected:
void onClick(Event& ev) override {
CheckBox::onClick(ev);
App::instance()->preferences().editor.autoSelectLayer(isSelected());
Preferences::instance().editor.autoSelectLayer(isSelected());
releaseFocus();
}
@ -776,7 +758,6 @@ protected:
ContextBar::ContextBar()
: Box(JI_HORIZONTAL)
, m_toolSettings(NULL)
{
border_width.b = 2*guiscale();
@ -853,18 +834,12 @@ ContextBar::ContextBar()
m_dropPixels->setupTooltips(tooltipManager);
m_freehandAlgo->setupTooltips(tooltipManager);
App::instance()->BrushSizeAfterChange.connect(&ContextBar::onBrushSizeChange, this);
App::instance()->BrushAngleAfterChange.connect(&ContextBar::onBrushAngleChange, this);
App::instance()->CurrentToolChange.connect(&ContextBar::onCurrentToolChange, this);
Preferences::instance().toolBox.activeTool.AfterChange.connect(
Bind<void>(&ContextBar::onCurrentToolChange, this));
m_dropPixels->DropPixels.connect(&ContextBar::onDropPixels, this);
setActiveBrush(createBrushFromSettings());
}
ContextBar::~ContextBar()
{
if (m_toolSettings)
m_toolSettings->removeObserver(this);
setActiveBrush(createBrushFromPreferences());
}
void ContextBar::onPreferredSize(PreferredSizeEvent& ev)
@ -872,8 +847,11 @@ void ContextBar::onPreferredSize(PreferredSizeEvent& ev)
ev.setPreferredSize(gfx::Size(0, 18*guiscale())); // TODO calculate height
}
void ContextBar::onSetOpacity(int newOpacity)
void ContextBar::onToolSetOpacity(const int& newOpacity)
{
if (g_updatingFromCode)
return;
m_inkOpacity->setTextf("%d", newOpacity);
}
@ -892,7 +870,7 @@ void ContextBar::onBrushAngleChange()
void ContextBar::onCurrentToolChange()
{
if (m_activeBrush->type() != kImageBrushType)
setActiveBrush(ContextBar::createBrushFromSettings());
setActiveBrush(ContextBar::createBrushFromPreferences());
else {
updateForCurrentTool();
}
@ -905,57 +883,54 @@ void ContextBar::onDropPixels(ContextBarObserver::DropAction action)
void ContextBar::updateForCurrentTool()
{
updateForTool(UIContext::instance()->settings()->getCurrentTool());
updateForTool(App::instance()->activeTool());
}
void ContextBar::updateForTool(tools::Tool* tool)
{
base::ScopedValue<bool> lockFlag(g_updatingFromTool, true, false);
base::ScopedValue<bool> lockFlag(g_updatingFromCode, true, g_updatingFromCode);
ISettings* settings = UIContext::instance()->settings();
IToolSettings* toolSettings = nullptr;
IBrushSettings* brushSettings = nullptr;
Preferences& preferences = App::instance()->preferences();
ToolPreferences* toolPref = nullptr;
ToolPreferences::Brush* brushPref = nullptr;
Preferences& preferences = Preferences::instance();
if (tool) {
toolSettings = settings->getToolSettings(tool);
brushSettings = toolSettings->getBrush();
toolPref = &preferences.tool(tool);
brushPref = &toolPref->brush;
}
if (m_toolSettings)
m_toolSettings->removeObserver(this);
m_toolSettings = toolSettings;
if (m_toolSettings)
m_toolSettings->addObserver(this);
if (toolPref) {
m_sizeConn = brushPref->size.AfterChange.connect(Bind<void>(&ContextBar::onBrushSizeChange, this));
m_angleConn = brushPref->angle.AfterChange.connect(Bind<void>(&ContextBar::onBrushAngleChange, this));
m_opacityConn = toolPref->opacity.AfterChange.connect(&ContextBar::onToolSetOpacity, this);
}
if (tool)
m_brushType->updateBrush(tool);
if (brushSettings) {
m_brushSize->setTextf("%d", brushSettings->getSize());
m_brushAngle->setTextf("%d", brushSettings->getAngle());
if (brushPref) {
m_brushSize->setTextf("%d", brushPref->size());
m_brushAngle->setTextf("%d", brushPref->angle());
}
m_brushPatternField->setBrushPattern(
preferences.brush.pattern());
if (toolSettings) {
m_tolerance->setTextf("%d", toolSettings->getTolerance());
m_contiguous->setSelected(toolSettings->getContiguous());
if (toolPref) {
m_tolerance->setTextf("%d", toolPref->tolerance());
m_contiguous->setSelected(toolPref->contiguous());
m_inkType->setInkType(toolSettings->getInkType());
m_inkOpacity->setTextf("%d", toolSettings->getOpacity());
m_inkType->setInkType(toolPref->ink());
m_inkOpacity->setTextf("%d", toolPref->opacity());
m_freehandAlgo->setFreehandAlgorithm(toolSettings->getFreehandAlgorithm());
m_freehandAlgo->setFreehandAlgorithm(toolPref->freehandAlgorithm());
m_sprayWidth->setValue(toolSettings->getSprayWidth());
m_spraySpeed->setValue(toolSettings->getSpraySpeed());
m_sprayWidth->setValue(toolPref->spray.width());
m_spraySpeed->setValue(toolPref->spray.speed());
}
if (settings) {
m_grabAlpha->setSelected(preferences.editor.grabAlpha());
m_autoSelectLayer->setSelected(preferences.editor.autoSelectLayer());
}
m_grabAlpha->setSelected(preferences.editor.grabAlpha());
m_autoSelectLayer->setSelected(preferences.editor.autoSelectLayer());
// True if the current tool needs opacity options
bool hasOpacity = tool &&
@ -1155,36 +1130,33 @@ doc::BrushRef ContextBar::activeBrush(tools::Tool* tool) const
if (!tool ||
(tool->getInk(0)->isPaint() &&
m_activeBrush->type() == kImageBrushType)) {
m_activeBrush->setPattern(App::instance()->preferences().brush.pattern());
m_activeBrush->setPattern(Preferences::instance().brush.pattern());
return m_activeBrush;
}
ISettings* settings = UIContext::instance()->settings();
IToolSettings* toolSettings = settings->getToolSettings(tool);
return ContextBar::createBrushFromSettings(toolSettings->getBrush());
return ContextBar::createBrushFromPreferences(
&Preferences::instance().tool(tool).brush);
}
void ContextBar::discardActiveBrush()
{
setActiveBrush(ContextBar::createBrushFromSettings());
setActiveBrush(ContextBar::createBrushFromPreferences());
}
// static
doc::BrushRef ContextBar::createBrushFromSettings(IBrushSettings* brushSettings)
doc::BrushRef ContextBar::createBrushFromPreferences(ToolPreferences::Brush* brushPref)
{
if (brushSettings == nullptr) {
ISettings* settings = UIContext::instance()->settings();
tools::Tool* tool = settings->getCurrentTool();
IToolSettings* toolSettings = settings->getToolSettings(tool);
brushSettings = toolSettings->getBrush();
if (brushPref == nullptr) {
tools::Tool* tool = App::instance()->activeTool();
brushPref = &Preferences::instance().tool(tool).brush;
}
doc::BrushRef brush;
brush.reset(
new Brush(
brushSettings->getType(),
brushSettings->getSize(),
brushSettings->getAngle()));
static_cast<doc::BrushType>(brushPref->type()),
brushPref->size(),
brushPref->angle()));
return brush;
}

View File

@ -9,8 +9,10 @@
#define APP_UI_CONTEXT_BAR_H_INCLUDED
#pragma once
#include "app/settings/settings_observers.h"
#include "app/pref/preferences.h"
#include "app/tools/selection_mode.h"
#include "app/ui/context_bar_observer.h"
#include "base/connection.h"
#include "base/observable.h"
#include "doc/brush.h"
#include "doc/brushes.h"
@ -34,17 +36,15 @@ namespace app {
class IToolSettings;
class ContextBar : public ui::Box,
public ToolSettingsObserver,
public base::Observable<ContextBarObserver> {
public:
ContextBar();
~ContextBar();
void updateForCurrentTool();
void updateForTool(tools::Tool* tool);
void updateForMovingPixels();
void updateForSelectingBox(const std::string& text);
void updateSelectionMode(SelectionMode mode);
void updateSelectionMode(app::tools::SelectionMode mode);
void updateAutoSelectLayer(bool state);
void setActiveBrush(const doc::BrushRef& brush);
@ -63,14 +63,12 @@ namespace app {
void unlockBrushSlot(int slot);
bool isBrushSlotLocked(int slot) const;
static doc::BrushRef createBrushFromSettings(
IBrushSettings* brushSettings = nullptr);
static doc::BrushRef createBrushFromPreferences(
ToolPreferences::Brush* brushPref = nullptr);
protected:
void onPreferredSize(ui::PreferredSizeEvent& ev) override;
// ToolSettingsObserver impl
void onSetOpacity(int newOpacity) override;
void onToolSetOpacity(const int& newOpacity);
private:
void onBrushSizeChange();
@ -111,7 +109,6 @@ namespace app {
class DropPixelsField;
class AutoSelectLayerField;
IToolSettings* m_toolSettings;
BrushTypeField* m_brushType;
BrushAngleField* m_brushAngle;
BrushSizeField* m_brushSize;
@ -138,6 +135,9 @@ namespace app {
doc::BrushRef m_activeBrush;
BrushSlots m_brushes;
ui::Label* m_selectBoxHelp;
ScopedConnection m_sizeConn;
ScopedConnection m_angleConn;
ScopedConnection m_opacityConn;
};
} // namespace app

View File

@ -16,7 +16,6 @@
#include "app/color_utils.h"
#include "app/ini_file.h"
#include "app/modules/editors.h"
#include "app/settings/settings.h"
#include "app/tools/controller.h"
#include "app/tools/ink.h"
#include "app/tools/intertwine.h"
@ -77,6 +76,8 @@ static int saved_pixel_n;
static gfx::Region clipping_region;
static gfx::Region old_clipping_region;
static gfx::Rect lastBrushBounds;
static void generate_cursor_boundaries(Editor* editor);
static void trace_thincross_pixels(ui::Graphics* g, Editor* editor, const gfx::Point& pt, gfx::Color color, Editor::PixelDelegate pixel);
@ -114,36 +115,6 @@ void Editor::set_cursor_color(const app::Color& color)
update_cursor_color();
}
//////////////////////////////////////////////////////////////////////
// Slots for App signals
//////////////////////////////////////////////////////////////////////
static gfx::Rect lastBrushBounds;
static bool brush_on_screen = false;
static void on_palette_change_update_cursor_color()
{
update_cursor_color();
}
static void on_brush_before_change()
{
if (current_editor) {
brush_on_screen = current_editor->cursorOnScreen();
if (brush_on_screen)
current_editor->hideDrawingCursor();
}
}
static void on_brush_after_change()
{
if (current_editor) {
// Show drawing cursor
if (current_editor->sprite() && brush_on_screen)
current_editor->showDrawingCursor();
}
}
static Brush* get_current_brush()
{
return App::instance()->getMainWindow()->getContextBar()->activeBrush().get();
@ -158,11 +129,8 @@ void Editor::editor_cursor_init()
// Cursor color
set_cursor_color(get_config_color("Tools", "CursorColor", app::Color::fromMask()));
App::instance()->PaletteChange.connect(&on_palette_change_update_cursor_color);
App::instance()->BrushSizeBeforeChange.connect(&on_brush_before_change);
App::instance()->BrushSizeAfterChange.connect(&on_brush_after_change);
App::instance()->BrushAngleBeforeChange.connect(&on_brush_before_change);
App::instance()->BrushAngleAfterChange.connect(&on_brush_after_change);
App::instance()->PaletteChange.connect(&update_cursor_color);
update_cursor_color();
}
void Editor::editor_cursor_exit()
@ -570,7 +538,7 @@ static void clearpixel(ui::Graphics* g, const gfx::Point& pt, gfx::Color color)
static color_t get_brush_color(Sprite* sprite, Layer* layer)
{
app::Color c = UIContext::instance()->settings()->getFgColor();
app::Color c = Preferences::instance().colorBar.fgColor();
ASSERT(sprite != NULL);
// Avoid using invalid colors

View File

@ -23,7 +23,6 @@
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/pref/preferences.h"
#include "app/settings/settings.h"
#include "app/tools/ink.h"
#include "app/tools/tool.h"
#include "app/tools/tool_box.h"
@ -156,7 +155,7 @@ Editor::Editor(Document* document, EditorFlags flags)
, m_cursorScreen(0, 0)
, m_cursorEditor(0, 0)
, m_quicktool(NULL)
, m_selectionMode(kDefaultSelectionMode)
, m_selectionMode(tools::SelectionMode::DEFAULT)
, m_offset_x(0)
, m_offset_y(0)
, m_mask_timer(100, this)
@ -173,13 +172,14 @@ Editor::Editor(Document* document, EditorFlags flags)
this->setFocusStop(true);
m_currentToolChangeConn =
App::instance()->CurrentToolChange.connect(&Editor::onCurrentToolChange, this);
Preferences::instance().toolBox.activeTool.AfterChange.connect(
Bind<void>(&Editor::onCurrentToolChange, this));
m_fgColorChangeConn =
ColorBar::instance()->FgColorChange.connect(Bind<void>(&Editor::onFgColorChange, this));
Preferences::instance().colorBar.fgColor.AfterChange.connect(
Bind<void>(&Editor::onFgColorChange, this));
DocumentPreferences& docPref = App::instance()
->preferences().document(m_document);
DocumentPreferences& docPref = Preferences::instance().document(m_document);
m_tiledConn = docPref.tiled.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
m_gridConn = docPref.grid.AfterChange.connect(Bind<void>(&Editor::invalidate, this));
@ -248,7 +248,7 @@ void Editor::setStateInternal(const EditorStatePtr& newState)
m_observers.notifyStateChanged(this);
// Setup the new mouse cursor
editor_setcursor();
setCursor();
updateStatusBar();
}
@ -424,8 +424,8 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite
m_renderEngine.setOnionskin(render::OnionskinType::NONE, 0, 0, 0, 0);
if ((m_flags & kShowOnionskin) == kShowOnionskin) {
DocumentPreferences& docPref = App::instance()
->preferences().document(m_document);
DocumentPreferences& docPref = Preferences::instance()
.document(m_document);
if (docPref.onionskin.active()) {
m_renderEngine.setOnionskin(
@ -502,9 +502,9 @@ void Editor::drawSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& _rc)
gfx::Region outside(client);
outside.createSubtraction(outside, gfx::Region(spriteRect));
// Document settings
// Document preferences
DocumentPreferences& docPref =
App::instance()->preferences().document(m_document);
Preferences::instance().document(m_document);
if (int(docPref.tiled.mode()) & int(filters::TiledMode::X_AXIS)) {
drawOneSpriteUnclippedRect(g, rc, -spriteRect.w, 0);
@ -772,7 +772,7 @@ void Editor::drawGrid(Graphics* g, const gfx::Rect& spriteBounds, const Rect& gr
void Editor::flashCurrentLayer()
{
if (!App::instance()->preferences().experimental.flashLayer())
if (!Preferences::instance().experimental.flashLayer())
return;
Site site = getSite();
@ -848,9 +848,7 @@ gfx::Point Editor::autoScroll(MouseMessage* msg, AutoScroll dir, bool blit_valid
bool Editor::isCurrentToolAffectedByRightClickMode()
{
Context* context = UIContext::instance();
tools::Tool* tool = context->settings()->getCurrentTool();
tools::Tool* tool = App::instance()->activeTool();
return
(tool->getInk(0)->isPaint() || tool->getInk(0)->isEffect()) &&
(!tool->getInk(0)->isEraser());
@ -861,13 +859,12 @@ tools::Tool* Editor::getCurrentEditorTool()
if (m_quicktool)
return m_quicktool;
Context* context = UIContext::instance();
tools::Tool* tool = context->settings()->getCurrentTool();
tools::Tool* tool = App::instance()->activeTool();
if (m_secondaryButton && isCurrentToolAffectedByRightClickMode()) {
tools::ToolBox* toolbox = App::instance()->getToolBox();
switch (App::instance()->preferences().editor.rightClickMode()) {
switch (Preferences::instance().editor.rightClickMode()) {
case app::gen::RightClickMode::PAINT_BGCOLOR:
// Do nothing, use the current tool
break;
@ -896,7 +893,7 @@ tools::Ink* Editor::getCurrentEditorInk()
if (m_quicktool)
return ink;
app::gen::RightClickMode rightClickMode = App::instance()->preferences().editor.rightClickMode();
app::gen::RightClickMode rightClickMode = Preferences::instance().editor.rightClickMode();
if (m_secondaryButton &&
rightClickMode != app::gen::RightClickMode::DEFAULT &&
@ -916,47 +913,48 @@ tools::Ink* Editor::getCurrentEditorInk()
}
}
else {
IToolSettings* toolSettings = context->settings()->getToolSettings(tool);
InkType inkType = toolSettings->getInkType();
tools::InkType inkType = Preferences::instance().tool(tool).ink();
const char* id = NULL;
switch (inkType) {
case kDefaultInk:
case tools::InkType::DEFAULT:
// Do nothing
break;
case kOpaqueInk:
id = tools::WellKnownInks::PaintOpaque;
break;
case kSetAlphaInk:
case tools::InkType::SET_ALPHA:
id = tools::WellKnownInks::PaintSetAlpha;
break;
case kLockAlphaInk:
case tools::InkType::LOCK_ALPHA:
id = tools::WellKnownInks::PaintLockAlpha;
break;
case kMergeInk:
#if 0
case tools::InkType::OPAQUE:
id = tools::WellKnownInks::PaintOpaque;
break;
case tools::InkType::MERGE:
id = tools::WellKnownInks::Paint;
break;
case kShadingInk:
case tools::InkType::SHADING:
id = tools::WellKnownInks::Shading;
break;
case kReplaceInk:
case tools::InkType::REPLACE:
if (!m_secondaryButton)
id = tools::WellKnownInks::ReplaceBgWithFg;
else
id = tools::WellKnownInks::ReplaceFgWithBg;
break;
case kEraseInk:
case tools::InkType::ERASER:
id = tools::WellKnownInks::Eraser;
break;
case kSelectionInk:
case tools::InkType::SELECTION:
id = tools::WellKnownInks::Selection;
break;
case kBlurInk:
case tools::InkType::BLUR:
id = tools::WellKnownInks::Blur;
break;
case kJumbleInk:
case tools::InkType::JUMBLE:
id = tools::WellKnownInks::Jumble;
break;
#endif
}
if (id)
@ -1101,8 +1099,7 @@ void Editor::updateStatusBar()
void Editor::updateQuicktool()
{
if (m_customizationDelegate) {
UIContext* context = UIContext::instance();
tools::Tool* current_tool = context->settings()->getCurrentTool();
tools::Tool* current_tool = App::instance()->activeTool();
// Don't change quicktools if we are in a selection tool and using
// the selection modifiers.
@ -1158,14 +1155,14 @@ void Editor::updateContextBarFromModifiers()
// Selection mode
SelectionMode mode = UIContext::instance()->settings()->selection()->getSelectionMode();
tools::SelectionMode mode = Preferences::instance().selection.mode();
if (m_customizationDelegate && m_customizationDelegate->isAddSelectionPressed())
mode = kAddSelectionMode;
mode = tools::SelectionMode::ADD;
else if (m_customizationDelegate && m_customizationDelegate->isSubtractSelectionPressed())
mode = kSubtractSelectionMode;
mode = tools::SelectionMode::SUBTRACT;
else if (m_secondaryButton)
mode = kSubtractSelectionMode;
mode = tools::SelectionMode::SUBTRACT;
if (mode != m_selectionMode) {
m_selectionMode = mode;
@ -1174,7 +1171,7 @@ void Editor::updateContextBarFromModifiers()
// Move tool options
bool autoSelectLayer = App::instance()->preferences().editor.autoSelectLayer();
bool autoSelectLayer = Preferences::instance().editor.autoSelectLayer();
if (m_customizationDelegate && m_customizationDelegate->isAutoSelectLayerPressed())
autoSelectLayer = true;
@ -1229,7 +1226,7 @@ bool Editor::onProcessMessage(Message* msg)
updateQuicktool();
updateContextBarFromModifiers();
editor_setcursor();
setCursor();
}
EditorStatePtr holdState(m_state);
@ -1254,7 +1251,7 @@ bool Editor::onProcessMessage(Message* msg)
updateQuicktool();
updateContextBarFromModifiers();
editor_setcursor();
setCursor();
}
if (result)
@ -1270,7 +1267,7 @@ bool Editor::onProcessMessage(Message* msg)
if (hasMouse()) {
updateQuicktool();
updateContextBarFromModifiers();
editor_setcursor();
setCursor();
}
if (used)
@ -1286,7 +1283,7 @@ bool Editor::onProcessMessage(Message* msg)
if (hasMouse()) {
updateQuicktool();
updateContextBarFromModifiers();
editor_setcursor();
setCursor();
}
if (used)
@ -1309,7 +1306,7 @@ bool Editor::onProcessMessage(Message* msg)
break;
case kSetCursorMessage:
editor_setcursor();
setCursor();
return true;
}
@ -1398,6 +1395,12 @@ void Editor::onPaint(ui::PaintEvent& ev)
void Editor::onCurrentToolChange()
{
m_state->onCurrentToolChange(this);
ToolPreferences::Brush& brushPref =
Preferences::instance().tool(App::instance()->activeTool()).brush;
m_sizeConn = brushPref.size.AfterChange.connect(Bind<void>(&Editor::onBrushSizeOrAngleChange, this));
m_angleConn = brushPref.angle.AfterChange.connect(Bind<void>(&Editor::onBrushSizeOrAngleChange, this));
}
void Editor::onFgColorChange()
@ -1408,13 +1411,21 @@ void Editor::onFgColorChange()
}
}
void Editor::onBrushSizeOrAngleChange()
{
if (m_cursorOnScreen) {
hideDrawingCursor();
showDrawingCursor();
}
}
void Editor::onExposeSpritePixels(doc::DocumentEvent& ev)
{
if (m_state && ev.sprite() == m_sprite)
m_state->onExposeSpritePixels(ev.region());
}
void Editor::editor_setcursor()
void Editor::setCursor()
{
bool used = false;
if (m_sprite)
@ -1438,7 +1449,7 @@ bool Editor::isInsideSelection()
{
gfx::Point spritePos = screenToEditor(ui::get_mouse_position());
return
(m_selectionMode != kSubtractSelectionMode) &&
(m_selectionMode != tools::SelectionMode::SUBTRACT) &&
m_document != NULL &&
m_document->isMaskVisible() &&
m_document->mask()->containsPoint(spritePos.x, spritePos.y);

View File

@ -12,7 +12,7 @@
#include "app/app_render.h"
#include "app/color.h"
#include "app/document.h"
#include "app/settings/selection_mode.h"
#include "app/tools/selection_mode.h"
#include "app/ui/editor/editor_observers.h"
#include "app/ui/editor/editor_state.h"
#include "app/ui/editor/editor_states_history.h"
@ -167,7 +167,7 @@ namespace app {
tools::Tool* getCurrentEditorTool();
tools::Ink* getCurrentEditorInk();
SelectionMode getSelectionMode() const { return m_selectionMode; }
tools::SelectionMode getSelectionMode() const { return m_selectionMode; }
bool isAutoSelectLayer() const { return m_autoSelectLayer; }
bool isSecondaryButton() const { return m_secondaryButton; }
@ -220,7 +220,7 @@ namespace app {
void onPaint(ui::PaintEvent& ev) override;
void onCurrentToolChange();
void onFgColorChange();
void onBrushSizeOrAngleChange();
void onExposeSpritePixels(doc::DocumentEvent& ev);
private:
@ -237,7 +237,7 @@ namespace app {
void drawGrid(ui::Graphics* g, const gfx::Rect& spriteBounds, const gfx::Rect& gridBounds,
const app::Color& color, int alpha);
void editor_setcursor();
void setCursor();
void forEachBrushPixel(
ui::Graphics* g,
@ -276,7 +276,7 @@ namespace app {
// the user is not pressing any keyboard key).
tools::Tool* m_quicktool;
SelectionMode m_selectionMode;
tools::SelectionMode m_selectionMode;
bool m_autoSelectLayer;
// Offset for the sprite
@ -293,6 +293,8 @@ namespace app {
// signals).
ScopedConnection m_currentToolChangeConn;
ScopedConnection m_fgColorChangeConn;
ScopedConnection m_sizeConn;
ScopedConnection m_angleConn;
// Slots listeing document preferences.
ScopedConnection m_tiledConn;

View File

@ -51,7 +51,7 @@ EditorView::EditorView(EditorView::Type type)
setupScrollbars();
m_scrollSettingsConn =
App::instance()->preferences().editor.showScrollbars.AfterChange.connect(
Preferences::instance().editor.showScrollbars.AfterChange.connect(
Bind(&EditorView::setupScrollbars, this));
}
@ -127,7 +127,7 @@ void EditorView::onScrollChange()
void EditorView::setupScrollbars()
{
if (m_type == AlwaysSelected ||
!App::instance()->preferences().editor.showScrollbars()) {
!Preferences::instance().editor.showScrollbars()) {
hideScrollBars();
}
else {

View File

@ -9,7 +9,6 @@
#define APP_UI_EDITOR_VIEW_H_INCLUDED
#pragma once
#include "app/settings/settings_observers.h"
#include "base/connection.h"
#include "ui/view.h"

View File

@ -17,7 +17,7 @@
#include "app/commands/cmd_move_mask.h"
#include "app/commands/command.h"
#include "app/commands/commands.h"
#include "app/settings/settings.h"
#include "app/pref/preferences.h"
#include "app/tools/ink.h"
#include "app/tools/tool.h"
#include "app/ui/context_bar.h"
@ -31,11 +31,12 @@
#include "app/ui/status_bar.h"
#include "app/ui_context.h"
#include "app/util/clipboard.h"
#include "base/bind.h"
#include "base/unique_ptr.h"
#include "gfx/rect.h"
#include "doc/algorithm/flip_image.h"
#include "doc/mask.h"
#include "doc/sprite.h"
#include "gfx/rect.h"
#include "ui/manager.h"
#include "ui/message.h"
#include "ui/system.h"
@ -68,16 +69,17 @@ MovingPixelsState::MovingPixelsState(Editor* editor, MouseMessage* msg, PixelsMo
}
// Setup mask color
setTransparentColor(context->settings()->selection()->getMoveTransparentColor());
setTransparentColor(Preferences::instance().selection.transparentColor());
// Hook BeforeCommandExecution signal so we know if the user wants
// to execute other command, so we can drop pixels.
m_ctxConn =
context->BeforeCommandExecution.connect(&MovingPixelsState::onBeforeCommandExecution, this);
// Observe SelectionSettings to be informed of changes to
// Transparent Color from Context Bar.
context->settings()->selection()->addObserver(this);
// Listen to any change to the transparent color from the ContextBar.
m_transparentConn =
Preferences::instance().selection.transparentColor.AfterChange.connect(
Bind<void>(&MovingPixelsState::onTransparentColorChange, this));
// Add the current editor as filter for key message of the manager
// so we can catch the Enter key, and avoid to execute the
@ -98,7 +100,7 @@ MovingPixelsState::~MovingPixelsState()
contextBar->updateForCurrentTool();
m_ctxConn.disconnect();
UIContext::instance()->settings()->selection()->removeObserver(this);
m_transparentConn.disconnect();
m_pixelsMovement.reset(NULL);
@ -472,9 +474,9 @@ void MovingPixelsState::onBeforeLayerChanged(Editor* editor)
dropPixels();
}
void MovingPixelsState::onSetMoveTransparentColor(app::Color newColor)
void MovingPixelsState::onTransparentColorChange()
{
app::Color color = UIContext::instance()->settings()->selection()->getMoveTransparentColor();
app::Color color = Preferences::instance().selection.transparentColor();
setTransparentColor(color);
}

View File

@ -9,7 +9,6 @@
#define APP_UI_EDITOR_MOVING_PIXELS_STATE_H_INCLUDED
#pragma once
#include "app/settings/settings_observers.h"
#include "app/ui/context_bar_observer.h"
#include "app/ui/editor/editor_observer.h"
#include "app/ui/editor/handle_type.h"
@ -29,7 +28,6 @@ namespace app {
class MovingPixelsState
: public StandbyState
, EditorObserver
, SelectionSettingsObserver
, ContextBarObserver {
public:
MovingPixelsState(Editor* editor, ui::MouseMessage* msg, PixelsMovementPtr pixelsMovement, HandleType handle);
@ -54,15 +52,14 @@ namespace app {
virtual void onBeforeFrameChanged(Editor* editor) override;
virtual void onBeforeLayerChanged(Editor* editor) override;
// SettingsObserver
virtual void onSetMoveTransparentColor(app::Color newColor) override;
// ContextBarObserver
virtual void onDropPixels(ContextBarObserver::DropAction action) override;
virtual gfx::Transformation getTransformation(Editor* editor) override;
private:
void onTransparentColorChange();
// ContextObserver
void onBeforeCommandExecution(Command* command);
@ -81,6 +78,7 @@ namespace app {
bool m_discarded;
Connection m_ctxConn;
Connection m_transparentConn;
};
} // namespace app

View File

@ -20,11 +20,11 @@
#include "app/document_api.h"
#include "app/modules/gui.h"
#include "app/pref/preferences.h"
#include "app/settings/settings.h"
#include "app/snap_to_grid.h"
#include "app/ui/status_bar.h"
#include "app/ui_context.h"
#include "app/util/expand_cel_canvas.h"
#include "base/bind.h"
#include "base/vector2d.h"
#include "doc/algorithm/flip_image.h"
#include "doc/algorithm/rotate.h"
@ -76,13 +76,13 @@ PixelsMovement::PixelsMovement(Context* context,
m_initialMask = new Mask(*m_document->mask());
m_currentMask = new Mask(*m_document->mask());
UIContext::instance()->settings()->selection()->addObserver(this);
m_rotAlgoConn =
Preferences::instance().selection.rotationAlgorithm.AfterChange.connect(
Bind<void>(&PixelsMovement::onRotationAlgorithmChange, this));
}
PixelsMovement::~PixelsMovement()
{
UIContext::instance()->settings()->selection()->removeObserver(this);
delete m_originalImage;
delete m_initialMask;
delete m_currentMask;
@ -614,14 +614,14 @@ void PixelsMovement::drawParallelogram(doc::Image* dst, doc::Image* src,
const gfx::Transformation::Corners& corners,
const gfx::Point& leftTop)
{
RotationAlgorithm rotAlgo = UIContext::instance()->settings()->selection()->getRotationAlgorithm();
tools::RotationAlgorithm rotAlgo = Preferences::instance().selection.rotationAlgorithm();
// If the angle and the scale weren't modified, we should use the
// fast rotation algorithm, as it's pixel-perfect match with the
// original selection when just a translation is applied.
if (m_currentData.angle() == 0.0 &&
m_currentData.bounds().getSize() == src->size()) {
rotAlgo = kFastRotationAlgorithm;
rotAlgo = tools::RotationAlgorithm::FAST;
}
retry:; // In case that we don't have enough memory for RotSprite
@ -629,7 +629,7 @@ retry:; // In case that we don't have enough memory for RotSprite
switch (rotAlgo) {
case kFastRotationAlgorithm:
case tools::RotationAlgorithm::FAST:
doc::algorithm::parallelogram(dst, src,
int(corners.leftTop().x-leftTop.x),
int(corners.leftTop().y-leftTop.y),
@ -641,7 +641,7 @@ retry:; // In case that we don't have enough memory for RotSprite
int(corners.leftBottom().y-leftTop.y));
break;
case kRotSpriteRotationAlgorithm:
case tools::RotationAlgorithm::ROTSPRITE:
try {
doc::algorithm::rotsprite_image(dst, src,
int(corners.leftTop().x-leftTop.x),
@ -657,7 +657,7 @@ retry:; // In case that we don't have enough memory for RotSprite
StatusBar::instance()->showTip(1000,
"Not enough memory for RotSprite");
rotAlgo = kFastRotationAlgorithm;
rotAlgo = tools::RotationAlgorithm::FAST;
goto retry;
}
break;
@ -665,7 +665,7 @@ retry:; // In case that we don't have enough memory for RotSprite
}
}
void PixelsMovement::onSetRotationAlgorithm(RotationAlgorithm algorithm)
void PixelsMovement::onRotationAlgorithmChange()
{
try {
redrawExtraImage();

View File

@ -10,9 +10,9 @@
#pragma once
#include "app/context_access.h"
#include "app/settings/settings_observers.h"
#include "app/transaction.h"
#include "app/ui/editor/handle_type.h"
#include "base/connection.h"
#include "base/shared_ptr.h"
#include "doc/algorithm/flip_type.h"
#include "doc/site.h"
@ -35,7 +35,7 @@ namespace app {
// feedback, drag, and drop the specified image in the constructor
// (which generally would be the selected region or the clipboard
// content).
class PixelsMovement : public SelectionSettingsObserver {
class PixelsMovement {
public:
enum MoveModifier {
NormalMovement = 1,
@ -92,10 +92,8 @@ namespace app {
const gfx::Transformation& getTransformation() const { return m_currentData; }
protected:
void onSetRotationAlgorithm(RotationAlgorithm algorithm) override;
private:
void onRotationAlgorithmChange();
void redrawExtraImage();
void redrawCurrentMask();
void drawImage(doc::Image* dst, const gfx::Point& pos);
@ -121,6 +119,7 @@ namespace app {
Mask* m_initialMask;
Mask* m_currentMask;
color_t m_maskColor;
ScopedConnection m_rotAlgoConn;
};
inline PixelsMovement::MoveModifier& operator|=(PixelsMovement::MoveModifier& a,

View File

@ -17,7 +17,6 @@
#include "app/commands/params.h"
#include "app/ini_file.h"
#include "app/pref/preferences.h"
#include "app/settings/settings.h"
#include "app/tools/ink.h"
#include "app/tools/pick_ink.h"
#include "app/tools/tool.h"
@ -372,7 +371,7 @@ bool StandbyState::onUpdateStatusBar(Editor* editor)
}
// For eye-dropper
else if (ink->isEyedropper()) {
bool grabAlpha = App::instance()->preferences().editor.grabAlpha();
bool grabAlpha = Preferences::instance().editor.grabAlpha();
ColorPicker picker;
picker.pickColor(editor->getSite(),
spritePos,

View File

@ -14,7 +14,6 @@
#include "app/app.h"
#include "app/commands/commands.h"
#include "app/pref/preferences.h"
#include "app/settings/settings.h"
#include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h"
#include "app/ui_context.h"
@ -46,7 +45,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
wheelAction = WHEEL_FG;
}
// Normal behavior: mouse wheel zooms
else if (App::instance()->preferences().editor.zoomWithWheel()) {
else if (Preferences::instance().editor.zoomWithWheel()) {
if (msg->ctrlPressed())
wheelAction = WHEEL_FRAME;
else if (msg->wheelDelta().x != 0 || msg->shiftPressed())
@ -116,7 +115,7 @@ bool StateWithWheelBehavior::onMouseWheel(Editor* editor, MouseMessage* msg)
}
if (editor->zoom() != zoom) {
bool center = App::instance()->preferences().editor.zoomFromCenterWithWheel();
bool center = Preferences::instance().editor.zoomFromCenterWithWheel();
editor->setZoomAndCenterInMouse(
zoom, mouseMsg->position(),

View File

@ -21,7 +21,6 @@
#include "app/document_undo.h"
#include "app/modules/gui.h"
#include "app/pref/preferences.h"
#include "app/settings/settings.h"
#include "app/tools/controller.h"
#include "app/tools/ink.h"
#include "app/tools/point_shape.h"
@ -66,9 +65,8 @@ class ToolLoopImpl : public tools::ToolLoop,
bool m_previewFilled;
int m_sprayWidth;
int m_spraySpeed;
ISettings* m_settings;
DocumentPreferences& m_docPref;
IToolSettings* m_toolSettings;
ToolPreferences& m_toolPref;
bool m_useMask;
Mask* m_mask;
gfx::Point m_maskOrigin;
@ -80,12 +78,13 @@ class ToolLoopImpl : public tools::ToolLoop,
bool m_canceled;
tools::ToolLoop::Button m_button;
tools::Ink* m_ink;
int m_primary_color;
int m_secondary_color;
doc::color_t m_fgColor;
doc::color_t m_bgColor;
doc::color_t m_primaryColor;
doc::color_t m_secondaryColor;
Transaction m_transaction;
ExpandCelCanvas m_expandCelCanvas;
gfx::Region m_dirtyArea;
tools::ShadeTable8* m_shadeTable;
public:
ToolLoopImpl(Editor* editor,
@ -94,8 +93,8 @@ public:
tools::Ink* ink,
Document* document,
tools::ToolLoop::Button button,
const app::Color& primary_color,
const app::Color& secondary_color)
const app::Color& fgColor,
const app::Color& bgColor)
: m_editor(editor)
, m_context(context)
, m_tool(tool)
@ -103,14 +102,15 @@ public:
, m_sprite(editor->sprite())
, m_layer(editor->layer())
, m_frame(editor->frame())
, m_settings(m_context->settings())
, m_docPref(App::instance()->preferences().document(m_document))
, m_toolSettings(m_settings->getToolSettings(m_tool))
, m_docPref(Preferences::instance().document(m_document))
, m_toolPref(Preferences::instance().tool(m_tool))
, m_canceled(false)
, m_button(button)
, m_ink(ink)
, m_primary_color(color_utils::color_for_layer(primary_color, m_layer))
, m_secondary_color(color_utils::color_for_layer(secondary_color, m_layer))
, m_fgColor(color_utils::color_for_layer(fgColor, m_layer))
, m_bgColor(color_utils::color_for_layer(bgColor, m_layer))
, m_primaryColor(button == tools::ToolLoop::Left ? m_fgColor: m_bgColor)
, m_secondaryColor(button == tools::ToolLoop::Left ? m_bgColor: m_fgColor)
, m_transaction(m_context,
m_tool->getText().c_str(),
((getInk()->isSelection() ||
@ -131,7 +131,6 @@ public:
(getController()->isFreehand() ?
ExpandCelCanvas::UseModifiedRegionAsUndoInfo:
ExpandCelCanvas::None)))
, m_shadeTable(NULL)
{
// Settings
switch (tool->getFill(m_button)) {
@ -142,13 +141,13 @@ public:
m_filled = true;
break;
case tools::FillOptional:
m_filled = m_toolSettings->getFilled();
m_filled = m_toolPref.filled();
break;
}
m_previewFilled = m_toolSettings->getPreviewFilled();
m_sprayWidth = m_toolSettings->getSprayWidth();
m_spraySpeed = m_toolSettings->getSpraySpeed();
m_previewFilled = m_toolPref.filledPreview();
m_sprayWidth = m_toolPref.spray.width();
m_spraySpeed = m_toolPref.spray.speed();
m_brush = App::instance()->getMainWindow()->getContextBar()->activeBrush();
if (m_ink->isSelection())
@ -159,7 +158,7 @@ public:
// Start with an empty mask if the user is selecting with "default selection mode"
if (getInk()->isSelection() &&
(!m_document->isMaskVisible() ||
getSelectionMode() == kDefaultSelectionMode)) {
getSelectionMode() == tools::SelectionMode::DEFAULT)) {
Mask emptyMask;
m_transaction.execute(new cmd::SetMask(m_document, &emptyMask));
}
@ -172,9 +171,9 @@ public:
m_mask->bounds().y-y1):
gfx::Point(0, 0));
m_opacity = m_toolSettings->getOpacity();
m_tolerance = m_toolSettings->getTolerance();
m_contiguous = m_toolSettings->getContiguous();
m_opacity = m_toolPref.opacity();
m_tolerance = m_toolPref.tolerance();
m_contiguous = m_toolPref.contiguous();
m_speed.x = 0;
m_speed.y = 0;
@ -222,8 +221,6 @@ public:
}
}
delete m_shadeTable;
if (redraw)
update_screen_for_document(m_document);
}
@ -262,15 +259,16 @@ public:
gfx::Point getMaskOrigin() override { return m_maskOrigin; }
const render::Zoom& zoom() override { return m_editor->zoom(); }
ToolLoop::Button getMouseButton() override { return m_button; }
int getPrimaryColor() override { return m_primary_color; }
void setPrimaryColor(int color) override { m_primary_color = color; }
int getSecondaryColor() override { return m_secondary_color; }
void setSecondaryColor(int color) override { m_secondary_color = color; }
doc::color_t getFgColor() override { return m_fgColor; }
doc::color_t getBgColor() override { return m_bgColor; }
doc::color_t getPrimaryColor() override { return m_primaryColor; }
void setPrimaryColor(doc::color_t color) override { m_primaryColor = color; }
doc::color_t getSecondaryColor() override { return m_secondaryColor; }
void setSecondaryColor(doc::color_t color) override { m_secondaryColor = color; }
int getOpacity() override { return m_opacity; }
int getTolerance() override { return m_tolerance; }
bool getContiguous() override { return m_contiguous; }
SelectionMode getSelectionMode() override { return m_editor->getSelectionMode(); }
ISettings* settings() override { return m_settings; }
tools::SelectionMode getSelectionMode() override { return m_editor->getSelectionMode(); }
filters::TiledMode getTiledMode() override { return m_docPref.tiled.mode(); }
bool getGridVisible() override { return m_docPref.grid.visible(); }
bool getSnapToGrid() override { return m_docPref.grid.snap(); }
@ -292,38 +290,27 @@ public:
void cancel() override { m_canceled = true; }
bool isCanceled() override { return m_canceled; }
gfx::Point screenToSprite(const gfx::Point& screenPoint) override
{
gfx::Point screenToSprite(const gfx::Point& screenPoint) override {
return m_editor->screenToEditor(screenPoint);
}
gfx::Region& getDirtyArea() override
{
gfx::Region& getDirtyArea() override {
return m_dirtyArea;
}
void updateDirtyArea() override
{
void updateDirtyArea() override {
m_editor->hideDrawingCursor();
m_document->notifySpritePixelsModified(m_sprite, m_dirtyArea);
m_editor->showDrawingCursor();
}
void updateStatusBar(const char* text) override
{
void updateStatusBar(const char* text) override {
StatusBar::instance()->setStatusText(0, text);
}
// ShadingOptions implementation
tools::ShadeTable8* getShadeTable() override
{
if (m_shadeTable == NULL) {
app::ColorSwatches* colorSwatches = m_settings->getColorSwatches();
ASSERT(colorSwatches != NULL);
m_shadeTable = new tools::ShadeTable8(*colorSwatches,
tools::kRotateShadingMode);
}
return m_shadeTable;
tools::ShadeTable8* getShadeTable() override {
return nullptr;
}
};
@ -370,13 +357,13 @@ tools::ToolLoop* create_tool_loop(Editor* editor, Context* context)
// Create the new tool loop
try {
return new ToolLoopImpl(editor, context,
return new ToolLoopImpl(
editor, context,
current_tool,
current_ink,
editor->document(),
!editor->isSecondaryButton() ? tools::ToolLoop::Left: tools::ToolLoop::Right,
!editor->isSecondaryButton() ? fg: bg,
!editor->isSecondaryButton() ? bg: fg);
fg, bg);
}
catch (const std::exception& ex) {
Alert::show(PACKAGE
@ -401,9 +388,8 @@ class PreviewToolLoopImpl : public tools::ToolLoop,
Sprite* m_sprite;
Layer* m_layer;
frame_t m_frame;
ISettings* m_settings;
DocumentPreferences& m_docPref;
IToolSettings* m_toolSettings;
ToolPreferences& m_toolPref;
int m_opacity;
int m_tolerance;
bool m_contiguous;
@ -412,8 +398,10 @@ class PreviewToolLoopImpl : public tools::ToolLoop,
bool m_canceled;
tools::ToolLoop::Button m_button;
tools::Ink* m_ink;
int m_primary_color;
int m_secondary_color;
doc::color_t m_fgColor;
doc::color_t m_bgColor;
doc::color_t m_primaryColor;
doc::color_t m_secondaryColor;
gfx::Region m_dirtyArea;
tools::ShadeTable8* m_shadeTable;
Image* m_image;
@ -426,9 +414,8 @@ public:
tools::Tool* tool,
tools::Ink* ink,
Document* document,
tools::ToolLoop::Button button,
const app::Color& primary_color,
const app::Color& secondary_color,
const app::Color& fgColor,
const app::Color& bgColor,
Image* image,
const gfx::Point& offset)
: m_editor(editor)
@ -438,22 +425,22 @@ public:
, m_sprite(editor->sprite())
, m_layer(editor->layer())
, m_frame(editor->frame())
, m_settings(m_context->settings())
, m_docPref(App::instance()->preferences().document(m_document))
, m_toolSettings(m_settings->getToolSettings(m_tool))
, m_docPref(Preferences::instance().document(m_document))
, m_toolPref(Preferences::instance().tool(m_tool))
, m_offset(offset)
, m_canceled(false)
, m_button(button)
, m_button(tools::ToolLoop::Left)
, m_ink(ink)
, m_primary_color(color_utils::color_for_layer(primary_color, m_layer))
, m_secondary_color(color_utils::color_for_layer(secondary_color, m_layer))
, m_shadeTable(NULL)
, m_fgColor(color_utils::color_for_layer(fgColor, m_layer))
, m_bgColor(color_utils::color_for_layer(bgColor, m_layer))
, m_primaryColor(m_fgColor)
, m_secondaryColor(m_bgColor)
, m_image(image)
{
m_brush = App::instance()->getMainWindow()->getContextBar()->activeBrush();
m_opacity = m_toolSettings->getOpacity();
m_tolerance = m_toolSettings->getTolerance();
m_contiguous = m_toolSettings->getContiguous();
m_opacity = m_toolPref.opacity();
m_tolerance = m_toolPref.tolerance();
m_contiguous = m_toolPref.contiguous();
m_speed.x = 0;
m_speed.y = 0;
@ -495,15 +482,16 @@ public:
}
const render::Zoom& zoom() override { return m_editor->zoom(); }
ToolLoop::Button getMouseButton() override { return m_button; }
int getPrimaryColor() override { return m_primary_color; }
void setPrimaryColor(int color) override { m_primary_color = color; }
int getSecondaryColor() override { return m_secondary_color; }
void setSecondaryColor(int color) override { m_secondary_color = color; }
doc::color_t getFgColor() override { return m_fgColor; }
doc::color_t getBgColor() override { return m_bgColor; }
doc::color_t getPrimaryColor() override { return m_primaryColor; }
void setPrimaryColor(doc::color_t color) override { m_primaryColor = color; }
doc::color_t getSecondaryColor() override { return m_secondaryColor; }
void setSecondaryColor(doc::color_t color) override { m_secondaryColor = color; }
int getOpacity() override { return m_opacity; }
int getTolerance() override { return m_tolerance; }
bool getContiguous() override { return m_contiguous; }
SelectionMode getSelectionMode() override { return m_editor->getSelectionMode(); }
ISettings* settings() override { return m_settings; }
tools::SelectionMode getSelectionMode() override { return m_editor->getSelectionMode(); }
filters::TiledMode getTiledMode() override { return m_docPref.tiled.mode(); }
bool getGridVisible() override { return m_docPref.grid.visible(); }
bool getSnapToGrid() override { return m_docPref.grid.snap(); }
@ -542,13 +530,7 @@ public:
// ShadingOptions implementation
tools::ShadeTable8* getShadeTable() override {
if (m_shadeTable == NULL) {
app::ColorSwatches* colorSwatches = m_settings->getColorSwatches();
ASSERT(colorSwatches != NULL);
m_shadeTable = new tools::ShadeTable8(*colorSwatches,
tools::kRotateShadingMode);
}
return m_shadeTable;
return nullptr;
}
};
@ -583,7 +565,6 @@ tools::ToolLoop* create_tool_loop_preview(
current_tool,
current_ink,
editor->document(),
tools::ToolLoop::Left,
fg, bg, image, offset);
}
catch (const std::exception&) {

View File

@ -168,11 +168,6 @@ void HomeView::onNewUpdate(const std::string& url, const std::string& version)
layout();
}
Preferences& HomeView::getPreferences()
{
return App::instance()->preferences();
}
#endif // ENABLE_UPDATER
void HomeView::onRecoverSprites()

View File

@ -61,7 +61,6 @@ namespace app {
void onCheckingUpdates() override;
void onUpToDate() override;
void onNewUpdate(const std::string& url, const std::string& version) override;
Preferences& getPreferences() override;
#endif
private:

View File

@ -17,7 +17,6 @@
#include "app/commands/commands.h"
#include "app/commands/params.h"
#include "app/document.h"
#include "app/settings/settings.h"
#include "app/tools/ink.h"
#include "app/tools/tool.h"
#include "app/tools/tool_box.h"
@ -633,12 +632,11 @@ void KeyboardShortcuts::disableAccel(const ui::Accelerator& accel, KeyContext ke
KeyContext KeyboardShortcuts::getCurrentKeyContext()
{
app::Context* ctx = UIContext::instance();
Document* doc = ctx->activeDocument();
Document* doc = UIContext::instance()->activeDocument();
if (doc &&
doc->isMaskVisible() &&
ctx->settings()->getCurrentTool()->getInk(0)->isSelection())
App::instance()->activeTool()->getInk(0)->isSelection())
return KeyContext::Selection;
else
return KeyContext::Normal;

View File

@ -18,7 +18,6 @@
#include "app/load_widget.h"
#include "app/modules/editors.h"
#include "app/pref/preferences.h"
#include "app/settings/settings.h"
#include "app/ui/color_bar.h"
#include "app/ui/context_bar.h"
#include "app/ui/devconsole_view.h"
@ -214,19 +213,19 @@ void MainWindow::setMode(Mode mode)
bool MainWindow::getTimelineVisibility() const
{
return App::instance()->preferences().general.visibleTimeline();
return Preferences::instance().general.visibleTimeline();
}
void MainWindow::setTimelineVisibility(bool visible)
{
App::instance()->preferences().general.visibleTimeline(visible);
Preferences::instance().general.visibleTimeline(visible);
configureWorkspaceLayout();
}
void MainWindow::popTimeline()
{
Preferences& preferences = App::instance()->preferences();
Preferences& preferences = Preferences::instance();
if (!preferences.general.autoshowTimeline())
return;
@ -383,7 +382,7 @@ void MainWindow::configureWorkspaceLayout()
isDoc &&
(m_mode == NormalMode ||
m_mode == ContextBarAndTimelineMode) &&
App::instance()->preferences().general.visibleTimeline());
Preferences::instance().general.visibleTimeline());
if (m_contextBar->isVisible()) {
m_contextBar->updateForCurrentTool();

View File

@ -187,7 +187,7 @@ NewsListBox::NewsListBox()
{
m_timer.Tick.connect(&NewsListBox::onTick, this);
std::string cache = App::instance()->preferences().news.cacheFile();
std::string cache = Preferences::instance().news.cacheFile();
if (!cache.empty() && base::is_file(cache) && validCache(cache))
parseFile(cache);
else
@ -302,7 +302,7 @@ void NewsListBox::parseFile(const std::string& filename)
view->updateView();
// Save as cached news
App::instance()->preferences().news.cacheFile(filename);
Preferences::instance().news.cacheFile(filename);
}
bool NewsListBox::validCache(const std::string& filename)

View File

@ -19,7 +19,6 @@
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/settings/settings.h"
#include "app/tools/tool.h"
#include "app/ui/button_set.h"
#include "app/ui/color_button.h"
@ -196,7 +195,9 @@ StatusBar::StatusBar()
tooltipManager->addTooltipFor(m_currentFrame, "Current Frame", JI_BOTTOM);
tooltipManager->addTooltipFor(m_slider, "Cel Opacity", JI_BOTTOM);
App::instance()->CurrentToolChange.connect(&StatusBar::onCurrentToolChange, this);
Preferences::instance().toolBox.activeTool.AfterChange.connect(
Bind<void>(&StatusBar::onCurrentToolChange, this));
UIContext::instance()->addObserver(this);
}
@ -211,10 +212,10 @@ StatusBar::~StatusBar()
void StatusBar::onCurrentToolChange()
{
if (isVisible()) {
tools::Tool* currentTool = UIContext::instance()->settings()->getCurrentTool();
if (currentTool) {
showTool(500, currentTool);
setTextf("%s Selected", currentTool->getText().c_str());
tools::Tool* tool = App::instance()->activeTool();
if (tool) {
showTool(500, tool);
setTextf("%s Selected", tool->getText().c_str());
}
}
}

View File

@ -2306,7 +2306,7 @@ bool Timeline::isCopyKeyPressed(ui::Message* msg)
DocumentPreferences& Timeline::docPref() const
{
return App::instance()->preferences().document(m_document);
return Preferences::instance().document(m_document);
}
skin::SkinTheme* Timeline::skinTheme() const

View File

@ -16,7 +16,7 @@
#include "app/commands/commands.h"
#include "app/modules/editors.h"
#include "app/modules/gfx.h"
#include "app/settings/settings.h"
#include "app/pref/preferences.h"
#include "app/tools/tool_box.h"
#include "app/ui/keyboard_shortcuts.h"
#include "app/ui/main_window.h"
@ -321,8 +321,7 @@ void ToolBar::onPaint(ui::PaintEvent& ev)
gfx::Color face;
int nw;
if (UIContext::instance()->settings()->getCurrentTool() == tool ||
m_hotIndex == c) {
if (App::instance()->activeTool() == tool || m_hotIndex == c) {
nw = PART_TOOLBUTTON_HOT_NW;
face = hotFace;
}
@ -583,11 +582,12 @@ void ToolBar::closeTipWindow()
void ToolBar::selectTool(Tool* tool)
{
ASSERT(tool != NULL);
ASSERT(tool);
m_selectedInGroup[tool->getGroup()] = tool;
UIContext::instance()->settings()->setCurrentTool(tool);
// Set active tool in preferences.
Preferences::instance().toolBox.activeTool(tool->getId());
if (m_currentStrip)
m_currentStrip->invalidate();
@ -731,8 +731,8 @@ void ToolBar::ToolStrip::onPaint(PaintEvent& ev)
gfx::Color face;
int nw;
if (UIContext::instance()->settings()->getCurrentTool() == tool ||
m_hotTool == tool) {
if (App::instance()->activeTool() == tool ||
m_hotTool == tool) {
nw = PART_TOOLBUTTON_HOT_NW;
face = theme->colors.buttonHotFace();
}

View File

@ -13,7 +13,6 @@
#include "app/document.h"
#include "app/modules/editors.h"
#include "app/pref/preferences.h"
#include "app/settings/ui_settings_impl.h"
#include "app/ui/color_bar.h"
#include "app/ui/document_view.h"
#include "app/ui/editor/editor.h"
@ -34,11 +33,10 @@ namespace app {
UIContext* UIContext::m_instance = nullptr;
UIContext::UIContext()
: Context(new UISettingsImpl)
, m_lastSelectedDoc(nullptr)
: m_lastSelectedDoc(nullptr)
, m_lastSelectedView(nullptr)
{
documents().addObserver(&App::instance()->preferences());
documents().addObserver(&Preferences::instance());
ASSERT(m_instance == NULL);
m_instance = this;
@ -49,7 +47,7 @@ UIContext::~UIContext()
ASSERT(m_instance == this);
m_instance = NULL;
documents().removeObserver(&App::instance()->preferences());
documents().removeObserver(&Preferences::instance());
// The context must be empty at this point. (It's to check if the UI
// is working correctly, i.e. closing all files when the user can

View File

@ -21,7 +21,6 @@
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
#include "app/modules/palettes.h"
#include "app/settings/settings.h"
#include "app/transaction.h"
#include "app/ui/color_bar.h"
#include "app/ui/editor/editor.h"

View File

@ -183,14 +183,6 @@ void gen_pref_header(TiXmlDocument* doc, const std::string& inputFn)
<< "#define GENERATED_PREF_TYPES_H_INCLUDED\n"
<< "#pragma once\n"
<< "\n"
<< "#include \"app/color.h\"\n"
<< "#include \"app/pref/option.h\"\n"
<< "#include \"doc/anidir.h\"\n"
<< "#include \"doc/brush_pattern.h\"\n"
<< "#include \"doc/frame.h\"\n"
<< "#include \"gfx/rect.h\"\n"
<< "#include \"filters/tiled_mode.h\"\n"
<< "\n"
<< "#include <string>\n"
<< "\n"
<< "namespace app {\n"
@ -258,9 +250,8 @@ void gen_pref_impl(TiXmlDocument* doc, const std::string& inputFn)
<< "#include \"config.h\"\n"
<< "#endif\n"
<< "\n"
<< "#include \"generated_pref_types.h\"\n"
<< "\n"
<< "#include \"app/pref/option_io.h\"\n"
<< "#include \"app/pref/preferences.h\"\n"
<< "\n"
<< "namespace app {\n"
<< "namespace gen {\n";

View File

@ -10,6 +10,7 @@
#include "ui/int_entry.h"
#include "base/scoped_value.h"
#include "gfx/rect.h"
#include "gfx/region.h"
#include "ui/manager.h"
@ -31,6 +32,7 @@ IntEntry::IntEntry(int min, int max)
, m_max(max)
, m_popupWindow(NULL)
, m_slider(NULL)
, m_changeFromSlider(false)
{
}
@ -51,7 +53,7 @@ void IntEntry::setValue(int value)
setTextf("%d", value);
if (m_slider != NULL)
if (m_slider && !m_changeFromSlider)
m_slider->setValue(value);
onValueChange();
@ -171,6 +173,7 @@ void IntEntry::closePopup()
void IntEntry::onChangeSlider()
{
base::ScopedValue<bool> lockFlag(m_changeFromSlider, true, false);
setValue(m_slider->getValue());
selectAllText();
}

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2001-2013 David Capello
// Copyright (C) 2001-2013, 2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -41,6 +41,7 @@ namespace ui {
int m_max;
PopupWindow* m_popupWindow;
Slider* m_slider;
bool m_changeFromSlider;
};
} // namespace ui