Example #1
0
void SetMaskPosition::setMaskPosition(const gfx::Point& pos)
{
  Doc* doc = document();
  doc->mask()->setOrigin(pos.x, pos.y);
  doc->resetTransformation();

  doc->notifySelectionChanged();
}
Example #2
0
void MaskContentCommand::onExecute(Context* context)
{
  Doc* document;
  {
    ContextWriter writer(context);
    document = writer.document();

    Cel* cel = writer.cel(); // Get current cel (can be NULL)
    if (!cel)
      return;

    gfx::Color color;
    if (writer.layer()->isBackground()) {
      ColorPicker picker;
      picker.pickColor(*writer.site(),
                       gfx::PointF(0.0, 0.0),
                       current_editor->projection(),
                       ColorPicker::FromComposition);
      color = color_utils::color_for_layer(picker.color(), writer.layer());
    }
    else
      color = cel->image()->maskColor();

    Mask newMask;
    gfx::Rect imgBounds = cel->image()->bounds();
    if (algorithm::shrink_bounds(cel->image(), imgBounds, color)) {
      newMask.replace(imgBounds.offset(cel->bounds().origin()));
    }
    else {
      newMask.replace(cel->bounds());
    }

    Tx tx(writer.context(), "Select Content", DoesntModifyDocument);
    tx(new cmd::SetMask(document, &newMask));
    document->resetTransformation();
    tx.commit();
  }

  // Select marquee tool
  if (tools::Tool* tool = App::instance()->toolBox()
      ->getToolById(tools::WellKnownTools::RectangularMarquee)) {
    ToolBar::instance()->selectTool(tool);
  }

  update_screen_for_document(document);
}