diff --git a/Engine.cc b/Engine.cc index 9fb6744..bd9daef 100644 --- a/Engine.cc +++ b/Engine.cc @@ -496,6 +496,12 @@ int Engine::renderText(const char * text, int mode, Uint8 r, Uint8 g, Uint8 b, return 0; } +void Engine::getScreenSize(int * width, int * height) +{ + *width = m_video.getWidth(); + *height = m_video.getHeight(); +} + /* called by SDL when the update timer expires */ Uint32 Engine::updateCallback(Uint32 interval, void * param) { diff --git a/Engine.h b/Engine.h index 170db2d..85dfee6 100644 --- a/Engine.h +++ b/Engine.h @@ -137,6 +137,7 @@ class Engine void debug_hook(lua_Debug * debug); int renderText(const char * text, int mode, Uint8 r, Uint8 g, Uint8 b, Uint8 br = 0, Uint8 bg = 0, Uint8 bb = 0); + void getScreenSize(int * width, int * height); /* lua services */ int setCamera(lua_State * L); diff --git a/Video.cc b/Video.cc index 138880d..bd7be07 100644 --- a/Video.cc +++ b/Video.cc @@ -29,6 +29,8 @@ Video::Video() m_surface = NULL; m_inputGrabbed = false; + m_width = 0; + m_height = 0; } void Video::start(int width, int height, bool fullscreen, bool grab_input, @@ -58,6 +60,8 @@ void Video::start(int width, int height, bool fullscreen, bool grab_input, } m_inputGrabbed = grab_input; m_fullscreen = fullscreen; + m_width = width; + m_height = height; glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); diff --git a/Video.h b/Video.h index db33b07..3ed6b01 100644 --- a/Video.h +++ b/Video.h @@ -15,10 +15,14 @@ class Video int getDefaultWidth() { return m_defaultWidth; } int getDefaultHeight() { return m_defaultHeight; } void toggleFullScreen() { SDL_WM_ToggleFullScreen(m_surface); } + int getWidth() { return m_width; } + int getHeight() { return m_height; } protected: int m_defaultWidth; int m_defaultHeight; + int m_width; + int m_height; SDL_Surface * m_surface; bool m_fullscreen; bool m_inputGrabbed; diff --git a/ag.cc b/ag.cc index 92d9a77..3451804 100644 --- a/ag.cc +++ b/ag.cc @@ -43,6 +43,7 @@ namespace ag { "exit", exit }, { "import", import }, { "loadTexture", loadTexture }, + { "getScreenSize", getScreenSize }, { "createBox", createBox}, { "createStaticBox", createStaticBox}, @@ -337,6 +338,15 @@ namespace ag return 1; } + int getScreenSize(lua_State * L) + { + int width, height; + g_engine->getScreenSize(&width, &height); + lua_pushinteger(L, width); + lua_pushinteger(L, height); + return 2; + } + static void addManagedObject(lua_State * L, bool is_static, OdeWorld::GeomType geom_type, refptr< vector > args) { diff --git a/ag.h b/ag.h index debf7ac..0a0a633 100644 --- a/ag.h +++ b/ag.h @@ -29,6 +29,7 @@ namespace ag int exit(lua_State * L); int import(lua_State * L); int loadTexture(lua_State * L); + int getScreenSize(lua_State * L); int createBox(lua_State * L); int createStaticBox(lua_State * L);