Add xor-ed bounding box in SelectBoxState when QUICKBOX style is enabled

This is useful when we want to select a brush in a black image (the
DARKOUTSIDE style is not useful in this case).
This commit is contained in:
David Capello 2015-04-27 12:03:18 -03:00
parent 96769d061e
commit 955383f91a
7 changed files with 27 additions and 8 deletions

View File

@ -99,17 +99,14 @@ class EditorPostRenderImpl : public EditorPostRender {
public:
EditorPostRenderImpl(Editor* editor, Graphics* g)
: m_editor(editor)
, m_g(g)
{
, m_g(g) {
}
Editor* getEditor()
{
Editor* getEditor() {
return m_editor;
}
void drawLine(int x1, int y1, int x2, int y2, gfx::Color screenColor)
{
void drawLine(int x1, int y1, int x2, int y2, gfx::Color screenColor) override {
gfx::Point a(x1, y1);
gfx::Point b(x2, y2);
a = m_editor->editorToScreen(a);
@ -122,6 +119,17 @@ public:
m_g->drawLine(screenColor, a, b);
}
void drawRectXor(const gfx::Rect& rc) override {
gfx::Rect rc2 = m_editor->editorToScreen(rc);
gfx::Rect bounds = m_editor->getBounds();
rc2.x -= bounds.x;
rc2.y -= bounds.y;
m_g->setDrawMode(Graphics::DrawMode::Xor);
m_g->drawRect(gfx::rgba(255, 255, 255), rc2);
m_g->setDrawMode(Graphics::DrawMode::Solid);
}
private:
Editor* m_editor;
Graphics* m_g;

View File

@ -38,6 +38,7 @@ namespace app {
virtual ~EditorPostRender() { }
virtual Editor* getEditor() = 0;
virtual void drawLine(int x1, int y1, int x2, int y2, gfx::Color screenColor) = 0;
virtual void drawRectXor(const gfx::Rect& rc) = 0;
};
// Used by editor's states to pre- and post-render customized

View File

@ -263,6 +263,10 @@ void SelectBoxState::postRenderDecorator(EditorPostRender* render)
}
}
}
if (hasFlag(QUICKBOX)) {
render->drawRectXor(getBoxBounds());
}
}
bool SelectBoxState::touchRuler(Editor* editor, Ruler& ruler, int x, int y)

View File

@ -161,6 +161,7 @@ namespace she {
void setDrawMode(DrawMode mode, int param) {
switch (mode) {
case DrawMode::Solid: checked_mode(-1); break;
case DrawMode::Xor: xor_mode(TRUE); break;
case DrawMode::Checked: checked_mode(param); break;
}
}

View File

@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2012-2013 David Capello
// Copyright (C) 2012-2013, 2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -16,7 +16,8 @@ namespace she {
enum class DrawMode {
Solid,
Checked
Checked,
Xor
};
class Surface {

View File

@ -67,6 +67,9 @@ void Graphics::setDrawMode(DrawMode mode, int param)
case DrawMode::Solid:
m_surface->setDrawMode(she::DrawMode::Solid);
break;
case DrawMode::Xor:
m_surface->setDrawMode(she::DrawMode::Xor);
break;
case DrawMode::Checked:
m_surface->setDrawMode(she::DrawMode::Checked, param);
break;

View File

@ -33,6 +33,7 @@ namespace ui {
public:
enum class DrawMode {
Solid,
Xor,
Checked,
};