Example #1
0
void NewBrushCommand::onQuickboxEnd(const gfx::Rect& rect, ui::MouseButtons buttons)
{
  Mask mask;
  mask.replace(rect);
  createBrush(&mask);
  selectPencilTool();

  // If the right-button was used, we clear the selected area.
  if (buttons & ui::kButtonRight) {
    try {
      ContextWriter writer(UIContext::instance(), 250);
      Transaction transaction(writer.context(), "Clear");
      transaction.execute(new cmd::ClearRect(writer.cel(), rect));
      transaction.commit();
    }
    catch (const std::exception& ex) {
      Console::showException(ex);
    }
  }

  // Update the context bar
  // TODO find a way to avoid all these singletons. Maybe a simple
  // signal in the context like "brush has changed" could be enough.
  App::instance()->getMainWindow()->getContextBar()
    ->updateForCurrentTool();

  current_editor->backToPreviousState();
}
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);
}
Example #3
0
// Loads a MSK file (Animator and Animator Pro format)
Mask* load_msk_file(const char* filename)
{
#if (MAKE_VERSION(4, 2, 1) >= MAKE_VERSION(ALLEGRO_VERSION,             \
                                           ALLEGRO_SUB_VERSION,         \
                                           ALLEGRO_WIP_VERSION))
  int orig_size = file_size(filename);
#else
  int orig_size = file_size_ex(filename);
#endif
  int i, c, u, v, byte, magic, size;
  Mask *mask = NULL;
  PACKFILE *f;

  f = pack_fopen(filename, F_READ);
  if (!f)
    return NULL;

  size = pack_igetl(f);
  magic = pack_igetw(f);

  // Animator Pro MSK format
  if ((size == orig_size) && (magic == 0x9500)) {
    int x, y;

    pack_fclose(f);

    // Just load an Animator Pro PIC file
    base::UniquePtr<Image> image(load_pic_file(filename, &x, &y, NULL));
    if (image != NULL && (image->getPixelFormat() == IMAGE_BITMAP)) {
      mask = new Mask(x, y, image.release());
    }
  }
  // Animator MSK format
  else if (orig_size == 8000) {
    mask = new Mask();
    mask->replace(0, 0, 320, 200);

    u = v = 0;
    for (i=0; i<8000; i++) {
      byte = pack_getc (f);
      for (c=0; c<8; c++) {
        mask->getBitmap()->putpixel(u, v, byte & (1<<(7-c)));
        u++;
        if (u == 320) {
          u = 0;
          v++;
        }
      }
    }
    pack_fclose(f);
  }
  else {
    pack_fclose(f);
  }

  return mask;
}
Example #4
0
// Loads a MSK file (Animator and Animator Pro format)
Mask* load_msk_file(const char* filename)
{
  int orig_size = base::file_size(filename);
  int i, c, u, v, byte, magic, size;
  Mask* mask = NULL;

  FILE* f = base::open_file_raw(filename, "r");
  if (!f)
    return NULL;

  size = base::fgetl(f);
  magic = base::fgetw(f);

  // Animator Pro MSK format
  if ((size == orig_size) && (magic == 0x9500)) {
    int x, y;

    fclose(f);

    // Just load an Animator Pro PIC file
    base::UniquePtr<Image> image(load_pic_file(filename, &x, &y, NULL));
    if (image != NULL && (image->pixelFormat() == IMAGE_BITMAP))
      mask = new Mask(x, y, image.release());
  }
  // Animator MSK format
  else if (orig_size == 8000) {
    mask = new Mask();
    mask->replace(0, 0, 320, 200);

    u = v = 0;
    for (i=0; i<8000; i++) {
      byte = getc(f);
      for (c=0; c<8; c++) {
        mask->bitmap()->putPixel(u, v, byte & (1<<(7-c)));
        u++;
        if (u == 320) {
          u = 0;
          v++;
        }
      }
    }
    fclose(f);
  }
  else {
    fclose(f);
  }

  return mask;
}
Example #5
0
void MaskAllCommand::onExecute(Context* context)
{
  ContextWriter writer(context);
  Document* document(writer.document());
  Sprite* sprite(writer.sprite());

  Mask newMask;
  newMask.replace(sprite->bounds());

  Transaction transaction(writer.context(), "Select All", DoesntModifyDocument);
  transaction.execute(new cmd::SetMask(document, &newMask));
  transaction.commit();

  document->resetTransformation();
  document->generateMaskBoundaries();
  update_screen_for_document(document);
}
Example #6
0
void MaskAllCommand::onExecute(Context* context)
{
  ContextWriter writer(context);
  Doc* document(writer.document());
  Sprite* sprite(writer.sprite());

  Mask newMask;
  newMask.replace(sprite->bounds());

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

  if (Preferences::instance().selection.autoShowSelectionEdges()) {
    DocumentPreferences& docPref = Preferences::instance().document(document);
    docPref.show.selectionEdges(true);
  }

  update_screen_for_document(document);
}