void stroke_selection(Image* image, const gfx::Point& offset, const Mask* origMask, const color_t color) { ASSERT(origMask); ASSERT(origMask->bitmap()); if (!origMask || !origMask->bitmap()) return; gfx::Rect bounds = origMask->bounds(); if (bounds.isEmpty()) return; Mask mask; mask.reserve(bounds); mask.freeze(); modify_selection( SelectionModifier::Border, origMask, &mask, 1, BrushType::kCircleBrushType); mask.unfreeze(); // Both mask must have the same bounds. ASSERT(mask.bounds() == origMask->bounds()); if (mask.bitmap()) fill_selection(image, offset, &mask, color); }
void InvertMaskCommand::onExecute(Context* context) { bool hasMask = false; { const ContextReader reader(context); if (reader.document()->isMaskVisible()) hasMask = true; } // without mask?... if (!hasMask) { // so we select all Command* mask_all_cmd = CommandsModule::instance()->getCommandByName(CommandId::MaskAll); context->executeCommand(mask_all_cmd); } // invert the current mask else { ContextWriter writer(context); Document* document(writer.document()); Sprite* sprite(writer.sprite()); // Select all the sprite area base::UniquePtr<Mask> mask(new Mask()); mask->replace(sprite->bounds()); // Remove in the new mask the current sprite marked region const gfx::Rect& maskBounds = document->mask()->bounds(); doc::fill_rect(mask->bitmap(), maskBounds.x, maskBounds.y, maskBounds.x + maskBounds.w-1, maskBounds.y + maskBounds.h-1, 0); Mask* curMask = document->mask(); if (curMask->bitmap()) { // Copy the inverted region in the new mask (we just modify the // document's mask temporaly here) curMask->freeze(); curMask->invert(); doc::copy_image(mask->bitmap(), curMask->bitmap(), curMask->bounds().x, curMask->bounds().y); curMask->invert(); curMask->unfreeze(); } // We need only need the area inside the sprite mask->intersect(sprite->bounds()); // Set the new mask Transaction transaction(writer.context(), "Mask Invert", DoesntModifyDocument); transaction.execute(new cmd::SetMask(document, mask)); transaction.commit(); document->generateMaskBoundaries(); update_screen_for_document(document); } }
EditorState::LeaveAction MovingSelectionState::onLeaveState(Editor* editor, EditorState* newState) { Document* doc = editor->document(); Mask* mask = doc->mask(); gfx::Point newOrigin = mask->bounds().origin(); // Restore the mask to the original state so we can transform it // with the a undoable transaction. mask->setOrigin(m_selOrigin.x, m_selOrigin.y); mask->unfreeze(); { ContextWriter writer(UIContext::instance(), 1000); Transaction transaction(writer.context(), "Move Selection Edges", DoesntModifyDocument); transaction.execute(new cmd::SetMaskPosition(doc, newOrigin)); transaction.commit(); } doc->resetTransformation(); doc->notifyGeneralUpdate(); return StandbyState::onLeaveState(editor, newState); }