Show real-time filter preview in all editors

Fix: https://community.aseprite.org/t/1649
This commit is contained in:
David Capello 2018-07-23 23:43:31 -03:00
parent 0abbc98343
commit 3c8220aa7d
8 changed files with 65 additions and 36 deletions

View File

@ -18,7 +18,6 @@
#include "app/context_access.h"
#include "app/doc.h"
#include "app/ini_file.h"
#include "app/modules/editors.h"
#include "app/modules/palettes.h"
#include "app/site.h"
#include "app/transaction.h"
@ -26,6 +25,7 @@
#include "app/ui/editor/editor.h"
#include "app/ui/palette_view.h"
#include "app/ui/timeline/timeline.h"
#include "app/ui_context.h"
#include "app/util/range_utils.h"
#include "doc/algorithm/shrink_bounds.h"
#include "doc/cel.h"
@ -136,20 +136,20 @@ void FilterManagerImpl::beginForPreview()
m_row = m_nextRowToFlush = 0;
m_mask = m_previewMask;
Editor* editor = current_editor;
// If we have a tiled mode enabled, we'll apply the filter to the whole areaes
if (editor->docPref().tiled.mode() == filters::TiledMode::NONE) {
Sprite* sprite = m_site.sprite();
gfx::Rect vp = View::getView(editor)->viewportBounds();
vp = editor->screenToEditor(vp);
vp = vp.createIntersection(sprite->bounds());
Editor* activeEditor = UIContext::instance()->activeEditor();
if (activeEditor->docPref().tiled.mode() == filters::TiledMode::NONE) {
gfx::Rect vp;
for (Editor* editor : UIContext::instance()->getAllEditorsIncludingPreview(document)) {
vp |= editor->screenToEditor(
View::getView(editor)->viewportBounds());
}
vp &= m_site.sprite()->bounds();
if (vp.isEmpty()) {
m_previewMask.reset(nullptr);
m_row = -1;
return;
}
m_previewMask->intersect(vp);
}
@ -336,41 +336,43 @@ void FilterManagerImpl::flush()
int h = m_row - m_nextRowToFlush;
if (m_row >= 0 && h > 0) {
Editor* editor = current_editor;
// Redraw the color palette
if (m_nextRowToFlush == 0 && paletteHasChanged())
redrawColorPalette();
// We expand the region one pixel at the top and bottom of the
// region [m_row,m_nextRowToFlush) to be updated on the screen to
// avoid screen artifacts when we apply filters like convolution
// matrices.
gfx::Rect rect(
editor->editorToScreen(
gfx::Point(
m_bounds.x,
m_bounds.y+m_nextRowToFlush-1)),
gfx::Size(
editor->projection().applyX(m_bounds.w),
(editor->projection().scaleY() >= 1 ? editor->projection().applyY(h+2):
editor->projection().removeY(h+2))));
for (Editor* editor : UIContext::instance()->getAllEditorsIncludingPreview(document())) {
// We expand the region one pixel at the top and bottom of the
// region [m_row,m_nextRowToFlush) to be updated on the screen to
// avoid screen artifacts when we apply filters like convolution
// matrices.
gfx::Rect rect(
editor->editorToScreen(
gfx::Point(
m_bounds.x,
m_bounds.y+m_nextRowToFlush-1)),
gfx::Size(
editor->projection().applyX(m_bounds.w),
(editor->projection().scaleY() >= 1 ? editor->projection().applyY(h+2):
editor->projection().removeY(h+2))));
gfx::Region reg1(rect);
editor->expandRegionByTiledMode(reg1, true);
gfx::Region reg1(rect);
editor->expandRegionByTiledMode(reg1, true);
gfx::Region reg2;
editor->getDrawableRegion(reg2, Widget::kCutTopWindows);
reg1.createIntersection(reg1, reg2);
gfx::Region reg2;
editor->getDrawableRegion(reg2, Widget::kCutTopWindows);
reg1.createIntersection(reg1, reg2);
editor->invalidateRegion(reg1);
}
editor->invalidateRegion(reg1);
m_nextRowToFlush = m_row+1;
}
}
void FilterManagerImpl::disablePreview()
{
current_editor->invalidate();
for (Editor* editor : UIContext::instance()->getAllEditorsIncludingPreview(document()))
editor->invalidate();
// Redraw the color bar in case the filter modified the palette.
if (paletteHasChanged()) {

View File

@ -21,6 +21,7 @@
#include <cstring>
#include <memory>
#include <vector>
namespace doc {
class Cel;
@ -35,9 +36,9 @@ namespace filters {
}
namespace app {
class Context;
class Doc;
class Editor;
class Transaction;
using namespace filters;

View File

@ -11,7 +11,6 @@
#include "app/commands/filters/filter_preview.h"
#include "app/commands/filters/filter_manager_impl.h"
#include "app/modules/editors.h"
#include "app/ui/editor/editor.h"
#include "app/ui/editor/editor_render.h"
#include "base/bind.h"
@ -44,7 +43,7 @@ FilterPreview::~FilterPreview()
void FilterPreview::setEnablePreview(bool state)
{
if (state) {
current_editor->renderEngine().setPreviewImage(
Editor::renderEngine().setPreviewImage(
m_filterMgr->layer(),
m_filterMgr->frame(),
m_filterMgr->destinationImage(),
@ -52,7 +51,7 @@ void FilterPreview::setEnablePreview(bool state)
static_cast<doc::LayerImage*>(m_filterMgr->layer())->blendMode());
}
else {
current_editor->renderEngine().removePreviewImage();
Editor::renderEngine().removePreviewImage();
}
}

View File

@ -257,7 +257,7 @@ namespace app {
// Gets the brush preview controller.
BrushPreview& brushPreview() { return m_brushPreview; }
EditorRender& renderEngine() { return *m_renderEngine; }
static EditorRender& renderEngine() { return *m_renderEngine; }
// IColorSource
app::Color getColorByPosition(const gfx::Point& pos) override;

View File

@ -333,6 +333,11 @@ void PreviewEditorWindow::onPopupSpeed()
m_aniSpeed = miniEditor->getAnimationSpeedMultiplier();
}
Editor* PreviewEditorWindow::previewEditor() const
{
return (m_docView ? m_docView->editor(): nullptr);
}
void PreviewEditorWindow::updateUsingEditor(Editor* editor)
{
if (!m_isEnabled || !editor) {

View File

@ -30,6 +30,7 @@ namespace app {
void pressPlayButton();
void updateUsingEditor(Editor* editor);
Editor* previewEditor() const;
Editor* relatedEditor() const { return m_relatedEditor; }
// EditorObserver impl

View File

@ -168,6 +168,25 @@ DocViews UIContext::getAllDocViews(Doc* document) const
return docViews;
}
Editors UIContext::getAllEditorsIncludingPreview(Doc* document) const
{
std::vector<Editor*> editors;
for (DocView* docView : getAllDocViews(document)) {
if (docView->editor())
editors.push_back(docView->editor());
}
if (MainWindow* mainWin = App::instance()->mainWindow()) {
PreviewEditorWindow* previewWin = mainWin->getPreviewEditor();
if (previewWin) {
Editor* miniEditor = previewWin->previewEditor();
if (miniEditor && miniEditor->document() == document)
editors.push_back(miniEditor);
}
}
return editors;
}
Editor* UIContext::activeEditor()
{
DocView* view = activeView();

View File

@ -16,6 +16,7 @@ namespace app {
class Editor;
typedef std::vector<DocView*> DocViews;
typedef std::vector<Editor*> Editors;
class UIContext : public app::Context {
public:
@ -31,6 +32,7 @@ namespace app {
DocView* getFirstDocView(Doc* document) const override;
DocViews getAllDocViews(Doc* document) const;
Editors getAllEditorsIncludingPreview(Doc* document) const;
// Returns the current editor. It can be null.
Editor* activeEditor();