| 
									
										
										
										
											2015-02-12 23:16:25 +08:00
										 |  |  | // Aseprite
 | 
					
						
							| 
									
										
										
										
											2016-02-13 12:33:43 +08:00
										 |  |  | // Copyright (C) 2001-2016  David Capello
 | 
					
						
							| 
									
										
										
										
											2015-02-12 23:16:25 +08:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-08-27 04:02:58 +08:00
										 |  |  | // This program is distributed under the terms of
 | 
					
						
							|  |  |  | // the End-User License Agreement for Aseprite.
 | 
					
						
							| 
									
										
										
										
											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"
 | 
					
						
							| 
									
										
										
										
											2015-07-03 05:13:47 +08:00
										 |  |  | #include "app/commands/cmd_eyedropper.h"
 | 
					
						
							| 
									
										
										
										
											2015-07-30 03:35:34 +08:00
										 |  |  | #include "app/commands/commands.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/commands/params.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-04 01:05:28 +08:00
										 |  |  | #include "app/document_range.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/ini_file.h"
 | 
					
						
							| 
									
										
										
										
											2015-05-13 22:46:49 +08:00
										 |  |  | #include "app/pref/preferences.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"
 | 
					
						
							| 
									
										
										
										
											2015-08-15 00:06:26 +08:00
										 |  |  | #include "app/ui/document_view.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #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"
 | 
					
						
							| 
									
										
										
										
											2015-12-04 01:05:28 +08:00
										 |  |  | #include "app/ui/editor/moving_symmetry_state.h"
 | 
					
						
							| 
									
										
										
										
											2015-07-30 03:35:34 +08:00
										 |  |  | #include "app/ui/editor/pivot_helpers.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #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"
 | 
					
						
							| 
									
										
										
										
											2015-12-04 01:05:28 +08:00
										 |  |  | #include "app/ui/main_window.h"
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  | #include "app/ui/skin/skin_theme.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/ui/status_bar.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-04 01:05:28 +08:00
										 |  |  | #include "app/ui/timeline.h"
 | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | #include "app/ui_context.h"
 | 
					
						
							| 
									
										
										
										
											2015-04-02 20:55:18 +08:00
										 |  |  | #include "app/util/new_image_from_mask.h"
 | 
					
						
							| 
									
										
										
										
											2015-07-30 03:35:34 +08:00
										 |  |  | #include "base/bind.h"
 | 
					
						
							| 
									
										
										
										
											2015-06-17 02:04:00 +08:00
										 |  |  | #include "base/pi.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"
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  | #include "she/surface.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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 08:47:30 +08:00
										 |  |  | #include <cmath>
 | 
					
						
							| 
									
										
										
										
											2016-04-20 01:24:27 +08:00
										 |  |  | #include <cstring>
 | 
					
						
							| 
									
										
										
										
											2015-08-14 08:47:30 +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)) | 
					
						
							| 
									
										
										
										
											2016-04-26 02:26:46 +08:00
										 |  |  |   , m_transformSelectionHandlesAreVisible(false) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | StandbyState::~StandbyState() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   delete m_decorator; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-11 06:32:42 +08:00
										 |  |  | void StandbyState::onEnterState(Editor* editor) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-02-18 22:40:11 +08:00
										 |  |  |   StateWithWheelBehavior::onEnterState(editor); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   editor->setDecorator(m_decorator); | 
					
						
							| 
									
										
										
										
											2015-07-30 03:35:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 21:09:15 +08:00
										 |  |  |   m_pivotVisConn = | 
					
						
							|  |  |  |     Preferences::instance().selection.pivotVisibility.AfterChange.connect( | 
					
						
							| 
									
										
										
										
											2015-12-05 02:17:42 +08:00
										 |  |  |       base::Bind<void>(&StandbyState::onPivotChange, this, editor)); | 
					
						
							| 
									
										
										
										
											2015-08-14 21:09:15 +08:00
										 |  |  |   m_pivotPosConn = | 
					
						
							|  |  |  |     Preferences::instance().selection.pivotPosition.AfterChange.connect( | 
					
						
							| 
									
										
										
										
											2015-12-05 02:17:42 +08:00
										 |  |  |       base::Bind<void>(&StandbyState::onPivotChange, this, editor)); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 02:20:53 +08:00
										 |  |  | void StandbyState::onActiveToolChange(Editor* editor, tools::Tool* tool) | 
					
						
							| 
									
										
										
										
											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.
 | 
					
						
							| 
									
										
										
										
											2016-04-26 02:26:46 +08:00
										 |  |  |   bool needDecorators = (tool && tool->getInk(0)->isSelection()); | 
					
						
							|  |  |  |   if (m_transformSelectionHandlesAreVisible != needDecorators) { | 
					
						
							|  |  |  |     m_transformSelectionHandlesAreVisible = false; | 
					
						
							|  |  |  |     editor->invalidate(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							| 
									
										
										
										
											2015-04-21 03:27:09 +08:00
										 |  |  |   Site site; | 
					
						
							|  |  |  |   editor->getSite(&site); | 
					
						
							|  |  |  |   app::Document* document = static_cast<app::Document*>(site.document()); | 
					
						
							|  |  |  |   Layer* layer = site.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; | 
					
						
							| 
									
										
										
										
											2015-04-21 03:27:09 +08:00
										 |  |  |       picker.pickColor(site, cursor, ColorPicker::FromComposition); | 
					
						
							| 
									
										
										
										
											2014-11-17 05:33:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-23 00:19:06 +08:00
										 |  |  |       auto range = App::instance()->timeline()->range(); | 
					
						
							| 
									
										
										
										
											2015-12-04 01:05:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Change layer only when the layer is diffrent from current one, and
 | 
					
						
							|  |  |  |       // the range we selected is not with multiple cels.
 | 
					
						
							|  |  |  |       bool layerChanged = (layer != picker.layer()); | 
					
						
							|  |  |  |       bool rangeEnabled = range.enabled(); | 
					
						
							|  |  |  |       bool rangeSingleCel = ((range.type() == DocumentRange::kCels) && | 
					
						
							|  |  |  |                              (range.layers() == 1) && (range.frames() == 1)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (layerChanged && (!rangeEnabled || rangeSingleCel)) { | 
					
						
							| 
									
										
										
										
											2014-11-17 05:33:31 +08:00
										 |  |  |         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
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2015-05-01 04:26:46 +08:00
										 |  |  |       else if (!layer->cel(editor->frame())) { | 
					
						
							|  |  |  |         StatusBar::instance()->showTip(1000, | 
					
						
							|  |  |  |           "Cel is empty, nothing to move"); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											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()) { | 
					
						
							| 
									
										
										
										
											2015-08-20 05:05:03 +08:00
										 |  |  |     editor->captureMouse(); | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  |     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
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |     if (editor->isActive() && | 
					
						
							|  |  |  |         document->isMaskVisible() && | 
					
						
							|  |  |  |         m_decorator->getTransformHandles(editor)) { | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  |       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; | 
					
						
							| 
									
										
										
										
											2015-04-21 03:27:09 +08:00
										 |  |  |         Image* image = site.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
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |   // Move symmetry
 | 
					
						
							|  |  |  |   gfx::Rect box1, box2; | 
					
						
							|  |  |  |   if (m_decorator->getSymmetryHandles(editor, box1, box2) && | 
					
						
							|  |  |  |       (box1.contains(msg->position()) || | 
					
						
							|  |  |  |        box2.contains(msg->position()))) { | 
					
						
							|  |  |  |     auto& symmetry = Preferences::instance().document(editor->document()).symmetry; | 
					
						
							|  |  |  |     auto mode = symmetry.mode(); | 
					
						
							|  |  |  |     bool horz = (mode == app::gen::SymmetryMode::HORIZONTAL); | 
					
						
							|  |  |  |     auto& axis = (horz ? symmetry.xAxis: | 
					
						
							|  |  |  |                          symmetry.yAxis); | 
					
						
							|  |  |  |     editor->setState( | 
					
						
							|  |  |  |       EditorStatePtr(new MovingSymmetryState(editor, msg, | 
					
						
							|  |  |  |                                              mode, axis))); | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   // Start the Tool-Loop
 | 
					
						
							| 
									
										
										
										
											2013-03-12 07:29:45 +08:00
										 |  |  |   if (layer) { | 
					
						
							| 
									
										
										
										
											2016-05-04 23:32:39 +08:00
										 |  |  |     // Disable layer edges to avoid showing the modified cel
 | 
					
						
							|  |  |  |     // information by ExpandCelCanvas (i.e. the cel origin is changed
 | 
					
						
							|  |  |  |     // to 0,0 coordinate.)
 | 
					
						
							|  |  |  |     auto& layerEdgesOption = editor->docPref().show.layerEdges; | 
					
						
							|  |  |  |     bool layerEdges = layerEdgesOption(); | 
					
						
							|  |  |  |     if (layerEdges) | 
					
						
							|  |  |  |       layerEdgesOption(false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-23 07:16:14 +08:00
										 |  |  |     // We need to clear and redraw the brush boundaries after the
 | 
					
						
							|  |  |  |     // first mouse pressed/point shape if drawn. This is to avoid
 | 
					
						
							|  |  |  |     // graphical glitches (invalid areas in the ToolLoop's src/dst
 | 
					
						
							|  |  |  |     // images).
 | 
					
						
							|  |  |  |     HideBrushPreview hide(editor->brushPreview()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-05-04 23:32:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Restore layer edges
 | 
					
						
							|  |  |  |     if (layerEdges) | 
					
						
							|  |  |  |       layerEdgesOption(true); | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							| 
									
										
										
										
											2015-08-20 05:05:03 +08:00
										 |  |  |     if (clickedInk->isEyedropper() && | 
					
						
							|  |  |  |         editor->hasCapture()) { | 
					
						
							| 
									
										
										
										
											2014-11-13 22:23:45 +08:00
										 |  |  |       callEyedropper(editor); | 
					
						
							| 
									
										
										
										
											2015-08-20 05:05:03 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   editor->updateStatusBar(); | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-19 22:33:05 +08:00
										 |  |  | bool StandbyState::onDoubleClick(Editor* editor, MouseMessage* msg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (editor->hasCapture()) | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   tools::Ink* ink = editor->getCurrentEditorInk(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Select a tile with double-click
 | 
					
						
							|  |  |  |   if (ink->isSelection()) { | 
					
						
							|  |  |  |     Command* selectTileCmd = | 
					
						
							|  |  |  |       CommandsModule::instance()->getCommandByName(CommandId::SelectTile); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-19 23:09:03 +08:00
										 |  |  |     Params params; | 
					
						
							| 
									
										
										
										
											2016-04-05 05:46:48 +08:00
										 |  |  |     if (int(editor->getToolLoopModifiers()) & int(tools::ToolLoopModifiers::kAddSelection)) | 
					
						
							|  |  |  |       params.set("mode", "add"); | 
					
						
							|  |  |  |     else if (int(editor->getToolLoopModifiers()) & int(tools::ToolLoopModifiers::kSubtractSelection)) | 
					
						
							|  |  |  |       params.set("mode", "subtract"); | 
					
						
							| 
									
										
										
										
											2016-03-19 23:09:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     UIContext::instance()->executeCommand(selectTileCmd, params); | 
					
						
							| 
									
										
										
										
											2016-03-19 23:04:39 +08:00
										 |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2016-03-19 22:33:05 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  | bool StandbyState::onSetCursor(Editor* editor, const gfx::Point& mouseScreenPos) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   tools::Ink* ink = editor->getCurrentEditorInk(); | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // See if the cursor is in some selection handle.
 | 
					
						
							|  |  |  |   if (m_decorator->onSetCursor(ink, editor, mouseScreenPos)) | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |   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
										 |  |  |       // Move pixels
 | 
					
						
							|  |  |  |       if (editor->isInsideSelection()) { | 
					
						
							|  |  |  |         EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); | 
					
						
							| 
									
										
										
										
											2015-08-26 00:29:19 +08:00
										 |  |  |         if ((customization) && | 
					
						
							| 
									
										
										
										
											2015-09-12 07:04:02 +08:00
										 |  |  |             int(customization->getPressedKeyAction(KeyContext::TranslatingSelection) & KeyAction::CopySelection)) | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |           editor->showMouseCursor(kArrowPlusCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |           editor->showMouseCursor(kMoveCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-05-03 05:42:02 +08:00
										 |  |  |       else | 
					
						
							|  |  |  |         editor->showBrushPreview(mouseScreenPos); | 
					
						
							|  |  |  |       return true; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isEyedropper()) { | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |       editor->showMouseCursor(kEyedropperCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isZoom()) { | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |       editor->showMouseCursor(kMagnifierCursor); | 
					
						
							| 
									
										
										
										
											2014-04-20 07:08:21 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isScrollMovement()) { | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |       editor->showMouseCursor(kScrollCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isCelMovement()) { | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |       editor->showMouseCursor(kMoveCursor); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2014-08-19 19:17:57 +08:00
										 |  |  |     else if (ink->isSlice()) { | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |       editor->showBrushPreview(mouseScreenPos); | 
					
						
							| 
									
										
										
										
											2014-06-28 09:58:38 +08:00
										 |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Draw
 | 
					
						
							|  |  |  |   if (editor->canDraw()) { | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |     editor->showBrushPreview(mouseScreenPos); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   // Forbidden
 | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |     editor->showMouseCursor(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()) { | 
					
						
							| 
									
										
										
										
											2015-07-03 05:13:47 +08:00
										 |  |  |     EyedropperCommand cmd; | 
					
						
							|  |  |  |     app::Color color = Preferences::instance().colorBar.fgColor(); | 
					
						
							|  |  |  |     cmd.pickSample(editor->getSite(), spritePos, color); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     char buf[256]; | 
					
						
							| 
									
										
										
										
											2016-04-20 00:45:23 +08:00
										 |  |  |     sprintf(buf, " :pos: %d %d", spritePos.x, spritePos.y); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-03 05:13:47 +08:00
										 |  |  |     StatusBar::instance()->showColor(0, buf, color); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-20 00:45:23 +08:00
										 |  |  |     char buf[1024]; | 
					
						
							|  |  |  |     sprintf( | 
					
						
							|  |  |  |       buf, ":pos: %d %d :%s: %d %d", | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |       spritePos.x, spritePos.y, | 
					
						
							| 
									
										
										
										
											2016-04-20 00:45:23 +08:00
										 |  |  |       (mask ? "selsize": "size"), | 
					
						
							| 
									
										
										
										
											2014-07-30 12:28:15 +08:00
										 |  |  |       (mask ? mask->bounds().w: sprite->width()), | 
					
						
							| 
									
										
										
										
											2016-04-20 00:45:23 +08:00
										 |  |  |       (mask ? mask->bounds().h: sprite->height())); | 
					
						
							| 
									
										
										
										
											2016-04-20 02:51:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-20 00:45:23 +08:00
										 |  |  |     if (sprite->totalFrames() > 1) { | 
					
						
							|  |  |  |       sprintf( | 
					
						
							| 
									
										
										
										
											2016-04-20 01:24:27 +08:00
										 |  |  |         buf+std::strlen(buf), " :frame: %d :clock: %d", | 
					
						
							| 
									
										
										
										
											2016-04-20 00:45:23 +08:00
										 |  |  |         editor->frame()+1, | 
					
						
							|  |  |  |         sprite->frameDuration(editor->frame())); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-20 02:51:34 +08:00
										 |  |  |     if (editor->docPref().show.grid()) { | 
					
						
							|  |  |  |       auto gb = editor->docPref().grid.bounds(); | 
					
						
							|  |  |  |       int col = (spritePos.x - (gb.x % gb.w)) / gb.w; | 
					
						
							|  |  |  |       int row = (spritePos.y - (gb.y % gb.h)) / gb.h; | 
					
						
							|  |  |  |       sprintf( | 
					
						
							|  |  |  |         buf+std::strlen(buf), " :grid: %d %d", col, row); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-20 00:45:23 +08:00
										 |  |  |     StatusBar::instance()->setStatusText(0, buf); | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-12 01:16:01 +08:00
										 |  |  | Transformation StandbyState::getTransformation(Editor* editor) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-12 01:16:01 +08:00
										 |  |  |   Transformation t = editor->document()->getTransformation(); | 
					
						
							| 
									
										
										
										
											2015-07-30 03:35:34 +08:00
										 |  |  |   set_pivot_from_preferences(t); | 
					
						
							|  |  |  |   return t; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 08:47:30 +08:00
										 |  |  | void StandbyState::startSelectionTransformation(Editor* editor, | 
					
						
							|  |  |  |                                                 const gfx::Point& move, | 
					
						
							|  |  |  |                                                 double angle) | 
					
						
							| 
									
										
										
										
											2014-08-08 12:00:02 +08:00
										 |  |  | { | 
					
						
							|  |  |  |   transformSelection(editor, NULL, NoHandle); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-14 08:47:30 +08:00
										 |  |  |   if (MovingPixelsState* movingPixels = dynamic_cast<MovingPixelsState*>(editor->getState().get())) { | 
					
						
							| 
									
										
										
										
											2014-11-24 11:09:22 +08:00
										 |  |  |     movingPixels->translate(move); | 
					
						
							| 
									
										
										
										
											2015-08-14 08:47:30 +08:00
										 |  |  |     if (std::fabs(angle) > 1e-5) | 
					
						
							|  |  |  |       movingPixels->rotate(angle); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-08-15 00:06:26 +08:00
										 |  |  |   Document* document = editor->document(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (auto docView : UIContext::instance()->getAllDocumentViews(document)) { | 
					
						
							| 
									
										
										
										
											2016-02-13 12:33:43 +08:00
										 |  |  |     if (docView->editor()->isMovingPixels()) { | 
					
						
							| 
									
										
										
										
											2015-08-15 00:06:26 +08:00
										 |  |  |       // TODO Transfer moving pixels state to this editor
 | 
					
						
							| 
									
										
										
										
											2016-02-13 12:33:43 +08:00
										 |  |  |       docView->editor()->dropMovingPixels(); | 
					
						
							| 
									
										
										
										
											2015-08-15 00:06:26 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  |   try { | 
					
						
							| 
									
										
										
										
											2015-06-08 23:13:55 +08:00
										 |  |  |     // Clear brush preview, as the extra cel will be replaced with the
 | 
					
						
							|  |  |  |     // transformed image.
 | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |     editor->brushPreview().hide(); | 
					
						
							| 
									
										
										
										
											2015-06-08 23:13:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  |     EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); | 
					
						
							| 
									
										
										
										
											2015-04-21 03:27:09 +08:00
										 |  |  |     base::UniquePtr<Image> tmpImage(new_image_from_mask(editor->getSite())); | 
					
						
							| 
									
										
										
										
											2015-06-26 01:54:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  |     PixelsMovementPtr pixelsMovement( | 
					
						
							|  |  |  |       new PixelsMovement(UIContext::instance(), | 
					
						
							| 
									
										
										
										
											2015-07-24 09:42:14 +08:00
										 |  |  |                          editor->getSite(), | 
					
						
							|  |  |  |                          tmpImage, | 
					
						
							|  |  |  |                          document->mask(), | 
					
						
							|  |  |  |                          "Transformation")); | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // If the Ctrl key is pressed start dragging a copy of the selection
 | 
					
						
							| 
									
										
										
										
											2015-08-26 00:29:19 +08:00
										 |  |  |     if ((customization) && | 
					
						
							| 
									
										
										
										
											2015-09-12 07:04:02 +08:00
										 |  |  |         int(customization->getPressedKeyAction(KeyContext::TranslatingSelection) & KeyAction::CopySelection)) | 
					
						
							| 
									
										
										
										
											2013-12-30 06:53:28 +08:00
										 |  |  |       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"); | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |     editor->showMouseCursor(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"); | 
					
						
							| 
									
										
										
										
											2015-06-25 23:44:47 +08:00
										 |  |  |     editor->showMouseCursor(kForbiddenCursor); | 
					
						
							| 
									
										
										
										
											2015-04-16 00:59:41 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-30 03:35:34 +08:00
										 |  |  | void StandbyState::onPivotChange(Editor* editor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (editor->isActive() && | 
					
						
							|  |  |  |       editor->editorFlags() & Editor::kShowMask && | 
					
						
							|  |  |  |       editor->document()->isMaskVisible() && | 
					
						
							|  |  |  |       !editor->document()->mask()->isFrozen()) { | 
					
						
							|  |  |  |     editor->invalidate(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  | bool StandbyState::Decorator::onSetCursor(tools::Ink* ink, Editor* editor, const gfx::Point& mouseScreenPos) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |   if (!editor->isActive()) | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |     return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |   if (ink && ink->isSelection() && editor->document()->isMaskVisible()) { | 
					
						
							| 
									
										
										
										
											2016-07-12 01:16:01 +08:00
										 |  |  |     const Transformation transformation(m_standbyState->getTransformation(editor)); | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |     TransformHandles* tr = getTransformHandles(editor); | 
					
						
							|  |  |  |     HandleType handle = tr->getHandleAtPoint( | 
					
						
							|  |  |  |       editor, mouseScreenPos, transformation); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     CursorType newCursor = kArrowCursor; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (handle) { | 
					
						
							|  |  |  |       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; | 
					
						
							|  |  |  |       case PivotHandle:           newCursor = kHandCursor; break; | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |     // Adjust the cursor depending the current transformation angle.
 | 
					
						
							|  |  |  |     fixmath::fixed angle = fixmath::ftofix(128.0 * transformation.angle() / PI); | 
					
						
							|  |  |  |     angle = fixmath::fixadd(angle, fixmath::itofix(16)); | 
					
						
							|  |  |  |     angle &= (255<<16); | 
					
						
							|  |  |  |     angle >>= 16; | 
					
						
							|  |  |  |     angle /= 32; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (newCursor >= kSizeNCursor && newCursor <= kSizeNWCursor) { | 
					
						
							|  |  |  |       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]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (newCursor >= kRotateNCursor && newCursor <= kRotateNWCursor) { | 
					
						
							|  |  |  |       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]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |     editor->showMouseCursor(newCursor); | 
					
						
							|  |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |   gfx::Rect box1, box2; | 
					
						
							|  |  |  |   if (getSymmetryHandles(editor, box1, box2) && | 
					
						
							|  |  |  |       (box1.contains(mouseScreenPos) || | 
					
						
							|  |  |  |        box2.contains(mouseScreenPos))) { | 
					
						
							|  |  |  |     switch (Preferences::instance().document(editor->document()).symmetry.mode()) { | 
					
						
							|  |  |  |       case app::gen::SymmetryMode::HORIZONTAL: | 
					
						
							|  |  |  |         editor->showMouseCursor(kSizeWECursor); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case app::gen::SymmetryMode::VERTICAL: | 
					
						
							|  |  |  |         editor->showMouseCursor(kSizeNSCursor); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return true; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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).
 | 
					
						
							| 
									
										
										
										
											2015-04-27 21:08:48 +08:00
										 |  |  |   if (editor->isActive() && | 
					
						
							|  |  |  |       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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 02:26:46 +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)); | 
					
						
							| 
									
										
										
										
											2016-04-26 02:26:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       m_standbyState->m_transformSelectionHandlesAreVisible = true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Draw transformation handles (if the mask is visible and isn't frozen).
 | 
					
						
							|  |  |  |   gfx::Rect box1, box2; | 
					
						
							|  |  |  |   if (StandbyState::Decorator::getSymmetryHandles(editor, box1, box2)) { | 
					
						
							|  |  |  |     skin::SkinTheme* theme = static_cast<skin::SkinTheme*>(CurrentTheme::get()); | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  |     she::Surface* part = theme->parts.transformationHandle()->bitmap(0); | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |     ScreenGraphics g; | 
					
						
							|  |  |  |     g.drawRgbaSurface(part, box1.x, box1.y); | 
					
						
							|  |  |  |     g.drawRgbaSurface(part, box2.x, box2.y); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-08 02:25:10 +08:00
										 |  |  | void StandbyState::Decorator::getInvalidDecoratoredRegion(Editor* editor, gfx::Region& region) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   gfx::Rect box1, box2; | 
					
						
							|  |  |  |   if (getSymmetryHandles(editor, box1, box2)) { | 
					
						
							|  |  |  |     region.createUnion(region, gfx::Region(box1)); | 
					
						
							|  |  |  |     region.createUnion(region, gfx::Region(box2)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  | bool StandbyState::Decorator::getSymmetryHandles(Editor* editor, gfx::Rect& box1, gfx::Rect& box2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   // Draw transformation handles (if the mask is visible and isn't frozen).
 | 
					
						
							|  |  |  |   if (editor->isActive() && | 
					
						
							|  |  |  |       editor->editorFlags() & Editor::kShowSymmetryLine && | 
					
						
							|  |  |  |       Preferences::instance().symmetryMode.enabled()) { | 
					
						
							|  |  |  |     const auto& symmetry = Preferences::instance().document(editor->document()).symmetry; | 
					
						
							|  |  |  |     auto mode = symmetry.mode(); | 
					
						
							|  |  |  |     if (mode != app::gen::SymmetryMode::NONE) { | 
					
						
							|  |  |  |       bool horz = (mode == app::gen::SymmetryMode::HORIZONTAL); | 
					
						
							|  |  |  |       int pos = (horz ? symmetry.xAxis(): | 
					
						
							|  |  |  |                         symmetry.yAxis()); | 
					
						
							|  |  |  |       gfx::Rect spriteBounds = editor->sprite()->bounds(); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:56:53 +08:00
										 |  |  |       gfx::Rect editorViewport = View::getView(editor)->viewportBounds(); | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |       skin::SkinTheme* theme = static_cast<skin::SkinTheme*>(CurrentTheme::get()); | 
					
						
							| 
									
										
										
											
												Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
											
										 
											2015-12-05 01:39:04 +08:00
										 |  |  |       she::Surface* part = theme->parts.transformationHandle()->bitmap(0); | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |       gfx::Point pt1, pt2; | 
					
						
							| 
									
										
										
										
											2015-12-06 21:56:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |       if (horz) { | 
					
						
							|  |  |  |         pt1 = gfx::Point(spriteBounds.x+pos, spriteBounds.y); | 
					
						
							|  |  |  |         pt1 = editor->editorToScreen(pt1); | 
					
						
							|  |  |  |         pt2 = gfx::Point(spriteBounds.x+pos, spriteBounds.y+spriteBounds.h); | 
					
						
							|  |  |  |         pt2 = editor->editorToScreen(pt2); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:56:53 +08:00
										 |  |  |         pt1.y = std::max(pt1.y-part->height(), editorViewport.y); | 
					
						
							|  |  |  |         pt2.y = std::min(pt2.y, editorViewport.point2().y-part->height()); | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |         pt1.x -= part->width()/2; | 
					
						
							|  |  |  |         pt2.x -= part->width()/2; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         pt1 = gfx::Point(spriteBounds.x, spriteBounds.y+pos); | 
					
						
							|  |  |  |         pt1 = editor->editorToScreen(pt1); | 
					
						
							|  |  |  |         pt2 = gfx::Point(spriteBounds.x+spriteBounds.w, spriteBounds.y+pos); | 
					
						
							|  |  |  |         pt2 = editor->editorToScreen(pt2); | 
					
						
							| 
									
										
										
										
											2015-12-06 21:56:53 +08:00
										 |  |  |         pt1.x = std::max(pt1.x-part->width(), editorViewport.x); | 
					
						
							|  |  |  |         pt2.x = std::min(pt2.x, editorViewport.point2().x-part->width()); | 
					
						
							| 
									
										
										
										
											2015-10-29 07:00:18 +08:00
										 |  |  |         pt1.y -= part->height()/2; | 
					
						
							|  |  |  |         pt2.y -= part->height()/2; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       box1 = gfx::Rect(pt1.x, pt1.y, part->width(), part->height()); | 
					
						
							|  |  |  |       box2 = gfx::Rect(pt2.x, pt2.y, part->width(), part->height()); | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2012-01-06 06:45:03 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-06 08:20:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace app
 |