diff --git a/src/app/context.cpp b/src/app/context.cpp index f15ff1222..7a818d5b9 100644 --- a/src/app/context.cpp +++ b/src/app/context.cpp @@ -1,5 +1,5 @@ /* Aseprite - * Copyright (C) 2001-2013 David Capello + * Copyright (C) 2001-2014 David Capello * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,6 +30,7 @@ #include "app/settings/settings.h" #include +#include namespace app { diff --git a/src/app/document.cpp b/src/app/document.cpp index 220edddf4..9ac0f9100 100644 --- a/src/app/document.cpp +++ b/src/app/document.cpp @@ -34,9 +34,9 @@ #include "base/mutex.h" #include "base/scoped_lock.h" #include "base/unique_ptr.h" +#include "doc/cel.h" #include "doc/document_event.h" #include "doc/document_observer.h" -#include "doc/cel.h" #include "doc/layer.h" #include "doc/mask.h" #include "doc/palette.h" @@ -139,6 +139,12 @@ void Document::notifyCelCopied(Layer* fromLayer, FrameNumber fromFrame, Layer* t notifyObservers(&doc::DocumentObserver::onCelCopied, ev); } +void Document::notifySelectionChanged() +{ + doc::DocumentEvent ev(this); + notifyObservers(&doc::DocumentObserver::onSelectionChanged, ev); +} + bool Document::isModified() const { return !m_undo->isSavedState(); @@ -210,6 +216,9 @@ void Document::generateMaskBoundaries(Mask* mask) m_bound.seg[c].y2 += mask->bounds().y; } } + + // TODO move this to the exact place where selection is modified. + notifySelectionChanged(); } ////////////////////////////////////////////////////////////////////// diff --git a/src/app/document.h b/src/app/document.h index ad3940ebc..7bd27f3ce 100644 --- a/src/app/document.h +++ b/src/app/document.h @@ -93,6 +93,7 @@ namespace app { void notifyLayerMergedDown(Layer* srcLayer, Layer* targetLayer); void notifyCelMoved(Layer* fromLayer, FrameNumber fromFrame, Layer* toLayer, FrameNumber toFrame); void notifyCelCopied(Layer* fromLayer, FrameNumber fromFrame, Layer* toLayer, FrameNumber toFrame); + void notifySelectionChanged(); ////////////////////////////////////////////////////////////////////// // File related properties diff --git a/src/app/document_exporter.cpp b/src/app/document_exporter.cpp index ca1a153d9..11ec84604 100644 --- a/src/app/document_exporter.cpp +++ b/src/app/document_exporter.cpp @@ -203,8 +203,8 @@ DocumentExporter::DocumentExporter() , m_textureWidth(0) , m_textureHeight(0) , m_texturePack(false) - , m_scaleMode(DefaultScaleMode) , m_scale(1.0) + , m_scaleMode(DefaultScaleMode) { } diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 2e1399895..b26720ab9 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -966,7 +966,8 @@ Rect Editor::getVisibleSpriteBounds() screenToEditor(vp.x, vp.y, &x1, &y1); screenToEditor(vp.x+vp.w-1, vp.y+vp.h-1, &x2, &y2); - return Rect(x1, y1, x2-x1+1, y2-y1+1); + return Rect(0, 0, m_sprite->width(), m_sprite->height()) + .createIntersect(Rect(x1, y1, x2-x1+1, y2-y1+1)); } // Changes the scroll to see the given point as the center of the editor. @@ -1361,10 +1362,6 @@ void Editor::pasteImage(const Image* image, int x, int y) // Check bounds where the image will be pasted. { - // First we limit the image inside the sprite's bounds. - x = MID(0, x, sprite->width() - image->width()); - y = MID(0, y, sprite->height() - image->height()); - // Then we check if the image will be visible by the user. Rect visibleBounds = getVisibleSpriteBounds(); x = MID(visibleBounds.x-image->width(), x, visibleBounds.x+visibleBounds.w-1); @@ -1381,6 +1378,10 @@ void Editor::pasteImage(const Image* image, int x, int y) x = visibleBounds.x + visibleBounds.w/2 - image->width()/2; y = visibleBounds.y + visibleBounds.h/2 - image->height()/2; } + + // We limit the image inside the sprite's bounds. + x = MID(0, x, sprite->width() - image->width()); + y = MID(0, y, sprite->height() - image->height()); } PixelsMovementPtr pixelsMovement( diff --git a/src/app/ui/timeline.cpp b/src/app/ui/timeline.cpp index af56898b1..087dbe72c 100644 --- a/src/app/ui/timeline.cpp +++ b/src/app/ui/timeline.cpp @@ -967,6 +967,14 @@ void Timeline::onRemoveFrame(doc::DocumentEvent& ev) invalidate(); } +void Timeline::onSelectionChanged(doc::DocumentEvent& ev) +{ + m_range.disableRange(); + + clearClipboardRange(); + invalidate(); +} + void Timeline::onAfterFrameChanged(Editor* editor) { setFrame(editor->frame()); diff --git a/src/app/ui/timeline.h b/src/app/ui/timeline.h index 9cbfccab3..839a85d24 100644 --- a/src/app/ui/timeline.h +++ b/src/app/ui/timeline.h @@ -108,6 +108,7 @@ namespace app { void onAfterRemoveLayer(doc::DocumentEvent& ev) override; void onAddFrame(doc::DocumentEvent& ev) override; void onRemoveFrame(doc::DocumentEvent& ev) override; + void onSelectionChanged(doc::DocumentEvent& ev) override; // app::Context slots. void onAfterCommandExecution(Command* command); diff --git a/src/doc/document_observer.h b/src/doc/document_observer.h index 8b3d0aa4b..fb60b2ff4 100644 --- a/src/doc/document_observer.h +++ b/src/doc/document_observer.h @@ -55,6 +55,9 @@ namespace doc { // When the number of total frames available is modified. virtual void onTotalFramesChanged(DocumentEvent& ev) { } + // The selection has changed. + virtual void onSelectionChanged(DocumentEvent& ev) { } + // Called to destroy the observable. (Here you could call "delete this".) virtual void dispose() { } };