From 4daec02c3174efa387df06b98f43ccc45394bd65 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 17 Feb 2010 04:16:29 +0000 Subject: [PATCH] reworked cursor visibility and input grabbed control git-svn-id: svn://anubis/anaglym/trunk@247 99a6e188-d820-4881-8870-2d33a10e2619 --- Engine.cc | 15 +++++++-------- Engine.h | 8 ++++++++ Video.cc | 2 -- Video.h | 17 ++++++++++++++++- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Engine.cc b/Engine.cc index 6ad9b5d..2b44f52 100644 --- a/Engine.cc +++ b/Engine.cc @@ -96,6 +96,9 @@ Engine::Engine(const string & path, Video & video) m_fileLoader = new EngineFileLoader(this); m_event_time = 0; m_font = NULL; + m_engine_cursor_visible = m_video.getCursorVisible(); + m_script_cursor_visible = false; + m_input_grabbed = m_video.getInputGrabbed(); size_t pos = path.find_last_of("\\/"); m_engine_path = (pos != string::npos) ? string(path, 0, pos) : "."; @@ -826,14 +829,10 @@ void Engine::run() m_video.toggleFullScreen(); break; case SDLK_F2: - SDL_ShowCursor( - SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE - ? SDL_DISABLE - : SDL_ENABLE); - SDL_WM_GrabInput( - SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON - ? SDL_GRAB_OFF - : SDL_GRAB_ON); + m_engine_cursor_visible = !m_engine_cursor_visible; + m_input_grabbed = !m_input_grabbed; + updateCursorVisibility(); + m_video.setInputGrabbed(m_input_grabbed); break; case SDLK_F5: reloadProgram(); diff --git a/Engine.h b/Engine.h index e0679cc..700b2bb 100644 --- a/Engine.h +++ b/Engine.h @@ -233,8 +233,16 @@ class Engine const std::string & event_name, bool & presentFlag); void reloadProgram(); void checkForAllHandlerFunctions(); + void updateCursorVisibility() + { + m_video.setCursorVisible( + m_engine_cursor_visible || m_script_cursor_visible); + } Video & m_video; + bool m_engine_cursor_visible; + bool m_script_cursor_visible; + bool m_input_grabbed; TextureCache m_textureCache; EngineFileLoader * m_fileLoader; lua_State * m_luaState; diff --git a/Video.cc b/Video.cc index 371f678..d8f67ac 100644 --- a/Video.cc +++ b/Video.cc @@ -28,7 +28,6 @@ Video::Video() } m_surface = NULL; - m_inputGrabbed = false; m_width = 0; m_height = 0; } @@ -59,7 +58,6 @@ void Video::start(int width, int height, bool fullscreen, bool grab_input, SDL_WM_GrabInput(SDL_GRAB_ON); } SDL_WM_SetCaption("Anaglym", "Anaglym"); - m_inputGrabbed = grab_input; m_fullscreen = fullscreen; m_width = width; m_height = height; diff --git a/Video.h b/Video.h index 0638d81..0efc275 100644 --- a/Video.h +++ b/Video.h @@ -18,6 +18,22 @@ class Video int getWidth() { return m_width; } int getHeight() { return m_height; } SDL_Surface * getSurface() { return m_surface; } + void setCursorVisible(bool visible) + { + SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE); + } + bool getCursorVisible() + { + return SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE; + } + void setInputGrabbed(bool grabbed) + { + SDL_WM_GrabInput(grabbed ? SDL_GRAB_ON : SDL_GRAB_OFF); + } + bool getInputGrabbed() + { + return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON; + } protected: int m_defaultWidth; @@ -26,7 +42,6 @@ class Video int m_height; SDL_Surface * m_surface; bool m_fullscreen; - bool m_inputGrabbed; }; #endif