From a81a41b67ffea3284fa5e17ce51a8e6e1d8134ba Mon Sep 17 00:00:00 2001 From: jacob1 Date: Tue, 22 Sep 2015 21:40:19 -0400 Subject: [PATCH] fix being able to change between box/line/flood fill while drawing (by releasing keys), a bunch of other extremely obscure fixes --- src/gui/game/GameView.cpp | 27 +++++++++++++-------------- src/gui/game/ToolButton.cpp | 6 ++++++ src/gui/game/ToolButton.h | 1 + src/gui/interface/Button.cpp | 30 +++++++++++++++++------------- src/gui/interface/Button.h | 2 +- 5 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index a04d9aab0..ef3671f28 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -482,6 +482,9 @@ public: } 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); } @@ -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); @@ -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)) @@ -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; @@ -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); } } @@ -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; @@ -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; @@ -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) { diff --git a/src/gui/game/ToolButton.cpp b/src/gui/game/ToolButton.cpp index 520970a07..238c6d479 100644 --- a/src/gui/game/ToolButton.cpp +++ b/src/gui/game/ToolButton.cpp @@ -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; diff --git a/src/gui/game/ToolButton.h b/src/gui/game/ToolButton.h index a14595d6b..d0ad7c0ce 100644 --- a/src/gui/game/ToolButton.h +++ b/src/gui/game/ToolButton.h @@ -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); diff --git a/src/gui/interface/Button.cpp b/src/gui/interface/Button.cpp index 13b270780..dadbaa1a1 100644 --- a/src/gui/interface/Button.cpp +++ b/src/gui/interface/Button.cpp @@ -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 { @@ -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) diff --git a/src/gui/interface/Button.h b/src/gui/interface/Button.h index d24ba28a9..2ebf99f1e 100644 --- a/src/gui/interface/Button.h +++ b/src/gui/interface/Button.h @@ -26,7 +26,7 @@ public: 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);