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);
}
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;
activeTool->Draw(sim, cBrush, newPos);
gameModel->Log("Initial mouse coord at "+ format::NumberToString<int>(newPos.X) + " " + format::NumberToString<int>(newPos.Y), true);
}
else
{
activeTool->Draw(sim, cBrush, fPoint);
}
sPoint = fPoint;
}
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);
}
}

View File

@ -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<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);

View File

@ -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<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,7 +1109,6 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
if (button == BUTTON_MIDDLE)
toolIndex = 2;
isMouseDown = true;
if (!pointQueue.size())
c->HistorySnapshot();
if (drawMode == DrawRect || drawMode == DrawLine)
{
@ -1115,7 +1116,8 @@ void GameView::OnMouseDown(int x, int y, unsigned button)
}
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);
}

View File

@ -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<ui::Point> pointQueue;
ui::Point currentPoint, lastPoint;
GameController * c;
Renderer * ren;
Brush * activeBrush;