void NewBrushCommand::onExecute(Context* context) { ASSERT(current_editor); if (!current_editor) return; // If there is no visible mask, the brush must be selected from the // current editor. if (!context->activeDocument()->isMaskVisible()) { EditorStatePtr state = current_editor->getState(); if (dynamic_cast<SelectBoxState*>(state.get())) { // If already are in "SelectBoxState" state, in this way we // avoid creating a stack of several "SelectBoxState" states. return; } current_editor->setState( EditorStatePtr( new SelectBoxState( this, current_editor->sprite()->bounds(), SelectBoxState::DARKOUTSIDE | SelectBoxState::QUICKBOX))); } // Create a brush from the active selection else { createBrush(context->activeDocument()->mask()); selectPencilTool(); // Deselect mask Command* cmd = CommandsModule::instance()->getCommandByName(CommandId::DeselectMask); UIContext::instance()->executeCommand(cmd); } }
void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleType handle) { try { EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); Document* document = editor->document(); base::UniquePtr<Image> tmpImage(new_image_from_mask(editor->getSite())); gfx::Point origin = document->mask()->bounds().getOrigin(); int opacity = 255; PixelsMovementPtr pixelsMovement( new PixelsMovement(UIContext::instance(), editor->getSite(), tmpImage, origin, opacity, "Transformation")); // If the Ctrl key is pressed start dragging a copy of the selection if (customization && customization->isCopySelectionKeyPressed()) 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"); ui::set_mouse_cursor(kForbiddenCursor); } catch (const std::bad_alloc&) { StatusBar::instance()->showTip(1000, "Not enough memory to transform the selection"); ui::set_mouse_cursor(kForbiddenCursor); } }
void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleType handle) { try { EditorCustomizationDelegate* customization = editor->getCustomizationDelegate(); Document* document = editor->document(); base::UniquePtr<Image> tmpImage(NewImageFromMask(editor->getDocumentLocation())); int x = document->mask()->bounds().x; int y = document->mask()->bounds().y; int opacity = 255; Sprite* sprite = editor->sprite(); Layer* layer = editor->layer(); 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(); 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. } }
void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleType handle) { Document* document = editor->document(); for (auto docView : UIContext::instance()->getAllDocumentViews(document)) { if (docView->editor()->isMovingPixels()) { // TODO Transfer moving pixels state to this editor docView->editor()->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::onMouseDown(Editor* editor, MouseMessage* msg) { if (editor->hasCapture()) return true; UIContext* context = UIContext::instance(); tools::Ink* clickedInk = editor->getCurrentEditorInk(); Site site; editor->getSite(&site); app::Document* document = static_cast<app::Document*>(site.document()); Layer* layer = site.layer(); // When an editor is clicked the current view is changed. context->setActiveView(editor->getDocumentView()); // Start scroll loop if (checkForScroll(editor, msg) || checkForZoom(editor, msg)) return true; // Move cel X,Y coordinates if (clickedInk->isCelMovement()) { // Handle "Auto Select Layer" if (editor->isAutoSelectLayer()) { gfx::Point cursor = editor->screenToEditor(msg->position()); ColorPicker picker; picker.pickColor(site, cursor, ColorPicker::FromComposition); if (layer != picker.layer()) { layer = picker.layer(); if (layer) { editor->setLayer(layer); editor->flashCurrentLayer(); } } } if ((layer) && (layer->type() == ObjectType::LayerImage)) { // TODO we should be able to move the `Background' with tiled mode if (layer->isBackground()) { StatusBar::instance()->showTip(1000, "The background layer cannot be moved"); } else if (!layer->isVisible()) { StatusBar::instance()->showTip(1000, "Layer '%s' is hidden", layer->name().c_str()); } else if (!layer->isMovable() || !layer->isEditable()) { StatusBar::instance()->showTip(1000, "Layer '%s' is locked", layer->name().c_str()); } else { // Change to MovingCelState editor->setState(EditorStatePtr(new MovingCelState(editor, msg))); } } return true; } // Call the eyedropper command if (clickedInk->isEyedropper()) { callEyedropper(editor); return true; } if (clickedInk->isSelection()) { // Transform selected pixels if (document->isMaskVisible() && m_decorator->getTransformHandles(editor)) { TransformHandles* transfHandles = m_decorator->getTransformHandles(editor); // Get the handle covered by the mouse. HandleType handle = transfHandles->getHandleAtPoint(editor, msg->position(), document->getTransformation()); if (handle != NoHandle) { int x, y, opacity; Image* image = site.image(&x, &y, &opacity); if (layer && image) { if (!layer->isEditable()) { StatusBar::instance()->showTip(1000, "Layer '%s' is locked", layer->name().c_str()); return true; } // Change to MovingPixelsState transformSelection(editor, msg, handle); } return true; } } // Move selected pixels if (layer && editor->isInsideSelection() && msg->left()) { if (!layer->isEditable()) { StatusBar::instance()->showTip(1000, "Layer '%s' is locked", layer->name().c_str()); return true; } // Change to MovingPixelsState transformSelection(editor, msg, MoveHandle); return true; } } // Start the Tool-Loop if (layer) { tools::ToolLoop* toolLoop = create_tool_loop(editor, context); if (toolLoop) { EditorStatePtr newState(new DrawingState(toolLoop)); editor->setState(newState); static_cast<DrawingState*>(newState.get()) ->initToolLoop(editor, msg); } return true; } return true; }
bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg) { if (editor->hasCapture()) return true; UIContext* context = UIContext::instance(); tools::Ink* clickedInk = editor->getCurrentEditorInk(); Site site; editor->getSite(&site); app::Document* document = static_cast<app::Document*>(site.document()); Layer* layer = site.layer(); // When an editor is clicked the current view is changed. context->setActiveView(editor->getDocumentView()); // Start scroll loop if (checkForScroll(editor, msg) || checkForZoom(editor, msg)) return true; // Move cel X,Y coordinates if (clickedInk->isCelMovement()) { // Handle "Auto Select Layer" if (editor->isAutoSelectLayer()) { gfx::Point cursor = editor->screenToEditor(msg->position()); ColorPicker picker; picker.pickColor(site, cursor, ColorPicker::FromComposition); DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range(); // 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)) { layer = picker.layer(); if (layer) { editor->setLayer(layer); editor->flashCurrentLayer(); } } } if ((layer) && (layer->type() == ObjectType::LayerImage)) { // TODO we should be able to move the `Background' with tiled mode if (layer->isBackground()) { StatusBar::instance()->showTip(1000, "The background layer cannot be moved"); } else if (!layer->isVisible()) { StatusBar::instance()->showTip(1000, "Layer '%s' is hidden", layer->name().c_str()); } else if (!layer->isMovable() || !layer->isEditable()) { StatusBar::instance()->showTip(1000, "Layer '%s' is locked", layer->name().c_str()); } else if (!layer->cel(editor->frame())) { StatusBar::instance()->showTip(1000, "Cel is empty, nothing to move"); } else { // Change to MovingCelState editor->setState(EditorStatePtr(new MovingCelState(editor, msg))); } } return true; } // Call the eyedropper command if (clickedInk->isEyedropper()) { editor->captureMouse(); callEyedropper(editor); return true; } if (clickedInk->isSelection()) { // Transform selected pixels if (editor->isActive() && document->isMaskVisible() && m_decorator->getTransformHandles(editor)) { TransformHandles* transfHandles = m_decorator->getTransformHandles(editor); // Get the handle covered by the mouse. HandleType handle = transfHandles->getHandleAtPoint(editor, msg->position(), document->getTransformation()); if (handle != NoHandle) { int x, y, opacity; Image* image = site.image(&x, &y, &opacity); if (layer && image) { if (!layer->isEditable()) { StatusBar::instance()->showTip(1000, "Layer '%s' is locked", layer->name().c_str()); return true; } // Change to MovingPixelsState transformSelection(editor, msg, handle); } return true; } } // Move selected pixels if (layer && editor->isInsideSelection() && msg->left()) { if (!layer->isEditable()) { StatusBar::instance()->showTip(1000, "Layer '%s' is locked", layer->name().c_str()); return true; } // Change to MovingPixelsState transformSelection(editor, msg, MoveHandle); return true; } } // 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; } // Start the Tool-Loop if (layer) { tools::ToolLoop* toolLoop = create_tool_loop(editor, context); if (toolLoop) { EditorStatePtr newState(new DrawingState(toolLoop)); editor->setState(newState); static_cast<DrawingState*>(newState.get()) ->initToolLoop(editor, msg); } return true; } return true; }
EditorStatePtr EditorStatesHistory::top() { return (!m_states.empty() ? m_states.back(): EditorStatePtr(NULL)); }
bool StandbyState::onMouseDown(Editor* editor, Message* msg) { if (editor->hasCapture()) return true; UIContext* context = UIContext::instance(); tools::Tool* current_tool = editor->getCurrentEditorTool(); Sprite* sprite = editor->getSprite(); // Each time an editor is clicked the current editor and the active // document are set. set_current_editor(editor); context->setActiveDocument(editor->getDocument()); // Start scroll loop if (msg->mouse.middle || current_tool->getInk(msg->mouse.right ? 1: 0)->isScrollMovement()) { editor->setState(EditorStatePtr(new ScrollingState())); editor->captureMouse(); return true; } // Move frames position if (current_tool->getInk(msg->mouse.right ? 1: 0)->isCelMovement()) { if ((sprite->getCurrentLayer()) && (sprite->getCurrentLayer()->getType() == GFXOBJ_LAYER_IMAGE)) { // TODO you can move the `Background' with tiled mode if (sprite->getCurrentLayer()->is_background()) { Alert::show(PACKAGE "<<You can't move the `Background' layer." "||&Close"); } else if (!sprite->getCurrentLayer()->is_moveable()) { Alert::show(PACKAGE "<<The layer movement is locked.||&Close"); } else { bool click2 = get_config_bool("Options", "MoveClick2", FALSE); // TODO replace "interactive_move_layer" with a new EditorState interactive_move_layer(click2 ? Editor::MODE_CLICKANDCLICK: Editor::MODE_CLICKANDRELEASE, TRUE, NULL); } } } // Move selected pixels else if (editor->isInsideSelection() && current_tool->getInk(0)->isSelection() && msg->mouse.left) { int x, y, opacity; Image* image = sprite->getCurrentImage(&x, &y, &opacity); if (image) { if (!sprite->getCurrentLayer()->is_writable()) { Alert::show(PACKAGE "<<The layer is locked.||&Close"); return true; } // Change to MovingPixelsState editor->setState(EditorStatePtr(new MovingPixelsState(editor, msg, image, x, y, opacity))); } } // Call the eyedropper command else if (current_tool->getInk(msg->mouse.right ? 1: 0)->isEyedropper()) { Command* eyedropper_cmd = CommandsModule::instance()->getCommandByName(CommandId::Eyedropper); Params params; params.set("target", msg->mouse.right ? "background": "foreground"); UIContext::instance()->executeCommand(eyedropper_cmd, ¶ms); return true; } // Start the Tool-Loop else if (sprite->getCurrentLayer()) { tools::ToolLoop* toolLoop = create_tool_loop(editor, context, msg); if (toolLoop) editor->setState(EditorStatePtr(new DrawingState(toolLoop, editor, msg))); } return true; }
bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg) { if (editor->hasCapture()) return true; UIContext* context = UIContext::instance(); tools::Tool* currentTool = editor->getCurrentEditorTool(); tools::Ink* clickedInk = editor->getCurrentEditorInk(); DocumentLocation location; editor->getDocumentLocation(&location); Document* document = location.document(); Layer* layer = location.layer(); // When an editor is clicked the current view is changed. context->setActiveView(editor->getDocumentView()); // Start scroll loop if (checkForScroll(editor, msg) || checkForZoom(editor, msg)) return true; // Move cel X,Y coordinates if (clickedInk->isCelMovement()) { if ((layer) && (layer->type() == OBJECT_LAYER_IMAGE)) { // TODO you can move the `Background' with tiled mode if (layer->isBackground()) { Alert::show(PACKAGE "<<You can't move the `Background' layer." "||&Close"); } else if (!layer->isMoveable()) { 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, msg->position(), document->getTransformation()); if (handle != NoHandle) { int x, y, opacity; Image* image = location.image(&x, &y, &opacity); if (image) { if (!layer->isWritable()) { Alert::show(PACKAGE "<<The layer is locked.||&Close"); return true; } // Change to MovingPixelsState transformSelection(editor, msg, handle); } return true; } } // Move selected pixels if (editor->isInsideSelection() && currentTool->getInk(0)->isSelection() && msg->left()) { if (!layer->isWritable()) { Alert::show(PACKAGE "<<The layer is locked.||&Close"); return true; } // Change to MovingPixelsState transformSelection(editor, msg, MoveHandle); return true; } // Call the eyedropper command if (clickedInk->isEyedropper()) { onMouseMove(editor, msg); return true; } // Start the Tool-Loop if (layer) { tools::ToolLoop* toolLoop = create_tool_loop(editor, context); if (toolLoop) editor->setState(EditorStatePtr(new DrawingState(toolLoop, editor, msg))); return true; } return true; }