summary refs log tree commit diff stats
path: root/src/renderer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/renderer.cpp')
-rw-r--r--src/renderer.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/renderer.cpp b/src/renderer.cpp index eddd11d..9d3af97 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -288,22 +288,33 @@ void Renderer::render(
288 288
289 SDL_SetRenderTarget(ren_.get(), nullptr); 289 SDL_SetRenderTarget(ren_.get(), nullptr);
290 290
291 if (!game.zooming) 291 SDL_Rect zoomRect;
292
293 std::tie(zoomRect.x, zoomRect.y, zoomRect.w, zoomRect.h) =
294 calculateZoomRect(game);
295
296 SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr);
297 SDL_RenderPresent(ren_.get());
298}
299
300std::tuple<int, int, int, int> Renderer::calculateZoomRect(const Game& game)
301{
302 int x = game.map.getTrueX(game.curBoundX) * TILE_WIDTH;
303 int y = game.map.getTrueY(game.curBoundY) * TILE_HEIGHT;
304 int w = game.curZoom * TILE_WIDTH * ZOOM_X_FACTOR;
305 int h = game.curZoom * TILE_HEIGHT * ZOOM_Y_FACTOR;
306
307 if (game.zooming)
292 { 308 {
293 SDL_RenderCopy(ren_.get(), canvas.get(), nullptr, nullptr); 309 double interp =
294 } else { 310 static_cast<double>(game.zoomProgress) /
295 // TODO: zooming back in to the player 311 static_cast<double>(game.zoomLength);
296 SDL_Rect zoomRect { 312
297 ((game.maxZoom - game.curZoom) * TILE_WIDTH + game.zoomProgress) 313 x = (x - game.lastZoomLeft) * interp + game.lastZoomLeft;
298 * ZOOM_X_FACTOR / 2, 314 y = (y - game.lastZoomTop) * interp + game.lastZoomTop;
299 ((game.maxZoom - game.curZoom) * TILE_HEIGHT + game.zoomProgress) 315 w = (w - game.lastZoomWidth) * interp + game.lastZoomWidth;
300 * ZOOM_Y_FACTOR / 2, 316 h = (h - game.lastZoomHeight) * interp + game.lastZoomHeight;
301 (game.curZoom * TILE_WIDTH - game.zoomProgress) * ZOOM_X_FACTOR,
302 (game.curZoom * TILE_HEIGHT - game.zoomProgress) * ZOOM_Y_FACTOR
303 };
304
305 SDL_RenderCopy(ren_.get(), canvas.get(), &zoomRect, nullptr);
306 } 317 }
307 318
308 SDL_RenderPresent(ren_.get()); 319 return {x, y, w, h};
309} 320}