Skip to content

Commit

Permalink
Show all frame tags again in some special cases
Browse files Browse the repository at this point in the history
When we add/remove frame tags or change the active document we have to show all tags again. Related to #920
  • Loading branch information
dacap committed Mar 30, 2017
1 parent 04a3729 commit 9d2e542
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
27 changes: 26 additions & 1 deletion src/app/cmd/add_frame_tag.cpp
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2016 David Capello
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
Expand All @@ -10,6 +10,8 @@

#include "app/cmd/add_frame_tag.h"

#include "doc/document.h"
#include "doc/document_event.h"
#include "doc/frame_tag.h"
#include "doc/frame_tag_io.h"
#include "doc/sprite.h"
Expand All @@ -33,6 +35,13 @@ void AddFrameTag::onExecute()

sprite->frameTags().add(frameTag);
sprite->incrementVersion();

// Notify observers about the new frame.
Document* doc = sprite->document();
DocumentEvent ev(doc);
ev.sprite(sprite);
ev.frameTag(frameTag);
doc->notify_observers<DocumentEvent&>(&DocumentObserver::onAddFrameTag, ev);
}

void AddFrameTag::onUndo()
Expand All @@ -42,6 +51,15 @@ void AddFrameTag::onUndo()
write_frame_tag(m_stream, frameTag);
m_size = size_t(m_stream.tellp());

// Notify observers about the new frame.
{
Document* doc = sprite->document();
DocumentEvent ev(doc);
ev.sprite(sprite);
ev.frameTag(frameTag);
doc->notify_observers<DocumentEvent&>(&DocumentObserver::onRemoveFrameTag, ev);
}

sprite->frameTags().remove(frameTag);
sprite->incrementVersion();
delete frameTag;
Expand All @@ -58,6 +76,13 @@ void AddFrameTag::onRedo()
m_stream.str(std::string());
m_stream.clear();
m_size = 0;

// Notify observers about the new frame.
Document* doc = sprite->document();
DocumentEvent ev(doc);
ev.sprite(sprite);
ev.frameTag(frameTag);
doc->notify_observers<DocumentEvent&>(&DocumentObserver::onAddFrameTag, ev);
}

} // namespace cmd
Expand Down
19 changes: 19 additions & 0 deletions src/app/ui/timeline/timeline.cpp
Expand Up @@ -211,8 +211,13 @@ void Timeline::onThumbnailsPrefChange()

void Timeline::updateUsingEditor(Editor* editor)
{
// TODO if editor == m_editor, avoid doing a lot of extra work here

m_aniControls.updateUsingEditor(editor);

if (editor != m_editor)
m_tagFocusBand = -1;

detachDocument();

if (m_range.enabled()) {
Expand Down Expand Up @@ -1439,6 +1444,20 @@ void Timeline::onLayerNameChange(doc::DocumentEvent& ev)
invalidate();
}

void Timeline::onAddFrameTag(DocumentEvent& ev)
{
if (m_tagFocusBand >= 0) {
m_tagFocusBand = -1;
regenerateLayers();
layout();
}
}

void Timeline::onRemoveFrameTag(DocumentEvent& ev)
{
onAddFrameTag(ev);
}

void Timeline::onStateChanged(Editor* editor)
{
m_aniControls.updateUsingEditor(editor);
Expand Down
2 changes: 2 additions & 0 deletions src/app/ui/timeline/timeline.h
Expand Up @@ -126,6 +126,8 @@ namespace app {
void onRemoveFrame(doc::DocumentEvent& ev) override;
void onSelectionChanged(doc::DocumentEvent& ev) override;
void onLayerNameChange(doc::DocumentEvent& ev) override;
void onAddFrameTag(DocumentEvent& ev) override;
void onRemoveFrameTag(DocumentEvent& ev) override;

// app::Context slots.
void onAfterCommandExecution(CommandExecutionEvent& ev);
Expand Down
6 changes: 5 additions & 1 deletion src/doc/document_event.h
@@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2001-2014 David Capello
// Copyright (c) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -13,6 +13,7 @@

namespace doc {
class Cel;
class FrameTag;
class Image;
class Layer;
class LayerImage;
Expand Down Expand Up @@ -46,6 +47,7 @@ namespace doc {
Image* image() const { return m_image; }
int imageIndex() const { return m_imageIndex; }
frame_t frame() const { return m_frame; }
FrameTag* frameTag() const { return m_frameTag; }
const gfx::Region& region() const { return m_region; }

void sprite(Sprite* sprite) { m_sprite = sprite; }
Expand All @@ -54,6 +56,7 @@ namespace doc {
void image(Image* image) { m_image = image; }
void imageIndex(int imageIndex) { m_imageIndex = imageIndex; }
void frame(frame_t frame) { m_frame = frame; }
void frameTag(FrameTag* frameTag) { m_frameTag = frameTag; }
void region(const gfx::Region& rgn) { m_region = rgn; }

// Destination of the operation.
Expand All @@ -71,6 +74,7 @@ namespace doc {
Image* m_image;
int m_imageIndex;
frame_t m_frame;
FrameTag* m_frameTag;
gfx::Region m_region;

// For copy/move commands, the m_layer/m_frame are source of the
Expand Down
5 changes: 3 additions & 2 deletions src/doc/document_observer.h
@@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2001-2016 David Capello
// Copyright (c) 2001-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -27,14 +27,15 @@ namespace doc {
virtual void onAddLayer(DocumentEvent& ev) { }
virtual void onAddFrame(DocumentEvent& ev) { }
virtual void onAddCel(DocumentEvent& ev) { }
virtual void onAddFrameTag(DocumentEvent& ev) { }

virtual void onBeforeRemoveLayer(DocumentEvent& ev) { }
virtual void onAfterRemoveLayer(DocumentEvent& ev) { }

// Called when a frame is removed. It's called after the frame was
// removed, and the sprite's total number of frames is modified.
virtual void onRemoveFrame(DocumentEvent& ev) { }

virtual void onRemoveFrameTag(DocumentEvent& ev) { }
virtual void onRemoveCel(DocumentEvent& ev) { }

virtual void onSpriteSizeChanged(DocumentEvent& ev) { }
Expand Down

0 comments on commit 9d2e542

Please sign in to comment.