| 
									
										
										
										
											2015-02-12 23:16:25 +08:00
										 |  |  | // Aseprite
 | 
					
						
							|  |  |  | // Copyright (C) 2001-2015  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
 | 
					
						
							|  |  |  | // published by the Free Software Foundation.
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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/standby_state.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "app/app.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-29 10:56:44 +08:00
										 |  |  | #include "app/color_picker.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/commands/commands.h"
 | 
					
						
							|  |  |  | #include "app/commands/params.h"
 | 
					
						
							|  |  |  | #include "app/document_location.h"
 | 
					
						
							|  |  |  | #include "app/ini_file.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-29 10:56:44 +08:00
										 |  |  | #include "app/settings/settings.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/tools/ink.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-24 19:08:34 +08:00
										 |  |  | #include "app/tools/pick_ink.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/tools/tool.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/drawing_state.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/editor.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/editor_customization_delegate.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/handle_type.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/moving_cel_state.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/moving_pixels_state.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/pixels_movement.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/scrolling_state.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/tool_loop_impl.h"
 | 
					
						
							|  |  |  | #include "app/ui/editor/transform_handles.h"
 | 
					
						
							| 
									
										
										
										
											2014-04-20 07:08:21 +08:00
										 |  |  | #include "app/ui/editor/zooming_state.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/ui/status_bar.h"
 | 
					
						
							|  |  |  | #include "app/ui_context.h"
 | 
					
						
							| 
									
										
										
										
											2015-04-02 20:55:18 +08:00
										 |  |  | #include "app/util/new_image_from_mask.h"
 | 
					
						
							| 
									
										
										
										
											2014-10-21 09:21:31 +08:00
										 |  |  | #include "doc/layer.h"
 | 
					
						
							|  |  |  | #include "doc/mask.h"
 | 
					
						
							|  |  |  | #include "doc/sprite.h"
 | 
					
						
							| 
									
										
										
										
											2015-04-02 20:55:18 +08:00
										 |  |  | #include "fixmath/fixmath.h"
 | 
					
						
							|  |  |  | #include "gfx/rect.h"
 | 
					
						
							| 
									
										
										
										
											2012-06-18 09:49:58 +08:00
										 |  |  | #include "ui/alert.h"
 | 
					
						
							|  |  |  | #include "ui/message.h"
 | 
					
						
							|  |  |  | #include "ui/system.h"
 | 
					
						
							|  |  |  | #include "ui/view.h"
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | namespace app { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 09:02:54 +08:00
										 |  |  | using namespace ui; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-11 10:14:54 +08:00
										 |  |  | static CursorType rotated_size_cursors[] = { | 
					
						
							| 
									
										
										
										
											2014-08-11 06:51:14 +08:00
										 |  |  |   kSizeECursor, | 
					
						
							|  |  |  |   kSizeNECursor, | 
					
						
							|  |  |  |   kSizeNCursor, | 
					
						
							|  |  |  |   kSizeNWCursor, | 
					
						
							|  |  |  |   kSizeWCursor, | 
					
						
							|  |  |  |   kSizeSWCursor, | 
					
						
							|  |  |  |   kSizeSCursor, | 
					
						
							|  |  |  |   kSizeSECursor | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-11 10:14:54 +08:00
										 |  |  | static CursorType rotated_rotate_cursors[] = { | 
					
						
							| 
									
										
										
										
											2014-08-11 06:51:14 +08:00
										 |  |  |   kRotateECursor, | 
					
						
							|  |  |  |   kRotateNECursor, | 
					
						
							|  |  |  |   kRotateNCursor, | 
					
						
							|  |  |  |   kRotateNWCursor, | 
					
						
							|  |  |  |   kRotateWCursor, | 
					
						
							|  |  |  |   kRotateSWCursor, | 
					
						
							|  |  |  |   kRotateSCursor, | 
					
						
							|  |  |  |   kRotateSECursor | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-15 10:38:06 +08:00
										 |  |  | #ifdef _MSC_VER
 | 
					
						
							| 
									
										
										
										
											2012-01-08 03:32:03 +08:00
										 |  |  | #pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
 | 
					
						
							| 
									
										
										
										
											2014-08-15 10:38:06 +08:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-01-08 03:32:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | StandbyState::StandbyState() | 
					
						
							|  |  |  |   : m_decorator(new Decorator(this)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | StandbyState::~StandbyState() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   delete m_decorator; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void StandbyState::onAfterChangeState(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   editor->setDecorator(m_decorator); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void StandbyState::onCurrentToolChange(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-18 07:37:12 +08:00
										 |  |  |   //tools::Tool* currentTool = editor->getCurrentEditorTool();
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // If the user change from a selection tool to a non-selection tool,
 | 
					
						
							|  |  |  |   // or viceversa, we've to show or hide the transformation handles.
 | 
					
						
							|  |  |  |   // TODO Compare the ink (isSelection()) of the previous tool with
 | 
					
						
							|  |  |  |   // the new one.
 | 
					
						
							|  |  |  |   editor->invalidate(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-25 08:15:59 +08:00
										 |  |  | void StandbyState::onQuickToolChange(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   editor->invalidate(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  | bool StandbyState::checkForScroll(Editor* editor, MouseMessage* msg) | 
					
						
							| 
									
										
										
										
											2012-01-12 11:46:04 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   tools::Ink* clickedInk = editor->getCurrentEditorInk(); | 
					
						
							| 
									
										
										
										
											2012-01-12 11:46:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Start scroll loop
 | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  |   if (msg->middle() || clickedInk->isScrollMovement()) { // TODO msg->middle() should be customizable
 | 
					
						
							| 
									
										
										
										
											2014-02-03 05:46:19 +08:00
										 |  |  |     EditorStatePtr newState(new ScrollingState()); | 
					
						
							|  |  |  |     editor->setState(newState); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     newState->onMouseDown(editor, msg); | 
					
						
							| 
									
										
										
										
											2012-01-12 11:46:04 +08:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-20 07:08:21 +08:00
										 |  |  | bool StandbyState::checkForZoom(Editor* editor, MouseMessage* msg) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   tools::Ink* clickedInk = editor->getCurrentEditorInk(); | 
					
						
							| 
									
										
										
										
											2014-04-20 07:08:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Start scroll loop
 | 
					
						
							|  |  |  |   if (clickedInk->isZoom()) { | 
					
						
							|  |  |  |     EditorStatePtr newState(new ZoomingState()); | 
					
						
							|  |  |  |     editor->setState(newState); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     newState->onMouseDown(editor, msg); | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  | bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							|  |  |  |   if (editor->hasCapture()) | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   UIContext* context = UIContext::instance(); | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   tools::Ink* clickedInk = editor->getCurrentEditorInk(); | 
					
						
							| 
									
										
										
										
											2013-03-12 07:29:45 +08:00
										 |  |  |   DocumentLocation location; | 
					
						
							|  |  |  |   editor->getDocumentLocation(&location); | 
					
						
							|  |  |  |   Document* document = location.document(); | 
					
						
							|  |  |  |   Layer* layer = location.layer(); | 
					
						
							| 
									
										
										
										
											2013-01-21 05:40:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // When an editor is clicked the current view is changed.
 | 
					
						
							|  |  |  |   context->setActiveView(editor->getDocumentView()); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Start scroll loop
 | 
					
						
							| 
									
										
										
										
											2014-04-20 07:08:21 +08:00
										 |  |  |   if (checkForScroll(editor, msg) || checkForZoom(editor, msg)) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Move cel X,Y coordinates
 | 
					
						
							| 
									
										
										
										
											2012-01-12 11:46:04 +08:00
										 |  |  |   if (clickedInk->isCelMovement()) { | 
					
						
							| 
									
										
										
										
											2014-11-17 05:33:31 +08:00
										 |  |  |     // Handle "Auto Select Layer"
 | 
					
						
							|  |  |  |     if (editor->isAutoSelectLayer()) { | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |       gfx::Point cursor = editor->screenToEditor(msg->position()); | 
					
						
							| 
									
										
										
										
											2014-11-17 05:33:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |       ColorPicker picker; | 
					
						
							|  |  |  |       picker.pickColor(location, cursor, ColorPicker::FromComposition); | 
					
						
							| 
									
										
										
										
											2014-11-17 05:33:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (layer != picker.layer()) { | 
					
						
							|  |  |  |         layer = picker.layer(); | 
					
						
							|  |  |  |         if (layer) { | 
					
						
							|  |  |  |           editor->setLayer(layer); | 
					
						
							|  |  |  |           editor->flashCurrentLayer(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-12 07:29:45 +08:00
										 |  |  |     if ((layer) && | 
					
						
							| 
									
										
										
										
											2014-11-25 08:53:10 +08:00
										 |  |  |         (layer->type() == ObjectType::LayerImage)) { | 
					
						
							| 
									
										
										
										
											2014-11-24 22:50:02 +08:00
										 |  |  |       // TODO we should be able to move the `Background' with tiled mode
 | 
					
						
							| 
									
										
										
										
											2013-03-12 07:29:45 +08:00
										 |  |  |       if (layer->isBackground()) { | 
					
						
							| 
									
										
										
										
											2014-11-24 22:50:02 +08:00
										 |  |  |         StatusBar::instance()->showTip(1000, | 
					
						
							|  |  |  |           "The background layer cannot be moved"); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2014-12-03 22:15:09 +08:00
										 |  |  |       else if (!layer->isVisible()) { | 
					
						
							| 
									
										
										
										
											2014-11-30 20:43:33 +08:00
										 |  |  |         StatusBar::instance()->showTip(1000, | 
					
						
							|  |  |  |           "Layer '%s' is hidden", layer->name().c_str()); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2014-11-25 08:53:10 +08:00
										 |  |  |       else if (!layer->isMovable() || !layer->isEditable()) { | 
					
						
							| 
									
										
										
										
											2014-11-24 22:50:02 +08:00
										 |  |  |         StatusBar::instance()->showTip(1000, | 
					
						
							|  |  |  |           "Layer '%s' is locked", layer->name().c_str()); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         // Change to MovingCelState
 | 
					
						
							|  |  |  |         editor->setState(EditorStatePtr(new MovingCelState(editor, msg))); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-11-17 05:33:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  |   // Call the eyedropper command
 | 
					
						
							|  |  |  |   if (clickedInk->isEyedropper()) { | 
					
						
							|  |  |  |     callEyedropper(editor); | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  |   if (clickedInk->isSelection()) { | 
					
						
							|  |  |  |     // Transform selected pixels
 | 
					
						
							|  |  |  |     if (document->isMaskVisible() && m_decorator->getTransformHandles(editor)) { | 
					
						
							|  |  |  |       TransformHandles* transfHandles = m_decorator->getTransformHandles(editor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Get the handle covered by the mouse.
 | 
					
						
							|  |  |  |       HandleType handle = transfHandles->getHandleAtPoint(editor, | 
					
						
							|  |  |  |         msg->position(), | 
					
						
							|  |  |  |         document->getTransformation()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (handle != NoHandle) { | 
					
						
							|  |  |  |         int x, y, opacity; | 
					
						
							|  |  |  |         Image* image = location.image(&x, &y, &opacity); | 
					
						
							| 
									
										
										
										
											2015-01-28 22:04:07 +08:00
										 |  |  |         if (layer && image) { | 
					
						
							| 
									
										
										
										
											2014-11-17 10:03:30 +08:00
										 |  |  |           if (!layer->isEditable()) { | 
					
						
							| 
									
										
										
										
											2014-11-24 22:50:02 +08:00
										 |  |  |             StatusBar::instance()->showTip(1000, | 
					
						
							|  |  |  |               "Layer '%s' is locked", layer->name().c_str()); | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  |             return true; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           // Change to MovingPixelsState
 | 
					
						
							|  |  |  |           transformSelection(editor, msg, handle); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  |     // Move selected pixels
 | 
					
						
							| 
									
										
										
										
											2015-01-28 22:04:07 +08:00
										 |  |  |     if (layer && editor->isInsideSelection() && msg->left()) { | 
					
						
							| 
									
										
										
										
											2014-11-17 10:03:30 +08:00
										 |  |  |       if (!layer->isEditable()) { | 
					
						
							| 
									
										
										
										
											2014-11-24 22:50:02 +08:00
										 |  |  |         StatusBar::instance()->showTip(1000, | 
					
						
							|  |  |  |           "Layer '%s' is locked", layer->name().c_str()); | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Change to MovingPixelsState
 | 
					
						
							|  |  |  |       transformSelection(editor, msg, MoveHandle); | 
					
						
							| 
									
										
										
										
											2014-08-25 06:37:24 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Start the Tool-Loop
 | 
					
						
							| 
									
										
										
										
											2013-03-12 07:29:45 +08:00
										 |  |  |   if (layer) { | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     tools::ToolLoop* toolLoop = create_tool_loop(editor, context); | 
					
						
							| 
									
										
										
										
											2014-12-09 01:57:56 +08:00
										 |  |  |     if (toolLoop) { | 
					
						
							|  |  |  |       EditorStatePtr newState(new DrawingState(toolLoop)); | 
					
						
							|  |  |  |       editor->setState(newState); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       static_cast<DrawingState*>(newState.get()) | 
					
						
							|  |  |  |         ->initToolLoop(editor, msg); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  | bool StandbyState::onMouseUp(Editor* editor, MouseMessage* msg) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							|  |  |  |   editor->releaseMouse(); | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  | bool StandbyState::onMouseMove(Editor* editor, MouseMessage* msg) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   // We control eyedropper tool from here. TODO move this to another place
 | 
					
						
							|  |  |  |   if (msg->left() || msg->right()) { | 
					
						
							|  |  |  |     tools::Ink* clickedInk = editor->getCurrentEditorInk(); | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  |     if (clickedInk->isEyedropper()) | 
					
						
							|  |  |  |       callEyedropper(editor); | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   editor->moveDrawingCursor(); | 
					
						
							|  |  |  |   editor->updateStatusBar(); | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool StandbyState::onSetCursor(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   tools::Ink* ink = editor->getCurrentEditorInk(); | 
					
						
							|  |  |  |   if (ink) { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     // If the current tool change selection (e.g. rectangular marquee, etc.)
 | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     if (ink->isSelection()) { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       // See if the cursor is in some selection handle.
 | 
					
						
							|  |  |  |       if (m_decorator->onSetCursor(editor)) | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Move pixels
 | 
					
						
							|  |  |  |       if (editor->isInsideSelection()) { | 
					
						
							|  |  |  |         EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         editor->hideDrawingCursor(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (customization && customization->isCopySelectionKeyPressed()) | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |           ui::set_mouse_cursor(kArrowPlusCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |           ui::set_mouse_cursor(kMoveCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isEyedropper()) { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       editor->hideDrawingCursor(); | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |       ui::set_mouse_cursor(kEyedropperCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isZoom()) { | 
					
						
							| 
									
										
										
										
											2014-04-20 07:08:21 +08:00
										 |  |  |       editor->hideDrawingCursor(); | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |       ui::set_mouse_cursor(kMagnifierCursor); | 
					
						
							| 
									
										
										
										
											2014-04-20 07:08:21 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isScrollMovement()) { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       editor->hideDrawingCursor(); | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |       ui::set_mouse_cursor(kScrollCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isCelMovement()) { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       editor->hideDrawingCursor(); | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |       ui::set_mouse_cursor(kMoveCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isSlice()) { | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |       ui::set_mouse_cursor(kNoCursor); | 
					
						
							| 
									
										
										
										
											2014-06-28 09:58:38 +08:00
										 |  |  |       editor->showDrawingCursor(); | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Draw
 | 
					
						
							|  |  |  |   if (editor->canDraw()) { | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |     ui::set_mouse_cursor(kNoCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     editor->showDrawingCursor(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   // Forbidden
 | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     editor->hideDrawingCursor(); | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |     ui::set_mouse_cursor(kForbiddenCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  | bool StandbyState::onKeyDown(Editor* editor, KeyMessage* msg) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-13 11:22:29 +08:00
										 |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  | bool StandbyState::onKeyUp(Editor* editor, KeyMessage* msg) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							|  |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool StandbyState::onUpdateStatusBar(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   tools::Ink* ink = editor->getCurrentEditorInk(); | 
					
						
							| 
									
										
										
										
											2014-07-30 12:28:15 +08:00
										 |  |  |   const Sprite* sprite = editor->sprite(); | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |   gfx::Point spritePos = editor->screenToEditor(ui::get_mouse_position()); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!sprite) { | 
					
						
							| 
									
										
										
										
											2012-07-10 00:20:58 +08:00
										 |  |  |     StatusBar::instance()->clearText(); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   // For eye-dropper
 | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   else if (ink->isEyedropper()) { | 
					
						
							| 
									
										
										
										
											2014-01-29 10:56:44 +08:00
										 |  |  |     bool grabAlpha = UIContext::instance()->settings()->getGrabAlpha(); | 
					
						
							|  |  |  |     ColorPicker picker; | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |     picker.pickColor(editor->getDocumentLocation(), | 
					
						
							|  |  |  |       spritePos, | 
					
						
							| 
									
										
										
										
											2014-01-29 10:56:44 +08:00
										 |  |  |       grabAlpha ? | 
					
						
							|  |  |  |       ColorPicker::FromActiveLayer: | 
					
						
							|  |  |  |       ColorPicker::FromComposition); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     char buf[256]; | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |     sprintf(buf, "- Pos %d %d", spritePos.x, spritePos.y); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 10:56:44 +08:00
										 |  |  |     StatusBar::instance()->showColor(0, buf, picker.color(), picker.alpha()); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2013-03-12 07:29:45 +08:00
										 |  |  |     Mask* mask = | 
					
						
							| 
									
										
										
										
											2015-02-12 23:16:25 +08:00
										 |  |  |       (editor->document()->isMaskVisible() ? | 
					
						
							| 
									
										
										
										
											2014-07-30 12:28:15 +08:00
										 |  |  |        editor->document()->mask(): NULL); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-22 23:28:07 +08:00
										 |  |  |     StatusBar::instance()->setStatusText(0, | 
					
						
							|  |  |  |       "Pos %d %d, Size %d %d, Frame %d [%d msecs]", | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |       spritePos.x, spritePos.y, | 
					
						
							| 
									
										
										
										
											2014-07-30 12:28:15 +08:00
										 |  |  |       (mask ? mask->bounds().w: sprite->width()), | 
					
						
							|  |  |  |       (mask ? mask->bounds().h: sprite->height()), | 
					
						
							|  |  |  |       editor->frame()+1, | 
					
						
							| 
									
										
										
										
											2014-12-29 07:39:11 +08:00
										 |  |  |       sprite->frameDuration(editor->frame())); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | gfx::Transformation StandbyState::getTransformation(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-30 12:28:15 +08:00
										 |  |  |   return editor->document()->getTransformation(); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-08 12:00:02 +08:00
										 |  |  | void StandbyState::startSelectionTransformation(Editor* editor, const gfx::Point& move) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   transformSelection(editor, NULL, NoHandle); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (MovingPixelsState* movingPixels = dynamic_cast<MovingPixelsState*>(editor->getState().get())) | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |     movingPixels->translate(move); | 
					
						
							| 
									
										
										
										
											2014-08-08 12:00:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-29 08:17:07 +08:00
										 |  |  | void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleType handle) | 
					
						
							| 
									
										
										
										
											2012-01-06 10:21:51 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  |   try { | 
					
						
							|  |  |  |     EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); | 
					
						
							| 
									
										
										
										
											2014-07-30 12:28:15 +08:00
										 |  |  |     Document* document = editor->document(); | 
					
						
							| 
									
										
										
										
											2015-04-02 20:55:18 +08:00
										 |  |  |     base::UniquePtr<Image> tmpImage(new_image_from_mask(editor->getDocumentLocation())); | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |     gfx::Point origin = document->mask()->bounds().getOrigin(); | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  |     int opacity = 255; | 
					
						
							|  |  |  |     PixelsMovementPtr pixelsMovement( | 
					
						
							|  |  |  |       new PixelsMovement(UIContext::instance(), | 
					
						
							| 
									
										
										
										
											2015-02-16 04:08:21 +08:00
										 |  |  |         editor->getDocumentLocation(), | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |         tmpImage, origin, opacity, | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  |         "Transformation")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // If the Ctrl key is pressed start dragging a copy of the selection
 | 
					
						
							|  |  |  |     if (customization && customization->isCopySelectionKeyPressed()) | 
					
						
							|  |  |  |       pixelsMovement->copyMask(); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       pixelsMovement->cutMask(); | 
					
						
							| 
									
										
										
										
											2012-01-06 10:21:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  |     editor->setState(EditorStatePtr(new MovingPixelsState(editor, msg, pixelsMovement, handle))); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   catch (const LockedDocumentException&) { | 
					
						
							|  |  |  |     // Other editor is locking the document.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // TODO steal the PixelsMovement of the other editor and use it for this one.
 | 
					
						
							| 
									
										
										
										
											2014-11-03 03:15:52 +08:00
										 |  |  |     StatusBar::instance()->showTip(1000, "The sprite is locked in other editor"); | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |     ui::set_mouse_cursor(kForbiddenCursor); | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-04-16 00:59:41 +08:00
										 |  |  |   catch (const std::bad_alloc&) { | 
					
						
							|  |  |  |     StatusBar::instance()->showTip(1000, "Not enough memory to transform the selection"); | 
					
						
							|  |  |  |     ui::set_mouse_cursor(kForbiddenCursor); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-01-06 10:21:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  | void StandbyState::callEyedropper(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   tools::Ink* clickedInk = editor->getCurrentEditorInk(); | 
					
						
							|  |  |  |   if (!clickedInk->isEyedropper()) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Command* eyedropper_cmd = | 
					
						
							|  |  |  |     CommandsModule::instance()->getCommandByName(CommandId::Eyedropper); | 
					
						
							|  |  |  |   bool fg = (static_cast<tools::PickInk*>(clickedInk)->target() == tools::PickInk::Fg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Params params; | 
					
						
							|  |  |  |   params.set("target", fg ? "foreground": "background"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-12 02:40:22 +08:00
										 |  |  |   UIContext::instance()->executeCommand(eyedropper_cmd, params); | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | //////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Decorator
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | StandbyState::Decorator::Decorator(StandbyState* standbyState) | 
					
						
							|  |  |  |   : m_transfHandles(NULL) | 
					
						
							|  |  |  |   , m_standbyState(standbyState) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | StandbyState::Decorator::~Decorator() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   delete m_transfHandles; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TransformHandles* StandbyState::Decorator::getTransformHandles(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!m_transfHandles) | 
					
						
							|  |  |  |     m_transfHandles = new TransformHandles(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return m_transfHandles; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool StandbyState::Decorator::onSetCursor(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-30 12:28:15 +08:00
										 |  |  |   if (!editor->document()->isMaskVisible()) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const gfx::Transformation transformation(m_standbyState->getTransformation(editor)); | 
					
						
							|  |  |  |   TransformHandles* tr = getTransformHandles(editor); | 
					
						
							|  |  |  |   HandleType handle = tr->getHandleAtPoint(editor, | 
					
						
							| 
									
										
										
										
											2014-11-26 09:10:28 +08:00
										 |  |  |     ui::get_mouse_position(), transformation); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-11 10:14:54 +08:00
										 |  |  |   CursorType newCursor = kArrowCursor; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   switch (handle) { | 
					
						
							| 
									
										
										
										
											2014-08-11 06:51:14 +08:00
										 |  |  |     case ScaleNWHandle:         newCursor = kSizeNWCursor; break; | 
					
						
							|  |  |  |     case ScaleNHandle:          newCursor = kSizeNCursor; break; | 
					
						
							|  |  |  |     case ScaleNEHandle:         newCursor = kSizeNECursor; break; | 
					
						
							|  |  |  |     case ScaleWHandle:          newCursor = kSizeWCursor; break; | 
					
						
							|  |  |  |     case ScaleEHandle:          newCursor = kSizeECursor; break; | 
					
						
							|  |  |  |     case ScaleSWHandle:         newCursor = kSizeSWCursor; break; | 
					
						
							|  |  |  |     case ScaleSHandle:          newCursor = kSizeSCursor; break; | 
					
						
							|  |  |  |     case ScaleSEHandle:         newCursor = kSizeSECursor; break; | 
					
						
							|  |  |  |     case RotateNWHandle:        newCursor = kRotateNWCursor; break; | 
					
						
							|  |  |  |     case RotateNHandle:         newCursor = kRotateNCursor; break; | 
					
						
							|  |  |  |     case RotateNEHandle:        newCursor = kRotateNECursor; break; | 
					
						
							|  |  |  |     case RotateWHandle:         newCursor = kRotateWCursor; break; | 
					
						
							|  |  |  |     case RotateEHandle:         newCursor = kRotateECursor; break; | 
					
						
							|  |  |  |     case RotateSWHandle:        newCursor = kRotateSWCursor; break; | 
					
						
							|  |  |  |     case RotateSHandle:         newCursor = kRotateSCursor; break; | 
					
						
							|  |  |  |     case RotateSEHandle:        newCursor = kRotateSECursor; break; | 
					
						
							| 
									
										
										
										
											2012-08-11 10:14:54 +08:00
										 |  |  |     case PivotHandle:           newCursor = kHandCursor; break; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     default: | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Adjust the cursor depending the current transformation angle.
 | 
					
						
							| 
									
										
										
										
											2014-09-21 22:51:24 +08:00
										 |  |  |   fixmath::fixed angle = fixmath::ftofix(128.0 * transformation.angle() / PI); | 
					
						
							|  |  |  |   angle = fixmath::fixadd(angle, fixmath::itofix(16)); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   angle &= (255<<16); | 
					
						
							|  |  |  |   angle >>= 16; | 
					
						
							|  |  |  |   angle /= 32; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-11 06:51:14 +08:00
										 |  |  |   if (newCursor >= kSizeNCursor && newCursor <= kSizeNWCursor) { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     size_t num = sizeof(rotated_size_cursors) / sizeof(rotated_size_cursors[0]); | 
					
						
							|  |  |  |     size_t c; | 
					
						
							|  |  |  |     for (c=num-1; c>0; --c) | 
					
						
							|  |  |  |       if (rotated_size_cursors[c] == newCursor) | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     newCursor = rotated_size_cursors[(c+angle) % num]; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-08-11 06:51:14 +08:00
										 |  |  |   else if (newCursor >= kRotateNCursor && newCursor <= kRotateNWCursor) { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     size_t num = sizeof(rotated_rotate_cursors) / sizeof(rotated_rotate_cursors[0]); | 
					
						
							|  |  |  |     size_t c; | 
					
						
							|  |  |  |     for (c=num-1; c>0; --c) | 
					
						
							|  |  |  |       if (rotated_rotate_cursors[c] == newCursor) | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     newCursor = rotated_rotate_cursors[(c+angle) % num]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Hide the drawing cursor (just in case) and show the new system cursor.
 | 
					
						
							|  |  |  |   editor->hideDrawingCursor(); | 
					
						
							| 
									
										
										
										
											2014-11-26 08:30:56 +08:00
										 |  |  |   ui::set_mouse_cursor(newCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void StandbyState::Decorator::preRenderDecorator(EditorPreRender* render) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   // Do nothing
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void StandbyState::Decorator::postRenderDecorator(EditorPostRender* render) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   Editor* editor = render->getEditor(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Draw transformation handles (if the mask is visible and isn't frozen).
 | 
					
						
							| 
									
										
										
										
											2014-08-10 04:14:56 +08:00
										 |  |  |   if (editor->editorFlags() & Editor::kShowMask && | 
					
						
							| 
									
										
										
										
											2014-08-09 23:24:04 +08:00
										 |  |  |       editor->document()->isMaskVisible() && | 
					
						
							| 
									
										
										
										
											2014-07-30 12:28:15 +08:00
										 |  |  |       !editor->document()->mask()->isFrozen()) { | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     // And draw only when the user has a selection tool as active tool.
 | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     tools::Ink* ink = editor->getCurrentEditorInk(); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     if (ink->isSelection()) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       getTransformHandles(editor)->drawHandles(editor, | 
					
						
							| 
									
										
										
										
											2014-08-09 23:24:04 +08:00
										 |  |  |         m_standbyState->getTransformation(editor)); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace app
 |