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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user