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
This commit is contained in:
jacob1 2015-09-21 02:13:01 -04:00
parent 16781bcb8e
commit 6ae3593465
4 changed files with 41 additions and 50 deletions

View File

@ -450,48 +450,28 @@ void GameController::DrawFill(int toolSelection, ui::Point point)
activeTool->DrawFill(sim, cBrush, 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(); Simulation * sim = gameModel->GetSimulation();
Tool * activeTool = gameModel->GetActiveTool(toolSelection); Tool * activeTool = gameModel->GetActiveTool(toolSelection);
gameModel->SetLastTool(activeTool); gameModel->SetLastTool(activeTool);
Brush * cBrush = gameModel->GetBrush(); Brush * cBrush = gameModel->GetBrush();
if(!activeTool || !cBrush) if (!activeTool || !cBrush)
{ {
if(!pointQueue.empty())
{
while(!pointQueue.empty())
{
pointQueue.pop();
}
}
return; return;
} }
activeTool->SetStrength(gameModel->GetToolStrength()); activeTool->SetStrength(gameModel->GetToolStrength());
if(!pointQueue.empty()) if (!held)
{ {
ui::Point sPoint(0, 0); activeTool->Draw(sim, cBrush, newPos);
int size = pointQueue.size(); gameModel->Log("Initial mouse coord at "+ format::NumberToString<int>(newPos.X) + " " + format::NumberToString<int>(newPos.Y), true);
bool first = true; }
while(!pointQueue.empty()) else
{ {
ui::Point fPoint = pointQueue.front(); gameModel->Log("Previous mouse coord at "+ format::NumberToString<int>(oldPos.X) + " " + format::NumberToString<int>(oldPos.Y), true);
pointQueue.pop(); gameModel->Log("Current mouse coord at "+ format::NumberToString<int>(newPos.X) + " " + format::NumberToString<int>(newPos.Y), true);
if(size > 1) activeTool->DrawLine(sim, cBrush, oldPos, newPos, true);
{
if (!first)
{
activeTool->DrawLine(sim, cBrush, sPoint, fPoint, true);
}
first = false;
}
else
{
activeTool->Draw(sim, cBrush, fPoint);
}
sPoint = fPoint;
}
} }
} }

View File

@ -83,7 +83,7 @@ public:
void SetBrushSize(ui::Point newSize); void SetBrushSize(ui::Point newSize);
void AdjustZoomSize(int direction, bool logarithmic = false); void AdjustZoomSize(int direction, bool logarithmic = false);
void ToolClick(int toolSelection, ui::Point point); 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 DrawRect(int toolSelection, ui::Point point1, ui::Point point2);
void DrawLine(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); void DrawFill(int toolSelection, ui::Point point);

View File

