Unverified Commit 20f9acf2 authored by RobLoach's avatar RobLoach
Browse files

Add lutro.window.showMessageBox

parent e751294b
......@@ -967,7 +967,6 @@ static int gfx_print(lua_State *L)
if (canvas->font == NULL)
return luaL_error(L, "lutro.graphics.print requires a font to be set.");
const char* message = luaL_checkstring(L, 1);
int dest_x = luaL_checknumber(L, 2);
int dest_y = luaL_checknumber(L, 3);
......
......@@ -127,6 +127,7 @@ void retro_set_environment(retro_environment_t cb)
{
struct retro_vfs_interface_info vfs_iface_info = { 1, NULL };
environ_cb = cb;
settings.environ_cb = &environ_cb;
bool no_rom = false;
cb(RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME, &no_rom);
......
......@@ -29,6 +29,7 @@ typedef struct lutro_settings_t {
double deltaCounter;
int frameCounter;
int fps;
retro_environment_t* environ_cb;
} lutro_settings_t;
extern lutro_settings_t settings;
......
function lutro.keyboard.setBackgroundColorTest()
red = 115
green = 27
blue = 135
alpha = 50
color = { red, green, blue, alpha }
lutro.graphics.setBackgroundColor(color)
lutro.graphics.setBackgroundColor(red, green, blue, alpha)
end
function lutro.keyboard.getBackgroundColorTest()
r, g, b, a = lutro.graphics.getBackgroundColor()
unit.assertEquals(r, 115)
unit.assertEquals(g, 27)
unit.assertEquals(b, 135)
unit.assertEquals(a, 50)
end
return {
lutro.keyboard.setBackgroundColorTest,
lutro.keyboard.getBackgroundColorTest
}
\ No newline at end of file
......@@ -50,6 +50,11 @@ function lutro.window.setDisplaySleepEnabledTest()
lutro.window.setDisplaySleepEnabled(true)
end
function lutro.window.showMessageBoxTest()
success = lutro.window.showMessageBox("Title", "lutro.window.showMessageBoxTest() has been run.", "info", true)
unit.assertEquals(success, true)
end
return {
lutro.window.minimizeTest,
lutro.window.maximizeTest,
......@@ -59,5 +64,6 @@ return {
lutro.window.getPositionTest,
lutro.window.requestAttentionTest,
lutro.window.getDisplayNameTest,
lutro.window.setDisplaySleepEnabledTest
lutro.window.setDisplaySleepEnabledTest,
lutro.window.showMessageBoxTest
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ unit = require 'luaunit'
function runTests()
local moduleTests = {
require 'modules/filesystem',
require 'modules/graphics',
require 'modules/keyboard',
require 'modules/math',
require 'modules/system',
......
......@@ -23,6 +23,7 @@ int lutro_window_preload(lua_State *L)
{ "requestAttention", win_requestAttention },
{ "getDisplayName", win_getDisplayName },
{ "setDisplaySleepEnabled", win_setDisplaySleepEnabled },
{ "showMessageBox", win_showMessageBox },
{NULL, NULL}
};
......@@ -246,3 +247,26 @@ int win_setDisplaySleepEnabled(lua_State *L)
// Ignore setting the display sleep.
return 0;
}
/**
* lutro.window.showMessageBox
*
* https://love2d.org/wiki/love.window.showMessageBox
*/
int win_showMessageBox(lua_State *L)
{
int n = lua_gettop(L);
if (n < 2)
return luaL_error(L, "lutro.window.win_showMessageBox expects at least 2 arguments, %d given.", n);
if (n > 5)
return luaL_error(L, "lutro.window.win_showMessageBox expects at most 5 arguments, %d given.", n);
const char* title = luaL_checkstring(L, 1);
const char* message = luaL_checkstring(L, 2);
struct retro_message msg = { message, 600 };
(*settings.environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &msg);
lua_pushboolean(L, 1); // success
return 1;
}
......@@ -23,5 +23,6 @@ int win_getPosition(lua_State *L);
int win_requestAttention(lua_State *L);
int win_getDisplayName(lua_State *L);
int win_setDisplaySleepEnabled(lua_State *L);
int win_showMessageBox(lua_State *L);
#endif // WINDOW_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment