- [NEW] draw::setZoom() i getZoom()

- [NEW] Ara amb F1 i F2 se pot fer zoom del contingut de la finestra
- [NEW] Ja es pot editar els camps de text (pero encara no es guarda a arxiu)
This commit is contained in:
2025-11-19 22:46:44 +01:00
parent 546ab9aa55
commit 19441c5289
6 changed files with 92 additions and 18 deletions

View File

@@ -9,9 +9,12 @@ namespace draw
SDL_Renderer *sdl_renderer {nullptr}; // El renderer de SDL
SDL_Texture *sdl_texture {nullptr}; // La textura a la que ho renderitze tot
SDL_Texture *sdl_source {nullptr};
float zoom = 1.0f;
void init(const char *titol, const uint16_t width, const uint16_t height)
{
zoom = file::getConfigValueFloat("zoom", 1.0f);
sdl_window = SDL_CreateWindow(titol, width, height, SDL_WINDOW_RESIZABLE);
if (!sdl_window) {
SDL_LogCritical(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n");
@@ -32,12 +35,14 @@ namespace draw
printf("Using: %s\n", SDL_GetRendererName(sdl_renderer));
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
}
void resizeSystemTexture(const uint16_t width, const uint16_t height)
{
SDL_DestroyTexture(sdl_texture);
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width*zoom, height*zoom);
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
}
void quit()
@@ -49,6 +54,20 @@ namespace draw
sdl_renderer = nullptr;
}
void setZoom(const float value)
{
zoom = value;
file::setConfigValueFloat("zoom", zoom);
int w, h;
SDL_GetWindowSize(sdl_window, &w, &h);
resizeSystemTexture(w, h);
}
const float getZoom()
{
return zoom;
}
SDL_Texture *createSurface(const uint16_t w, const uint16_t h)
{
SDL_Texture *surf = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, w, h);
@@ -121,10 +140,11 @@ namespace draw
SDL_SetRenderClipRect(sdl_renderer, nullptr);
}
SDL_Point getWindowSize()
SDL_FPoint getWindowSize()
{
SDL_Point p;
SDL_GetWindowSize(sdl_window, &p.x, &p.y);
int w, h;
SDL_GetWindowSize(sdl_window, &w, &h);
SDL_FPoint p {w*zoom, h*zoom};
return p;
}