From 6ae3593465ed9684744bd080df1f9674fd6cc429 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 21 Sep 2015 02:13:01 -0400 Subject: [PATCH] remove pointQueue, replace with something that works properly No longer draws a single point by itself at the start, and draws a final line to the point where the mouse is released --- src/gui/game/GameController.cpp | 42 +++++++++---------------------- src/gui/game/GameController.h | 2 +- src/gui/game/GameView.cpp | 44 ++++++++++++++++++++------------- src/gui/game/GameView.h | 3 ++- 4 files changed, 41 insertions(+), 50 deletions(-) diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index e0ded7bb2..4430beda4 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -450,48 +450,28 @@ void GameController::DrawFill(int toolSelection, ui::Point point) activeTool->DrawFill(sim, cBrush, point); } -void GameController::DrawPoints(int toolSelection, queue & pointQueue) +void GameController::DrawPoints(int toolSelection, ui::Point oldPos, ui::Point newPos, bool held) { Simulation * sim = gameModel->GetSimulation(); Tool * activeTool = gameModel->GetActiveTool(toolSelection); gameModel->SetLastTool(activeTool); Brush * cBrush = gameModel->GetBrush(); - if(!activeTool || !cBrush) + if (!activeTool || !cBrush) { - if(!pointQueue.empty()) - { - while(!pointQueue.empty()) - { - pointQueue.pop(); - } - } return; } activeTool->SetStrength(gameModel->GetToolStrength()); - if(!pointQueue.empty()) + if (!held) { - ui::Point sPoint(0, 0); - int size = pointQueue.size(); - bool first = true; - while(!pointQueue.empty()) - { - ui::Point fPoint = pointQueue.front(); - pointQueue.pop(); - if(size > 1) - { - if (!first) - { - activeTool->DrawLine(sim, cBrush, sPoint, fPoint, true); - } - first = false; - } - else - { - activeTool->Draw(sim, cBrush, fPoint); - } - sPoint = fPoint; - } + activeTool->Draw(sim, cBrush, newPos); + gameModel->Log("Initial mouse coord at "+ format::NumberToString(newPos.X) + " " + format::NumberToString(newPos.Y), true); + } + else + { + gameModel->Log("Previous mouse coord at "+ format::NumberToString(oldPos.X) + " " + format::NumberToString(oldPos.Y), true); + gameModel->Log("Current mouse coord at "+ format::NumberToString(newPos.X) + " " + format::NumberToString(newPos.Y), true); + activeTool->DrawLine(sim, cBrush, oldPos, newPos, true); } } diff --git a/src/gui/game/GameController.h b/src/gui/game/GameController.h index 87d20d853..127105384 100644 --- a/src/gui/game/GameController.h +++ b/src/gui/game/GameController.h @@ -83,7 +83,7 @@ public: void SetBrushSize(ui::Point newSize); void AdjustZoomSize(int direction, bool logarithmic = false); void ToolClick(int toolSelection, ui::Point point); - void DrawPoints(int toolSelection, queue & pointQueue); + void DrawPoints(int toolSelection, ui::Point oldPos, ui::Point newPos, bool held); void DrawRect(int toolSelection, ui::Point point1, ui::Point point2); void DrawLine(int toolSelection, ui::Point point1, ui::Point point2); void DrawFill(int toolSelection, ui::Point point); diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index 8d73984d9..5a2fc7a77 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -150,6 +150,7 @@ public: GameView::GameView(): ui::Window(ui::Point(0, 0), ui::Point(WINDOWW, WINDOWH)), isMouseDown(false), + isMouseHeld(false), zoomEnabled(false), zoomCursorFixed(false), mouseInZoom(false), @@ -183,7 +184,8 @@ GameView::GameView(): recording(false), screenshotIndex(0), recordingIndex(0), - pointQueue(queue()), + currentPoint(ui::Point(0, 0)), + lastPoint(ui::Point(0, 0)), ren(NULL), activeBrush(NULL), saveSimulationButtonEnabled(false), @@ -1064,19 +1066,19 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy) if (selectPoint1.X != -1) selectPoint2 = c->PointTranslate(ui::Point(x, y)); } - else if (isMouseDown) + else if (isMouseDown || isMouseHeld) { if (newMouseInZoom == mouseInZoom) { if (drawMode == DrawPoints) { - pointQueue.push(ui::Point(c->PointTranslate(ui::Point(x-dx, y-dy)))); - pointQueue.push(ui::Point(c->PointTranslate(ui::Point(x, y)))); + currentPoint = mousePosition; } } else if (drawMode == DrawPoints || drawMode == DrawFill) { isMouseDown = false; + isMouseHeld = false; c->MouseUp(x, y, 0, 2); } } @@ -1107,15 +1109,15 @@ void GameView::OnMouseDown(int x, int y, unsigned button) if (button == BUTTON_MIDDLE) toolIndex = 2; isMouseDown = true; - if (!pointQueue.size()) - c->HistorySnapshot(); + c->HistorySnapshot(); if (drawMode == DrawRect || drawMode == DrawLine) { drawPoint1 = c->PointTranslate(ui::Point(x, y)); } if (drawMode == DrawPoints) { - pointQueue.push(ui::Point(c->PointTranslate(ui::Point(x, y)))); + lastPoint = currentPoint = c->PointTranslate(ui::Point(x, y)); + c->DrawPoints(toolIndex, lastPoint, currentPoint, false); } } } @@ -1128,6 +1130,7 @@ void GameView::OnMouseUp(int x, int y, unsigned button) zoomCursorFixed = true; drawMode = DrawPoints; isMouseDown = false; + isMouseHeld = false; } else { @@ -1392,7 +1395,10 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool else { if (drawMode != DrawLine && !windTool) + { isMouseDown = false; + isMouseHeld = false; + } zoomCursorFixed = false; c->SetZoomEnabled(true); } @@ -1528,6 +1534,7 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool c->LoadStamp(Client::Ref().GetStamp(stampList[0])->GetGameSave()); selectPoint1 = selectPoint2 = mousePosition; isMouseDown = false; + isMouseHeld = false; break; } } @@ -1616,28 +1623,32 @@ void GameView::OnBlur() disableCtrlBehaviour(); disableShiftBehaviour(); isMouseDown = false; + isMouseHeld = false; drawMode = DrawPoints; c->MouseUp(0, 0, 0, 1); // tell lua that mouse is up (even if it really isn't) } void GameView::OnTick(float dt) { - if(selectMode==PlaceSave && !placeSaveThumb) + if (selectMode==PlaceSave && !placeSaveThumb) selectMode = SelectNone; - if(zoomEnabled && !zoomCursorFixed) + if (zoomEnabled && !zoomCursorFixed) c->SetZoomPosition(currentMouse); - if(drawMode == DrawPoints) + if (drawMode == DrawPoints) { - if(isMouseDown && pointQueue.empty()) + if (isMouseDown) { - pointQueue.push(ui::Point(c->PointTranslate(currentMouse))); + c->DrawPoints(toolIndex, lastPoint, currentPoint, true); + lastPoint = currentPoint; + isMouseHeld = true; } - if(!pointQueue.empty()) + else if (isMouseHeld) { - c->DrawPoints(toolIndex, pointQueue); + c->DrawPoints(toolIndex, lastPoint, currentPoint, true); + isMouseHeld = false; } } - else if(drawMode == DrawFill && isMouseDown) + else if (drawMode == DrawFill && isMouseDown) { c->DrawFill(toolIndex, c->PointTranslate(currentMouse)); } @@ -1805,9 +1816,8 @@ void GameView::DoTick(float dt) if (!c->MouseTick()) { isMouseDown = false; + isMouseHeld = false; drawMode = DrawPoints; - while (!pointQueue.empty()) - pointQueue.pop(); } Window::DoTick(dt); } diff --git a/src/gui/game/GameView.h b/src/gui/game/GameView.h index 60c799b84..18b2b228d 100644 --- a/src/gui/game/GameView.h +++ b/src/gui/game/GameView.h @@ -34,6 +34,7 @@ class GameView: public ui::Window { private: bool isMouseDown; + bool isMouseHeld; // same as isMouseDown but with a frame of lag (to do lines / ending point properly) bool zoomEnabled; bool zoomCursorFixed; bool mouseInZoom; @@ -68,7 +69,7 @@ private: int screenshotIndex; int recordingIndex; - queue pointQueue; + ui::Point currentPoint, lastPoint; GameController * c; Renderer * ren; Brush * activeBrush;