[aseprite] 51/134: Add SetLoopSection command and F2 keyboard shortcut (close #491)

Tobias Hansen thansen at moszumanska.debian.org
Sat Mar 14 17:10:03 UTC 2015


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

thansen pushed a commit to branch master
in repository aseprite.

commit 8716214718b5dadd2fa49cbf251e5c1e675fd231
Author: David Capello <davidcapello at gmail.com>
Date:   Sat Nov 8 19:57:46 2014 -0300

    Add SetLoopSection command and F2 keyboard shortcut (close #491)
---
 data/gui.xml                              |   2 +
 src/app/CMakeLists.txt                    |   1 +
 src/app/commands/cmd_set_loop_section.cpp | 131 ++++++++++++++++++++++++++++++
 src/app/commands/commands_list.h          |   1 +
 src/app/context.cpp                       |  10 +++
 src/app/context.h                         |   1 +
 src/app/ui/configure_timeline_popup.cpp   |  10 +--
 7 files changed, 148 insertions(+), 8 deletions(-)

diff --git a/data/gui.xml b/data/gui.xml
index f35cc1d..1630de0 100644
--- a/data/gui.xml
+++ b/data/gui.xml
@@ -91,6 +91,7 @@
       <key command="ShowGrid" shortcut="Shift+G" />
       <key command="ShowPixelGrid" shortcut="Alt+Shift+G" />
       <key command="SnapToGrid" shortcut="Shift+S" />
+      <key command="SetLoopSection" shortcut="F2" />
       <key command="ShowOnionSkin" shortcut="F3" />
       <key command="Timeline" shortcut="Tab">
         <param name="switch" value="true" />
@@ -557,6 +558,7 @@
         <item command="SnapToGrid" text="&Snap to Grid" />
         <item command="GridSettings" text="Gri&d Settings" />
         <separator />
+        <item command="SetLoopSection" text="Set &Loop Section" />
         <item command="ShowOnionSkin" text="Show &Onion Skin" />
         <separator />
         <item command="Timeline" text="&Timeline">
diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt
index f408e6f..00e55c1 100644
--- a/src/app/CMakeLists.txt
+++ b/src/app/CMakeLists.txt
@@ -79,6 +79,7 @@ add_library(app-lib
   commands/cmd_save_mask.cpp
   commands/cmd_save_palette.cpp
   commands/cmd_scroll.cpp
+  commands/cmd_set_loop_section.cpp
   commands/cmd_set_palette.cpp
   commands/cmd_sprite_editor.cpp
   commands/cmd_sprite_properties.cpp
diff --git a/src/app/commands/cmd_set_loop_section.cpp b/src/app/commands/cmd_set_loop_section.cpp
new file mode 100644
index 0000000..78bb3ea
--- /dev/null
+++ b/src/app/commands/cmd_set_loop_section.cpp
@@ -0,0 +1,131 @@
+/* Aseprite
+ * Copyright (C) 2001-2014  David Capello
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "app/app.h"
+#include "app/commands/command.h"
+#include "app/commands/params.h"
+#include "app/context_access.h"
+#include "app/settings/document_settings.h"
+#include "app/settings/settings.h"
+#include "app/ui/main_window.h"
+#include "app/ui/timeline.h"
+
+namespace app {
+
+class SetLoopSectionCommand : public Command {
+public:
+  enum class Action { Auto, On, Off };
+
+  SetLoopSectionCommand();
+  Command* clone() const override { return new SetLoopSectionCommand(*this); }
+
+protected:
+  void onLoadParams(Params* params) override;
+  bool onEnabled(Context* context) override;
+  void onExecute(Context* context) override;
+
+  Action m_action;
+  FrameNumber m_begin, m_end;
+};
+
+SetLoopSectionCommand::SetLoopSectionCommand()
+  : Command("SetLoopSection",
+            "Set Loop Section",
+            CmdRecordableFlag)
+  , m_action(Action::Auto)
+  , m_begin(0)
+  , m_end(0)
+{
+}
+
+void SetLoopSectionCommand::onLoadParams(Params* params)
+{
+  std::string action = params->get("action");
+  if (action == "on") m_action = Action::On;
+  else if (action == "off") m_action = Action::Off;
+  else m_action = Action::Auto;
+
+  std::string begin = params->get("begin");
+  std::string end = params->get("end");
+
+  m_begin = FrameNumber(strtol(begin.c_str(), NULL, 10));
+  m_end = FrameNumber(strtol(end.c_str(), NULL, 10));
+}
+
+bool SetLoopSectionCommand::onEnabled(Context* ctx)
+{
+  return ctx->checkFlags(ContextFlags::HasActiveDocument);
+}
+
+void SetLoopSectionCommand::onExecute(Context* ctx)
+{
+  Document* doc = ctx->activeDocument();
+  if (!doc)
+    return;
+
+  IDocumentSettings* docSets = ctx->settings()->getDocumentSettings(doc);
+  if (!docSets)
+    return;
+
+  FrameNumber begin = m_begin;
+  FrameNumber end = m_end;
+  bool on = false;
+
+  switch (m_action) {
+
+    case Action::Auto: {
+      Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
+      if (range.enabled() && (range.frames() > 1)) {
+        begin = range.frameBegin();
+        end = range.frameEnd();
+        on = true;
+      }
+      else {
+        on = false;
+      }
+      break;
+    }
+
+    case Action::On:
+      on = true;
+      break;
+
+    case Action::Off:
+      on = false;
+      break;
+
+  }
+
+  if (on) {
+    docSets->setLoopAnimation(true);
+    docSets->setLoopRange(begin, end);
+  }
+  else 
+    docSets->setLoopAnimation(false);
+}
+
+Command* CommandFactory::createSetLoopSectionCommand()
+{
+  return new SetLoopSectionCommand;
+}
+
+} // namespace app
diff --git a/src/app/commands/commands_list.h b/src/app/commands/commands_list.h
index 58aa4c2..0239692 100644
--- a/src/app/commands/commands_list.h
+++ b/src/app/commands/commands_list.h
@@ -100,6 +100,7 @@ FOR_EACH_COMMAND(SaveFileCopyAs)
 FOR_EACH_COMMAND(SaveMask)
 FOR_EACH_COMMAND(SavePalette)
 FOR_EACH_COMMAND(Scroll)
+FOR_EACH_COMMAND(SetLoopSection)
 FOR_EACH_COMMAND(SetPalette)
 FOR_EACH_COMMAND(ShowGrid)
 FOR_EACH_COMMAND(ShowOnionSkin)
diff --git a/src/app/context.cpp b/src/app/context.cpp
index 28401f9..f15ff12 100644
--- a/src/app/context.cpp
+++ b/src/app/context.cpp
@@ -23,6 +23,7 @@
 #include "app/context.h"
 
 #include "app/commands/command.h"
+#include "app/commands/commands.h"
 #include "app/console.h"
 #include "app/document.h"
 #include "app/document_location.h"
@@ -69,6 +70,15 @@ DocumentLocation Context::activeLocation() const
   return location;
 }
 
+void Context::executeCommand(const char* commandName)
+{
+  Command* cmd = CommandsModule::instance()->getCommandByName(commandName);
+  if (cmd)
+    executeCommand(cmd);
+  else
+    throw std::runtime_error("Invalid command name");
+}
+
 void Context::executeCommand(Command* command, Params* params)
 {
   Console console;
diff --git a/src/app/context.h b/src/app/context.h
index af3176e..7f47cf7 100644
--- a/src/app/context.h
+++ b/src/app/context.h
@@ -63,6 +63,7 @@ namespace app {
     app::Document* activeDocument() const;
     DocumentLocation activeLocation() const;
 
+    void executeCommand(const char* commandName);
     virtual void executeCommand(Command* command, Params* params = NULL);
 
     Signal1<void, Command*> BeforeCommandExecution;
diff --git a/src/app/ui/configure_timeline_popup.cpp b/src/app/ui/configure_timeline_popup.cpp
index 74b10cf..ae0de08 100644
--- a/src/app/ui/configure_timeline_popup.cpp
+++ b/src/app/ui/configure_timeline_popup.cpp
@@ -29,6 +29,7 @@
 #include "app/load_widget.h"
 #include "app/settings/document_settings.h"
 #include "app/settings/settings.h"
+#include "app/commands/commands.h"
 #include "app/ui/main_window.h"
 #include "app/ui/timeline.h"
 #include "app/ui_context.h"
@@ -184,14 +185,7 @@ void ConfigureTimelinePopup::onResetOnionskin()
 
 void ConfigureTimelinePopup::onSetLoopSection()
 {
-  IDocumentSettings* docSet = docSettings();
-  if (docSet) {
-    Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
-    if (range.enabled() && (range.frames() >= 1)) {
-      docSet->setLoopAnimation(true);
-      docSet->setLoopRange(range.frameBegin(), range.frameEnd());
-    }
-  }
+  UIContext::instance()->executeCommand(CommandId::SetLoopSection);
 }
 
 void ConfigureTimelinePopup::onResetLoopSection()

-- 
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