Permalink
Browse files

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
  • Loading branch information...
jacob1 committed Sep 21, 2015
1 parent 16781bc commit 6ae3593465ed9684744bd080df1f9674fd6cc429
Showing with 41 additions and 50 deletions.
  1. +11 −31 src/gui/game/GameController.cpp
  2. +1 −1 src/gui/game/GameController.h
  3. +27 −17 src/gui/game/GameView.cpp
  4. +2 −1 src/gui/game/GameView.h
@@ -450,48 +450,28 @@ void GameController::DrawFill(int toolSelection, ui::Point point)
activeTool->DrawFill(sim, cBrush, point);
}
void GameController::DrawPoints(int toolSelection, queue<ui::Point> & 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<int>(newPos.X) + " " + format::NumberToString<int>(newPos.Y), true);
}
else
{
gameModel->Log("Previous mouse coord at "+ format::NumberToString<int>(oldPos.X) + " " + format::NumberToString<int>(oldPos.Y), true);
gameModel->Log("Current mouse coord at "+ format::NumberToString<int>(newPos.X) + " " + format::NumberToString<int>(newPos.Y), true);
activeTool->DrawLine(sim, cBrush, oldPos, newPos, true);
}
}
@@ -83,7 +83,7 @@ class GameController: public ClientListener
void SetBrushSize(ui::Point newSize);
void AdjustZoomSize(int direction, bool logarithmic = false);
void ToolClick(int toolSelection, ui::Point point);
void DrawPoints(int toolSelection, queue<ui::Point> & 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);
@@ -150,6 +150,7 @@ class SplitButton : public ui::Button
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<ui::Point>()),
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);
}
@@ -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 @@ class GameView: public ui::Window
int screenshotIndex;
int recordingIndex;
queue<ui::Point> pointQueue;
ui::Point currentPoint, lastPoint;
GameController * c;
Renderer * ren;
Brush * activeBrush;

0 comments on commit 6ae3593

Please sign in to comment.