F1 toggles fullscreen, F2 toggles mouse cursor grabbing

git-svn-id: svn://anubis/anaglym/trunk@113 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-10-20 00:11:58 +00:00
parent 66e8b9c015
commit f8e918526e
4 changed files with 26 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#include "ag.h"
#include "anaglym.h"
#include "Engine.h"
#include "Video.h"
#include "sdl_keymap.h"
#include <lua.hpp>
#include <stdlib.h> /* exit() */
@ -24,7 +25,8 @@ Engine * g_engine;
SDL_Event Engine::userEvent;
Engine::Engine(const string & path)
Engine::Engine(const string & path, Video & video)
: m_video(video)
{
m_next_object_index = 1;
m_eye[0] = 0;
@ -312,11 +314,26 @@ void Engine::run()
switch (event.type)
{
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
goto RET;
}
case SDLK_F1:
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);
break;
default:
key_down_event(event.key.keysym.sym);
}
break;
case SDL_KEYUP:
key_up_event(event.key.keysym.sym);

View File

@ -9,6 +9,7 @@
#include "OdeWorld/OdeWorld.h"
#include "TextureCache/TextureCache.h"
#include "wfobj/WFObj.h"
#include "Video.h"
class Engine
{
@ -78,7 +79,7 @@ class Engine
Engine * m_engine;
};
Engine(const std::string & path);
Engine(const std::string & path, Video & video);
~Engine();
std::string locateResource(const std::string & shortname);
@ -130,6 +131,7 @@ class Engine
void checkForFunctionFull(const std::string & lua_fn_name,
const std::string & event_name, bool & presentFlag);
Video & m_video;
TextureCache m_textureCache;
EngineFileLoader * m_fileLoader;
lua_State * m_luaState;

View File

@ -14,6 +14,7 @@ class Video
void stop();
int getDefaultWidth() { return m_defaultWidth; }
int getDefaultHeight() { return m_defaultHeight; }
void toggleFullScreen() { SDL_WM_ToggleFullScreen(m_surface); }
protected:
int m_defaultWidth;

View File

@ -72,7 +72,7 @@ int main(int argc, char * argv[])
Video video;
video.start(width, height, fullscreen, grab_input);
g_engine = new Engine(argv[0]);
g_engine = new Engine(argv[0], video);
if (g_engine->load(program))
g_engine->run();
delete g_engine;