Unverified Commit 5baf7c54 authored by RobLoach's avatar RobLoach Committed by GitHub
Browse files

Merge pull request #175 from libretro/lutro.window.showMessageBox

Add lutro.window.showMessageBox
parents 77a05136 83afb04b
......@@ -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);
......
......@@ -13,7 +13,7 @@
#include "system.h"
#include "timer.h"
#include "lutro_math.h"
#include "window.h"
#include "lutro_window.h"
#include "live.h"
#include "mouse.h"
#include "joystick.h"
......
......@@ -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;
......
......@@ -3,7 +3,7 @@
#include <libretro.h>
#include "window.h"
#include "lutro_window.h"
#include "lutro.h"
#include "graphics.h"
......@@ -24,6 +24,7 @@ int lutro_window_preload(lua_State *L)
{ "getDisplayName", win_getDisplayName },
{ "setDisplaySleepEnabled", win_setDisplaySleepEnabled },
{ "isDisplaySleepEnabled", win_isDisplaySleepEnabled },
{ "showMessageBox", win_showMessageBox },
{NULL, NULL}
};
......@@ -264,3 +265,27 @@ int win_isDisplaySleepEnabled(lua_State *L)
return 1;
}
/**
* 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;
}
......@@ -24,5 +24,6 @@ int win_requestAttention(lua_State *L);
int win_getDisplayName(lua_State *L);
int win_setDisplaySleepEnabled(lua_State *L);
int win_isDisplaySleepEnabled(lua_State *L);
int win_showMessageBox(lua_State *L);
#endif // WINDOW_H
function lutro.graphics.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.graphics.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.graphics.setBackgroundColorTest,
lutro.graphics.getBackgroundColorTest
}
\ No newline at end of file
......@@ -55,6 +55,11 @@ function lutro.window.isDisplaySleepEnabledTest()
unit.assertIsBoolean(sleep)
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,
......@@ -65,5 +70,6 @@ return {
lutro.window.requestAttentionTest,
lutro.window.getDisplayNameTest,
lutro.window.setDisplaySleepEnabledTest,
lutro.window.isDisplaySleepEnabledTest
lutro.window.isDisplaySleepEnabledTest,
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',
......
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