@ -150,6 +150,7 @@ public:
GameView::GameView(): GameView::GameView():
ui::Window(ui::Point(0, 0), ui::Point(WINDOWW, WINDOWH)), ui::Window(ui::Point(0, 0), ui::Point(WINDOWW, WINDOWH)),
isMouseDown(false), isMouseDown(false),
isMouseHeld(false),
zoomEnabled(false), zoomEnabled(false),
zoomCursorFixed(false), zoomCursorFixed(false),
mouseInZoom(false), mouseInZoom(false),
@ -183,7 +184,8 @@ GameView::GameView():
recording(false), recording(false),
screenshotIndex(0), screenshotIndex(0),
recordingIndex(0), recordingIndex(0),
pointQueue(queue<ui::Point>()), currentPoint(ui::Point(0, 0)),
lastPoint(ui::Point(0, 0)),
ren(NULL), ren(NULL),
activeBrush(NULL), activeBrush(NULL),
saveSimulationButtonEnabled(false), saveSimulationButtonEnabled(false),
@ -1064,19 +1066,19 @@ void GameView::OnMouseMove(int x, int y, int dx, int dy)
if (selectPoint1.X != -1) if (selectPoint1.X != -1)
selectPoint2 = c->PointTranslate(ui::Point(x, y)); selectPoint2 = c->PointTranslate(ui::Point(x, y));
} }
else if (isMouseDown) else if (isMouseDown || isMouseHeld)
{ {
if (newMouseInZoom == mouseInZoom) if (newMouseInZoom == mouseInZoom)
{ {
if (drawMode == DrawPoints) if (drawMode == DrawPoints)
{ {
pointQueue.push(ui::Point(c->PointTranslate(ui::Point(x-dx, y-dy)))); currentPoint = mousePosition;
pointQueue.push(ui::Point(c->PointTranslate(ui::Point(x, y))));
} }
} }
else if (drawMode == DrawPoints || drawMode == DrawFill) else if (drawMode == DrawPoints || drawMode == DrawFill)
{ {
isMouseDown = false; isMouseDown = false;
isMouseHeld = false;
c->MouseUp(x, y, 0, 2); c->MouseUp(x, y, 0, 2);
} }
} }
@ -1107,15 +1109,15 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
if (button == BUTTON_MIDDLE) if (button == BUTTON_MIDDLE)
toolIndex = 2; toolIndex = 2;
isMouseDown = true; isMouseDown = true;
if (!pointQueue.size()) c->HistorySnapshot();
c->HistorySnapshot();
if (drawMode == DrawRect || drawMode == DrawLine) if (drawMode == DrawRect || drawMode == DrawLine)
{ {
drawPoint1 = c->PointTranslate(ui::Point(x, y)); drawPoint1 = c->PointTranslate(ui::Point(x, y));
} }
if (drawMode == DrawPoints) 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; zoomCursorFixed = true;
drawMode = DrawPoints; drawMode = DrawPoints;
isMouseDown = false; isMouseDown = false;
isMouseHeld = false;
} }
else else
{ {
@ -1392,7 +1395,10 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
else else
{ {
if (drawMode != DrawLine && !windTool) if (drawMode != DrawLine && !windTool)
{
isMouseDown = false; isMouseDown = false;
isMouseHeld = false;
}
zoomCursorFixed = false; zoomCursorFixed = false;
c->SetZoomEnabled(true); 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()); c->LoadStamp(Client::Ref().GetStamp(stampList[0])->GetGameSave());
selectPoint1 = selectPoint2 = mousePosition; selectPoint1 = selectPoint2 = mousePosition;
isMouseDown = false; isMouseDown = false;
isMouseHeld = false;
break; break;
} }
} }
@ -1616,28 +1623,32 @@ void GameView::OnBlur()
disableCtrlBehaviour(); disableCtrlBehaviour();
disableShiftBehaviour(); disableShiftBehaviour();
isMouseDown = false; isMouseDown = false;
isMouseHeld = false;
drawMode = DrawPoints; drawMode = DrawPoints;
c->MouseUp(0, 0, 0, 1); // tell lua that mouse is up (even if it really isn't) c->MouseUp(0, 0, 0, 1); // tell lua that mouse is up (even if it really isn't)
} }
void GameView::OnTick(float dt) void GameView::OnTick(float dt)
{ {
if(selectMode==PlaceSave && !placeSaveThumb) if (selectMode==PlaceSave && !placeSaveThumb)
selectMode = SelectNone; selectMode = SelectNone;
if(zoomEnabled && !zoomCursorFixed) if (zoomEnabled && !zoomCursorFixed)
c->SetZoomPosition(currentMouse); 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)); c->DrawFill(toolIndex, c->PointTranslate(currentMouse));
} }
@ -1805,9 +1816,8 @@ void GameView::DoTick(float dt)
if (!c->MouseTick()) if (!c->MouseTick())
{ {
isMouseDown = false; isMouseDown = false;
isMouseHeld = false;
drawMode = DrawPoints; drawMode = DrawPoints;
while (!pointQueue.empty())
pointQueue.pop();
} }
Window::DoTick(dt); Window::DoTick(dt);
} }

View File

@ -34,6 +34,7 @@ class GameView: public ui::Window
{ {
private: private:
bool isMouseDown; bool isMouseDown;
bool isMouseHeld; // same as isMouseDown but with a frame of lag (to do lines / ending point properly)
bool zoomEnabled; bool zoomEnabled;
bool zoomCursorFixed; bool zoomCursorFixed;
bool mouseInZoom; bool mouseInZoom;
@ -68,7 +69,7 @@ private:
int screenshotIndex; int screenshotIndex;
int recordingIndex; int recordingIndex;
queue<ui::Point> pointQueue; ui::Point currentPoint, lastPoint;
GameController * c; GameController * c;
Renderer * ren; Renderer * ren;
Brush * activeBrush; Brush * activeBrush;