Use a flags table for setMode now, implement resizable and borderless windows, and add resize event

Example setMode invocation: love.graphics.setMode(800, 600, {fullscreen = false, vsync = true, borderless = true})
t.screen.resizable and t.screen.borderless are available in love.conf
And love.resize(w, h) gets called if it exists on a resize event.
NOTE: love.handlers.resize(w, h) does the required setMode, but that does mean a visual reload

--HG--
branch : minor
This commit is contained in:
Bart van Strien
2012-07-23 11:53:13 +02:00
parent 787bb868a1
commit bddee1753b
9 changed files with 185 additions and 48 deletions
+11 -8
View File
@@ -30,6 +30,8 @@
#include <algorithm>
#include <iterator>
using love::window::WindowFlags;
namespace love
{
namespace graphics
@@ -105,7 +107,7 @@ void Graphics::restoreState(const DisplayState &s)
setScissor();
}
bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int fsaa)
bool Graphics::setMode(int width, int height, WindowFlags *flags)
{
// This operation destroys the OpenGL context, so
// we must save the state.
@@ -117,7 +119,7 @@ bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int f
// the display mode change.
Volatile::unloadAll();
bool success = currentWindow->setWindow(width, height, fullscreen, vsync, fsaa);
bool success = currentWindow->setWindow(width, height, flags);
// Regardless of failure, we'll have to set up OpenGL once again.
width = currentWindow->getWidth();
@@ -171,17 +173,18 @@ bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int f
return success;
}
void Graphics::getMode(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa)
void Graphics::getMode(int &width, int &height, WindowFlags &flags)
{
currentWindow->getWindow(width, height, fullscreen, vsync, fsaa);
currentWindow->getWindow(width, height, flags);
}
bool Graphics::toggleFullscreen()
{
int width, height, fsaa;
bool fullscreen, vsync;
currentWindow->getWindow(width, height, fullscreen, vsync, fsaa);
return setMode(width, height, !fullscreen, vsync, fsaa);
int width, height;
WindowFlags flags;
currentWindow->getWindow(width, height, flags);
flags.fullscreen = !flags.fullscreen;
return setMode(width, height, &flags);
}
+6 -8
View File
@@ -46,6 +46,8 @@
#include "Canvas.h"
#include "PixelEffect.h"
using love::window::WindowFlags;
namespace love
{
namespace graphics
@@ -128,21 +130,17 @@ public:
* Sets the current display mode.
* @param width The window width.
* @param height The window height.
* @param fullscreen True if fullscreen, false otherwise.
* @param vsync True if we should wait for vsync, false otherwise.
* @param fsaa Number of full scene anti-aliasing buffer, or 0 for disabled.
* @param flags An optional WindowFlags structure.
**/
bool setMode(int width, int height, bool fullscreen, bool vsync, int fsaa);
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 fullscreen Pointer to a boolean for the fullscreen status.
* @param vsync Pointer to a boolean for the vsync status.
* @param fsaa Pointer to an integer for the current number of full scene anti-aliasing buffers.
* @param flags A WindowFlags structure.
**/
void getMode(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa);
void getMode(int &width, int &height, WindowFlags &flags);
/**
* Toggles fullscreen. Note that this also needs to reload the
+69 -11
View File
@@ -27,6 +27,8 @@
#include "scripts/graphics.lua.h"
#include <cassert>
using love::window::WindowFlags;
namespace love
{
namespace graphics
@@ -36,6 +38,34 @@ 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);
@@ -49,24 +79,52 @@ int w_setMode(lua_State *L)
{
int w = luaL_checkint(L, 1);
int h = luaL_checkint(L, 2);
bool fs = luax_optboolean(L, 3, false);
bool vsync = luax_optboolean(L, 4, true);
int fsaa = luaL_optint(L, 5, 0);
luax_pushboolean(L, instance->setMode(w, h, fs, vsync, fsaa));
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);
luax_pushboolean(L, instance->setMode(w, h, &flags));
return 1;
}
int w_getMode(lua_State *L)
{
int w, h, fsaa;
bool fs, vsync;
instance->getMode(w, h, fs, vsync, fsaa);
int w, h;
WindowFlags flags;
instance->getMode(w, h, flags);
lua_pushnumber(L, w);
lua_pushnumber(L, h);
lua_pushboolean(L, fs);
lua_pushboolean(L, vsync);
lua_pushnumber(L, fsaa);
return 5;
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");
return 3;
}
int w_toggleFullscreen(lua_State *L)