Merged default into minor

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2014-09-28 15:56:04 -03:00
26 changed files with 271 additions and 282 deletions
+6 -1
View File
@@ -83,6 +83,11 @@ public:
{
int width;
int height;
bool operator == (const WindowSize &w) const
{
return w.width == width && w.height == height;
}
};
struct MessageBoxData
@@ -156,7 +161,7 @@ public:
virtual const void *getHandle() const = 0;
virtual bool showMessageBox(MessageBoxType type, const std::string &title, const std::string &message, bool attachtowindow) = 0;
virtual bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow) = 0;
virtual int showMessageBox(const MessageBoxData &data) = 0;
//virtual static Window *createSingleton() = 0;
+5 -17
View File
@@ -497,29 +497,17 @@ std::vector<WindowSize> Window::getFullscreenSizes(int displayindex) const
{
std::vector<WindowSize> sizes;
SDL_DisplayMode mode = {};
std::vector<WindowSize>::const_iterator it;
for (int i = 0; i < SDL_GetNumDisplayModes(displayindex); i++)
{
SDL_DisplayMode mode = {};
SDL_GetDisplayMode(displayindex, i, &mode);
WindowSize w = {mode.w, mode.h};
// SDL2's display mode list has multiple entries for modes of the same
// size with different bits per pixel, so we need to filter those out.
bool alreadyhassize = false;
for (it = sizes.begin(); it != sizes.end(); ++it)
{
if (it->width == mode.w && it->height == mode.h)
{
alreadyhassize = true;
break;
}
}
if (!alreadyhassize)
{
WindowSize w = {mode.w, mode.h};
if (std::find(sizes.begin(), sizes.end(), w) == sizes.end())
sizes.push_back(w);
}
}
return sizes;
@@ -767,7 +755,7 @@ SDL_MessageBoxFlags Window::convertMessageBoxType(MessageBoxType type) const
}
}
bool Window::showMessageBox(MessageBoxType type, const std::string &title, const std::string &message, bool attachtowindow)
bool Window::showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow)
{
SDL_MessageBoxFlags flags = convertMessageBoxType(type);
SDL_Window *sdlwindow = attachtowindow ? window : nullptr;
+1 -1
View File
@@ -92,7 +92,7 @@ public:
const void *getHandle() const;
bool showMessageBox(MessageBoxType type, const std::string &title, const std::string &message, bool attachtowindow);
bool showMessageBox(const std::string &title, const std::string &message, MessageBoxType type, bool attachtowindow);
int showMessageBox(const MessageBoxData &data);
static love::window::Window *createSingleton();
+17 -12
View File
@@ -395,32 +395,29 @@ int w_minimize(lua_State* /*L*/)
int w_showMessageBox(lua_State *L)
{
Window::MessageBoxData data = {};
data.type = Window::MESSAGEBOX_INFO;
const char *typestr = luaL_checkstring(L, 1);
if (!Window::getConstant(typestr, data.type))
return luaL_error(L, "Invalid messagebox type: %s", typestr);
data.title = luaL_checkstring(L, 2);
data.message = luaL_checkstring(L, 3);
data.title = luaL_checkstring(L, 1);
data.message = luaL_checkstring(L, 2);
// If we have a table argument, we assume a list of button names, which
// means we should use the more complex message box API.
if (lua_istable(L, 4))
if (lua_istable(L, 3))
{
size_t numbuttons = lua_objlen(L, 4);
size_t numbuttons = lua_objlen(L, 3);
if (numbuttons == 0)
return luaL_error(L, "Must have at least one messagebox button.");
// Array of button names.
for (size_t i = 0; i < numbuttons; i++)
{
lua_rawgeti(L, 4, i + 1);
lua_rawgeti(L, 3, i + 1);
data.buttons.push_back(luax_checkstring(L, -1));
lua_pop(L, 1);
}
// Optional table entry specifying the button to use when enter is pressed.
lua_getfield(L, 4, "enterbutton");
lua_getfield(L, 3, "enterbutton");
if (!lua_isnoneornil(L, -1))
data.enterButtonIndex = luaL_checkint(L, -1) - 1;
else
@@ -428,13 +425,17 @@ int w_showMessageBox(lua_State *L)
lua_pop(L, 1);
// Optional table entry specifying the button to use when esc is pressed.
lua_getfield(L, 4, "escapebutton");
lua_getfield(L, 3, "escapebutton");
if (!lua_isnoneornil(L, -1))
data.escapeButtonIndex = luaL_checkint(L, -1) - 1;
else
data.escapeButtonIndex = (int) data.buttons.size() - 1;
lua_pop(L, 1);
const char *typestr = lua_isnoneornil(L, 4) ? nullptr : luaL_checkstring(L, 4);
if (typestr && !Window::getConstant(typestr, data.type))
return luaL_error(L, "Invalid messagebox type: %s", typestr);
data.attachToWindow = luax_optboolean(L, 5, true);
int pressedbutton = instance()->showMessageBox(data);
@@ -442,10 +443,14 @@ int w_showMessageBox(lua_State *L)
}
else
{
const char *typestr = lua_isnoneornil(L, 3) ? nullptr : luaL_checkstring(L, 3);
if (typestr && !Window::getConstant(typestr, data.type))
return luaL_error(L, "Invalid messagebox type: %s", typestr);
data.attachToWindow = luax_optboolean(L, 4, true);
// Display a simple message box.
bool success = instance()->showMessageBox(data.type, data.title, data.message, data.attachToWindow);
bool success = instance()->showMessageBox(data.title, data.message, data.type, data.attachToWindow);
luax_pushboolean(L, success);
}