Пример #1
0
  frame_t onGetFrame(Editor* editor) override {
    frame_t frame = editor->frame();
    FrameTag* tag = editor
      ->getCustomizationDelegate()
      ->getFrameTagProvider()
      ->getFrameTagByFrame(frame, false);
    frame_t first = (tag ? tag->fromFrame(): 0);
    frame_t last = (tag ? tag->toFrame(): editor->sprite()->lastFrame());

    return (frame < last ? frame+1: first);
  }
void FrameTagPropertiesCommand::onExecute(Context* context)
{
  const ContextReader reader(context);
  const Sprite* sprite = reader.sprite();
  frame_t frame = reader.frame();
  const FrameTag* foundTag = nullptr;

  if (!m_tagName.empty())
    foundTag = sprite->frameTags().getByName(m_tagName);
  else if (m_tagId != NullId)
    foundTag = sprite->frameTags().getById(m_tagId);
  else
    foundTag = sprite->frameTags().innerTag(frame);

  if (!foundTag)
    return;

  FrameTagWindow window(sprite, foundTag);
  if (!window.show())
    return;

  ContextWriter writer(reader);
  Transaction transaction(writer.context(), "Change Frame Tag Properties");
  FrameTag* tag = const_cast<FrameTag*>(foundTag);

  std::string name = window.nameValue();
  if (tag->name() != name)
    transaction.execute(new cmd::SetFrameTagName(tag, name));

  doc::frame_t from, to;
  window.rangeValue(from, to);
  if (tag->fromFrame() != from ||
      tag->toFrame() != to) {
    transaction.execute(new cmd::SetFrameTagRange(tag, from, to));
  }

  doc::color_t docColor = window.colorValue();
  if (tag->color() != docColor)
    transaction.execute(new cmd::SetFrameTagColor(tag, docColor));

  doc::AniDir anidir = window.aniDirValue();
  if (tag->aniDir() != anidir)
    transaction.execute(new cmd::SetFrameTagAniDir(tag, anidir));

  transaction.commit();
}