mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Merged default into minor
--HG-- branch : minor
This commit is contained in:
@@ -58,6 +58,9 @@ public:
|
||||
Event();
|
||||
virtual ~Event();
|
||||
|
||||
// Implements Module.
|
||||
virtual ModuleType getModuleType() const { return M_EVENT; }
|
||||
|
||||
void push(Message *msg);
|
||||
bool poll(Message *&msg);
|
||||
virtual void clear();
|
||||
|
||||
@@ -44,7 +44,7 @@ static void windowToPixelCoords(int *x, int *y)
|
||||
{
|
||||
double scale = 1.0;
|
||||
|
||||
window::Window *window = (window::Window *) Module::findInstance("love.window.");
|
||||
window::Window *window = Module::getInstance<window::Window>(Module::M_WINDOW);
|
||||
if (window != nullptr)
|
||||
scale = window->getPixelScale();
|
||||
|
||||
@@ -129,7 +129,7 @@ Message *Event::convert(const SDL_Event &e) const
|
||||
case SDL_KEYDOWN:
|
||||
if (e.key.repeat)
|
||||
{
|
||||
kb = (love::keyboard::Keyboard *) Module::findInstance("love.keyboard.");
|
||||
kb = Module::getInstance<love::keyboard::Keyboard>(Module::M_KEYBOARD);
|
||||
if (kb && !kb->hasKeyRepeat())
|
||||
break;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ Message *Event::convert(const SDL_Event &e) const
|
||||
|
||||
Message *Event::convertJoystickEvent(const SDL_Event &e) const
|
||||
{
|
||||
joystick::JoystickModule *joymodule = (joystick::JoystickModule *) Module::findInstance("love.joystick.");
|
||||
joystick::JoystickModule *joymodule = Module::getInstance<joystick::JoystickModule>(Module::M_JOYSTICK);
|
||||
if (!joymodule)
|
||||
return 0;
|
||||
|
||||
@@ -403,7 +403,7 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
|
||||
arg1->release();
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
win = (window::Window *) Module::findInstance("love.window.");
|
||||
win = Module::getInstance<window::Window>(Module::M_WINDOW);
|
||||
if (win)
|
||||
{
|
||||
int px_w = e.window.data1;
|
||||
@@ -418,7 +418,7 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
|
||||
|
||||
win->onWindowResize(e.window.data1, e.window.data2);
|
||||
|
||||
graphics::Graphics *gfx = (graphics::Graphics *) Module::findInstance("love.graphics.");
|
||||
graphics::Graphics *gfx = Module::getInstance<graphics::Graphics>(Module::M_GRAPHICS);
|
||||
if (gfx)
|
||||
gfx->setViewportSize(px_w, px_h);
|
||||
|
||||
|
||||
@@ -33,13 +33,13 @@ namespace event
|
||||
namespace sdl
|
||||
{
|
||||
|
||||
static Event *instance = 0;
|
||||
#define instance() (Module::getInstance<Event>(Module::M_EVENT))
|
||||
|
||||
static int poll_i(lua_State *L)
|
||||
{
|
||||
Message *m;
|
||||
|
||||
while (instance->poll(m))
|
||||
while (instance()->poll(m))
|
||||
{
|
||||
int args = m->toLua(L);
|
||||
m->release();
|
||||
@@ -52,7 +52,7 @@ static int poll_i(lua_State *L)
|
||||
|
||||
int w_pump(lua_State *)
|
||||
{
|
||||
instance->pump();
|
||||
instance()->pump();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ int w_wait(lua_State *L)
|
||||
{
|
||||
Message *m;
|
||||
|
||||
if ((m = instance->wait()))
|
||||
if ((m = instance()->wait()))
|
||||
{
|
||||
int args = m->toLua(L);
|
||||
m->release();
|
||||
@@ -86,7 +86,7 @@ int w_push(lua_State *L)
|
||||
if (!success)
|
||||
return 1;
|
||||
|
||||
instance->push(m);
|
||||
instance()->push(m);
|
||||
m->release();
|
||||
|
||||
return 1;
|
||||
@@ -94,14 +94,14 @@ int w_push(lua_State *L)
|
||||
|
||||
int w_clear(lua_State *)
|
||||
{
|
||||
instance->clear();
|
||||
instance()->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_quit(lua_State *L)
|
||||
{
|
||||
Message *m = new Message("quit");
|
||||
instance->push(m);
|
||||
instance()->push(m);
|
||||
m->release();
|
||||
luax_pushboolean(L, true);
|
||||
return 1;
|
||||
@@ -121,7 +121,8 @@ static const luaL_Reg functions[] =
|
||||
|
||||
extern "C" int luaopen_love_event(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
Event *instance = instance();
|
||||
if (instance == nullptr)
|
||||
{
|
||||
luax_catchexcept(L, [&](){ instance = new Event(); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user