mirror of
https://github.com/love2d/love-android.git
synced 2026-08-19 12:14:49 +02:00
updated to latest mobile-common (0cf55b7da58e), removed libtiff, libpng, libmng, devil, jasper, jpeg-8d, added libturbo-jpeg
This commit is contained in:
@@ -26,11 +26,22 @@ namespace love
|
||||
namespace window
|
||||
{
|
||||
|
||||
static Window *instance = nullptr;
|
||||
#define instance() (Module::getInstance<Window>(Module::M_WINDOW))
|
||||
|
||||
int w_getDisplayCount(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getDisplayCount());
|
||||
lua_pushinteger(L, instance()->getDisplayCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getDisplayName(lua_State *L)
|
||||
{
|
||||
int index = luaL_checkint(L, 1) - 1;
|
||||
|
||||
const char *name = nullptr;
|
||||
luax_catchexcept(L, [&](){ name = instance()->getDisplayName(index); });
|
||||
|
||||
lua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -48,7 +59,7 @@ int w_setMode(lua_State *L)
|
||||
|
||||
if (lua_isnoneornil(L, 3))
|
||||
{
|
||||
luax_pushboolean(L, instance->setWindow(w, h, 0));
|
||||
luax_pushboolean(L, instance()->setWindow(w, h, 0));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -88,7 +99,7 @@ int w_setMode(lua_State *L)
|
||||
|
||||
settings.fullscreen = luax_boolflag(L, 3, settingName(Window::SETTING_FULLSCREEN), false);
|
||||
settings.vsync = luax_boolflag(L, 3, settingName(Window::SETTING_VSYNC), true);
|
||||
settings.fsaa = luax_intflag(L, 3, settingName(Window::SETTING_FSAA), 0);
|
||||
settings.msaa = luax_intflag(L, 3, settingName(Window::SETTING_MSAA), 0);
|
||||
settings.resizable = luax_boolflag(L, 3, settingName(Window::SETTING_RESIZABLE), false);
|
||||
settings.minwidth = luax_intflag(L, 3, settingName(Window::SETTING_MIN_WIDTH), 1);
|
||||
settings.minheight = luax_intflag(L, 3, settingName(Window::SETTING_MIN_HEIGHT), 1);
|
||||
@@ -98,10 +109,17 @@ int w_setMode(lua_State *L)
|
||||
settings.highdpi = luax_boolflag(L, 3, settingName(Window::SETTING_HIGHDPI), false);
|
||||
settings.sRGB = luax_boolflag(L, 3, settingName(Window::SETTING_SRGB), false);
|
||||
|
||||
// For backward-compatibility. TODO: remove!
|
||||
int fsaa = luax_intflag(L, 3, settingName(Window::SETTING_FSAA), 0);
|
||||
if (fsaa > settings.msaa) settings.msaa = fsaa;
|
||||
|
||||
// Display index is 1-based in Lua and 0-based internally.
|
||||
settings.display--;
|
||||
|
||||
EXCEPT_GUARD(luax_pushboolean(L, instance->setWindow(w, h, &settings));)
|
||||
luax_catchexcept(L,
|
||||
[&](){ luax_pushboolean(L, instance()->setWindow(w, h, &settings)); }
|
||||
);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -109,7 +127,7 @@ int w_getMode(lua_State *L)
|
||||
{
|
||||
int w, h;
|
||||
WindowSettings settings;
|
||||
instance->getWindow(w, h, settings);
|
||||
instance()->getWindow(w, h, settings);
|
||||
lua_pushnumber(L, w);
|
||||
lua_pushnumber(L, h);
|
||||
|
||||
@@ -127,8 +145,11 @@ int w_getMode(lua_State *L)
|
||||
luax_pushboolean(L, settings.vsync);
|
||||
lua_setfield(L, -2, settingName(Window::SETTING_VSYNC));
|
||||
|
||||
lua_pushinteger(L, settings.fsaa);
|
||||
lua_setfield(L, -2, settingName(Window::SETTING_FSAA));
|
||||
lua_pushinteger(L, settings.msaa);
|
||||
lua_setfield(L, -2, settingName(Window::SETTING_MSAA));
|
||||
|
||||
lua_pushinteger(L, settings.msaa);
|
||||
lua_setfield(L, -2, settingName(Window::SETTING_FSAA)); // For backward-compatibility. TODO: remove!
|
||||
|
||||
luax_pushboolean(L, settings.resizable);
|
||||
lua_setfield(L, -2, settingName(Window::SETTING_RESIZABLE));
|
||||
@@ -162,7 +183,7 @@ int w_getFullscreenModes(lua_State *L)
|
||||
{
|
||||
int displayindex = luaL_optint(L, 1, 1) - 1;
|
||||
|
||||
std::vector<Window::WindowSize> modes = instance->getFullscreenSizes(displayindex);
|
||||
std::vector<Window::WindowSize> modes = instance()->getFullscreenSizes(displayindex);
|
||||
|
||||
lua_createtable(L, modes.size(), 0);
|
||||
|
||||
@@ -198,9 +219,9 @@ int w_setFullscreen(lua_State *L)
|
||||
|
||||
bool success = false;
|
||||
if (fstype == Window::FULLSCREEN_TYPE_MAX_ENUM)
|
||||
success = instance->setFullscreen(fullscreen);
|
||||
success = instance()->setFullscreen(fullscreen);
|
||||
else
|
||||
success = instance->setFullscreen(fullscreen, fstype);
|
||||
success = instance()->setFullscreen(fullscreen, fstype);
|
||||
|
||||
luax_pushboolean(L, success);
|
||||
return 1;
|
||||
@@ -210,7 +231,7 @@ int w_getFullscreen(lua_State *L)
|
||||
{
|
||||
int w, h;
|
||||
WindowSettings settings;
|
||||
instance->getWindow(w, h, settings);
|
||||
instance()->getWindow(w, h, settings);
|
||||
|
||||
const char *typestr;
|
||||
if (!Window::getConstant(settings.fstype, typestr))
|
||||
@@ -223,26 +244,26 @@ int w_getFullscreen(lua_State *L)
|
||||
|
||||
int w_isCreated(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance->isCreated());
|
||||
luax_pushboolean(L, instance()->isCreated());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getWidth(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getWidth());
|
||||
lua_pushinteger(L, instance()->getWidth());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getHeight(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getHeight());
|
||||
lua_pushinteger(L, instance()->getHeight());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getDimensions(lua_State *L)
|
||||
{
|
||||
lua_pushinteger(L, instance->getWidth());
|
||||
lua_pushinteger(L, instance->getHeight());
|
||||
lua_pushinteger(L, instance()->getWidth());
|
||||
lua_pushinteger(L, instance()->getHeight());
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -250,7 +271,7 @@ int w_getDesktopDimensions(lua_State *L)
|
||||
{
|
||||
int width = 0, height = 0;
|
||||
int displayindex = luaL_optint(L, 1, 1) - 1;
|
||||
instance->getDesktopDimensions(displayindex, width, height);
|
||||
instance()->getDesktopDimensions(displayindex, width, height);
|
||||
lua_pushinteger(L, width);
|
||||
lua_pushinteger(L, height);
|
||||
return 2;
|
||||
@@ -259,18 +280,15 @@ int w_getDesktopDimensions(lua_State *L)
|
||||
int w_setIcon(lua_State *L)
|
||||
{
|
||||
image::ImageData *i = luax_checktype<image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
luax_pushboolean(L, instance->setIcon(i));
|
||||
luax_pushboolean(L, instance()->setIcon(i));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getIcon(lua_State *L)
|
||||
{
|
||||
image::ImageData *i = instance->getIcon();
|
||||
image::ImageData *i = instance()->getIcon();
|
||||
if (i)
|
||||
{
|
||||
i->retain();
|
||||
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, i);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
@@ -279,43 +297,117 @@ int w_getIcon(lua_State *L)
|
||||
int w_setTitle(lua_State *L)
|
||||
{
|
||||
std::string title = luax_checkstring(L, 1);
|
||||
instance->setWindowTitle(title);
|
||||
instance()->setWindowTitle(title);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_getTitle(lua_State *L)
|
||||
{
|
||||
luax_pushstring(L, instance->getWindowTitle());
|
||||
luax_pushstring(L, instance()->getWindowTitle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_hasFocus(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance->hasFocus());
|
||||
luax_pushboolean(L, instance()->hasFocus());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_hasMouseFocus(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance->hasMouseFocus());
|
||||
luax_pushboolean(L, instance()->hasMouseFocus());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_isVisible(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance->isVisible());
|
||||
luax_pushboolean(L, instance()->isVisible());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getPixelScale(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getPixelScale());
|
||||
lua_pushnumber(L, instance()->getPixelScale());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_isTouchScreen(lua_State *L)
|
||||
{
|
||||
int index = luaL_optint(L, 1, 1) - 1;
|
||||
luax_pushboolean(L, instance()->isTouchScreen(index));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_minimize(lua_State* /*L*/)
|
||||
{
|
||||
instance()->minimize();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_showMessageBox(lua_State *L)
|
||||
{
|
||||
Window::MessageBoxData data = {};
|
||||
|
||||
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);
|
||||
|
||||
// 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))
|
||||
{
|
||||
size_t numbuttons = lua_objlen(L, 4);
|
||||
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);
|
||||
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");
|
||||
if (!lua_isnoneornil(L, -1))
|
||||
data.enterButtonIndex = luaL_checkint(L, -1) - 1;
|
||||
else
|
||||
data.enterButtonIndex = 0;
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Optional table entry specifying the button to use when esc is pressed.
|
||||
lua_getfield(L, 4, "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);
|
||||
|
||||
data.attachToWindow = luax_optboolean(L, 5, true);
|
||||
|
||||
int pressedbutton = instance()->showMessageBox(data);
|
||||
lua_pushinteger(L, pressedbutton + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
data.attachToWindow = luax_optboolean(L, 4, true);
|
||||
|
||||
// Display a simple message box.
|
||||
bool success = instance()->showMessageBox(data.type, data.title, data.message, data.attachToWindow);
|
||||
luax_pushboolean(L, success);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getDisplayCount", w_getDisplayCount },
|
||||
{ "getDisplayName", w_getDisplayName },
|
||||
{ "setMode", w_setMode },
|
||||
{ "getMode", w_getMode },
|
||||
{ "getFullscreenModes", w_getFullscreenModes },
|
||||
@@ -334,12 +426,16 @@ static const luaL_Reg functions[] =
|
||||
{ "hasMouseFocus", w_hasMouseFocus },
|
||||
{ "isVisible", w_isVisible },
|
||||
{ "getPixelScale", w_getPixelScale },
|
||||
{ "isTouchScreen", w_isTouchScreen },
|
||||
{ "minimize", w_minimize },
|
||||
{ "showMessageBox", w_showMessageBox },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
extern "C" int luaopen_love_window(lua_State *L)
|
||||
{
|
||||
EXCEPT_GUARD(instance = sdl::Window::createSingleton();)
|
||||
Window *instance = nullptr;
|
||||
luax_catchexcept(L, [&](){ instance = sdl::Window::createSingleton(); });
|
||||
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
|
||||
Reference in New Issue
Block a user