diff --git a/data/gui.xml b/data/gui.xml
index 8355df820..2ebc57bc4 100644
--- a/data/gui.xml
+++ b/data/gui.xml
@@ -393,12 +393,18 @@
-
+
+
+
+
+
+
+
diff --git a/src/app/commands/cmd_select_tile.cpp b/src/app/commands/cmd_select_tile.cpp
index 1c4a4190b..0de6d17a5 100644
--- a/src/app/commands/cmd_select_tile.cpp
+++ b/src/app/commands/cmd_select_tile.cpp
@@ -32,20 +32,37 @@ public:
Command* clone() const override { return new SelectTileCommand(*this); }
protected:
- bool onEnabled(Context* context) override;
- void onExecute(Context* context) override;
+ void onLoadParams(const Params& params) override;
+ bool onEnabled(Context* ctx) override;
+ void onExecute(Context* ctx) override;
+ std::string onGetFriendlyName() const override;
+
+private:
+ tools::SelectionMode m_mode;
};
SelectTileCommand::SelectTileCommand()
: Command("SelectTile",
"Select Tile",
CmdRecordableFlag)
+ , m_mode(tools::SelectionMode::DEFAULT)
{
}
-bool SelectTileCommand::onEnabled(Context* context)
+void SelectTileCommand::onLoadParams(const Params& params)
{
- return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
+ std::string mode = params.get("mode");
+ if (mode == "add")
+ m_mode = tools::SelectionMode::ADD;
+ else if (mode == "subtract")
+ m_mode = tools::SelectionMode::SUBTRACT;
+ else
+ m_mode = tools::SelectionMode::DEFAULT;
+}
+
+bool SelectTileCommand::onEnabled(Context* ctx)
+{
+ return ctx->checkFlags(ContextFlags::ActiveDocumentIsWritable);
}
void SelectTileCommand::onExecute(Context* ctx)
@@ -60,12 +77,20 @@ void SelectTileCommand::onExecute(Context* ctx)
auto& docPref = Preferences::instance().document(doc);
base::UniquePtr mask(new Mask());
+
+ if (m_mode != tools::SelectionMode::DEFAULT)
+ mask->copyFrom(doc->mask());
+
{
- const gfx::Rect gridBounds = docPref.grid.bounds();
+ gfx::Rect gridBounds = docPref.grid.bounds();
gfx::Point pos = current_editor->screenToEditor(ui::get_mouse_position());
pos = snap_to_grid(gridBounds, pos, PreferSnapTo::BoxOrigin);
+ gridBounds.setOrigin(pos);
- mask->add(gfx::Rect(pos, gridBounds.size()));
+ if (m_mode != tools::SelectionMode::SUBTRACT)
+ mask->add(gridBounds);
+ else
+ mask->subtract(gridBounds);
}
// Set the new mask
@@ -79,6 +104,18 @@ void SelectTileCommand::onExecute(Context* ctx)
update_screen_for_document(doc);
}
+std::string SelectTileCommand::onGetFriendlyName() const
+{
+ std::string text = "Select Tile";
+
+ switch (m_mode) {
+ case tools::SelectionMode::ADD: text += " (Add)"; break;
+ case tools::SelectionMode::SUBTRACT: text += " (Subtract)"; break;
+ }
+
+ return text;
+}
+
Command* CommandFactory::createSelectTileCommand()
{
return new SelectTileCommand;
diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp
index 1e477a2a3..7aebb9704 100644
--- a/src/app/ui/editor/standby_state.cpp
+++ b/src/app/ui/editor/standby_state.cpp
@@ -349,7 +349,17 @@ bool StandbyState::onDoubleClick(Editor* editor, MouseMessage* msg)
Command* selectTileCmd =
CommandsModule::instance()->getCommandByName(CommandId::SelectTile);
- UIContext::instance()->executeCommand(selectTileCmd);
+ Params params;
+ switch (editor->getSelectionMode()) {
+ case tools::SelectionMode::ADD:
+ params.set("mode", "add");
+ break;
+ case tools::SelectionMode::SUBTRACT:
+ params.set("mode", "subtract");
+ break;
+ }
+
+ UIContext::instance()->executeCommand(selectTileCmd, params);
return true;
}