[aseprite] 41/64: Add MoveMaskCommand::getDelta member function
Tobias Hansen
thansen at moszumanska.debian.org
Tue Jun 21 14:43:03 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 591b3b19acc9b6dd5265219f931e25d953f15efe
Author: David Capello <davidcapello at gmail.com>
Date: Wed May 18 12:03:28 2016 -0300
Add MoveMaskCommand::getDelta member function
---
src/app/commands/cmd_move_mask.cpp | 93 ++++++++++++++++++++++----------------
src/app/commands/cmd_move_mask.h | 3 +-
src/app/ui/document_view.h | 1 +
3 files changed, 56 insertions(+), 41 deletions(-)
diff --git a/src/app/commands/cmd_move_mask.cpp b/src/app/commands/cmd_move_mask.cpp
index 962bfa9..1c974f3 100644
--- a/src/app/commands/cmd_move_mask.cpp
+++ b/src/app/commands/cmd_move_mask.cpp
@@ -20,7 +20,9 @@
#include "app/modules/gui.h"
#include "app/pref/preferences.h"
#include "app/transaction.h"
+#include "app/ui/document_view.h"
#include "app/ui/editor/editor.h"
+#include "app/ui_context.h"
#include "base/convert_to.h"
#include "doc/mask.h"
#include "doc/sprite.h"
@@ -89,9 +91,53 @@ bool MoveMaskCommand::onEnabled(Context* context)
void MoveMaskCommand::onExecute(Context* context)
{
- DocumentPreferences& docPref = Preferences::instance().document(context->activeDocument());
- ui::View* view = ui::View::getView(current_editor);
- gfx::Rect vp = view->viewportBounds();
+ gfx::Point delta = getDelta(context);
+
+ switch (m_target) {
+
+ case Boundaries: {
+ ContextWriter writer(context);
+ Document* document(writer.document());
+ {
+ Transaction transaction(writer.context(), "Move Selection", DoesntModifyDocument);
+ gfx::Point pt = document->mask()->bounds().origin();
+ document->getApi(transaction).setMaskPosition(pt.x+delta.x, pt.y+delta.y);
+ transaction.commit();
+ }
+
+ document->generateMaskBoundaries();
+ update_screen_for_document(document);
+ break;
+ }
+
+ case Content:
+ if (m_wrap) {
+ ContextWriter writer(context);
+ if (writer.cel()) {
+ // Rotate content
+ Transaction transaction(writer.context(), "Shift Pixels");
+ transaction.execute(new cmd::ShiftMaskedCel(writer.cel(), delta.x, delta.y));
+ transaction.commit();
+ }
+ update_screen_for_document(writer.document());
+ }
+ else {
+ current_editor->startSelectionTransformation(delta, 0.0);
+ }
+ break;
+
+ }
+}
+
+gfx::Point MoveMaskCommand::getDelta(Context* context) const
+{
+ DocumentView* view = static_cast<UIContext*>(context)->activeView();
+ if (!view)
+ return gfx::Point(0, 0);
+
+ DocumentPreferences& docPref = Preferences::instance().document(view->document());
+ Editor* editor = view->editor();
+ gfx::Rect vp = view->viewWidget()->viewportBounds();
gfx::Rect gridBounds = docPref.grid.bounds();
int dx = 0;
int dy = 0;
@@ -108,13 +154,13 @@ void MoveMaskCommand::onExecute(Context* context)
pixels = gridBounds.h;
break;
case ZoomedPixel:
- pixels = current_editor->zoom().apply(1);
+ pixels = editor->zoom().apply(1);
break;
case ZoomedTileWidth:
- pixels = current_editor->zoom().apply(gridBounds.w);
+ pixels = editor->zoom().apply(gridBounds.w);
break;
case ZoomedTileHeight:
- pixels = current_editor->zoom().apply(gridBounds.h);
+ pixels = editor->zoom().apply(gridBounds.h);
break;
case ViewportWidth:
pixels = vp.h;
@@ -131,40 +177,7 @@ void MoveMaskCommand::onExecute(Context* context)
case Down: dy = +m_quantity * pixels; break;
}
- switch (m_target) {
-
- case Boundaries: {
- ContextWriter writer(context);
- Document* document(writer.document());
- {
- Transaction transaction(writer.context(), "Move Selection", DoesntModifyDocument);
- gfx::Point pt = document->mask()->bounds().origin();
- document->getApi(transaction).setMaskPosition(pt.x+dx, pt.y+dy);
- transaction.commit();
- }
-
- document->generateMaskBoundaries();
- update_screen_for_document(document);
- break;
- }
-
- case Content:
- if (m_wrap) {
- ContextWriter writer(context);
- if (writer.cel()) {
- // Rotate content
- Transaction transaction(writer.context(), "Shift Pixels");
- transaction.execute(new cmd::ShiftMaskedCel(writer.cel(), dx, dy));
- transaction.commit();
- }
- update_screen_for_document(writer.document());
- }
- else {
- current_editor->startSelectionTransformation(gfx::Point(dx, dy), 0.0);
- }
- break;
-
- }
+ return gfx::Point(dx, dy);
}
std::string MoveMaskCommand::onGetFriendlyName() const
diff --git a/src/app/commands/cmd_move_mask.h b/src/app/commands/cmd_move_mask.h
index 12f24e3..8def5cc 100644
--- a/src/app/commands/cmd_move_mask.h
+++ b/src/app/commands/cmd_move_mask.h
@@ -1,5 +1,5 @@
// Aseprite
-// Copyright (C) 2001-2015 David Capello
+// Copyright (C) 2001-2016 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
@@ -32,6 +32,7 @@ namespace app {
Command* clone() const override { return new MoveMaskCommand(*this); }
Target getTarget() const { return m_target; }
+ gfx::Point getDelta(Context* context) const;
protected:
void onLoadParams(const Params& params) override;
diff --git a/src/app/ui/document_view.h b/src/app/ui/document_view.h
index 4f03be8..7d9ef3b 100644
--- a/src/app/ui/document_view.h
+++ b/src/app/ui/document_view.h
@@ -52,6 +52,7 @@ namespace app {
Document* document() const { return m_document; }
Editor* editor() { return m_editor; }
+ ui::View* viewWidget() const { return m_view; }
void getSite(doc::Site* site) const;
bool isPreview() { return m_type == Preview; }
--
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