- [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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ namespace draw
|
||||
void resizeSystemTexture(const uint16_t width, const uint16_t height);
|
||||
void quit();
|
||||
|
||||
void setZoom(const float value);
|
||||
const float getZoom();
|
||||
|
||||
SDL_Texture *createSurface(const uint16_t w, const uint16_t h);
|
||||
SDL_Texture *loadSurface(const char* filename, const int transparent = -1);
|
||||
void freeSurface(SDL_Texture *surf);
|
||||
@@ -19,7 +22,7 @@ namespace draw
|
||||
void setClip(const int x, const int y, const int w, const int h);
|
||||
void resetClip();
|
||||
|
||||
SDL_Point getWindowSize();
|
||||
SDL_FPoint getWindowSize();
|
||||
|
||||
void setColor(const uint32_t col);
|
||||
void cls(const uint32_t color);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "input.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include "draw.h"
|
||||
|
||||
namespace input
|
||||
{
|
||||
@@ -78,7 +79,7 @@ namespace input
|
||||
{
|
||||
float x;
|
||||
SDL_GetMouseState(&x, NULL);
|
||||
return x;
|
||||
return x*draw::getZoom();
|
||||
}
|
||||
|
||||
// Torna la posició Y actual del ratolí
|
||||
@@ -86,7 +87,7 @@ namespace input
|
||||
{
|
||||
float y;
|
||||
SDL_GetMouseState(NULL, &y);
|
||||
return y;
|
||||
return y*draw::getZoom();
|
||||
}
|
||||
|
||||
// Determina si el botó del ratolí especificat està sent polsada ara mateix
|
||||
|
||||
Reference in New Issue
Block a user