2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-01-27 23:13:13 +08:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
2012-01-06 06:45:03 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/editor/moving_pixels_state.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "app/color_utils.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/cmd_flip.h"
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/commands/commands.h"
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/tools/ink.h"
|
|
|
|
#include "app/tools/tool.h"
|
|
|
|
#include "app/ui/editor/editor.h"
|
|
|
|
#include "app/ui/editor/editor_customization_delegate.h"
|
|
|
|
#include "app/ui/editor/pixels_movement.h"
|
|
|
|
#include "app/ui/editor/standby_state.h"
|
|
|
|
#include "app/ui/editor/transform_handles.h"
|
|
|
|
#include "app/ui/status_bar.h"
|
|
|
|
#include "app/ui_context.h"
|
|
|
|
#include "app/util/clipboard.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "base/unique_ptr.h"
|
|
|
|
#include "gfx/rect.h"
|
2012-03-12 09:20:59 +08:00
|
|
|
#include "raster/algorithm/flip_image.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "raster/mask.h"
|
|
|
|
#include "raster/sprite.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/manager.h"
|
|
|
|
#include "ui/message.h"
|
|
|
|
#include "ui/system.h"
|
|
|
|
#include "ui/view.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
#include <allegro.h>
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
MovingPixelsState::MovingPixelsState(Editor* editor, MouseMessage* msg, PixelsMovement* pixelsMovement, HandleType handle)
|
2012-02-06 11:17:42 +08:00
|
|
|
: m_currentEditor(editor)
|
2012-02-12 08:06:31 +08:00
|
|
|
, m_discarded(false)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2012-01-06 11:41:02 +08:00
|
|
|
// MovingPixelsState needs a selection tool to avoid problems
|
|
|
|
// sharing the extra cel between the drawing cursor preview and the
|
|
|
|
// pixels movement/transformation preview.
|
2012-01-08 05:52:42 +08:00
|
|
|
//ASSERT(!editor->getCurrentEditorTool()->getInk(0)->isSelection());
|
2012-01-06 11:41:02 +08:00
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
EditorCustomizationDelegate* customization = editor->getCustomizationDelegate();
|
2012-01-06 10:21:51 +08:00
|
|
|
m_pixelsMovement = pixelsMovement;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-01-06 10:21:51 +08:00
|
|
|
if (handle != NoHandle) {
|
|
|
|
int u, v;
|
2013-07-29 08:17:07 +08:00
|
|
|
editor->screenToEditor(msg->position().x, msg->position().y, &u, &v);
|
2012-01-06 10:21:51 +08:00
|
|
|
m_pixelsMovement->catchImage(u, v, handle);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-01-06 10:21:51 +08:00
|
|
|
editor->captureMouse();
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Setup mask color
|
2012-07-10 00:20:58 +08:00
|
|
|
setTransparentColor(StatusBar::instance()->getTransparentColor());
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-02-06 11:17:42 +08:00
|
|
|
// Add this class as:
|
2012-08-19 02:22:23 +08:00
|
|
|
// - observer of the UI context: so we know if the user wants to
|
|
|
|
// execute other command, so we can drop pixels.
|
|
|
|
// - observer of the status bar to know if the user has changed the
|
2012-02-06 11:17:42 +08:00
|
|
|
// transparent color.
|
2012-08-19 02:22:23 +08:00
|
|
|
UIContext::instance()->addObserver(this);
|
|
|
|
StatusBar::instance()->addObserver(this);
|
2012-02-06 11:17:42 +08:00
|
|
|
|
|
|
|
// Show controls to modify the "pixels movement" options (e.g. the
|
|
|
|
// transparent color).
|
2012-07-10 00:20:58 +08:00
|
|
|
StatusBar::instance()->showMovePixelsOptions();
|
2012-02-06 11:17:42 +08:00
|
|
|
|
|
|
|
// Add the current editor as filter for key message of the manager
|
|
|
|
// so we can catch the Enter key, and avoid to execute the
|
|
|
|
// PlayAnimation command.
|
2013-04-05 08:53:29 +08:00
|
|
|
m_currentEditor->getManager()->addMessageFilter(kKeyDownMessage, m_currentEditor);
|
|
|
|
m_currentEditor->getManager()->addMessageFilter(kKeyUpMessage, m_currentEditor);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MovingPixelsState::~MovingPixelsState()
|
|
|
|
{
|
2012-08-19 02:22:23 +08:00
|
|
|
UIContext::instance()->removeObserver(this);
|
|
|
|
StatusBar::instance()->removeObserver(this);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
delete m_pixelsMovement;
|
2012-02-06 11:17:42 +08:00
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
m_currentEditor->getManager()->removeMessageFilter(kKeyDownMessage, m_currentEditor);
|
|
|
|
m_currentEditor->getManager()->removeMessageFilter(kKeyUpMessage, m_currentEditor);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2012-01-12 11:39:39 +08:00
|
|
|
EditorState::BeforeChangeAction MovingPixelsState::onBeforeChangeState(Editor* editor, EditorState* newState)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
|
|
|
// If we are changing to another state, we've to drop the image.
|
|
|
|
if (m_pixelsMovement->isDragging())
|
|
|
|
m_pixelsMovement->dropImageTemporarily();
|
|
|
|
|
2012-01-12 11:39:39 +08:00
|
|
|
// Drop pixels if we are changing to a non-temporary state (a
|
|
|
|
// temporary state is something like ScrollingState).
|
|
|
|
if (!newState || !newState->isTemporalState()) {
|
2012-02-12 08:06:31 +08:00
|
|
|
if (!m_discarded)
|
|
|
|
m_pixelsMovement->dropImage();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-01-12 11:39:39 +08:00
|
|
|
editor->getDocument()->resetTransformation();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-01-12 11:39:39 +08:00
|
|
|
delete m_pixelsMovement;
|
|
|
|
m_pixelsMovement = NULL;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-01-12 11:39:39 +08:00
|
|
|
editor->releaseMouse();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-07-10 00:20:58 +08:00
|
|
|
StatusBar::instance()->hideMovePixelsOptions();
|
2012-01-12 11:39:39 +08:00
|
|
|
return DiscardState;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
editor->releaseMouse();
|
|
|
|
return KeepState;
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MovingPixelsState::onCurrentToolChange(Editor* editor)
|
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
|
|
|
tools::Tool* current_tool = editor->getCurrentEditorTool();
|
|
|
|
|
|
|
|
// If the user changed the tool when he/she is moving pixels,
|
|
|
|
// we have to drop the pixels only if the new tool is not selection...
|
|
|
|
if (m_pixelsMovement &&
|
|
|
|
(!current_tool->getInk(0)->isSelection() ||
|
|
|
|
!current_tool->getInk(1)->isSelection())) {
|
|
|
|
// We have to drop pixels
|
|
|
|
dropPixels(editor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
bool MovingPixelsState::onMouseDown(Editor* editor, MouseMessage* msg)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
|
|
|
Decorator* decorator = static_cast<Decorator*>(editor->getDecorator());
|
|
|
|
Document* document = editor->getDocument();
|
|
|
|
|
2012-01-12 11:39:39 +08:00
|
|
|
// Start scroll loop
|
2012-01-12 11:46:04 +08:00
|
|
|
if (checkForScroll(editor, msg))
|
2012-01-12 11:39:39 +08:00
|
|
|
return true;
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
// Transform selected pixels
|
|
|
|
if (document->isMaskVisible() &&
|
|
|
|
decorator->getTransformHandles(editor)) {
|
|
|
|
TransformHandles* transfHandles = decorator->getTransformHandles(editor);
|
|
|
|
|
|
|
|
// Get the handle covered by the mouse.
|
|
|
|
HandleType handle = transfHandles->getHandleAtPoint(editor,
|
2013-07-29 08:17:07 +08:00
|
|
|
msg->position(),
|
2012-01-06 06:45:03 +08:00
|
|
|
getTransformation(editor));
|
|
|
|
|
|
|
|
if (handle != NoHandle) {
|
|
|
|
// Re-catch the image
|
|
|
|
int x, y;
|
2013-07-29 08:17:07 +08:00
|
|
|
editor->screenToEditor(msg->position().x, msg->position().y, &x, &y);
|
2012-01-06 06:45:03 +08:00
|
|
|
m_pixelsMovement->catchImageAgain(x, y, handle);
|
|
|
|
|
|
|
|
editor->captureMouse();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start "moving pixels" loop
|
2013-07-29 08:17:07 +08:00
|
|
|
if (editor->isInsideSelection() && (msg->left() ||
|
|
|
|
msg->right())) {
|
2012-02-06 11:17:42 +08:00
|
|
|
// In case that the user is pressing the copy-selection keyboard shortcut.
|
|
|
|
EditorCustomizationDelegate* customization = editor->getCustomizationDelegate();
|
|
|
|
if (customization && customization->isCopySelectionKeyPressed()) {
|
|
|
|
// Stamp the pixels to create the copy.
|
|
|
|
m_pixelsMovement->stampImage();
|
|
|
|
}
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
// Re-catch the image
|
|
|
|
int x, y;
|
2013-07-29 08:17:07 +08:00
|
|
|
editor->screenToEditor(msg->position().x, msg->position().y, &x, &y);
|
2012-01-06 10:21:51 +08:00
|
|
|
m_pixelsMovement->catchImageAgain(x, y, MoveHandle);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
editor->captureMouse();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// End "moving pixels" loop
|
|
|
|
else {
|
|
|
|
// Drop pixels (e.g. to start drawing)
|
|
|
|
dropPixels(editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use StandbyState implementation
|
|
|
|
return StandbyState::onMouseDown(editor, msg);
|
|
|
|
}
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
bool MovingPixelsState::onMouseUp(Editor* editor, MouseMessage* msg)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
|
|
|
// Drop the image temporarily in this location (where the user releases the mouse)
|
|
|
|
m_pixelsMovement->dropImageTemporarily();
|
|
|
|
|
|
|
|
// Redraw the new pivot location.
|
|
|
|
editor->invalidate();
|
|
|
|
|
|
|
|
editor->releaseMouse();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
bool MovingPixelsState::onMouseMove(Editor* editor, MouseMessage* msg)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
|
|
|
// If there is a button pressed
|
|
|
|
if (m_pixelsMovement->isDragging()) {
|
|
|
|
// Infinite scroll
|
2013-07-29 08:17:07 +08:00
|
|
|
gfx::Point mousePos = editor->controlInfiniteScroll(msg);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Get the position of the mouse in the sprite
|
|
|
|
int x, y;
|
2013-07-29 08:17:07 +08:00
|
|
|
editor->screenToEditor(mousePos.x, mousePos.y, &x, &y);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-01-08 05:47:48 +08:00
|
|
|
// Get the customization for the pixels movement (snap to grid, angle snap, etc.).
|
2012-01-08 03:37:07 +08:00
|
|
|
PixelsMovement::MoveModifier moveModifier = PixelsMovement::NormalMovement;
|
|
|
|
|
2012-01-08 04:23:21 +08:00
|
|
|
if (editor->getCustomizationDelegate()->isSnapToGridKeyPressed())
|
|
|
|
moveModifier |= PixelsMovement::SnapToGridMovement;
|
|
|
|
|
2012-01-08 03:37:07 +08:00
|
|
|
if (editor->getCustomizationDelegate()->isAngleSnapKeyPressed())
|
2012-01-08 04:23:21 +08:00
|
|
|
moveModifier |= PixelsMovement::AngleSnapMovement;
|
2012-01-08 03:37:07 +08:00
|
|
|
|
2012-01-08 05:47:48 +08:00
|
|
|
if (editor->getCustomizationDelegate()->isMaintainAspectRatioKeyPressed())
|
|
|
|
moveModifier |= PixelsMovement::MaintainAspectRatioMovement;
|
|
|
|
|
2012-07-07 06:51:40 +08:00
|
|
|
if (editor->getCustomizationDelegate()->isLockAxisKeyPressed())
|
|
|
|
moveModifier |= PixelsMovement::LockAxisMovement;
|
|
|
|
|
2012-03-20 07:48:08 +08:00
|
|
|
// Invalidate handles area.
|
|
|
|
Decorator* decorator = static_cast<Decorator*>(editor->getDecorator());
|
|
|
|
TransformHandles* transfHandles = decorator->getTransformHandles(editor);
|
|
|
|
transfHandles->invalidateHandles(editor, m_pixelsMovement->getTransformation());
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
// Drag the image to that position
|
2013-01-21 05:40:37 +08:00
|
|
|
m_pixelsMovement->moveImage(x, y, moveModifier);
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
editor->updateStatusBar();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use StandbyState implementation
|
|
|
|
return StandbyState::onMouseMove(editor, msg);
|
|
|
|
}
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
bool MovingPixelsState::onMouseWheel(Editor* editor, MouseMessage* msg)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
|
|
|
// Use StandbyState implementation
|
|
|
|
return StandbyState::onMouseWheel(editor, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MovingPixelsState::onSetCursor(Editor* editor)
|
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
|
|
|
// Move selection
|
|
|
|
if (m_pixelsMovement->isDragging()) {
|
|
|
|
editor->hideDrawingCursor();
|
2012-08-11 10:14:54 +08:00
|
|
|
jmouse_set_cursor(kMoveCursor);
|
2012-01-06 06:45:03 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use StandbyState implementation
|
|
|
|
return StandbyState::onSetCursor(editor);
|
|
|
|
}
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
bool MovingPixelsState::onKeyDown(Editor* editor, KeyMessage* msg)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
if (msg->scancode() == kKeyEnter || // TODO make this key customizable
|
|
|
|
msg->scancode() == kKeyEnterPad ||
|
|
|
|
msg->scancode() == kKeyEsc) {
|
2012-02-06 11:17:42 +08:00
|
|
|
dropPixels(editor);
|
|
|
|
|
|
|
|
// The escape key drop pixels and deselect the mask.
|
2013-07-29 08:17:07 +08:00
|
|
|
if (msg->scancode() == kKeyEsc) { // TODO make this key customizable
|
2012-02-06 11:17:42 +08:00
|
|
|
Command* cmd = CommandsModule::instance()->getCommandByName(CommandId::DeselectMask);
|
|
|
|
UIContext::instance()->executeCommand(cmd);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2012-02-12 03:34:55 +08:00
|
|
|
|
|
|
|
return true;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2012-02-12 08:06:31 +08:00
|
|
|
else {
|
2012-03-21 01:41:20 +08:00
|
|
|
Command* command = NULL;
|
|
|
|
Params* params = NULL;
|
|
|
|
if (get_command_from_key_message(msg, &command, ¶ms)) {
|
2012-02-12 08:06:31 +08:00
|
|
|
// Intercept the "Cut" or "Copy" command to handle them locally
|
|
|
|
// with the current m_pixelsMovement data.
|
2012-03-21 01:41:20 +08:00
|
|
|
if (strcmp(command->short_name(), CommandId::Cut) == 0 ||
|
|
|
|
strcmp(command->short_name(), CommandId::Copy) == 0) {
|
2012-02-12 08:06:31 +08:00
|
|
|
// Copy the floating image to the clipboard.
|
|
|
|
{
|
|
|
|
Document* document = editor->getDocument();
|
|
|
|
gfx::Point origin;
|
2013-08-06 08:20:19 +08:00
|
|
|
base::UniquePtr<Image> floatingImage(m_pixelsMovement->getDraggedImageCopy(origin));
|
|
|
|
clipboard::copy_image(floatingImage.get(),
|
|
|
|
document->getSprite()->getPalette(editor->getFrame()),
|
|
|
|
origin);
|
2012-02-12 08:06:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// In case of "Cut" command.
|
2012-03-21 01:41:20 +08:00
|
|
|
if (strcmp(command->short_name(), CommandId::Cut) == 0) {
|
2012-02-12 08:06:31 +08:00
|
|
|
// Discard the dragged image.
|
|
|
|
m_pixelsMovement->discardImage();
|
|
|
|
m_discarded = true;
|
|
|
|
|
|
|
|
// Quit from MovingPixelsState, back to standby.
|
|
|
|
editor->backToPreviousState();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true because we've used the keyboard shortcut.
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-12 09:20:59 +08:00
|
|
|
// Flip Horizontally/Vertically commands are handled manually to
|
|
|
|
// avoid dropping the floating region of pixels.
|
2012-03-21 01:41:20 +08:00
|
|
|
else if (strcmp(command->short_name(), CommandId::Flip) == 0) {
|
|
|
|
if (FlipCommand* flipCommand = dynamic_cast<FlipCommand*>(command)) {
|
|
|
|
flipCommand->loadParams(params);
|
2012-03-12 09:20:59 +08:00
|
|
|
m_pixelsMovement->flipImage(flipCommand->getFlipType());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-02-12 08:06:31 +08:00
|
|
|
}
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
// Use StandbyState implementation
|
|
|
|
return StandbyState::onKeyDown(editor, msg);
|
|
|
|
}
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
bool MovingPixelsState::onKeyUp(Editor* editor, KeyMessage* msg)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
|
|
|
// Use StandbyState implementation
|
|
|
|
return StandbyState::onKeyUp(editor, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MovingPixelsState::onUpdateStatusBar(Editor* editor)
|
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
|
|
|
const gfx::Transformation& transform(getTransformation(editor));
|
2012-01-08 03:35:04 +08:00
|
|
|
Document* document = editor->getDocument();
|
|
|
|
gfx::Size imageSize = m_pixelsMovement->getInitialImageSize();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-07-10 00:20:58 +08:00
|
|
|
StatusBar::instance()->setStatusText
|
2012-01-08 03:35:04 +08:00
|
|
|
(100, "Pos %d %d, Size %d %d, Orig: %3d %3d (%.02f%% %.02f%%), Angle %.1f",
|
2012-01-06 06:45:03 +08:00
|
|
|
transform.bounds().x, transform.bounds().y,
|
|
|
|
transform.bounds().w, transform.bounds().h,
|
2012-01-08 03:35:04 +08:00
|
|
|
imageSize.w, imageSize.h,
|
|
|
|
(double)transform.bounds().w*100.0/imageSize.w,
|
|
|
|
(double)transform.bounds().h*100.0/imageSize.h,
|
2012-01-06 06:45:03 +08:00
|
|
|
180.0 * transform.angle() / PI);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-06 11:17:42 +08:00
|
|
|
// Before executing any command, we drop the pixels (go back to standby).
|
|
|
|
void MovingPixelsState::onCommandBeforeExecution(Context* context)
|
|
|
|
{
|
|
|
|
if (m_pixelsMovement)
|
|
|
|
dropPixels(m_currentEditor);
|
|
|
|
}
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
void MovingPixelsState::dispose()
|
|
|
|
{
|
|
|
|
// Never called as MovingPixelsState is removed automatically as
|
2012-08-19 02:22:23 +08:00
|
|
|
// StatusBar's observer.
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
void MovingPixelsState::onChangeTransparentColor(const app::Color& color)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
setTransparentColor(color);
|
|
|
|
}
|
|
|
|
|
2013-01-07 01:45:43 +08:00
|
|
|
void MovingPixelsState::setTransparentColor(const app::Color& color)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
|
|
|
ASSERT(m_pixelsMovement != NULL);
|
|
|
|
|
2013-01-21 05:40:37 +08:00
|
|
|
Sprite* sprite = m_currentEditor->getSprite();
|
2012-01-06 06:45:03 +08:00
|
|
|
ASSERT(sprite != NULL);
|
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
PixelFormat format = sprite->getPixelFormat();
|
|
|
|
m_pixelsMovement->setMaskColor(color_utils::color_for_image(color, format));
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MovingPixelsState::dropPixels(Editor* editor)
|
|
|
|
{
|
|
|
|
// Just change to default state (StandbyState generally). We'll
|
2012-01-12 11:39:39 +08:00
|
|
|
// receive an onBeforeChangeState() event after this call.
|
2012-01-06 06:45:03 +08:00
|
|
|
editor->backToPreviousState();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Transformation MovingPixelsState::getTransformation(Editor* editor)
|
|
|
|
{
|
|
|
|
return m_pixelsMovement->getTransformation();
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|