Add ToolLoop::Button enum type to avoid hardcoded 0 and 1 values.

This commit is contained in:
David Capello 2011-08-22 13:46:09 -03:00
parent 728da7a59b
commit e090c966bf
4 changed files with 18 additions and 13 deletions

View File

@ -246,9 +246,9 @@ public:
if (m_modify_selection) {
Point offset = loop->getOffset();
if (loop->getMouseButton() == 0)
if (loop->getMouseButton() == ToolLoop::Left)
loop->getMask()->add(x1-offset.x, y-offset.y, x2-x1+1, 1);
else if (loop->getMouseButton() == 1)
else if (loop->getMouseButton() == ToolLoop::Right)
mask_subtract(loop->getMask(), x1-offset.x, y-offset.y, x2-x1+1, 1);
}
else

View File

@ -48,6 +48,8 @@ class Tool;
class ToolLoop
{
public:
enum Button { Left = 0, Right = 1 };
virtual ~ToolLoop() { }
// Returns the context where we want to draw on (generally UIContext::instance() singleton)
@ -83,11 +85,11 @@ public:
// Gets mask X,Y origin coordinates
virtual gfx::Point getMaskOrigin() = 0;
// Return the mouse button which start the tool-loop (0 = left
// button, 1 = right button). It can be used by some tools that
// instead of using the primary/secondary color uses the pressed
// button for different behavior (like selection tools)
virtual int getMouseButton() = 0;
// Return the mouse button which start the tool-loop. It can be used
// by some tools that instead of using the primary/secondary color
// uses the pressed button for different behavior (like selection
// tools).
virtual Button getMouseButton() = 0;
// Primary color to draw (e.g. foreground if the user start drawing
// with the left button, or background color if he used the right

View File

@ -73,8 +73,8 @@ void ToolLoopManager::releaseLoop(const Pointer& pointer)
void ToolLoopManager::pressButton(const Pointer& pointer)
{
// If the user pressed the other mouse button...
if ((m_toolLoop->getMouseButton() == 0 && pointer.getButton() == Pointer::Right) ||
(m_toolLoop->getMouseButton() == 1 && pointer.getButton() == Pointer::Left)) {
if ((m_toolLoop->getMouseButton() == ToolLoop::Left && pointer.getButton() == Pointer::Right) ||
(m_toolLoop->getMouseButton() == ToolLoop::Right && pointer.getButton() == Pointer::Left)) {
// Cancel the tool-loop (the destination image should be completelly discarded)
m_toolLoop->cancel();
return;

View File

@ -81,7 +81,7 @@ class ToolLoopImpl : public tools::ToolLoop
gfx::Point m_offset;
gfx::Point m_speed;
bool m_canceled;
int m_button;
tools::ToolLoop::Button m_button;
int m_primary_color;
int m_secondary_color;
@ -92,7 +92,9 @@ public:
Document* document,
Sprite* sprite,
Layer* layer,
int button, const Color& primary_color, const Color& secondary_color)
tools::ToolLoop::Button button,
const Color& primary_color,
const Color& secondary_color)
: m_editor(editor)
, m_context(context)
, m_tool(tool)
@ -348,7 +350,7 @@ public:
bool useMask() { return m_useMask; }
Mask* getMask() { return m_mask; }
gfx::Point getMaskOrigin() { return m_maskOrigin; }
int getMouseButton() { return m_button; }
ToolLoop::Button getMouseButton() { return m_button; }
int getPrimaryColor() { return m_primary_color; }
void setPrimaryColor(int color) { m_primary_color = color; }
int getSecondaryColor() { return m_secondary_color; }
@ -449,7 +451,8 @@ tools::ToolLoop* create_tool_loop(Editor* editor, Context* context, Message* msg
current_tool,
editor->getDocument(),
sprite, layer,
msg->mouse.left ? 0: 1,
msg->mouse.left ? tools::ToolLoop::Left:
tools::ToolLoop::Right,
msg->mouse.left ? fg: bg,
msg->mouse.left ? bg: fg);
}