forked from jaildesigner-jailgames/jaildoctors_dilemma
Afegit globalEvents
This commit is contained in:
33
source/mouse.cpp
Normal file
33
source/mouse.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "mouse.h"
|
||||
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
||||
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||
|
||||
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
|
||||
|
||||
void handleEvent(const SDL_Event &event)
|
||||
{
|
||||
if (event.type == SDL_MOUSEMOTION)
|
||||
{
|
||||
last_mouse_move_time = SDL_GetTicks();
|
||||
if (!cursor_visible)
|
||||
{
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
cursor_visible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateCursorVisibility()
|
||||
{
|
||||
Uint32 current_time = SDL_GetTicks();
|
||||
if (cursor_visible && (current_time - last_mouse_move_time > cursor_hide_time))
|
||||
{
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
cursor_visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user