Receive a ui::Graphics in TransformHandles::drawHandles()

Instead of using a ScreenGraphics.
This commit is contained in:
David Capello 2020-07-21 16:39:51 -03:00
parent 06bf7eca2c
commit ce06b55894
5 changed files with 29 additions and 15 deletions

View File

@ -93,6 +93,10 @@ public:
return m_editor;
}
Graphics* getGraphics() override {
return m_g;
}
void drawLine(gfx::Color color, int x1, int y1, int x2, int y2) override {
gfx::Point a(x1, y1);
gfx::Point b(x2, y2);

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -36,6 +37,7 @@ namespace app {
public:
virtual ~EditorPostRender() { }
virtual Editor* getEditor() = 0;
virtual ui::Graphics* getGraphics() = 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 fillRect(gfx::Color color, const gfx::Rect& rc) = 0;

View File

@ -990,8 +990,9 @@ void StandbyState::Decorator::postRenderDecorator(EditorPostRender* render)
tools::Ink* ink = editor->getCurrentEditorInk();
if (ink->isSelection()) {
getTransformHandles(editor)->drawHandles(editor,
m_standbyState->getTransformation(editor));
getTransformHandles(editor)
->drawHandles(editor, render->getGraphics(),
m_standbyState->getTransformation(editor));
m_standbyState->m_transformSelectionHandlesAreVisible = true;
}

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -84,9 +85,9 @@ HandleType TransformHandles::getHandleAtPoint(Editor* editor, const gfx::Point&
return NoHandle;
}
void TransformHandles::drawHandles(Editor* editor, const Transformation& transform)
void TransformHandles::drawHandles(Editor* editor, ui::Graphics* g,
const Transformation& transform)
{
ScreenGraphics g;
fixmath::fixed angle = fixmath::ftofix(128.0 * transform.angle() / PI);
Transformation::Corners corners;
@ -95,29 +96,31 @@ void TransformHandles::drawHandles(Editor* editor, const Transformation& transfo
std::vector<gfx::Point> screenPoints;
getScreenPoints(editor, corners, screenPoints);
// TODO DO NOT COMMIT
const gfx::Point origin = editor->bounds().origin();
#if 0 // Uncomment this if you want to see the bounds in red (only for debugging purposes)
// -----------------------------------------------
{
gfx::Point
a(transform.bounds().origin()),
b(transform.bounds().point2());
a = editor->editorToScreen(a);
b = editor->editorToScreen(b);
g.drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a, b));
a = editor->editorToScreen(a) - origin;
b = editor->editorToScreen(b) - origin;
g->drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a, b));
a = transform.pivot();
a = editor->editorToScreen(a);
g.drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a.x-2, a.y-2, 5, 5));
a = editor->editorToScreen(a) - origin;
g->drawRect(gfx::rgba(255, 0, 0), gfx::Rect(a.x-2, a.y-2, 5, 5));
}
// -----------------------------------------------
#endif
// Draw corner handle
for (size_t c=0; c<HANDLES; ++c) {
drawHandle(&g,
(screenPoints[handles_info[c].i1].x+screenPoints[handles_info[c].i2].x)/2,
(screenPoints[handles_info[c].i1].y+screenPoints[handles_info[c].i2].y)/2,
drawHandle(
g,
(screenPoints[handles_info[c].i1].x+screenPoints[handles_info[c].i2].x)/2 - origin.x,
(screenPoints[handles_info[c].i1].y+screenPoints[handles_info[c].i2].y)/2 - origin.y,
angle + handles_info[c].angle);
}
@ -127,7 +130,9 @@ void TransformHandles::drawHandles(Editor* editor, const Transformation& transfo
SkinTheme* theme = SkinTheme::instance();
os::Surface* part = theme->parts.pivotHandle()->bitmap(0);
g.drawRgbaSurface(part, pivotBounds.x, pivotBounds.y);
g->drawRgbaSurface(part,
pivotBounds.x - origin.x,
pivotBounds.y - origin.y);
}
}

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -30,7 +31,8 @@ namespace app {
// has applied the given transformation to the selection.
HandleType getHandleAtPoint(Editor* editor, const gfx::Point& pt, const Transformation& transform);
void drawHandles(Editor* editor, const Transformation& transform);
void drawHandles(Editor* editor, ui::Graphics* g,
const Transformation& transform);
void invalidateHandles(Editor* editor, const Transformation& transform);
private: