diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-28 14:51:39 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-01-28 14:51:39 (GMT) |
| commit | b5728a9e3e983460a957fa0e576b751ebfe87172 (patch) | |
| tree | cb20500bc94da3fd00782981a45c9b05c6af36eb /src/game/GameController.cpp | |
| parent | 58ba7f8800403c572bae99115facc808c6dc34a3 (diff) | |
| download | powder-b5728a9e3e983460a957fa0e576b751ebfe87172.zip powder-b5728a9e3e983460a957fa0e576b751ebfe87172.tar.gz | |
Zoom
Diffstat (limited to 'src/game/GameController.cpp')
| -rw-r--r-- | src/game/GameController.cpp | 66 |
1 files changed, 58 insertions, 8 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 277c32c..752a0ba 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -107,6 +107,36 @@ void GameController::AdjustBrushSize(int direction) gameModel->GetBrush()->SetRadius(newSize); } +void GameController::AdjustZoomSize(int direction) +{ + int newSize = gameModel->GetZoomSize()+direction; + if(newSize<5) + newSize = 5; + if(newSize>64) + newSize = 64; + gameModel->SetZoomSize(newSize); + + int newZoomFactor = 256/newSize; + if(newZoomFactor<3) + newZoomFactor = 3; + gameModel->SetZoomFactor(newZoomFactor); +} + +ui::Point GameController::PointTranslate(ui::Point point) +{ + bool zoomEnabled = gameModel->GetZoomEnabled(); + if(!zoomEnabled) + return point; + //If we try to draw inside the zoom window, normalise the coordinates + int zoomFactor = gameModel->GetZoomFactor(); + ui::Point zoomWindowPosition = gameModel->GetZoomWindowPosition(); + ui::Point zoomWindowSize = ui::Point(gameModel->GetZoomSize()*zoomFactor, gameModel->GetZoomSize()*zoomFactor); + + if(point.X > zoomWindowPosition.X && point.X > zoomWindowPosition.Y && point.X < zoomWindowPosition.X+zoomWindowSize.X && point.Y < zoomWindowPosition.Y+zoomWindowSize.Y) + return ((point-zoomWindowPosition)/gameModel->GetZoomFactor())+gameModel->GetZoomPosition(); + return point; +} + void GameController::DrawPoints(queue<ui::Point*> & pointQueue) { Simulation * sim = gameModel->GetSimulation(); @@ -123,26 +153,27 @@ void GameController::DrawPoints(queue<ui::Point*> & pointQueue) } } } + if(!pointQueue.empty()) { - ui::Point * sPoint = NULL; + ui::Point sPoint(0, 0); + bool first = true; while(!pointQueue.empty()) { - ui::Point * fPoint = pointQueue.front(); + ui::Point fPoint = PointTranslate(*pointQueue.front()); + delete pointQueue.front(); pointQueue.pop(); - if(sPoint) + if(!first) { - activeTool->DrawLine(sim, cBrush, *fPoint, *sPoint); - delete sPoint; + activeTool->DrawLine(sim, cBrush, fPoint, sPoint); } else { - activeTool->Draw(sim, cBrush, *fPoint); + first = false; + activeTool->Draw(sim, cBrush, fPoint); } sPoint = fPoint; } - if(sPoint) - delete sPoint; } } @@ -168,6 +199,25 @@ void GameController::Update() } } +void GameController::SetZoomEnabled(bool zoomEnabled) +{ + gameModel->SetZoomEnabled(zoomEnabled); +} + +void GameController::SetZoomPosition(ui::Point position) +{ + ui::Point zoomPosition = position-(gameModel->GetZoomSize()/2); + if(zoomPosition.X < 0) + zoomPosition.X = 0; + if(zoomPosition.Y < 0) + zoomPosition.Y = 0; + if(zoomPosition.X >= XRES-gameModel->GetZoomSize()) + zoomPosition.X = XRES-gameModel->GetZoomSize(); + if(zoomPosition.Y >= YRES-gameModel->GetZoomSize()) + zoomPosition.Y = YRES-gameModel->GetZoomSize(); + gameModel->SetZoomPosition(zoomPosition); +} + void GameController::SetPaused(bool pauseState) { gameModel->SetPaused(pauseState); |
