void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleType handle) { Document* document = editor->document(); for (auto docView : UIContext::instance()->getAllDocumentViews(document)) { if (docView->getEditor()->isMovingPixels()) { // TODO Transfer moving pixels state to this editor docView->getEditor()->dropMovingPixels(); } } try { // Clear brush preview, as the extra cel will be replaced with the // transformed image. editor->brushPreview().hide(); EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); base::UniquePtr<Image> tmpImage(new_image_from_mask(editor->getSite())); PixelsMovementPtr pixelsMovement( new PixelsMovement(UIContext::instance(), editor->getSite(), tmpImage, document->mask(), "Transformation")); // If the Ctrl key is pressed start dragging a copy of the selection if ((customization) && int(customization->getPressedKeyAction(KeyContext::TranslatingSelection) & KeyAction::CopySelection)) pixelsMovement->copyMask(); else pixelsMovement->cutMask(); 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. StatusBar::instance()->showTip(1000, "The sprite is locked in other editor"); editor->showMouseCursor(kForbiddenCursor); } catch (const std::bad_alloc&) { StatusBar::instance()->showTip(1000, "Not enough memory to transform the selection"); editor->showMouseCursor(kForbiddenCursor); } }
bool StandbyState::onSetCursor(Editor* editor) { tools::Ink* ink = editor->getCurrentEditorInk(); if (ink) { // If the current tool change selection (e.g. rectangular marquee, etc.) if (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()) ui::set_mouse_cursor(kArrowPlusCursor); else ui::set_mouse_cursor(kMoveCursor); return true; } } else if (ink->isEyedropper()) { editor->hideDrawingCursor(); ui::set_mouse_cursor(kEyedropperCursor); return true; } else if (ink->isZoom()) { editor->hideDrawingCursor(); ui::set_mouse_cursor(kMagnifierCursor); return true; } else if (ink->isScrollMovement()) { editor->hideDrawingCursor(); ui::set_mouse_cursor(kScrollCursor); return true; } else if (ink->isCelMovement()) { editor->hideDrawingCursor(); ui::set_mouse_cursor(kMoveCursor); return true; } else if (ink->isSlice()) { ui::set_mouse_cursor(kNoCursor); editor->showDrawingCursor(); return true; } } // Draw if (editor->canDraw()) { ui::set_mouse_cursor(kNoCursor); editor->showDrawingCursor(); } // Forbidden else { editor->hideDrawingCursor(); ui::set_mouse_cursor(kForbiddenCursor); } return true; }
bool MovingPixelsState::onMouseDown(Editor* editor, MouseMessage* msg) { ASSERT(m_pixelsMovement != NULL); // Set this editor as the active one and setup the ContextBar for // moving pixels. This is needed in case that the user is working // with a couple of Editors, in one is moving pixels and the other // one not. UIContext* ctx = UIContext::instance(); ctx->setActiveView(editor->getDocumentView()); ContextBar* contextBar = App::instance()->getMainWindow()->getContextBar(); contextBar->updateForMovingPixels(); // Start scroll loop if (checkForScroll(editor, msg)) return true; Decorator* decorator = static_cast<Decorator*>(editor->decorator()); Document* document = editor->document(); // Transform selected pixels if (document->isMaskVisible() && decorator->getTransformHandles(editor)) { TransformHandles* transfHandles = decorator->getTransformHandles(editor); // Get the handle covered by the mouse. HandleType handle = transfHandles->getHandleAtPoint(editor, msg->position(), getTransformation(editor)); if (handle != NoHandle) { // Re-catch the image int x, y; editor->screenToEditor(msg->position().x, msg->position().y, &x, &y); m_pixelsMovement->catchImageAgain(x, y, handle); editor->captureMouse(); return true; } } // Start "moving pixels" loop if (editor->isInsideSelection() && (msg->left() || msg->right())) { // In case that the user is pressing the copy-selection keyboard shortcut. EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); if (customization && customization->isCopySelectionKeyPressed()) { // Stamp the pixels to create the copy. m_pixelsMovement->stampImage(); } // Re-catch the image int x, y; editor->screenToEditor(msg->position().x, msg->position().y, &x, &y); m_pixelsMovement->catchImageAgain(x, y, MoveHandle); editor->captureMouse(); return true; } // End "moving pixels" loop else { // Drop pixels (e.g. to start drawing) dropPixels(editor); } // Use StandbyState implementation return StandbyState::onMouseDown(editor, msg); }