Added love.window (issue #6.) All window-related functions have been moved from love.graphics to love.window.

love.graphics.setCaption has been renamed to love.window.setTitle.
This commit is contained in:
Alex Szpakowski
2013-05-10 22:32:15 -03:00
parent 13dd8d3199
commit ff77eb4b29
21 changed files with 555 additions and 478 deletions
+13
View File
@@ -112,6 +112,19 @@ public:
virtual ~Graphics();
/**
* Sets the current graphics display viewport and initializes the renderer.
* @param width The viewport width.
* @param height The viewport height.
**/
virtual bool setMode(int width, int height) = 0;
/**
* Un-sets the current graphics display mode (uninitializing objects if
* necessary.)
**/
virtual void unSetMode() = 0;
static bool getConstant(const char *in, DrawMode &out);
static bool getConstant(DrawMode in, const char *&out);
+28 -105
View File
@@ -46,8 +46,15 @@ Graphics::Graphics()
, matrixLimit(0)
, userMatrices(0)
, colorMask()
, width(0)
, height(0)
, created(false)
, savedState()
{
currentWindow = love::window::sdl::Window::getSingleton();
if (currentWindow->isCreated())
setMode(currentWindow->getWidth(), currentWindow->getHeight());
}
Graphics::~Graphics()
@@ -63,11 +70,6 @@ const char *Graphics::getName() const
return "love.graphics.opengl";
}
bool Graphics::checkMode(int width, int height, bool fullscreen) const
{
return currentWindow->checkWindowSize(width, height, fullscreen);
}
DisplayState Graphics::saveState()
{
DisplayState s;
@@ -120,31 +122,14 @@ void Graphics::restoreState(const DisplayState &s)
setColorMask(s.colorMask[0], s.colorMask[1], s.colorMask[2], s.colorMask[3]);
}
static void APIENTRY myErrorCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char *message, void *ud)
bool Graphics::setMode(int width, int height)
{
(void)ud;
std::cerr << "source = " << source << ", type = " << type << ", id = " << id << ", severity = " << severity << ", length = " << length << "\n" << message << std::endl;
}
bool Graphics::setMode(int width, int height, WindowFlags *flags)
{
// This operation destroys the OpenGL context, so
// we must save the state.
DisplayState tempState;
if (isCreated())
tempState = saveState();
savedState = saveState();
// Unload all volatile objects. These must be reloaded after
// the display mode change.
Volatile::unloadAll();
gl.deInitContext();
bool success = currentWindow->setWindow(width, height, flags);
// Regardless of failure, we'll have to set up OpenGL once again.
width = currentWindow->getWidth();
height = currentWindow->getHeight();
this->width = width;
this->height = height;
// Okay, setup OpenGL.
gl.initContext();
@@ -201,7 +186,7 @@ bool Graphics::setMode(int width, int height, WindowFlags *flags)
std::cerr << "Could not reload all volatile objects." << std::endl;
// Restore the display state.
restoreState(tempState);
restoreState(savedState);
pixel_size_stack.clear();
pixel_size_stack.reserve(5);
pixel_size_stack.push_back(1);
@@ -211,30 +196,22 @@ bool Graphics::setMode(int width, int height, WindowFlags *flags)
glGetIntegerv(GL_MAX_MODELVIEW_STACK_DEPTH, &matrixLimit);
matrixLimit -= 5;
// Debug output is temporarily disabled until we either improve it and make
// it optional or remove it.
if (GLEE_KHR_debug && false)
{
std::cerr << "debug on" << std::endl;
glDebugMessageCallback(myErrorCallback, NULL);
glEnable(GL_DEBUG_OUTPUT);
}
created = true;
return success;
return true;
}
void Graphics::getMode(int &width, int &height, WindowFlags &flags) const
void Graphics::unSetMode()
{
currentWindow->getWindow(width, height, flags);
}
// Window creation may destroy the OpenGL context, so we must save the state.
if (isCreated())
savedState = saveState();
bool Graphics::toggleFullscreen()
{
int width, height;
WindowFlags flags;
currentWindow->getWindow(width, height, flags);
flags.fullscreen = !flags.fullscreen;
return setMode(width, height, &flags);
// Unload all volatile objects. These must be reloaded after
// the display mode change.
Volatile::unloadAll();
gl.deInitContext();
}
void Graphics::reset()
@@ -259,39 +236,21 @@ void Graphics::present()
currentWindow->swapBuffers();
}
void Graphics::setIcon(Image *image)
{
if (image->isCompressed())
throw love::Exception("Cannot use compressed image data to set an icon.");
currentWindow->setIcon(image->getData());
}
void Graphics::setCaption(const char *caption)
{
std::string title(caption);
currentWindow->setWindowTitle(title);
}
std::string Graphics::getCaption() const
{
return currentWindow->getWindowTitle();
}
int Graphics::getWidth() const
{
return currentWindow->getWidth();
return width;
}
int Graphics::getHeight() const
{
return currentWindow->getHeight();
return height;
}
int Graphics::getRenderWidth() const
{
if (Canvas::current)
return Canvas::current->getWidth();
return getWidth();
}
@@ -299,44 +258,13 @@ int Graphics::getRenderHeight() const
{
if (Canvas::current)
return Canvas::current->getHeight();
return getHeight();
}
bool Graphics::isCreated() const
{
return currentWindow->isCreated();
}
int Graphics::getModes(lua_State *L) const
{
int n;
love::window::Window::WindowSize *modes = currentWindow->getFullscreenSizes(n);
if (modes == 0)
return 0;
lua_createtable(L, n, 0);
for (int i = 0; i < n ; i++)
{
lua_pushinteger(L, i+1);
lua_createtable(L, 0, 2);
// Inner table attribs.
lua_pushinteger(L, modes[i].width);
lua_setfield(L, -2, "width");
lua_pushinteger(L, modes[i].height);
lua_setfield(L, -2, "height");
// Inner table attribs end.
lua_settable(L, -3);
}
delete[] modes;
return 1;
return created;
}
void Graphics::setScissor(int x, int y, int width, int height)
@@ -1379,11 +1307,6 @@ void Graphics::origin()
pixel_size_stack.push_back(1);
}
bool Graphics::hasFocus() const
{
return currentWindow->hasFocus();
}
} // opengl
} // graphics
} // love
+14 -68
View File
@@ -111,40 +111,12 @@ public:
// Implements Module.
const char *getName() const;
/**
* Checks whether a display mode is supported or not. Note
* that fullscreen is assumed, because windowed modes are
* generally supported regardless of size.
* @param width The window width.
* @param height The window height.
**/
bool checkMode(int width, int height, bool fullscreen) const;
DisplayState saveState();
void restoreState(const DisplayState &s);
/**
* Sets the current display mode.
* @param width The window width.
* @param height The window height.
* @param flags An optional WindowFlags structure.
**/
bool setMode(int width, int height, WindowFlags *flags);
/**
* Gets the current display mode.
* @param width Pointer to an integer for the window width.
* @param height Pointer to an integer for the window height.
* @param flags A WindowFlags structure.
**/
void getMode(int &width, int &height, WindowFlags &flags) const;
/**
* Toggles fullscreen. Note that this also needs to reload the
* entire OpenGL context.
**/
bool toggleFullscreen();
virtual bool setMode(int width, int height);
virtual void unSetMode();
/**
* Resets the current color, background color,
@@ -159,56 +131,25 @@ public:
void clear();
/**
* Flips buffers. (Rendered geometry is
* presented on screen).
* Flips buffers. (Rendered geometry is presented on screen).
**/
void present();
/**
* Sets the window's icon.
**/
void setIcon(Image *image);
/**
* Sets the window's caption.
**/
void setCaption(const char *caption);
/**
* Gets the window's caption.
**/
std::string getCaption() const;
/**
* Gets the width of the current display mode.
* Gets the width of the current graphics viewport.
**/
int getWidth() const;
/**
* Gets the height of the current display mode.
* Gets the height of the current graphics viewport.
**/
int getHeight() const;
/**
* True if some display mode is set.
* True if a graphics viewport is set.
**/
bool isCreated() const;
/**
* This native Lua function gets available modes
* from SDL and returns them as a table on the following format:
*
* {
* { width = 800, height = 600 },
* { width = 1024, height = 768 },
* ...
* }
*
* Only fullscreen modes are returned here, as all
* window sizes are supported (normally).
**/
int getModes(lua_State *L) const;
/**
* Scissor defines a box such that everything outside that box is discarded and not drawn.
* Scissoring is automatically enabled.
@@ -541,9 +482,11 @@ public:
void shear(float kx, float ky);
void origin();
bool hasFocus() const;
private:
int getRenderWidth() const;
int getRenderHeight() const;
Font *currentFont;
love::window::Window *currentWindow;
@@ -554,8 +497,11 @@ private:
GLint userMatrices;
bool colorMask[4];
int getRenderWidth() const;
int getRenderHeight() const;
int width;
int height;
bool created;
DisplayState savedState;
}; // Graphics
+1 -175
View File
@@ -38,105 +38,6 @@ namespace opengl
static Graphics *instance = 0;
bool luax_boolflag(lua_State *L, int table_index, const char *key, bool defaultValue)
{
lua_getfield(L, table_index, key);
bool retval;
if (lua_isnoneornil(L, -1))
retval = defaultValue;
else
retval = lua_toboolean(L, -1);
lua_pop(L, 1);
return retval;
}
int luax_intflag(lua_State *L, int table_index, const char *key, int defaultValue)
{
lua_getfield(L, table_index, key);
int retval;
if (!lua_isnumber(L, -1))
retval = defaultValue;
else
retval = lua_tonumber(L, -1);
lua_pop(L, 1);
return retval;
}
int w_checkMode(lua_State *L)
{
int w = luaL_checkint(L, 1);
int h = luaL_checkint(L, 2);
bool fs = luax_toboolean(L, 3);
luax_pushboolean(L, instance->checkMode(w, h, fs));
return 1;
}
int w_setMode(lua_State *L)
{
int w = luaL_checkint(L, 1);
int h = luaL_checkint(L, 2);
if (lua_isnoneornil(L, 3))
{
luax_pushboolean(L, instance->setMode(w, h, 0));
return 1;
}
luaL_checktype(L, 3, LUA_TTABLE);
WindowFlags flags;
flags.fullscreen = luax_boolflag(L, 3, "fullscreen", false);
flags.vsync = luax_boolflag(L, 3, "vsync", true);
flags.fsaa = luax_intflag(L, 3, "fsaa", 0);
flags.resizable = luax_boolflag(L, 3, "resizable", false);
flags.borderless = luax_boolflag(L, 3, "borderless", false);
flags.centered = luax_boolflag(L, 3, "centered", true);
luax_pushboolean(L, instance->setMode(w, h, &flags));
return 1;
}
int w_getMode(lua_State *L)
{
int w, h;
WindowFlags flags;
instance->getMode(w, h, flags);
lua_pushnumber(L, w);
lua_pushnumber(L, h);
lua_newtable(L);
luax_pushboolean(L, flags.fullscreen);
lua_setfield(L, -2, "fullscreen");
luax_pushboolean(L, flags.vsync);
lua_setfield(L, -2, "vsync");
lua_pushnumber(L, flags.fsaa);
lua_setfield(L, -2, "fsaa");
luax_pushboolean(L, flags.resizable);
lua_setfield(L, -2, "resizable");
luax_pushboolean(L, flags.borderless);
lua_setfield(L, -2, "borderless");
luax_pushboolean(L, flags.centered);
lua_setfield(L, -2, "centered");
return 3;
}
int w_toggleFullscreen(lua_State *L)
{
luax_pushboolean(L, instance->toggleFullscreen());
return 1;
}
int w_reset(lua_State *)
{
instance->reset();
@@ -155,64 +56,12 @@ int w_present(lua_State *)
return 0;
}
int w_setIcon(lua_State *L)
{
Image *image = luax_checkimage(L, 1);
try
{
instance->setIcon(image);
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
return 0;
}
int w_setCaption(lua_State *L)
{
const char *str = luaL_checkstring(L, 1);
instance->setCaption(str);
return 0;
}
int w_getCaption(lua_State *L)
{
std::string caption = instance->getCaption();
lua_pushstring(L, caption.c_str());
return 1;
}
int w_getWidth(lua_State *L)
{
lua_pushnumber(L, instance->getWidth());
return 1;
}
int w_getHeight(lua_State *L)
{
lua_pushnumber(L, instance->getHeight());
return 1;
}
int w_getDimensions(lua_State *L)
{
lua_pushnumber(L, instance->getWidth());
lua_pushnumber(L, instance->getHeight());
return 2;
}
int w_isCreated(lua_State *L)
{
luax_pushboolean(L, instance->isCreated());
return 1;
}
int w_getModes(lua_State *L)
{
return instance->getModes(L);
}
int w_setScissor(lua_State *L)
{
if (lua_gettop(L) == 0)
@@ -1600,20 +1449,10 @@ int w_origin(lua_State * /*L*/)
return 0;
}
int w_hasFocus(lua_State *L)
{
luax_pushboolean(L, instance->hasFocus());
return 1;
}
// List of functions to wrap.
static const luaL_Reg functions[] =
{
{ "checkMode", w_checkMode },
{ "setMode", w_setMode },
{ "getMode", w_getMode },
{ "toggleFullscreen", w_toggleFullscreen },
{ "reset", w_reset },
{ "clear", w_clear },
{ "present", w_present },
@@ -1674,19 +1513,8 @@ static const luaL_Reg functions[] =
{ "print", w_print },
{ "printf", w_printf },
{ "setCaption", w_setCaption },
{ "getCaption", w_getCaption },
{ "setIcon", w_setIcon },
{ "getWidth", w_getWidth },
{ "getHeight", w_getHeight },
{ "getDimensions", w_getDimensions },
{ "isCreated", w_isCreated },
{ "getModes", w_getModes },
{ "setScissor", w_setScissor },
{ "getScissor", w_getScissor },
@@ -1712,8 +1540,6 @@ static const luaL_Reg functions[] =
{ "shear", w_shear },
{ "origin", w_origin },
{ "hasFocus", w_hasFocus },
{ 0, 0 }
};
@@ -1749,7 +1575,7 @@ extern "C" int luaopen_love_graphics(lua_State *L)
WrappedModule w;
w.module = instance;
w.name = "graphics";
w.flags = MODULE_T;
w.flags = MODULE_GRAPHICS_T;
w.functions = functions;
w.types = types;
@@ -38,19 +38,9 @@ namespace graphics
namespace opengl
{
int w_checkMode(lua_State *L);
int w_setMode(lua_State *L);
int w_getMode(lua_State *L);
int w_toggleFullscreen(lua_State *L);
int w_reset(lua_State *L);
int w_clear(lua_State *L);
int w_present(lua_State *L);
int w_setIcon(lua_State *L);
int w_setCaption(lua_State *L);
int w_getCaption(lua_State *L);
int w_getWidth(lua_State *L);
int w_getHeight(lua_State *L);
int w_getDimensions(lua_State *L);
int w_isCreated(lua_State *L);
int w_setScissor(lua_State *L);
int w_getScissor(lua_State *L);
@@ -115,7 +105,6 @@ int w_scale(lua_State *L);
int w_translate(lua_State *L);
int w_shear(lua_State *L);
int w_origin(lua_State *L);
int w_hasFocus(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_graphics(lua_State *L);
} // opengl
+3 -1
View File
@@ -98,12 +98,13 @@ extern "C"
extern int luaopen_love_image(lua_State*);
extern int luaopen_love_joystick(lua_State*);
extern int luaopen_love_keyboard(lua_State*);
extern int luaopen_love_math(lua_State*);
extern int luaopen_love_mouse(lua_State*);
extern int luaopen_love_physics(lua_State*);
extern int luaopen_love_sound(lua_State*);
extern int luaopen_love_timer(lua_State*);
extern int luaopen_love_thread(lua_State*);
extern int luaopen_love_math(lua_State*);
extern int luaopen_love_window(lua_State*);
extern int luaopen_love_boot(lua_State*);
}
@@ -122,6 +123,7 @@ static const luaL_Reg modules[] = {
{ "love.sound", luaopen_love_sound },
{ "love.timer", luaopen_love_timer },
{ "love.thread", luaopen_love_thread },
{ "love.window", luaopen_love_window },
{ "love.boot", luaopen_love_boot },
{ 0, 0 }
};
+5 -5
View File
@@ -66,7 +66,7 @@ Timer::Timer()
, fpsUpdateFrequency(1)
, frames(0)
, dt(0)
, timerFrequency(getTimerFrequency())
, timerPeriod(getTimerPeriod())
{
// Init the SDL timer system (needed for SDL_Delay.)
if (SDL_InitSubSystem(SDL_INIT_TIMER) < 0)
@@ -94,7 +94,7 @@ void Timer::step()
// "Current" time is previous time by now.
prevTime = currTime;
// Get ticks from system.
// Get time from system.
currTime = getTime();
// Convert to number of seconds.
@@ -132,7 +132,7 @@ double Timer::getAverageDelta() const
return averageDelta;
}
double Timer::getTimerFrequency()
double Timer::getTimerPeriod()
{
#if defined(LOVE_MACOSX)
mach_timebase_info_data_t info;
@@ -166,11 +166,11 @@ double Timer::getTime() const
mt = getTimeOfDay();
return mt;
#elif defined(LOVE_MACOSX)
return (double) mach_absolute_time() * timerFrequency;
return (double) mach_absolute_time() * timerPeriod;
#elif defined(LOVE_WINDOWS)
LARGE_INTEGER microTime;
QueryPerformanceCounter(&microTime);
return (double) microTime.QuadPart * timerFrequency;
return (double) microTime.QuadPart * timerPeriod;
#endif
}
+4 -4
View File
@@ -77,11 +77,11 @@ private:
// The current timestep.
double dt;
// The reciprocal of the timer frequency.
const double timerFrequency;
// The timer period (reciprocal of the frequency.)
const double timerPeriod;
// Returns the timer frequency on some platforms.
static double getTimerFrequency();
// Returns the timer period on some platforms.
static double getTimerPeriod();
}; // Timer
+4 -4
View File
@@ -46,7 +46,7 @@ int w_getDelta(lua_State *L)
int w_getFPS(lua_State *L)
{
lua_pushnumber(L, instance->getFPS());
lua_pushinteger(L, instance->getFPS());
return 1;
}
@@ -58,7 +58,7 @@ int w_getAverageDelta(lua_State *L)
int w_sleep(lua_State *L)
{
instance->sleep((float) luaL_checknumber(L, 1));
instance->sleep(luaL_checknumber(L, 1));
return 0;
}
@@ -90,9 +90,9 @@ extern "C" int luaopen_love_timer(lua_State *L)
instance = new love::timer::sdl::Timer();
}
catch(Exception &e)
catch (Exception &e)
{
return luaL_error(L, e.what());
return luaL_error(L, "%s", e.what());
}
}
else
+3 -2
View File
@@ -26,7 +26,8 @@
// LOVE
#include "common/Module.h"
#include <image/ImageData.h>
#include "image/ImageData.h"
#include "graphics/Graphics.h"
namespace love
{
@@ -55,7 +56,7 @@ public:
virtual ~Window();
virtual bool setWindow(int width = 800, int height = 600, WindowFlags *flags = 0) = 0;
virtual bool setWindow(int width = 800, int height = 600, graphics::Graphics *graphics = 0, WindowFlags *flags = 0) = 0;
virtual void getWindow(int &width, int &height, WindowFlags &flags) const = 0;
virtual bool checkWindowSize(int width, int height, bool fullscreen) const = 0;
+8 -1
View File
@@ -55,8 +55,12 @@ Window::_currentMode::_currentMode()
{
}
bool Window::setWindow(int width, int height, WindowFlags *flags)
bool Window::setWindow(int width, int height, graphics::Graphics *graphics, WindowFlags *flags)
{
if (graphics)
graphics->unSetMode();
bool fullscreen = false;
bool vsync = true;
int fsaa = 0;
@@ -186,6 +190,9 @@ bool Window::setWindow(int width, int height, WindowFlags *flags)
currentMode.flags.borderless = ((surface->flags & SDL_NOFRAME) != 0);
currentMode.flags.centered = centered;
if (graphics)
graphics->setMode(width, height);
return true;
}
+1 -1
View File
@@ -38,7 +38,7 @@ public:
Window();
~Window();
bool setWindow(int width = 800, int height = 600, WindowFlags *flags = 0);
bool setWindow(int width = 800, int height = 600, graphics::Graphics *graphics = 0, WindowFlags *flags = 0);
void getWindow(int &width, int &height, WindowFlags &flags) const;
bool checkWindowSize(int width, int height, bool fullscreen) const;
+251
View File
@@ -0,0 +1,251 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "wrap_Window.h"
#include "sdl/Window.h"
namespace love
{
namespace window
{
static Window *instance = 0;
int w_checkMode(lua_State *L)
{
int w = luaL_checkint(L, 1);
int h = luaL_checkint(L, 2);
bool fs = luax_toboolean(L, 3);
luax_pushboolean(L, instance->checkWindowSize(w, h, fs));
return 1;
}
int w_setMode(lua_State *L)
{
int w = luaL_checkint(L, 1);
int h = luaL_checkint(L, 2);
graphics::Graphics *g = luax_optmodule<graphics::Graphics>(L, "graphics", MODULE_GRAPHICS_T);
if (lua_isnoneornil(L, 3))
{
luax_pushboolean(L, instance->setWindow(w, h, g, 0));
return 1;
}
luaL_checktype(L, 3, LUA_TTABLE);
WindowFlags flags;
flags.fullscreen = luax_boolflag(L, 3, "fullscreen", false);
flags.vsync = luax_boolflag(L, 3, "vsync", true);
flags.fsaa = luax_intflag(L, 3, "fsaa", 0);
flags.resizable = luax_boolflag(L, 3, "resizable", false);
flags.borderless = luax_boolflag(L, 3, "borderless", false);
flags.centered = luax_boolflag(L, 3, "centered", true);
try
{
luax_pushboolean(L, instance->setWindow(w, h, g, &flags));
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
return 1;
}
int w_getMode(lua_State *L)
{
int w, h;
WindowFlags flags;
instance->getWindow(w, h, flags);
lua_pushnumber(L, w);
lua_pushnumber(L, h);
lua_newtable(L);
luax_pushboolean(L, flags.fullscreen);
lua_setfield(L, -2, "fullscreen");
luax_pushboolean(L, flags.vsync);
lua_setfield(L, -2, "vsync");
lua_pushnumber(L, flags.fsaa);
lua_setfield(L, -2, "fsaa");
luax_pushboolean(L, flags.resizable);
lua_setfield(L, -2, "resizable");
luax_pushboolean(L, flags.borderless);
lua_setfield(L, -2, "borderless");
luax_pushboolean(L, flags.centered);
lua_setfield(L, -2, "centered");
return 3;
}
int w_getModes(lua_State *L)
{
int n;
Window::WindowSize *modes = instance->getFullscreenSizes(n);
if (modes == 0)
return 0;
lua_createtable(L, n, 0);
for (int i = 0; i < n ; i++)
{
lua_pushinteger(L, i+1);
lua_createtable(L, 0, 2);
// Inner table attribs.
lua_pushinteger(L, modes[i].width);
lua_setfield(L, -2, "width");
lua_pushinteger(L, modes[i].height);
lua_setfield(L, -2, "height");
// Inner table attribs end.
lua_settable(L, -3);
}
delete[] modes;
return 1;
}
int w_toggleFullscreen(lua_State *L)
{
graphics::Graphics *g = luax_optmodule<graphics::Graphics>(L, "graphics", MODULE_GRAPHICS_T);
int width, height;
WindowFlags flags;
instance->getWindow(width, height, flags);
flags.fullscreen = !flags.fullscreen;
try
{
luax_pushboolean(L, instance->setWindow(width, height, g, &flags));
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
return 1;
}
int w_isCreated(lua_State *L)
{
luax_pushboolean(L, instance->isCreated());
return 1;
}
int w_getWidth(lua_State *L)
{
lua_pushinteger(L, instance->getWidth());
return 1;
}
int w_getHeight(lua_State *L)
{
lua_pushinteger(L, instance->getHeight());
return 1;
}
int w_getDimensions(lua_State *L)
{
lua_pushinteger(L, instance->getWidth());
lua_pushinteger(L, instance->getHeight());
return 2;
}
int w_setIcon(lua_State *L)
{
image::ImageData *i = luax_checktype<image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
instance->setIcon(i);
return 0;
}
int w_setTitle(lua_State *L)
{
std::string title = luax_checkstring(L, 1);
instance->setWindowTitle(title);
return 0;
}
int w_getTitle(lua_State *L)
{
luax_pushstring(L, instance->getWindowTitle());
return 1;
}
int w_hasFocus(lua_State *L)
{
luax_pushboolean(L, instance->hasFocus());
return 1;
}
static const luaL_Reg functions[] =
{
{ "checkMode", w_checkMode },
{ "setMode", w_setMode },
{ "getMode", w_getMode },
{ "getModes", w_getModes },
{ "toggleFullscreen", w_toggleFullscreen },
{ "isCreated", w_isCreated },
{ "getWidth", w_getWidth },
{ "getHeight", w_getHeight },
{ "getDimensions", w_getDimensions },
{ "setIcon", w_setIcon },
{ "setTitle", w_setTitle },
{ "getTitle", w_getTitle },
{ "hasFocus", w_hasFocus },
{ 0, 0 }
};
extern "C" int luaopen_love_window(lua_State *L)
{
try
{
instance = sdl::Window::getSingleton();
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
WrappedModule w;
w.module = instance;
w.name = "window";
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
return luax_register_module(L, w);
}
} // window
} // love
+50
View File
@@ -0,0 +1,50 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_WINDOW_WRAP_WINDOW_H
#define LOVE_WINDOW_WRAP_WINDOW_H
#include "common/config.h"
#include "common/runtime.h"
namespace love
{
namespace window
{
int w_checkMode(lua_State *L);
int w_setMode(lua_State *L);
int w_getMode(lua_State *L);
int w_getModes(lua_State *L);
int w_toggleFullscreen(lua_State *L);
int w_isCreated(lua_State *L);
int w_getWidth(lua_State *L);
int w_getHeight(lua_State *L);
int w_getDimensions(lua_State *L);
int w_setIcon(lua_State *L);
int w_setTitle(lua_State *L);
int w_getTitle(lua_State *L);
int w_hasFocus(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_window(lua_State *L);
} // window
} // love
#endif // LOVE_WINDOW_WRAP_WINDOW_H