Move EditorPreRender code to EditorPostRender

This simplify Editor::drawOneSpriteUnclippedRect() impl to create an
alternative version of the renderer in the future.
This commit is contained in:
David Capello 2018-06-21 12:58:11 -03:00
parent c3e233f34d
commit e06735a4c0
6 changed files with 63 additions and 120 deletions

View File

@ -77,42 +77,6 @@ using namespace render;
static base::Chrono renderChrono; static base::Chrono renderChrono;
static double renderElapsed = 0.0; static double renderElapsed = 0.0;
class EditorPreRenderImpl : public EditorPreRender {
public:
EditorPreRenderImpl(Editor* editor, Image* image,
const Point& offset,
const Projection& proj)
: m_editor(editor)
, m_image(image)
, m_offset(offset)
, m_proj(proj) {
}
Editor* getEditor() override {
return m_editor;
}
Image* getImage() override {
return m_image;
}
void fillRect(const gfx::Rect& rect, uint32_t rgbaColor, int opacity) override
{
blend_rect(
m_image,
m_offset.x + m_proj.applyX(rect.x),
m_offset.y + m_proj.applyY(rect.y),
m_offset.x + m_proj.applyX(rect.x+rect.w) - 1,
m_offset.y + m_proj.applyY(rect.y+rect.h) - 1, rgbaColor, opacity);
}
private:
Editor* m_editor;
Image* m_image;
Point m_offset;
Projection m_proj;
};
class EditorPostRenderImpl : public EditorPostRender { class EditorPostRenderImpl : public EditorPostRender {
public: public:
EditorPostRenderImpl(Editor* editor, Graphics* g) EditorPostRenderImpl(Editor* editor, Graphics* g)
@ -124,7 +88,7 @@ public:
return m_editor; return m_editor;
} }
void drawLine(int x1, int y1, int x2, int y2, gfx::Color screenColor) override { void drawLine(gfx::Color color, int x1, int y1, int x2, int y2) override {
gfx::Point a(x1, y1); gfx::Point a(x1, y1);
gfx::Point b(x2, y2); gfx::Point b(x2, y2);
a = m_editor->editorToScreen(a); a = m_editor->editorToScreen(a);
@ -134,7 +98,7 @@ public:
a.y -= bounds.y; a.y -= bounds.y;
b.x -= bounds.x; b.x -= bounds.x;
b.y -= bounds.y; b.y -= bounds.y;
m_g->drawLine(screenColor, a, b); m_g->drawLine(color, a, b);
} }
void drawRectXor(const gfx::Rect& rc) override { void drawRectXor(const gfx::Rect& rc) override {
@ -148,6 +112,14 @@ public:
m_g->setDrawMode(Graphics::DrawMode::Solid); m_g->setDrawMode(Graphics::DrawMode::Solid);
} }
void fillRect(gfx::Color color, const gfx::Rect& rc) override {
gfx::Rect rc2 = m_editor->editorToScreen(rc);
gfx::Rect bounds = m_editor->bounds();
rc2.x -= bounds.x;
rc2.y -= bounds.y;
m_g->fillRect(color, rc2);
}
private: private:
Editor* m_editor; Editor* m_editor;
Graphics* m_g; Graphics* m_g;
@ -629,13 +601,6 @@ void Editor::drawOneSpriteUnclippedRect(ui::Graphics* g, const gfx::Rect& sprite
} }
if (rendered) { if (rendered) {
// Pre-render decorator.
if ((m_flags & kShowDecorators) && m_decorator) {
EditorPreRenderImpl preRender(this, rendered,
Point(-rc.x, -rc.y), m_proj);
m_decorator->preRenderDecorator(&preRender);
}
// Convert the render to a she::Surface // Convert the render to a she::Surface
static she::Surface* tmp; static she::Surface* tmp;
if (!tmp || tmp->width() < rc.w || tmp->height() < rc.h) { if (!tmp || tmp->width() < rc.w || tmp->height() < rc.h) {

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2015 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -19,29 +19,26 @@ namespace doc {
class Image; class Image;
} }
namespace ui {
class Graphics;
}
namespace app { namespace app {
class Editor; class Editor;
class EditorDecorator; class EditorDecorator;
using namespace doc; using namespace doc;
// EditorPreRender and EditorPostRender are two interfaces used to // EditorPostRender is an interface used to draw elements in the
// draw elements in the editor's area. They are implemented by the // editor's area. It's implemented by the editor and used by a
// editor and used by a EditorDecorator. // EditorDecorator.
class EditorPreRender {
public:
virtual ~EditorPreRender() { }
virtual Editor* getEditor() = 0;
virtual Image* getImage() = 0;
virtual void fillRect(const gfx::Rect& rect, uint32_t rgbaColor, int opacity) = 0;
};
class EditorPostRender { class EditorPostRender {
public: public:
virtual ~EditorPostRender() { } virtual ~EditorPostRender() { }
virtual Editor* getEditor() = 0; virtual Editor* getEditor() = 0;
virtual void drawLine(int x1, int y1, int x2, int y2, gfx::Color screenColor) = 0; virtual void drawLine(gfx::Color color, int x1, int y1, int x2, int y2) = 0;
virtual void drawRectXor(const gfx::Rect& rc) = 0; virtual void drawRectXor(const gfx::Rect& rc) = 0;
virtual void fillRect(gfx::Color color, const gfx::Rect& rc) = 0;
}; };
// Used by editor's states to pre- and post-render customized // Used by editor's states to pre- and post-render customized
@ -50,7 +47,6 @@ namespace app {
class EditorDecorator { class EditorDecorator {
public: public:
virtual ~EditorDecorator() { } virtual ~EditorDecorator() { }
virtual void preRenderDecorator(EditorPreRender* render) = 0;
virtual void postRenderDecorator(EditorPostRender* render) = 0; virtual void postRenderDecorator(EditorPostRender* render) = 0;
virtual void getInvalidDecoratoredRegion(Editor* editor, gfx::Region& region) = 0; virtual void getInvalidDecoratoredRegion(Editor* editor, gfx::Region& region) = 0;
}; };

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -223,34 +223,6 @@ tools::Ink* SelectBoxState::getStateInk()
return nullptr; return nullptr;
} }
void SelectBoxState::preRenderDecorator(EditorPreRender* render)
{
// Without black shadow?
if (!hasFlag(Flags::DarkOutside))
return;
gfx::Rect rc = getBoxBounds();
Sprite* sprite = render->getEditor()->sprite();
int sprite_w = sprite->width();
int sprite_h = sprite->height();
// Top band
if (rc.y > 0)
render->fillRect(gfx::Rect(0, 0, sprite_w, rc.y), doc::rgba(0, 0, 0, 255), 128);
// Bottom band
if (rc.y+rc.h < sprite_h)
render->fillRect(gfx::Rect(0, rc.y+rc.h, sprite_w, sprite_h-(rc.y+rc.h)), doc::rgba(0, 0, 0, 255), 128);
// Left band
if (rc.x > 0)
render->fillRect(gfx::Rect(0, rc.y, rc.x, rc.h), doc::rgba(0, 0, 0, 255), 128);
// Right band
if (rc.x+rc.w < sprite_w)
render->fillRect(gfx::Rect(rc.x+rc.w, rc.y, sprite_w-(rc.x+rc.w), rc.h), doc::rgba(0, 0, 0, 255), 128);
}
void SelectBoxState::postRenderDecorator(EditorPostRender* render) void SelectBoxState::postRenderDecorator(EditorPostRender* render)
{ {
Editor* editor = render->getEditor(); Editor* editor = render->getEditor();
@ -262,51 +234,68 @@ void SelectBoxState::postRenderDecorator(EditorPostRender* render)
vp = editor->screenToEditor(vp); vp = editor->screenToEditor(vp);
// Paint a grid generated by the box // Paint a grid generated by the box
gfx::Color rulerColor = skin::SkinTheme::instance()->colors.selectBoxRuler(); const gfx::Color rulerColor = skin::SkinTheme::instance()->colors.selectBoxRuler();
gfx::Color gridColor = skin::SkinTheme::instance()->colors.selectBoxGrid(); const gfx::Color gridColor = skin::SkinTheme::instance()->colors.selectBoxGrid();
gfx::Point mainOffset = editor->mainTilePosition(); const gfx::Point mainOffset = editor->mainTilePosition();
gfx::Rect boxBounds = getBoxBounds(); gfx::Rect rc = getBoxBounds();
boxBounds.offset(mainOffset); rc.offset(mainOffset);
sp.offset(mainOffset); sp.offset(mainOffset);
// With black shadow?
if (hasFlag(Flags::DarkOutside)) {
const gfx::Color dark = doc::rgba(0, 0, 0, 128);
// Top band
if (rc.y > vp.y)
render->fillRect(dark, gfx::Rect(vp.x, vp.y, vp.w, rc.y-vp.y));
// Bottom band
if (rc.y2() < vp.y2())
render->fillRect(dark, gfx::Rect(vp.x, rc.y2(), vp.w, vp.y2()-rc.y2()));
// Left band
if (rc.x > vp.x)
render->fillRect(dark, gfx::Rect(vp.x, rc.y, rc.x-vp.x, rc.h));
// Right band
if (rc.x2() < vp.x2())
render->fillRect(dark, gfx::Rect(rc.x2(), rc.y, vp.x2()-rc.x2(), rc.h));
}
if (hasFlag(Flags::Grid)) { if (hasFlag(Flags::Grid)) {
if (boxBounds.w > 0) { if (rc.w > 0) {
for (int x=boxBounds.x+boxBounds.w*2; x<=sp.x+sp.w; x+=boxBounds.w) for (int x=rc.x+rc.w*2; x<=sp.x+sp.w; x+=rc.w)
render->drawLine(x, boxBounds.y, x, sp.y+sp.h, gridColor); render->drawLine(gridColor, x, rc.y, x, sp.y+sp.h);
} }
if (boxBounds.h > 0) { if (rc.h > 0) {
for (int y=boxBounds.y+boxBounds.h*2; y<=sp.y+sp.h; y+=boxBounds.h) for (int y=rc.y+rc.h*2; y<=sp.y+sp.h; y+=rc.h)
render->drawLine(boxBounds.x, y, sp.x+sp.w, y, gridColor); render->drawLine(gridColor, rc.x, y, sp.x+sp.w, y);
} }
} }
else if (hasFlag(Flags::HGrid)) { else if (hasFlag(Flags::HGrid)) {
if (boxBounds.w > 0) { if (rc.w > 0) {
for (int x=boxBounds.x+boxBounds.w*2; x<=sp.x+sp.w; x+=boxBounds.w) for (int x=rc.x+rc.w*2; x<=sp.x+sp.w; x+=rc.w)
render->drawLine(x, boxBounds.y, x, boxBounds.y+boxBounds.h, gridColor); render->drawLine(gridColor, x, rc.y, x, rc.y+rc.h);
} }
} }
else if (hasFlag(Flags::VGrid)) { else if (hasFlag(Flags::VGrid)) {
if (boxBounds.h > 0) { if (rc.h > 0) {
for (int y=boxBounds.y+boxBounds.h*2; y<=sp.y+sp.h; y+=boxBounds.h) for (int y=rc.y+rc.h*2; y<=sp.y+sp.h; y+=rc.h)
render->drawLine(boxBounds.x, y, boxBounds.x+boxBounds.w, y, gridColor); render->drawLine(gridColor, rc.x, y, rc.x+rc.w, y);
} }
} }
// Draw the rulers enclosing the box // Draw the rulers enclosing the box
if (hasFlag(Flags::Rulers)) { if (hasFlag(Flags::Rulers)) {
for (Rulers::iterator it = m_rulers.begin(), end = m_rulers.end(); it != end; ++it) { for (const Ruler& ruler : m_rulers) {
switch (it->orientation()) { switch (ruler.orientation()) {
case Ruler::Horizontal: { case Ruler::Horizontal: {
const int y = it->position()+mainOffset.y; const int y = ruler.position()+mainOffset.y;
render->drawLine(vp.x, y, vp.x+vp.w-1, y, rulerColor); render->drawLine(rulerColor, vp.x, y, vp.x+vp.w-1, y);
break; break;
} }
case Ruler::Vertical: { case Ruler::Vertical: {
const int x = it->position()+mainOffset.x; const int x = ruler.position()+mainOffset.x;
render->drawLine(x, vp.y, x, vp.y+vp.h-1, rulerColor); render->drawLine(rulerColor, x, vp.y, x, vp.y+vp.h-1);
break; break;
} }
} }
@ -314,7 +303,7 @@ void SelectBoxState::postRenderDecorator(EditorPostRender* render)
} }
if (hasFlag(Flags::QuickBox)) { if (hasFlag(Flags::QuickBox)) {
render->drawRectXor(boxBounds); render->drawRectXor(rc);
} }
} }

View File

@ -1,5 +1,5 @@
// Aseprite // Aseprite
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This program is distributed under the terms of // This program is distributed under the terms of
// the End-User License Agreement for Aseprite. // the End-User License Agreement for Aseprite.
@ -84,7 +84,6 @@ namespace app {
virtual tools::Ink* getStateInk() override; virtual tools::Ink* getStateInk() override;
// EditorDecorator overrides // EditorDecorator overrides
virtual void preRenderDecorator(EditorPreRender* render) override;
virtual void postRenderDecorator(EditorPostRender* render) override; virtual void postRenderDecorator(EditorPostRender* render) override;
virtual void getInvalidDecoratoredRegion(Editor* editor, gfx::Region& region) override; virtual void getInvalidDecoratoredRegion(Editor* editor, gfx::Region& region) override;

View File

@ -935,11 +935,6 @@ bool StandbyState::Decorator::onSetCursor(tools::Ink* ink, Editor* editor, const
return false; return false;
} }
void StandbyState::Decorator::preRenderDecorator(EditorPreRender* render)
{
// Do nothing
}
void StandbyState::Decorator::postRenderDecorator(EditorPostRender* render) void StandbyState::Decorator::postRenderDecorator(EditorPostRender* render)
{ {
Editor* editor = render->getEditor(); Editor* editor = render->getEditor();

View File

@ -71,7 +71,6 @@ namespace app {
bool onSetCursor(tools::Ink* ink, Editor* editor, const gfx::Point& mouseScreenPos); bool onSetCursor(tools::Ink* ink, Editor* editor, const gfx::Point& mouseScreenPos);
// EditorDecorator overrides // EditorDecorator overrides
void preRenderDecorator(EditorPreRender* render) override;
void postRenderDecorator(EditorPostRender* render) override; void postRenderDecorator(EditorPostRender* render) override;
void getInvalidDecoratoredRegion(Editor* editor, gfx::Region& region) override; void getInvalidDecoratoredRegion(Editor* editor, gfx::Region& region) override;