Skip to content

Commit a81a41b

Browse files
committed
fix being able to change between box/line/flood fill while drawing (by releasing keys), a bunch of other extremely obscure fixes
1 parent 13a71b6 commit a81a41b

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

src/gui/game/GameView.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ class GameView::MenuAction: public ui::ButtonAction
482482
}
483483
void MouseEnterCallback(ui::Button * sender)
484484
{
485+
// don't immediately change the active menu, the actual set is done inside GameView::OnMouseMove
486+
// if we change it here it causes components to be removed, which causes the window to stop sending events
487+
// and then the previous menusection button never gets sent the OnMouseLeave event and is never unhighlighted
485488
if(!needsClick && !v->GetMouseDown())
486489
v->SetActiveMenuDelayed(menuID);
487490
}
@@ -1083,6 +1086,7 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)
10831086
}
10841087
mouseInZoom = newMouseInZoom;
10851088

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

10931097
void GameView::OnMouseDown(int x, int y, unsigned button)
10941098
{
1095-
ui::Point mouseDownPoint = ui::Point(x, y);
1099+
currentMouse = ui::Point(x, y);
10961100
if (altBehaviour && !shiftBehaviour && !ctrlBehaviour)
10971101
button = BUTTON_MIDDLE;
10981102
if (!(zoomEnabled && !zoomCursorFixed))
@@ -1101,12 +1105,12 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
11011105
{
11021106
if (button == BUTTON_LEFT && selectPoint1.X == -1)
11031107
{
1104-
selectPoint1 = c->PointTranslate(mouseDownPoint);
1108+
selectPoint1 = c->PointTranslate(currentMouse);
11051109
selectPoint2 = selectPoint1;
11061110
}
11071111
return;
11081112
}
1109-
if (mouseDownPoint.X >= 0 && mouseDownPoint.X < XRES && mouseDownPoint.Y >= 0 && mouseDownPoint.Y < YRES)
1113+
if (currentMouse.X >= 0 && currentMouse.X < XRES && currentMouse.Y >= 0 && currentMouse.Y < YRES)
11101114
{
11111115
if (button == BUTTON_LEFT)
11121116
toolIndex = 0;
@@ -1118,11 +1122,11 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
11181122
c->HistorySnapshot();
11191123
if (drawMode == DrawRect || drawMode == DrawLine)
11201124
{
1121-
drawPoint1 = c->PointTranslate(mouseDownPoint);
1125+
drawPoint1 = c->PointTranslate(currentMouse);
11221126
}
11231127
if (drawMode == DrawPoints)
11241128
{
1125-
lastPoint = currentPoint = c->PointTranslate(mouseDownPoint);
1129+
lastPoint = currentPoint = c->PointTranslate(currentMouse);
11261130
c->DrawPoints(toolIndex, lastPoint, currentPoint, false);
11271131
}
11281132
}
@@ -1131,6 +1135,7 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
11311135

11321136
void GameView::OnMouseUp(int x, int y, unsigned button)
11331137
{
1138+
currentMouse = ui::Point(x, y);
11341139
if (zoomEnabled && !zoomCursorFixed)
11351140
{
11361141
zoomCursorFixed = true;
@@ -1184,7 +1189,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button)
11841189
if (isMouseDown)
11851190
{
11861191
isMouseDown = false;
1187-
ui::Point finalDrawPoint2 = c->PointTranslate(ui::Point(x, y));
1192+
ui::Point finalDrawPoint2 = c->PointTranslate(currentMouse);
11881193
if (drawMode == DrawRect || drawMode == DrawLine)
11891194
{
11901195
drawPoint2 = finalDrawPoint2;
@@ -1590,15 +1595,9 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
15901595

15911596
void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
15921597
{
1593-
if(ctrl && shift && drawMode != DrawPoints)
1594-
drawMode = DrawFill;
1595-
else if (ctrl && drawMode != DrawPoints)
1596-
drawMode = DrawRect;
1597-
else if (shift && drawMode != DrawPoints)
1598-
drawMode = DrawLine;
1599-
else if(!isMouseDown)
1598+
if (!isMouseDown)
16001599
drawMode = DrawPoints;
1601-
else
1600+
else if (drawMode == DrawPoints)
16021601
drawModeReset = true;
16031602
switch(key)
16041603
{

src/gui/game/ToolButton.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ void ToolButton::OnMouseUnclick(int x, int y, unsigned int button)
3232
}
3333
}
3434

35+
void ToolButton::OnMouseUp(int x, int y, unsigned int button)
36+
{
37+
// mouse was unclicked, reset variables in case the unclick happened outside
38+
isButtonDown = false;
39+
}
40+
3541
void ToolButton::Draw(const ui::Point& screenPos)
3642
{
3743
Graphics * g = ui::Engine::Ref().g;

src/gui/game/ToolButton.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ToolButton: public ui::Button
99
public:
1010
ToolButton(ui::Point position, ui::Point size, std::string text_, std::string toolTip = "");
1111
virtual void OnMouseUnclick(int x, int y, unsigned int button);
12+
virtual void OnMouseUp(int x, int y, unsigned int button);
1213
virtual void OnMouseClick(int x, int y, unsigned int button);
1314
virtual void Draw(const ui::Point& screenPos);
1415
void SetSelectionState(int state);

src/gui/interface/Button.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,17 @@ void Button::Draw(const Point& screenPos)
8585

8686
if (Enabled)
8787
{
88-
if (isMouseInside)
88+
if (isButtonDown || (isTogglable && toggle))
8989
{
90-
if (isButtonDown || (isTogglable && toggle))
91-
{
92-
textColour = Appearance.TextActive;
93-
borderColour = Appearance.BorderActive;
94-
backgroundColour = Appearance.BackgroundActive;
95-
}
96-
else
97-
{
98-
textColour = Appearance.TextHover;
99-
borderColour = Appearance.BorderHover;
100-
backgroundColour = Appearance.BackgroundHover;
101-
}
90+
textColour = Appearance.TextActive;
91+
borderColour = Appearance.BorderActive;
92+
backgroundColour = Appearance.BackgroundActive;
93+
}
94+
else if (isMouseInside)
95+
{
96+
textColour = Appearance.TextHover;
97+
borderColour = Appearance.BorderHover;
98+
backgroundColour = Appearance.BackgroundHover;
10299
}
103100
else
104101
{
@@ -166,6 +163,13 @@ void Button::OnMouseUnclick(int x, int y, unsigned int button)
166163
}
167164
}
168165

166+
void Button::OnMouseUp(int x, int y, unsigned int button)
167+
{
168+
// mouse was unclicked, reset variables in case the unclick happened outside
169+
isButtonDown = false;
170+
isAltButtonDown = false;
171+
}
172+
169173
void Button::OnMouseClick(int x, int y, unsigned int button)
170174
{
171175
if(!Enabled)

src/gui/interface/Button.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Button : public Component
2626

2727
virtual void OnMouseClick(int x, int y, unsigned int button);
2828
virtual void OnMouseUnclick(int x, int y, unsigned int button);
29-
//virtual void OnMouseUp(int x, int y, unsigned int button);
29+
virtual void OnMouseUp(int x, int y, unsigned int button);
3030

3131
virtual void OnMouseEnter(int x, int y);
3232
virtual void OnMouseHover(int x, int y);

0 commit comments

Comments
 (0)