amagat el cursor d'inici en mode finestra
This commit is contained in:
@@ -1,15 +1,32 @@
|
||||
#include "core/input/mouse.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace Mouse {
|
||||
Uint32 cursor_hide_time = 3000; // Tiempo en milisegundos para ocultar el cursor
|
||||
Uint32 last_mouse_move_time = 0; // Última vez que el ratón se movió
|
||||
bool cursor_visible = true; // Estado del cursor
|
||||
bool cursor_visible = false; // Estado del cursor (inicia ocult)
|
||||
|
||||
// Modo forzado: Usado cuando SDLManager entra en pantalla completa.
|
||||
// Cuando está activado, el cursor permanece oculto independientemente del movimiento del ratón.
|
||||
// SDLManager controla esto mediante llamadas a setForceHidden().
|
||||
bool force_hidden = false;
|
||||
|
||||
// Temps d'inicialització per ignorar esdeveniments fantasma de SDL
|
||||
Uint32 initialization_time = 0;
|
||||
constexpr Uint32 IGNORE_MOTION_DURATION = 1000; // Ignorar primers 1000ms
|
||||
|
||||
void forceHide() {
|
||||
// Forçar ocultació sincronitzant estat SDL i estat intern
|
||||
std::cout << "[Mouse::forceHide] Ocultant cursor i sincronitzant estat. cursor_visible=" << cursor_visible
|
||||
<< " -> false" << std::endl;
|
||||
SDL_HideCursor();
|
||||
cursor_visible = false;
|
||||
last_mouse_move_time = 0;
|
||||
initialization_time = SDL_GetTicks(); // Marcar temps per ignorar esdeveniments inicials
|
||||
std::cout << "[Mouse::forceHide] Ignorant moviments durant " << IGNORE_MOTION_DURATION << "ms" << std::endl;
|
||||
}
|
||||
|
||||
void setForceHidden(bool force) {
|
||||
force_hidden = force;
|
||||
|
||||
@@ -39,8 +56,18 @@ void handleEvent(const SDL_Event& event) {
|
||||
|
||||
// MODO NORMAL: Mostrar cursor al mover el ratón
|
||||
if (event.type == SDL_EVENT_MOUSE_MOTION) {
|
||||
last_mouse_move_time = SDL_GetTicks();
|
||||
Uint32 current_time = SDL_GetTicks();
|
||||
|
||||
// Ignorar esdeveniments fantasma de SDL durant el període inicial
|
||||
if (initialization_time > 0 && (current_time - initialization_time < IGNORE_MOTION_DURATION)) {
|
||||
std::cout << "[Mouse::handleEvent] Ignorant moviment fantasma de SDL. time=" << current_time
|
||||
<< " (inicialització fa " << (current_time - initialization_time) << "ms)" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
last_mouse_move_time = current_time;
|
||||
if (!cursor_visible) {
|
||||
std::cout << "[Mouse::handleEvent] Mostrant cursor per moviment REAL. time=" << last_mouse_move_time << std::endl;
|
||||
SDL_ShowCursor();
|
||||
cursor_visible = true;
|
||||
}
|
||||
@@ -56,6 +83,8 @@ void updateCursorVisibility() {
|
||||
// MODO NORMAL: Auto-ocultar basado en timeout
|
||||
Uint32 current_time = SDL_GetTicks();
|
||||
if (cursor_visible && (current_time - last_mouse_move_time > cursor_hide_time)) {
|
||||
std::cout << "[Mouse::updateCursorVisibility] Ocultant cursor per timeout. current=" << current_time
|
||||
<< " last=" << last_mouse_move_time << " diff=" << (current_time - last_mouse_move_time) << std::endl;
|
||||
SDL_HideCursor();
|
||||
cursor_visible = false;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ extern Uint32 cursor_hide_time; // Tiempo en milisegundos para ocultar el c
|
||||
extern Uint32 last_mouse_move_time; // Última vez que el ratón se movió
|
||||
extern bool cursor_visible; // Estado del cursor
|
||||
|
||||
void forceHide(); // Forçar ocultació del cursor (sincronitza estat intern)
|
||||
void handleEvent(const SDL_Event& event);
|
||||
void updateCursorVisibility();
|
||||
|
||||
|
||||
@@ -141,6 +141,12 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
|
||||
// Configurar viewport scaling
|
||||
updateLogicalPresentation();
|
||||
|
||||
// Inicialitzar sistema de cursor
|
||||
// En fullscreen: forzar ocultació permanent
|
||||
if (is_fullscreen_) {
|
||||
Mouse::setForceHidden(true);
|
||||
}
|
||||
|
||||
std::cout << "SDL3 inicialitzat: " << current_width_ << "x" << current_height_
|
||||
<< " (logic: " << Defaults::Game::WIDTH << "x"
|
||||
<< Defaults::Game::HEIGHT << ")";
|
||||
@@ -148,9 +154,6 @@ SDLManager::SDLManager(int width, int height, bool fullscreen)
|
||||
std::cout << " [FULLSCREEN]";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
// Inicialitzar mòdul Mouse amb l'estat actual de fullscreen
|
||||
Mouse::setForceHidden(is_fullscreen_);
|
||||
}
|
||||
|
||||
SDLManager::~SDLManager() {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "core/audio/audio_cache.hpp"
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/input/input.hpp"
|
||||
#include "core/input/mouse.hpp"
|
||||
#include "core/rendering/sdl_manager.hpp"
|
||||
#include "core/resources/resource_helper.hpp"
|
||||
#include "core/resources/resource_loader.hpp"
|
||||
@@ -217,6 +218,12 @@ auto Director::run() -> int {
|
||||
// Crear gestor SDL amb configuració de Options
|
||||
SDLManager sdl(initial_width, initial_height, Options::window.fullscreen);
|
||||
|
||||
// CRÍTIC: Forçar ocultació del cursor DESPRÉS de tota la inicialització SDL
|
||||
// Això evita que SDL mostre el cursor automàticament durant la creació de la finestra
|
||||
if (!Options::window.fullscreen) {
|
||||
Mouse::forceHide();
|
||||
}
|
||||
|
||||
// Inicialitzar sistema d'audio
|
||||
Audio::init();
|
||||
Audio::get()->setMusicVolume(1.0);
|
||||
|
||||
@@ -62,6 +62,12 @@ EscenaLogo::EscenaLogo(SDLManager& sdl, ContextEscenes& context)
|
||||
inicialitzar_lletres();
|
||||
}
|
||||
|
||||
EscenaLogo::~EscenaLogo() {
|
||||
// Aturar tots els sons i la música
|
||||
Audio::get()->stopAllSounds();
|
||||
std::cout << "Escena Logo: Sons aturats\n";
|
||||
}
|
||||
|
||||
void EscenaLogo::executar() {
|
||||
SDL_Event event;
|
||||
Uint64 last_time = SDL_GetTicks();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
class EscenaLogo {
|
||||
public:
|
||||
explicit EscenaLogo(SDLManager& sdl, GestorEscenes::ContextEscenes& context);
|
||||
~EscenaLogo(); // Destructor per aturar sons
|
||||
void executar(); // Bucle principal de l'escena
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user