2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-01-27 23:13:13 +08:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
2012-01-06 06:45:03 +08:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/editor/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/color_bar.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"
|
|
|
|
|
#include "app/util/misc.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "gfx/rect.h"
|
|
|
|
|
#include "raster/layer.h"
|
|
|
|
|
#include "raster/mask.h"
|
|
|
|
|
#include "raster/sprite.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
|
|
|
|
|
|
|
|
#include <allegro.h>
|
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
|
|
|
|
|
2012-01-06 06:45:03 +08:00
|
|
|
enum WHEEL_ACTION { WHEEL_NONE,
|
|
|
|
|
WHEEL_ZOOM,
|
|
|
|
|
WHEEL_VSCROLL,
|
|
|
|
|
WHEEL_HSCROLL,
|
|
|
|
|
WHEEL_FG,
|
|
|
|
|
WHEEL_BG,
|
|
|
|
|
WHEEL_FRAME };
|
|
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
static CursorType rotated_size_cursors[] = {
|
|
|
|
|
kSizeRCursor,
|
|
|
|
|
kSizeTRCursor,
|
|
|
|
|
kSizeTCursor,
|
|
|
|
|
kSizeTLCursor,
|
|
|
|
|
kSizeLCursor,
|
|
|
|
|
kSizeBLCursor,
|
|
|
|
|
kSizeBCursor,
|
|
|
|
|
kSizeBRCursor
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
static CursorType rotated_rotate_cursors[] = {
|
|
|
|
|
kRotateRCursor,
|
|
|
|
|
kRotateTRCursor,
|
|
|
|
|
kRotateTCursor,
|
|
|
|
|
kRotateTLCursor,
|
|
|
|
|
kRotateLCursor,
|
|
|
|
|
kRotateBLCursor,
|
|
|
|
|
kRotateBCursor,
|
|
|
|
|
kRotateBRCursor
|
2012-01-06 06:45:03 +08:00
|
|
|
};
|
|
|
|
|
|
2012-01-08 03:32:03 +08:00
|
|
|
#pragma warning(disable:4355) // warning C4355: 'this' : used in base member initializer list
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
tools::Tool* currentTool = editor->getCurrentEditorTool();
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
bool StandbyState::checkForScroll(Editor* editor, MouseMessage* msg)
|
2012-01-12 11:46:04 +08:00
|
|
|
{
|
|
|
|
|
UIContext* context = UIContext::instance();
|
|
|
|
|
tools::Tool* currentTool = editor->getCurrentEditorTool();
|
2013-07-29 08:17:07 +08:00
|
|
|
tools::Ink* clickedInk = currentTool->getInk(msg->right() ? 1: 0);
|
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)
|
|
|
|
|
{
|
|
|
|
|
UIContext* context = UIContext::instance();
|
|
|
|
|
tools::Tool* currentTool = editor->getCurrentEditorTool();
|
|
|
|
|
tools::Ink* clickedInk = currentTool->getInk(msg->right() ? 1: 0);
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
tools::Tool* current_tool = editor->getCurrentEditorTool();
|
2013-07-29 08:17:07 +08:00
|
|
|
tools::Ink* clickedInk = current_tool->getInk(msg->right() ? 1: 0);
|
2013-03-12 07:29:45 +08:00
|
|
|
DocumentLocation location;
|
|
|
|
|
editor->getDocumentLocation(&location);
|
|
|
|
|
Document* document = location.document();
|
|
|
|
|
Sprite* sprite = location.sprite();
|
|
|
|
|
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()) {
|
2013-03-12 07:29:45 +08:00
|
|
|
if ((layer) &&
|
2013-11-10 06:59:05 +08:00
|
|
|
(layer->type() == OBJECT_LAYER_IMAGE)) {
|
2012-01-06 06:45:03 +08:00
|
|
|
// TODO you can move the `Background' with tiled mode
|
2013-03-12 07:29:45 +08:00
|
|
|
if (layer->isBackground()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
Alert::show(PACKAGE
|
|
|
|
|
"<<You can't move the `Background' layer."
|
|
|
|
|
"||&Close");
|
|
|
|
|
}
|
2013-03-12 07:29:45 +08:00
|
|
|
else if (!layer->isMoveable()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
Alert::show(PACKAGE "<<The layer movement is locked.||&Close");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Change to MovingCelState
|
|
|
|
|
editor->setState(EditorStatePtr(new MovingCelState(editor, msg)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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,
|
2013-07-29 08:17:07 +08:00
|
|
|
msg->position(),
|
2012-01-06 06:45:03 +08:00
|
|
|
document->getTransformation());
|
|
|
|
|
|
|
|
|
|
if (handle != NoHandle) {
|
|
|
|
|
int x, y, opacity;
|
2013-03-12 07:29:45 +08:00
|
|
|
Image* image = location.image(&x, &y, &opacity);
|
2012-01-06 06:45:03 +08:00
|
|
|
if (image) {
|
2013-03-12 07:29:45 +08:00
|
|
|
if (!layer->isWritable()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
Alert::show(PACKAGE "<<The layer is locked.||&Close");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Change to MovingPixelsState
|
2012-01-06 10:21:51 +08:00
|
|
|
transformSelection(editor, msg, handle);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Move selected pixels
|
|
|
|
|
if (editor->isInsideSelection() &&
|
|
|
|
|
current_tool->getInk(0)->isSelection() &&
|
2013-07-29 08:17:07 +08:00
|
|
|
msg->left()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
int x, y, opacity;
|
2013-03-12 07:29:45 +08:00
|
|
|
Image* image = location.image(&x, &y, &opacity);
|
2012-01-06 06:45:03 +08:00
|
|
|
if (image) {
|
2013-03-12 07:29:45 +08:00
|
|
|
if (!layer->isWritable()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
Alert::show(PACKAGE "<<The layer is locked.||&Close");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Change to MovingPixelsState
|
2012-01-06 10:21:51 +08:00
|
|
|
transformSelection(editor, msg, MoveHandle);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call the eyedropper command
|
2012-01-12 11:46:04 +08:00
|
|
|
if (clickedInk->isEyedropper()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
Command* eyedropper_cmd =
|
|
|
|
|
CommandsModule::instance()->getCommandByName(CommandId::Eyedropper);
|
2014-02-24 19:31:02 +08:00
|
|
|
bool fg = (static_cast<tools::PickInk*>(clickedInk)->target() == tools::PickInk::Fg);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
|
Params params;
|
2014-02-24 19:08:34 +08:00
|
|
|
params.set("target", fg ? "foreground": "background");
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
|
UIContext::instance()->executeCommand(eyedropper_cmd, ¶ms);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start the Tool-Loop
|
2013-03-12 07:29:45 +08:00
|
|
|
if (layer) {
|
2012-01-06 06:45:03 +08:00
|
|
|
tools::ToolLoop* toolLoop = create_tool_loop(editor, context, msg);
|
|
|
|
|
if (toolLoop)
|
|
|
|
|
editor->setState(EditorStatePtr(new DrawingState(toolLoop, editor, msg)));
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
editor->moveDrawingCursor();
|
|
|
|
|
editor->updateStatusBar();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-29 08:17:07 +08:00
|
|
|
bool StandbyState::onMouseWheel(Editor* editor, MouseMessage* msg)
|
2012-01-06 06:45:03 +08:00
|
|
|
{
|
2014-04-29 09:02:56 +08:00
|
|
|
int dz = msg->wheelDelta().x + msg->wheelDelta().y;
|
2012-01-06 06:45:03 +08:00
|
|
|
WHEEL_ACTION wheelAction = WHEEL_NONE;
|
|
|
|
|
bool scrollBigSteps = false;
|
|
|
|
|
|
2014-06-23 09:35:51 +08:00
|
|
|
// Alt+mouse wheel changes the fg/bg colors
|
|
|
|
|
if (msg->altPressed()) {
|
|
|
|
|
if (msg->shiftPressed())
|
|
|
|
|
wheelAction = WHEEL_BG;
|
|
|
|
|
else
|
|
|
|
|
wheelAction = WHEEL_FG;
|
|
|
|
|
}
|
|
|
|
|
// Normal behavior: mouse wheel zooms
|
|
|
|
|
else if (UIContext::instance()->settings()->getZoomWithScrollWheel()) {
|
|
|
|
|
if (msg->ctrlPressed())
|
|
|
|
|
wheelAction = WHEEL_FRAME;
|
|
|
|
|
else if (msg->wheelDelta().x != 0 || msg->shiftPressed())
|
2014-04-29 09:02:56 +08:00
|
|
|
wheelAction = WHEEL_HSCROLL;
|
|
|
|
|
else
|
|
|
|
|
wheelAction = WHEEL_ZOOM;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
2014-06-23 09:35:51 +08:00
|
|
|
// For laptops, it's convenient to that Ctrl+wheel zoom (because
|
|
|
|
|
// it's the "pinch" gesture).
|
2012-01-06 06:45:03 +08:00
|
|
|
else {
|
2013-07-29 08:17:07 +08:00
|
|
|
if (msg->ctrlPressed())
|
2014-06-23 09:35:51 +08:00
|
|
|
wheelAction = WHEEL_ZOOM;
|
|
|
|
|
else if (msg->wheelDelta().x != 0 || msg->shiftPressed())
|
2012-01-06 06:45:03 +08:00
|
|
|
wheelAction = WHEEL_HSCROLL;
|
|
|
|
|
else
|
|
|
|
|
wheelAction = WHEEL_VSCROLL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (wheelAction) {
|
|
|
|
|
|
|
|
|
|
case WHEEL_NONE:
|
|
|
|
|
// Do nothing
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WHEEL_FG:
|
|
|
|
|
{
|
|
|
|
|
int newIndex = 0;
|
2013-01-07 01:45:43 +08:00
|
|
|
if (ColorBar::instance()->getFgColor().getType() == app::Color::IndexType) {
|
2012-07-10 00:20:58 +08:00
|
|
|
newIndex = ColorBar::instance()->getFgColor().getIndex() + dz;
|
2012-01-06 06:45:03 +08:00
|
|
|
newIndex = MID(0, newIndex, 255);
|
|
|
|
|
}
|
2013-01-07 01:45:43 +08:00
|
|
|
ColorBar::instance()->setFgColor(app::Color::fromIndex(newIndex));
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WHEEL_BG:
|
|
|
|
|
{
|
|
|
|
|
int newIndex = 0;
|
2013-01-07 01:45:43 +08:00
|
|
|
if (ColorBar::instance()->getBgColor().getType() == app::Color::IndexType) {
|
2012-07-10 00:20:58 +08:00
|
|
|
newIndex = ColorBar::instance()->getBgColor().getIndex() + dz;
|
2012-01-06 06:45:03 +08:00
|
|
|
newIndex = MID(0, newIndex, 255);
|
|
|
|
|
}
|
2013-01-07 01:45:43 +08:00
|
|
|
ColorBar::instance()->setBgColor(app::Color::fromIndex(newIndex));
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WHEEL_FRAME:
|
|
|
|
|
{
|
|
|
|
|
Command* command = CommandsModule::instance()->getCommandByName
|
|
|
|
|
((dz < 0) ? CommandId::GotoNextFrame:
|
|
|
|
|
CommandId::GotoPreviousFrame);
|
|
|
|
|
if (command)
|
|
|
|
|
UIContext::instance()->executeCommand(command, NULL);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WHEEL_ZOOM: {
|
2013-07-29 08:17:07 +08:00
|
|
|
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
|
2014-07-30 12:28:15 +08:00
|
|
|
int zoom = MID(MIN_ZOOM, editor->zoom()-dz, MAX_ZOOM);
|
|
|
|
|
if (editor->zoom() != zoom)
|
2014-04-20 07:43:23 +08:00
|
|
|
editor->setZoomAndCenterInMouse(zoom,
|
|
|
|
|
mouseMsg->position().x, mouseMsg->position().y,
|
|
|
|
|
Editor::kDontCenterOnZoom);
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case WHEEL_HSCROLL:
|
|
|
|
|
case WHEEL_VSCROLL: {
|
|
|
|
|
View* view = View::getView(editor);
|
|
|
|
|
gfx::Rect vp = view->getViewportBounds();
|
|
|
|
|
int dx = 0;
|
|
|
|
|
int dy = 0;
|
|
|
|
|
|
|
|
|
|
if (wheelAction == WHEEL_HSCROLL) {
|
|
|
|
|
dx = dz * vp.w;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dy = dz * vp.h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (scrollBigSteps) {
|
|
|
|
|
dx /= 2;
|
|
|
|
|
dy /= 2;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dx /= 10;
|
|
|
|
|
dy /= 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gfx::Point scroll = view->getViewScroll();
|
|
|
|
|
|
|
|
|
|
editor->hideDrawingCursor();
|
|
|
|
|
editor->setEditorScroll(scroll.x+dx, scroll.y+dy, true);
|
|
|
|
|
editor->showDrawingCursor();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool StandbyState::onSetCursor(Editor* editor)
|
|
|
|
|
{
|
|
|
|
|
tools::Tool* current_tool = editor->getCurrentEditorTool();
|
|
|
|
|
|
|
|
|
|
if (current_tool) {
|
|
|
|
|
tools::Ink* current_ink = current_tool->getInk(0);
|
|
|
|
|
|
|
|
|
|
// If the current tool change selection (e.g. rectangular marquee, etc.)
|
|
|
|
|
if (current_ink->isSelection()) {
|
|
|
|
|
// 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())
|
2012-08-11 10:14:54 +08:00
|
|
|
jmouse_set_cursor(kArrowPlusCursor);
|
2012-01-06 06:45:03 +08:00
|
|
|
else
|
2012-08-11 10:14:54 +08:00
|
|
|
jmouse_set_cursor(kMoveCursor);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (current_ink->isEyedropper()) {
|
|
|
|
|
editor->hideDrawingCursor();
|
2012-08-11 10:14:54 +08:00
|
|
|
jmouse_set_cursor(kEyedropperCursor);
|
2012-01-06 06:45:03 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-04-20 07:08:21 +08:00
|
|
|
else if (current_ink->isZoom()) {
|
|
|
|
|
editor->hideDrawingCursor();
|
|
|
|
|
jmouse_set_cursor(kMagnifierCursor);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
else if (current_ink->isScrollMovement()) {
|
|
|
|
|
editor->hideDrawingCursor();
|
2012-08-11 10:14:54 +08:00
|
|
|
jmouse_set_cursor(kScrollCursor);
|
2012-01-06 06:45:03 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else if (current_ink->isCelMovement()) {
|
|
|
|
|
editor->hideDrawingCursor();
|
2012-08-11 10:14:54 +08:00
|
|
|
jmouse_set_cursor(kMoveCursor);
|
2012-01-06 06:45:03 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-06-28 09:58:38 +08:00
|
|
|
else if (current_ink->isSlice()) {
|
|
|
|
|
jmouse_set_cursor(kNoCursor);
|
|
|
|
|
editor->showDrawingCursor();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw
|
|
|
|
|
if (editor->canDraw()) {
|
2012-08-11 10:14:54 +08:00
|
|
|
jmouse_set_cursor(kNoCursor);
|
2012-01-06 06:45:03 +08:00
|
|
|
editor->showDrawingCursor();
|
|
|
|
|
}
|
|
|
|
|
// Forbidden
|
|
|
|
|
else {
|
|
|
|
|
editor->hideDrawingCursor();
|
2012-08-11 10:14:54 +08:00
|
|
|
jmouse_set_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
|
|
|
{
|
2013-07-29 08:17:07 +08:00
|
|
|
return editor->processKeysToSetZoom(msg);
|
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)
|
|
|
|
|
{
|
|
|
|
|
tools::Tool* current_tool = editor->getCurrentEditorTool();
|
2014-07-30 12:28:15 +08:00
|
|
|
const Sprite* sprite = editor->sprite();
|
2012-01-06 06:45:03 +08:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
|
|
editor->screenToEditor(jmouse_x(0), jmouse_y(0), &x, &y);
|
|
|
|
|
|
|
|
|
|
if (!sprite) {
|
2012-07-10 00:20:58 +08:00
|
|
|
StatusBar::instance()->clearText();
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
// For eye-dropper
|
|
|
|
|
else if (current_tool->getInk(0)->isEyedropper()) {
|
2014-01-29 10:56:44 +08:00
|
|
|
bool grabAlpha = UIContext::instance()->settings()->getGrabAlpha();
|
|
|
|
|
ColorPicker picker;
|
|
|
|
|
picker.pickColor(editor->getDocumentLocation(), x, y,
|
|
|
|
|
grabAlpha ?
|
|
|
|
|
ColorPicker::FromActiveLayer:
|
|
|
|
|
ColorPicker::FromComposition);
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
|
usprintf(buf, "- Pos %d %d", x, y);
|
|
|
|
|
|
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 =
|
2014-07-30 12:28:15 +08:00
|
|
|
(editor->document()->isMaskVisible() ?
|
|
|
|
|
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]",
|
|
|
|
|
x, y,
|
2014-07-30 12:28:15 +08:00
|
|
|
(mask ? mask->bounds().w: sprite->width()),
|
|
|
|
|
(mask ? mask->bounds().h: sprite->height()),
|
|
|
|
|
editor->frame()+1,
|
|
|
|
|
sprite->getFrameDuration(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()))
|
|
|
|
|
movingPixels->translate(move.x, move.y);
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
2013-12-30 06:53:28 +08:00
|
|
|
base::UniquePtr<Image> tmpImage(NewImageFromMask(editor->getDocumentLocation()));
|
2014-07-30 12:28:15 +08:00
|
|
|
int x = document->mask()->bounds().x;
|
|
|
|
|
int y = document->mask()->bounds().y;
|
2013-12-30 06:53:28 +08:00
|
|
|
int opacity = 255;
|
2014-07-30 12:28:15 +08:00
|
|
|
Sprite* sprite = editor->sprite();
|
|
|
|
|
Layer* layer = editor->layer();
|
2013-12-30 06:53:28 +08:00
|
|
|
PixelsMovementPtr pixelsMovement(
|
|
|
|
|
new PixelsMovement(UIContext::instance(),
|
|
|
|
|
document, sprite, layer,
|
|
|
|
|
tmpImage, x, y, opacity,
|
|
|
|
|
"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.
|
|
|
|
|
}
|
2012-01-06 10:21:51 +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,
|
|
|
|
|
gfx::Point(jmouse_x(0), jmouse_y(0)),
|
|
|
|
|
transformation);
|
|
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
CursorType newCursor = kArrowCursor;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
|
switch (handle) {
|
2012-08-11 10:14:54 +08:00
|
|
|
case ScaleNWHandle: newCursor = kSizeTLCursor; break;
|
|
|
|
|
case ScaleNHandle: newCursor = kSizeTCursor; break;
|
|
|
|
|
case ScaleNEHandle: newCursor = kSizeTRCursor; break;
|
|
|
|
|
case ScaleWHandle: newCursor = kSizeLCursor; break;
|
|
|
|
|
case ScaleEHandle: newCursor = kSizeRCursor; break;
|
|
|
|
|
case ScaleSWHandle: newCursor = kSizeBLCursor; break;
|
|
|
|
|
case ScaleSHandle: newCursor = kSizeBCursor; break;
|
|
|
|
|
case ScaleSEHandle: newCursor = kSizeBRCursor; break;
|
|
|
|
|
case RotateNWHandle: newCursor = kRotateTLCursor; break;
|
|
|
|
|
case RotateNHandle: newCursor = kRotateTCursor; break;
|
|
|
|
|
case RotateNEHandle: newCursor = kRotateTRCursor; break;
|
|
|
|
|
case RotateWHandle: newCursor = kRotateLCursor; break;
|
|
|
|
|
case RotateEHandle: newCursor = kRotateRCursor; break;
|
|
|
|
|
case RotateSWHandle: newCursor = kRotateBLCursor; break;
|
|
|
|
|
case RotateSHandle: newCursor = kRotateBCursor; break;
|
|
|
|
|
case RotateSEHandle: newCursor = kRotateBRCursor; break;
|
|
|
|
|
case PivotHandle: newCursor = kHandCursor; break;
|
2012-01-06 06:45:03 +08:00
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Adjust the cursor depending the current transformation angle.
|
|
|
|
|
fixed angle = ftofix(128.0 * transformation.angle() / PI);
|
|
|
|
|
angle = fixadd(angle, itofix(16));
|
|
|
|
|
angle &= (255<<16);
|
|
|
|
|
angle >>= 16;
|
|
|
|
|
angle /= 32;
|
|
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
if (newCursor >= kSizeTLCursor && newCursor <= kSizeBRCursor) {
|
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];
|
|
|
|
|
}
|
2012-08-11 10:14:54 +08:00
|
|
|
else if (newCursor >= kRotateTLCursor && newCursor <= kRotateBRCursor) {
|
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();
|
|
|
|
|
jmouse_set_cursor(newCursor);
|
|
|
|
|
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-07-30 12:28:15 +08:00
|
|
|
if (editor->document()->isMaskVisible() &&
|
|
|
|
|
!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.
|
|
|
|
|
tools::Tool* currentTool = editor->getCurrentEditorTool();
|
|
|
|
|
|
|
|
|
|
if (currentTool->getInk(0)->isSelection())
|
|
|
|
|
getTransformHandles(editor)->drawHandles(editor,
|
|
|
|
|
m_standbyState->getTransformation(editor));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
} // namespace app
|