[aseprite] 87/196: Add different selection modes to SelectTile command

Tobias Hansen thansen at moszumanska.debian.org
Wed Apr 20 18:50:05 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit 417e431a328358a1c75c4a818cad2f3eda2204ee
Author: David Capello <davidcapello at gmail.com>
Date:   Sat Mar 19 12:09:03 2016 -0300

    Add different selection modes to SelectTile command
    
    Now we can add a tile using Shift+double click or substract one with
    Shift+Alt+double click.
---
 data/gui.xml                         |  8 +++++-
 src/app/commands/cmd_select_tile.cpp | 49 +++++++++++++++++++++++++++++++-----
 src/app/ui/editor/standby_state.cpp  | 12 ++++++++-
 3 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/data/gui.xml b/data/gui.xml
index 8355df8..2ebc57b 100644
--- a/data/gui.xml
+++ b/data/gui.xml
@@ -393,12 +393,18 @@
       <key command="SavePalette" />
       <key command="ColorQuantization" />
       <key command="AddColor">
-	<param name="source" value="fg" />
+        <param name="source" value="fg" />
       </key>
       <key command="AddColor">
         <param name="source" value="bg" />
       </key>
       <key command="SelectTile" />
+      <key command="SelectTile">
+        <param name="mode" value="add" />
+      </key>
+      <key command="SelectTile">
+        <param name="mode" value="subtract" />
+      </key>
     </commands>
 
     <!-- Keyboard shortcuts to select tools -->
diff --git a/src/app/commands/cmd_select_tile.cpp b/src/app/commands/cmd_select_tile.cpp
index 1c4a419..0de6d17 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)
+{
+}
+
+void SelectTileCommand::onLoadParams(const Params& params)
 {
+  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* context)
+bool SelectTileCommand::onEnabled(Context* ctx)
 {
-  return context->checkFlags(ContextFlags::ActiveDocumentIsWritable);
+  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> 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 1e477a2..7aebb97 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;
   }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list