From 8cc347f63989abf5f5797bd0554b1c310a96496c Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 1 Jul 2025 17:24:53 +0200 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20El=20ratol=C3=AD=20ja=20va=20correc?= =?UTF-8?q?tament=20en=20pantalla=20completa.=20-=20[FIX]=20Els=20shaders?= =?UTF-8?q?=20ja=20van=20correctament=20a=20pantalla=20completa.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/jdraw.cpp | 28 ++++++++++++++++++++++++++-- source/jdraw.h | 2 ++ source/jinput.cpp | 4 ++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/source/jdraw.cpp b/source/jdraw.cpp index e6d741c..f201679 100644 --- a/source/jdraw.cpp +++ b/source/jdraw.cpp @@ -28,6 +28,8 @@ namespace draw static int desktop_height; static int window_width; static int window_height; + static int offset_x = 0; + static int offset_y = 0; char window_title[256]; surface *screen {nullptr}; // La superficie screen, que representa la pantalla. Se crea i destrueix internament @@ -64,9 +66,21 @@ namespace draw window_width = canvas_width*screen_zoom; window_height = window_ratio != 1 ? int(float(canvas_width)*window_ratio*float(screen_zoom)) : canvas_height*screen_zoom; } + if (screen_fullscreen) { - window_width = desktop_width; - window_height = desktop_height; + if (desktop_width * window_ratio > desktop_height) { + offset_y = 0; + window_height = desktop_height; + window_width = desktop_height/window_ratio; + offset_x = (desktop_width - window_width)/2; + } else { + offset_x = 0; + window_width = desktop_width; + window_height = desktop_width*window_ratio; + offset_y = (desktop_height - window_height)/2; + } + } else { + offset_x = offset_y = 0; } sdl_window = SDL_CreateWindow(window_title, window_width, window_height, SDL_WINDOW_OPENGL|(screen_fullscreen?SDL_WINDOW_FULLSCREEN:0)); @@ -200,6 +214,16 @@ namespace draw return float(window_height) / float(canvas_height); } + const int getOffsetX() + { + return offset_x; + } + + const int getOffsetY() + { + return offset_y; + } + bool getFullscreen() { return screen_fullscreen; } diff --git a/source/jdraw.h b/source/jdraw.h index 04f5d40..762bc3e 100644 --- a/source/jdraw.h +++ b/source/jdraw.h @@ -34,6 +34,8 @@ namespace draw const int getZoom(); const float getScaleX(); const float getScaleY(); + const int getOffsetX(); + const int getOffsetY(); bool getFullscreen(); void setFullscreen(const bool value); diff --git a/source/jinput.cpp b/source/jinput.cpp index 36b9f73..c0f870c 100644 --- a/source/jinput.cpp +++ b/source/jinput.cpp @@ -79,7 +79,7 @@ namespace input { float x; SDL_GetMouseState(&x, NULL); - return x/draw::getScaleX(); + return (x-draw::getOffsetX())/draw::getScaleX(); } // Torna la posició Y actual del ratolí @@ -87,7 +87,7 @@ namespace input { float y; SDL_GetMouseState(NULL, &y); - return y/draw::getScaleY(); + return (y-draw::getOffsetY())/draw::getScaleY(); } // Determina si el botó del ratolí especificat està sent polsada ara mateix