Skip to content

Commit

Permalink
fix being able to change between box/line/flood fill while drawing (b…
Browse files Browse the repository at this point in the history
…y releasing keys), a bunch of other extremely obscure fixes
  • Loading branch information
jacob1 committed Sep 23, 2015
1 parent 13a71b6 commit a81a41b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
27 changes: 13 additions & 14 deletions src/gui/game/GameView.cpp
Expand Up @@ -482,6 +482,9 @@ class GameView::MenuAction: public ui::ButtonAction
}
void MouseEnterCallback(ui::Button * sender)
{
// don't immediately change the active menu, the actual set is done inside GameView::OnMouseMove
// if we change it here it causes components to be removed, which causes the window to stop sending events
// and then the previous menusection button never gets sent the OnMouseLeave event and is never unhighlighted
if(!needsClick && !v->GetMouseDown())
v->SetActiveMenuDelayed(menuID);
}
Expand Down Expand Up @@ -1083,6 +1086,7 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)
}
mouseInZoom = newMouseInZoom;

// set active menu (delayed)
if (delayedActiveMenu)
{
c->SetActiveMenu(delayedActiveMenu);
Expand All @@ -1092,7 +1096,7 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)

void GameView::OnMouseDown(int x, int y, unsigned button)
{
ui::Point mouseDownPoint = ui::Point(x, y);
currentMouse = ui::Point(x, y);
if (altBehaviour && !shiftBehaviour && !ctrlBehaviour)
button = BUTTON_MIDDLE;
if (!(zoomEnabled && !zoomCursorFixed))
Expand All @@ -1101,12 +1105,12 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
{
if (button == BUTTON_LEFT && selectPoint1.X == -1)
{
selectPoint1 = c->PointTranslate(mouseDownPoint);
selectPoint1 = c->PointTranslate(currentMouse);
selectPoint2 = selectPoint1;
}
return;
}
if (mouseDownPoint.X >= 0 && mouseDownPoint.X < XRES && mouseDownPoint.Y >= 0 && mouseDownPoint.Y < YRES)
if (currentMouse.X >= 0 && currentMouse.X < XRES && currentMouse.Y >= 0 && currentMouse.Y < YRES)
{
if (button == BUTTON_LEFT)
toolIndex = 0;
Expand All @@ -1118,11 +1122,11 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
c->HistorySnapshot();
if (drawMode == DrawRect || drawMode == DrawLine)
{
drawPoint1 = c->PointTranslate(mouseDownPoint);
drawPoint1 = c->PointTranslate(currentMouse);
}
if (drawMode == DrawPoints)
{
lastPoint = currentPoint = c->PointTranslate(mouseDownPoint);
lastPoint = currentPoint = c->PointTranslate(currentMouse);
c->DrawPoints(toolIndex, lastPoint, currentPoint, false);
}
}
Expand All @@ -1131,6 +1135,7 @@ void GameView::OnMouseDown(int x, int y, unsigned button)

void GameView::OnMouseUp(int x, int y, unsigned button)
{
currentMouse = ui::Point(x, y);
if (zoomEnabled && !zoomCursorFixed)
{
zoomCursorFixed = true;
Expand Down Expand Up @@ -1184,7 +1189,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
if (isMouseDown)
{
isMouseDown = false;
ui::Point finalDrawPoint2 = c->PointTranslate(ui::Point(x, y));
ui::Point finalDrawPoint2 = c->PointTranslate(currentMouse);
if (drawMode == DrawRect || drawMode == DrawLine)
{
drawPoint2 = finalDrawPoint2;
Expand Down Expand Up @@ -1590,15 +1595,9 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool

void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
if(ctrl && shift && drawMode != DrawPoints)
drawMode = DrawFill;
else if (ctrl && drawMode != DrawPoints)
drawMode = DrawRect;
else if (shift && drawMode != DrawPoints)
drawMode = DrawLine;
else if(!isMouseDown)
if (!isMouseDown)
drawMode = DrawPoints;
else
else if (drawMode == DrawPoints)
drawModeReset = true;
switch(key)
{
Expand Down
6 changes: 6 additions & 0 deletions src/gui/game/ToolButton.cpp
Expand Up @@ -32,6 +32,12 @@ void ToolButton::OnMouseUnclick(int x, int y, unsigned int button)
}
}

void ToolButton::OnMouseUp(int x, int y, unsigned int button)
{
// mouse was unclicked, reset variables in case the unclick happened outside
isButtonDown = false;
}

void ToolButton::Draw(const ui::Point& screenPos)
{
Graphics * g = ui::Engine::Ref().g;
Expand Down
1 change: 1 addition & 0 deletions src/gui/game/ToolButton.h
Expand Up @@ -9,6 +9,7 @@ class ToolButton: public ui::Button
public:
ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolTip = "");
virtual void OnMouseUnclick(int x, int y, unsigned int button);
virtual void OnMouseUp(int x, int y, unsigned int button);
virtual void OnMouseClick(int x, int y, unsigned int button);
virtual void Draw(const ui::Point& screenPos);
void SetSelectionState(int state);
Expand Down
30 changes: 17 additions & 13 deletions src/gui/interface/Button.cpp
Expand Up @@ -85,20 +85,17 @@ void Button::Draw(const Point& screenPos)

if (Enabled)
{
if (isMouseInside)
if (isButtonDown || (isTogglable && toggle))
{
if (isButtonDown || (isTogglable && toggle))
{
textColour = Appearance.TextActive;
borderColour = Appearance.BorderActive;
backgroundColour = Appearance.BackgroundActive;
}
else
{
textColour = Appearance.TextHover;
borderColour = Appearance.BorderHover;
backgroundColour = Appearance.BackgroundHover;
}
textColour = Appearance.TextActive;
borderColour = Appearance.BorderActive;
backgroundColour = Appearance.BackgroundActive;
}
else if (isMouseInside)
{
textColour = Appearance.TextHover;
borderColour = Appearance.BorderHover;
backgroundColour = Appearance.BackgroundHover;
}
else
{
Expand Down Expand Up @@ -166,6 +163,13 @@ void Button::OnMouseUnclick(int x, int y, unsigned int button)
}
}

void Button::OnMouseUp(int x, int y, unsigned int button)
{
// mouse was unclicked, reset variables in case the unclick happened outside
isButtonDown = false;
isAltButtonDown = false;
}

void Button::OnMouseClick(int x, int y, unsigned int button)
{
if(!Enabled)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/interface/Button.h
Expand Up @@ -26,7 +26,7 @@ class Button : public Component

virtual void OnMouseClick(int x, int y, unsigned int button);
virtual void OnMouseUnclick(int x, int y, unsigned int button);
//virtual void OnMouseUp(int x, int y, unsigned int button);
virtual void OnMouseUp(int x, int y, unsigned int button);

virtual void OnMouseEnter(int x, int y);
virtual void OnMouseHover(int x, int y);
Expand Down

0 comments on commit a81a41b

Please sign in to comment.