// playfield_grid.cpp - Implementació de la grilla de fons // © 2026 JailDesigner #include "core/graphics/playfield_grid.hpp" #include "core/defaults.hpp" #include "core/rendering/line_renderer.hpp" namespace Graphics { PlayfieldGrid::PlayfieldGrid(Rendering::Renderer* renderer) : renderer_(renderer) {} void PlayfieldGrid::draw() const { const SDL_FRect& zona = Defaults::Zones::PLAYAREA; const float CELL_W = zona.w / static_cast(Defaults::Grid::COLUMNS); const float CELL_H = zona.h / static_cast(Defaults::Grid::ROWS); const float SUB_W = CELL_W / static_cast(Defaults::Grid::SUBDIVISIONS); const float SUB_H = CELL_H / static_cast(Defaults::Grid::SUBDIVISIONS); const int SUB_VERTS = Defaults::Grid::COLUMNS * Defaults::Grid::SUBDIVISIONS; const int SUB_HORIZ = Defaults::Grid::ROWS * Defaults::Grid::SUBDIVISIONS; const int X1 = static_cast(zona.x); const int Y1 = static_cast(zona.y); const int X2 = static_cast(zona.x + zona.w); const int Y2 = static_cast(zona.y + zona.h); // PRIMER: sub-graella (queda per dessota — pintem primer). // Saltem les posicions que coincideixen amb la graella principal (i % SUBDIVISIONS == 0). for (int i = 1; i < SUB_VERTS; i++) { if (i % Defaults::Grid::SUBDIVISIONS == 0) { continue; } const int X = static_cast(zona.x + (static_cast(i) * SUB_W)); Rendering::linea(renderer_, X, Y1, X, Y2, Defaults::Grid::SUBGRID_BRIGHTNESS); } for (int j = 1; j < SUB_HORIZ; j++) { if (j % Defaults::Grid::SUBDIVISIONS == 0) { continue; } const int Y = static_cast(zona.y + (static_cast(j) * SUB_H)); Rendering::linea(renderer_, X1, Y, X2, Y, Defaults::Grid::SUBGRID_BRIGHTNESS); } // SEGON: graella principal (línies interiors, no repetim el border). for (int i = 1; i < Defaults::Grid::COLUMNS; i++) { const int X = static_cast(zona.x + (static_cast(i) * CELL_W)); Rendering::linea(renderer_, X, Y1, X, Y2, Defaults::Grid::BRIGHTNESS); } for (int j = 1; j < Defaults::Grid::ROWS; j++) { const int Y = static_cast(zona.y + (static_cast(j) * CELL_H)); Rendering::linea(renderer_, X1, Y, X2, Y, Defaults::Grid::BRIGHTNESS); } } } // namespace Graphics