コード例 #1
0
ファイル: cmd_undo.cpp プロジェクト: Julien-B/aseprite
void UndoCommand::onExecute(Context* context)
{
    ContextWriter writer(context);
    Document* document(writer.document());
    DocumentUndo* undo = document->getUndo();
    Sprite* sprite = document->sprite();

    if (context->settings()->undoGotoModified()) {
        SpritePosition spritePosition;
        SpritePosition currentPosition(writer.location()->layerIndex(),
                                       writer.location()->frame());

        if (m_type == Undo)
            spritePosition = undo->getNextUndoSpritePosition();
        else
            spritePosition = undo->getNextRedoSpritePosition();

        if (spritePosition != currentPosition) {
            current_editor->setLayer(sprite->indexToLayer(spritePosition.layerIndex()));
            current_editor->setFrame(spritePosition.frameNumber());

            // Draw the current layer/frame (which is not undone yet) so the
            // user can see the doUndo/doRedo effect.
            current_editor->drawSpriteClipped(
                gfx::Region(gfx::Rect(0, 0, sprite->width(), sprite->height())));

            ui::dirty_display_flag = true;
            gui_feedback();

            base::this_thread::sleep_for(0.01);
        }
    }

    StatusBar::instance()
    ->showTip(1000, "%s %s",
              (m_type == Undo ? "Undid": "Redid"),
              (m_type == Undo ? undo->getNextUndoLabel():
               undo->getNextRedoLabel()));

    // Effectively undo/redo.
    if (m_type == Undo)
        undo->doUndo();
    else
        undo->doRedo();

    document->generateMaskBoundaries();
    document->destroyExtraCel(); // Regenerate extras

    update_screen_for_document(document);
    set_current_palette(writer.palette(), false);
}
コード例 #2
0
ファイル: cmd_undo.cpp プロジェクト: 4144/aseprite
void UndoCommand::onExecute(Context* context)
{
  ContextWriter writer(context);
  Document* document(writer.document());
  DocumentUndo* undo = document->undoHistory();
  Sprite* sprite = document->sprite();
  SpritePosition spritePosition;
  const bool gotoModified =
    Preferences::instance().undo.gotoModified();

  if (gotoModified) {
    SpritePosition currentPosition(writer.site()->layerIndex(),
                                   writer.site()->frame());

    if (m_type == Undo)
      spritePosition = undo->nextUndoSpritePosition();
    else
      spritePosition = undo->nextRedoSpritePosition();

    if (spritePosition != currentPosition) {
      current_editor->setLayer(sprite->indexToLayer(spritePosition.layerIndex()));
      current_editor->setFrame(spritePosition.frame());

      // Draw the current layer/frame (which is not undone yet) so the
      // user can see the doUndo/doRedo effect.
      current_editor->drawSpriteClipped(
        gfx::Region(gfx::Rect(0, 0, sprite->width(), sprite->height())));

      current_editor->manager()->flipDisplay();
      base::this_thread::sleep_for(0.01);
    }
  }

  StatusBar* statusbar = StatusBar::instance();
  if (statusbar)
    statusbar->showTip(1000, "%s %s",
      (m_type == Undo ? "Undid": "Redid"),
      (m_type == Undo ?
        undo->nextUndoLabel().c_str():
        undo->nextRedoLabel().c_str()));

  // Effectively undo/redo.
  if (m_type == Undo)
    undo->undo();
  else
    undo->redo();

  // After redo/undo, we retry to change the current SpritePosition
  // (because new frames/layers could be added, positions that we
  // weren't able to reach before the undo).
  if (gotoModified) {
    SpritePosition currentPosition(
      writer.site()->layerIndex(),
      writer.site()->frame());

    if (spritePosition != currentPosition) {
      current_editor->setLayer(sprite->indexToLayer(spritePosition.layerIndex()));
      current_editor->setFrame(spritePosition.frame());
    }
  }

  document->generateMaskBoundaries();
  document->setExtraCel(ExtraCelRef(nullptr));

  update_screen_for_document(document);
  set_current_palette(writer.palette(), false);
}
コード例 #3
0
ファイル: cmd_undo.cpp プロジェクト: aseprite/aseprite
void UndoCommand::onExecute(Context* context)
{
  ContextWriter writer(context);
  Doc* document(writer.document());
  DocUndo* undo = document->undoHistory();

#ifdef ENABLE_UI
  Sprite* sprite = document->sprite();
  SpritePosition spritePosition;
  const bool gotoModified =
    (Preferences::instance().undo.gotoModified() &&
     context->isUIAvailable() && current_editor);
  if (gotoModified) {
    SpritePosition currentPosition(writer.site()->layer(),
                                   writer.site()->frame());

    if (m_type == Undo)
      spritePosition = undo->nextUndoSpritePosition();
    else
      spritePosition = undo->nextRedoSpritePosition();

    if (spritePosition != currentPosition) {
      Layer* selectLayer = spritePosition.layer();
      if (selectLayer)
        current_editor->setLayer(selectLayer);
      current_editor->setFrame(spritePosition.frame());

      // Draw the current layer/frame (which is not undone yet) so the
      // user can see the doUndo/doRedo effect.
      current_editor->drawSpriteClipped(
        gfx::Region(gfx::Rect(0, 0, sprite->width(), sprite->height())));

      current_editor->manager()->flipDisplay();
      base::this_thread::sleep_for(0.01);
    }
  }

  // Get the stream to deserialize the document range after executing
  // the undo/redo action. We cannot yet deserialize the document
  // range because there could be inexistent layers.
  std::istream* docRangeStream;
  if (m_type == Undo)
    docRangeStream = undo->nextUndoDocRange();
  else
    docRangeStream = undo->nextRedoDocRange();

  StatusBar* statusbar = StatusBar::instance();
  if (statusbar) {
    std::string msg;
    if (m_type == Undo)
      msg = "Undid " + undo->nextUndoLabel();
    else
      msg = "Redid " + undo->nextRedoLabel();
    if (Preferences::instance().undo.showTooltip())
      statusbar->showTip(1000, msg.c_str());
    else
      statusbar->setStatusText(0, msg.c_str());
  }
#endif // ENABLE_UI

  // Effectively undo/redo.
  if (m_type == Undo)
    undo->undo();
  else
    undo->redo();

#ifdef ENABLE_UI
  // After redo/undo, we retry to change the current SpritePosition
  // (because new frames/layers could be added, positions that we
  // weren't able to reach before the undo).
  if (gotoModified) {
    Site newSite = context->activeSite();
    SpritePosition currentPosition(
      newSite.layer(),
      newSite.frame());

    if (spritePosition != currentPosition) {
      Layer* selectLayer = spritePosition.layer();
      if (selectLayer)
        current_editor->setLayer(selectLayer);
      current_editor->setFrame(spritePosition.frame());
    }
  }

  // Update timeline range. We've to deserialize the DocRange at
  // this point when objects (possible layers) are re-created after
  // the undo and we can deserialize them.
  if (docRangeStream) {
    Timeline* timeline = App::instance()->timeline();
    if (timeline) {
      DocRange docRange;
      if (docRange.read(*docRangeStream))
        timeline->setRange(docRange);
    }
  }
#endif  // ENABLE_UI

  document->generateMaskBoundaries();
  document->setExtraCel(ExtraCelRef(nullptr));

#ifdef ENABLE_UI
  update_screen_for_document(document);
#endif
  set_current_palette(writer.palette(), false);
}