SDL Events.
This commit is contained in:
@@ -12,6 +12,7 @@ KEY CHANGES:
|
||||
- ADDED: Support for platforms.
|
||||
- ADDED: Platform desktop SDL.
|
||||
- CHANGE: Renamed event enums. Events are now platform specific.
|
||||
- ADDED: SDL Events.
|
||||
|
||||
DETAILED CHANGES:
|
||||
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
|
||||
|
||||
6
devnotes
6
devnotes
@@ -2,11 +2,11 @@ Current {
|
||||
}
|
||||
|
||||
Backlog {
|
||||
* Review events. Seems to be a lot of work for very little benefit if any.
|
||||
Might just increase traffic between Lua and C needlessly.
|
||||
* Platform specific API documentation.
|
||||
* Raylibgui.
|
||||
* Fix textbox focus.
|
||||
* Platform desktop SDL.
|
||||
* Thread safe Lua RL.event calling.
|
||||
* Text input not working on gui. Could this be Raylib issue?
|
||||
* Haptic functions.
|
||||
* Text
|
||||
* Text codepoints management functions (unicode characters)? Could be usefull for luajit.
|
||||
|
||||
@@ -6,6 +6,8 @@ function RL.init()
|
||||
RL.SetWindowTitle( "Events" )
|
||||
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
|
||||
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
||||
|
||||
RL.SetTextLineSpacing( 24 )
|
||||
end
|
||||
|
||||
local function getEventType( event )
|
||||
@@ -33,6 +35,8 @@ local function getEventType( event )
|
||||
return "Cursor Enter"
|
||||
elseif event.type == RL.EVENT_JOYSTICK then
|
||||
return "Joystick"
|
||||
elseif event.type == RL.SDL_KEYBOARD_EVENT then
|
||||
return "SDL_KEYBOARD_EVENT"
|
||||
end
|
||||
|
||||
return "Unknown"
|
||||
@@ -99,9 +103,29 @@ function RL.event( event )
|
||||
elseif event.event == RL.GLFW_DISCONNECTED then
|
||||
text = text.."\nDisconnected"
|
||||
end
|
||||
elseif event.type == RL.SDL_KEYBOARD_EVENT then
|
||||
text = text.."state: "..event.state
|
||||
end
|
||||
|
||||
-- Some SDL events.
|
||||
|
||||
-- text = event.type.."\n\n"
|
||||
|
||||
-- if event.type == RL.SDL_KEYDOWN or event.type == RL.SDL_KEYUP then
|
||||
-- text = text.."state: "..event.state.." repeat: "..event.repeating
|
||||
-- elseif event.type == RL.SDL_WINDOWEVENT then
|
||||
-- text = text.."event: "..event.event.." "..event.data1.." "..event.data2
|
||||
-- elseif event.type == RL.SDL_MOUSEMOTION then
|
||||
-- text = text.."Pos: "..event.x..", "..event.y
|
||||
-- elseif event.type == RL.SDL_MOUSEBUTTONDOWN or event.type == RL.SDL_MOUSEBUTTONUP then
|
||||
-- text = text.."button "..event.button.." Pos: "..event.x..", "..event.y
|
||||
-- elseif event.type == RL.SDL_MOUSEWHEEL then
|
||||
-- text = text.."which "..event.which.." Scroll: "..event.x..", "..event.y
|
||||
-- -- elseif event.type == RL.SDL_CONTROLLERAXISMOTION then
|
||||
-- elseif event.type == RL.SDL_JOYAXISMOTION then
|
||||
-- text = text.."which "..event.which.." Axis: "..event.axis.." Value: "..event.value
|
||||
-- -- elseif event.type == RL.SDL_CONTROLLERBUTTONDOWN or event.type == RL.SDL_CONTROLLERBUTTONUP then
|
||||
-- elseif event.type == RL.SDL_JOYBUTTONDOWN or event.type == RL.SDL_JOYBUTTONUP then
|
||||
-- text = text.."which "..event.which.." Button: "..event.button.." State: "..event.state
|
||||
-- end
|
||||
end
|
||||
|
||||
function RL.draw()
|
||||
|
||||
@@ -32,6 +32,8 @@ function RL.init()
|
||||
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
||||
RL.SetWindowSize( winSize )
|
||||
RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
|
||||
|
||||
RL.GuiSetStyle( RL.LISTVIEW, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT )
|
||||
end
|
||||
|
||||
function RL.draw()
|
||||
@@ -74,8 +76,8 @@ function RL.draw()
|
||||
if result == 1 then
|
||||
dropdownActive = not dropdownActive
|
||||
end
|
||||
|
||||
_, listView.scroll, listView.item = RL.GuiListView( { 200, 400, 200, 200 }, "Cat;Elefant;Squirrel", listView.scroll, listView.item )
|
||||
|
||||
_, listView.scroll, listView.item = RL.GuiListView( { 200, 400, 200, 200 }, "Cat\nElefant\nSquirrel", listView.scroll, listView.item )
|
||||
|
||||
result = RL.GuiMessageBox( { 420, 400, 200, 100 }, "Message", "Are you sure about this?", "Yes;No" )
|
||||
if 0 <= result then
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "glfw3.h"
|
||||
#include "glfw3native.h"
|
||||
|
||||
enum EventType {
|
||||
GLFW_WINDOW_SIZE_EVENT,
|
||||
GLFW_WINDOW_MAXIMIZE_EVENT,
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
// #include "SDL.h"
|
||||
// #define SDL_EVENT_QUEUE_LEN 128
|
||||
|
||||
enum EventType {
|
||||
SDL_WINDOW_EVENT,
|
||||
SDL_KEYBOARD_EVENT
|
||||
};
|
||||
#include "SDL.h"
|
||||
|
||||
// typedef struct {
|
||||
// int SDL_eventQueueLen;
|
||||
// SDL_Event **SDL_eventQueue;
|
||||
// } SDL_State;
|
||||
|
||||
// extern SDL_State *SDL_state;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#define ALLOC_PAGE_SIZE 256
|
||||
#ifdef PLATFORM_DESKTOP_SDL
|
||||
#define PLATFORM_SDL_EVENT_QUEUE_LEN 128
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char *exePath;
|
||||
@@ -14,7 +16,6 @@ typedef struct {
|
||||
Material defaultMaterial;
|
||||
int *RLGLcurrentShaderLocs;
|
||||
/* Events. */
|
||||
/* GLFW events. */
|
||||
#ifdef PLATFORM_DESKTOP
|
||||
/* Window events. */
|
||||
GLFWwindowsizefun raylibWindowSizeCallback;
|
||||
@@ -30,8 +31,9 @@ typedef struct {
|
||||
GLFWscrollfun raylibMouseScrollCallback;
|
||||
GLFWcursorenterfun raylibCursorEnterCallback;
|
||||
GLFWjoystickfun raylibJoystickCallback;
|
||||
// #elif PLATFORM_DESKTOP_SDL
|
||||
|
||||
#elif PLATFORM_DESKTOP_SDL
|
||||
int SDL_eventQueueLen;
|
||||
SDL_Event *SDL_eventQueue;
|
||||
#endif
|
||||
} State;
|
||||
|
||||
|
||||
@@ -983,7 +983,7 @@ bool luaInit( int argn, const char **argc ) {
|
||||
defineModelAnimation();
|
||||
/* Define globals. */
|
||||
defineGlobals();
|
||||
definePlatformGlobals();
|
||||
platformDefineGlobals();
|
||||
|
||||
/* Register functions. */
|
||||
luaRegister();
|
||||
@@ -1078,6 +1078,9 @@ bool luaCallMain() {
|
||||
}
|
||||
|
||||
void luaCallProcess() {
|
||||
#ifdef PLATFORM_DESKTOP_SDL
|
||||
platformSendEvents();
|
||||
#endif
|
||||
lua_State *L = state->luaState;
|
||||
|
||||
lua_pushcfunction( L, luaTraceback );
|
||||
@@ -1115,7 +1118,6 @@ void luaCallDraw() {
|
||||
state->run = false;
|
||||
return;
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
lua_pop( L, -1 );
|
||||
|
||||
@@ -64,7 +64,6 @@ int main( int argn, const char **argc ) {
|
||||
else {
|
||||
printVersion();
|
||||
stateInit( argn, argc, exePath );
|
||||
// luaRegister();
|
||||
state->run = luaCallMain();
|
||||
|
||||
while ( state->run ) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "core.h"
|
||||
#include "platforms/core_desktop.h"
|
||||
|
||||
static void definePlatformGlobals() {
|
||||
static void platformDefineGlobals() {
|
||||
lua_State *L = state->luaState;
|
||||
|
||||
lua_getglobal( L, "RL" );
|
||||
@@ -463,7 +463,7 @@ static void joystickInputEvent( int jid, int event ) {
|
||||
lua_pop( L, -1 );
|
||||
}
|
||||
|
||||
void platformRegisterEvents() {
|
||||
static void platformRegisterEvents() {
|
||||
/* Window events. */
|
||||
state->raylibWindowSizeCallback = glfwSetWindowSizeCallback( GetWindowHandle(), windowSizeEvent );
|
||||
#if !defined( PLATFORM_WEB )
|
||||
|
||||
@@ -3,19 +3,74 @@
|
||||
#include "core.h"
|
||||
#include "platforms/core_desktop_sdl.h"
|
||||
|
||||
static void definePlatformGlobals() {
|
||||
static void platformDefineGlobals() {
|
||||
lua_State *L = state->luaState;
|
||||
|
||||
lua_getglobal( L, "RL" );
|
||||
|
||||
/* KeyboardKey */
|
||||
assignGlobalInt( SDL_KEYDOWN, "SDL_KEYDOWN" ); // key pressed
|
||||
assignGlobalInt( SDL_KEYUP, "SDL_KEYUP" ); // key released
|
||||
assignGlobalInt( SDL_PRESSED, "SDL_PRESSED" ); // key pressed
|
||||
assignGlobalInt( SDL_RELEASED, "SDL_RELEASED" ); // key released
|
||||
/* Keyboard Events. */
|
||||
assignGlobalInt( SDL_WINDOW_EVENT, "SDL_WINDOW_EVENT" ); // SDL Window Event
|
||||
assignGlobalInt( SDL_KEYBOARD_EVENT, "SDL_KEYBOARD_EVENT" ); // SDL Keyboard Event
|
||||
/* KeyboardEvents */
|
||||
assignGlobalInt( SDL_KEYDOWN, "SDL_KEYDOWN" ); // Key pressed
|
||||
assignGlobalInt( SDL_KEYUP, "SDL_KEYUP" ); // Key released
|
||||
/* WindowEvents */
|
||||
assignGlobalInt( SDL_WINDOWEVENT, "SDL_WINDOWEVENT" ); // Window state change
|
||||
/* MouseEvents */
|
||||
assignGlobalInt( SDL_MOUSEMOTION, "SDL_MOUSEMOTION" ); // Mouse moved
|
||||
assignGlobalInt( SDL_MOUSEBUTTONDOWN, "SDL_MOUSEBUTTONDOWN" ); // Mouse button pressed
|
||||
assignGlobalInt( SDL_MOUSEBUTTONUP, "SDL_MOUSEBUTTONUP" ); // Mouse button released
|
||||
assignGlobalInt( SDL_MOUSEWHEEL, "SDL_MOUSEWHEEL" ); // Mouse wheel motion
|
||||
/* JoystickEvents */
|
||||
assignGlobalInt( SDL_JOYAXISMOTION, "SDL_JOYAXISMOTION" ); // Joystick axis motion
|
||||
assignGlobalInt( SDL_JOYBALLMOTION, "SDL_JOYBALLMOTION" ); // Joystick trackball motion
|
||||
assignGlobalInt( SDL_JOYHATMOTION, "SDL_JOYHATMOTION" );
|
||||
assignGlobalInt( SDL_JOYBUTTONDOWN, "SDL_JOYBUTTONDOWN" ); // Joystick button pressed
|
||||
assignGlobalInt( SDL_JOYBUTTONUP, "SDL_JOYBUTTONUP" ); // Joystick button released
|
||||
assignGlobalInt( SDL_JOYDEVICEADDED, "SDL_JOYDEVICEADDED" ); // Joystick connected
|
||||
assignGlobalInt( SDL_JOYDEVICEREMOVED, "SDL_JOYDEVICEREMOVED" ); // Joystick disconnected
|
||||
/* ControllerEvents */
|
||||
assignGlobalInt( SDL_CONTROLLERAXISMOTION, "SDL_CONTROLLERAXISMOTION" ); // Controller axis motion
|
||||
assignGlobalInt( SDL_CONTROLLERBUTTONDOWN, "SDL_CONTROLLERBUTTONDOWN" ); // Controller button pressed
|
||||
assignGlobalInt( SDL_CONTROLLERBUTTONUP, "SDL_CONTROLLERBUTTONUP" ); // Controller button released
|
||||
assignGlobalInt( SDL_CONTROLLERDEVICEADDED, "SDL_CONTROLLERDEVICEADDED" ); // Controller connected
|
||||
assignGlobalInt( SDL_CONTROLLERDEVICEREMOVED, "SDL_CONTROLLERDEVICEREMOVED" ); // Controller disconnected
|
||||
assignGlobalInt( SDL_CONTROLLERDEVICEREMAPPED, "SDL_CONTROLLERDEVICEREMAPPED" ); // Controller mapping updated
|
||||
/* TouchEvents */
|
||||
assignGlobalInt( SDL_FINGERDOWN, "SDL_FINGERDOWN" ); // User has touched input device
|
||||
assignGlobalInt( SDL_FINGERUP, "SDL_FINGERUP" ); // User stopped touching input device
|
||||
assignGlobalInt( SDL_FINGERMOTION, "SDL_FINGERMOTION" ); // User is dragging finger on input device
|
||||
/* GestureEvents */
|
||||
assignGlobalInt( SDL_DOLLARGESTURE, "SDL_DOLLARGESTURE" );
|
||||
assignGlobalInt( SDL_DOLLARRECORD, "SDL_DOLLARRECORD" );
|
||||
assignGlobalInt( SDL_MULTIGESTURE, "SDL_MULTIGESTURE" );
|
||||
/* WindowEventIDs */
|
||||
assignGlobalInt( SDL_WINDOWEVENT_SHOWN, "SDL_WINDOWEVENT_SHOWN" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_HIDDEN, "SDL_WINDOWEVENT_HIDDEN" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_EXPOSED, "SDL_WINDOWEVENT_EXPOSED" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_MOVED, "SDL_WINDOWEVENT_MOVED" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_RESIZED, "SDL_WINDOWEVENT_RESIZED" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_SIZE_CHANGED, "SDL_WINDOWEVENT_SIZE_CHANGED" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_MINIMIZED, "SDL_WINDOWEVENT_MINIMIZED" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_MAXIMIZED, "SDL_WINDOWEVENT_MAXIMIZED" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_RESTORED, "SDL_WINDOWEVENT_RESTORED" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_ENTER, "SDL_WINDOWEVENT_ENTER" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_LEAVE, "SDL_WINDOWEVENT_LEAVE" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_FOCUS_GAINED, "SDL_WINDOWEVENT_FOCUS_GAINED" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_FOCUS_LOST, "SDL_WINDOWEVENT_FOCUS_LOST" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_CLOSE, "SDL_WINDOWEVENT_CLOSE" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_TAKE_FOCUS, "SDL_WINDOWEVENT_TAKE_FOCUS" );
|
||||
assignGlobalInt( SDL_WINDOWEVENT_HIT_TEST, "SDL_WINDOWEVENT_HIT_TEST" );
|
||||
/* KeyboardAndMouseState */
|
||||
assignGlobalInt( SDL_RELEASED, "SDL_RELEASED" );
|
||||
assignGlobalInt( SDL_PRESSED, "SDL_PRESSED" );
|
||||
/* JoystickHatMotion */
|
||||
assignGlobalInt( SDL_HAT_LEFTUP, "SDL_HAT_LEFTUP" );
|
||||
assignGlobalInt( SDL_HAT_UP, "SDL_HAT_UP" );
|
||||
assignGlobalInt( SDL_HAT_RIGHTUP, "SDL_HAT_RIGHTUP" );
|
||||
assignGlobalInt( SDL_HAT_LEFT, "SDL_HAT_LEFT" );
|
||||
assignGlobalInt( SDL_HAT_CENTERED, "SDL_HAT_CENTERED" );
|
||||
assignGlobalInt( SDL_HAT_RIGHT, "SDL_HAT_RIGHT" );
|
||||
assignGlobalInt( SDL_HAT_LEFTDOWN, "SDL_HAT_LEFTDOWN" );
|
||||
assignGlobalInt( SDL_HAT_DOWN, "SDL_HAT_DOWN" );
|
||||
assignGlobalInt( SDL_HAT_RIGHTDOWN, "SDL_HAT_RIGHTDOWN" );
|
||||
|
||||
lua_pop( L, -1 );
|
||||
}
|
||||
@@ -69,59 +124,350 @@ static void luaPlatformRegister() {
|
||||
|
||||
/* Events. */
|
||||
|
||||
//TODO Thinking of different implementation since this could run on different thread than Lua.
|
||||
/* This function is not thread safe so we don't use Lua inside it directly. It only adds events to another queue. */
|
||||
static int SDLEventFilter( void *userdata, SDL_Event *event ) {
|
||||
/* Don't handle events if exiting. Prevent segfault. */
|
||||
if ( event->type == SDL_QUIT || !state->run ) {
|
||||
return 0;
|
||||
/* SDL_EVENT_POLL_SENTINEL = 0x7F00, /**< Signals the end of an event poll cycle */
|
||||
if ( event->type != SDL_QUIT && event->type != 0x7F00 && state->SDL_eventQueueLen < PLATFORM_SDL_EVENT_QUEUE_LEN ) {
|
||||
state->SDL_eventQueue[ state->SDL_eventQueueLen ] = *event;
|
||||
state->SDL_eventQueueLen++;
|
||||
|
||||
// printf( "event %u state->SDL_eventQueueLen %d\n", event->type, state->SDL_eventQueueLen );
|
||||
}
|
||||
}
|
||||
|
||||
static void platformRegisterEvents() {
|
||||
/* SDL Warning: Be very careful of what you do in the event filter function, as it may run in a different thread! */
|
||||
SDL_AddEventWatch( SDLEventFilter, NULL );
|
||||
}
|
||||
|
||||
static void platformSendEvents() {
|
||||
lua_State *L = state->luaState;
|
||||
|
||||
lua_pushcfunction( L, luaTraceback );
|
||||
int tracebackidx = lua_gettop( L );
|
||||
|
||||
/* If RL.event is not defined, we don't need to proceed. */
|
||||
lua_getglobal( L, "RL" );
|
||||
lua_getfield( L, -1, "event" );
|
||||
|
||||
if ( !lua_isfunction( L, -1 ) ) {
|
||||
return 0;
|
||||
state->SDL_eventQueueLen = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( event->type ) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
lua_createtable( L, 7, 0 );
|
||||
lua_pushinteger( L, SDL_KEYBOARD_EVENT );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event->key.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event->key.state );
|
||||
lua_setfield( L, -2, "state" );
|
||||
lua_pushinteger( L, event->key.repeat );
|
||||
lua_setfield( L, -2, "repeat" );
|
||||
lua_pushinteger( L, event->key.keysym.scancode );
|
||||
lua_setfield( L, -2, "scancode" );
|
||||
lua_pushinteger( L, event->key.keysym.sym );
|
||||
lua_setfield( L, -2, "sym" );
|
||||
lua_pushinteger( L, event->key.keysym.mod );
|
||||
lua_setfield( L, -2, "mod" );
|
||||
for ( int i = 0; i < state->SDL_eventQueueLen; i++ ) {
|
||||
bool call = false;
|
||||
lua_getglobal( L, "RL" );
|
||||
lua_getfield( L, -1, "event" );
|
||||
|
||||
SDL_Event event = state->SDL_eventQueue[i];
|
||||
|
||||
switch ( event.type ) {
|
||||
case SDL_KEYUP:
|
||||
case SDL_KEYDOWN:
|
||||
{
|
||||
lua_createtable( L, 7, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.key.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.key.state );
|
||||
lua_setfield( L, -2, "state" );
|
||||
lua_pushinteger( L, event.key.repeat );
|
||||
lua_setfield( L, -2, "repeating" ); /* repeat is Lua keyword. */
|
||||
lua_pushinteger( L, event.key.keysym.scancode );
|
||||
lua_setfield( L, -2, "scancode" );
|
||||
lua_pushinteger( L, event.key.keysym.sym );
|
||||
lua_setfield( L, -2, "sym" );
|
||||
lua_pushinteger( L, event.key.keysym.mod );
|
||||
lua_setfield( L, -2, "mod" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
{
|
||||
lua_createtable( L, 5, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.window.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.window.event );
|
||||
lua_setfield( L, -2, "event" );
|
||||
lua_pushinteger( L, event.window.data1 );
|
||||
lua_setfield( L, -2, "data1" );
|
||||
lua_pushinteger( L, event.window.data2 );
|
||||
lua_setfield( L, -2, "data2" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
lua_createtable( L, 8, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.motion.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.motion.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
lua_pushinteger( L, event.motion.state );
|
||||
lua_setfield( L, -2, "state" );
|
||||
lua_pushinteger( L, event.motion.x );
|
||||
lua_setfield( L, -2, "x" );
|
||||
lua_pushinteger( L, event.motion.y );
|
||||
lua_setfield( L, -2, "y" );
|
||||
lua_pushinteger( L, event.motion.xrel );
|
||||
lua_setfield( L, -2, "xrel" );
|
||||
lua_pushinteger( L, event.motion.yrel );
|
||||
lua_setfield( L, -2, "yrel" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
lua_createtable( L, 7, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.button.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.button.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
lua_pushinteger( L, event.button.button );
|
||||
lua_setfield( L, -2, "button" );
|
||||
lua_pushinteger( L, event.button.state );
|
||||
lua_setfield( L, -2, "state" );
|
||||
lua_pushinteger( L, event.button.x );
|
||||
lua_setfield( L, -2, "x" );
|
||||
lua_pushinteger( L, event.button.y );
|
||||
lua_setfield( L, -2, "y" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
{
|
||||
lua_createtable( L, 5, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.wheel.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.wheel.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
lua_pushinteger( L, event.wheel.x );
|
||||
lua_setfield( L, -2, "x" );
|
||||
lua_pushinteger( L, event.wheel.y );
|
||||
lua_setfield( L, -2, "y" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
{
|
||||
lua_createtable( L, 5, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.jaxis.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.jaxis.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
lua_pushinteger( L, event.jaxis.axis );
|
||||
lua_setfield( L, -2, "axis" );
|
||||
lua_pushinteger( L, event.jaxis.value );
|
||||
lua_setfield( L, -2, "value" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
{
|
||||
lua_createtable( L, 6, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.jball.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.jball.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
lua_pushinteger( L, event.jball.ball );
|
||||
lua_setfield( L, -2, "ball" );
|
||||
lua_pushinteger( L, event.jball.xrel );
|
||||
lua_setfield( L, -2, "xrel" );
|
||||
lua_pushinteger( L, event.jball.yrel );
|
||||
lua_setfield( L, -2, "yrel" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
{
|
||||
lua_createtable( L, 5, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.jhat.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.jhat.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
lua_pushinteger( L, event.jhat.hat );
|
||||
lua_setfield( L, -2, "hat" );
|
||||
lua_pushinteger( L, event.jhat.value );
|
||||
lua_setfield( L, -2, "value" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP:
|
||||
{
|
||||
lua_createtable( L, 5, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.jbutton.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.jbutton.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
lua_pushinteger( L, event.jbutton.button );
|
||||
lua_setfield( L, -2, "button" );
|
||||
lua_pushinteger( L, event.jbutton.state );
|
||||
lua_setfield( L, -2, "state" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYDEVICEADDED:
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
{
|
||||
lua_createtable( L, 3, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.jdevice.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.jdevice.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
{
|
||||
lua_createtable( L, 5, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.caxis.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.caxis.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
lua_pushinteger( L, event.caxis.axis );
|
||||
lua_setfield( L, -2, "axis" );
|
||||
lua_pushinteger( L, event.caxis.value );
|
||||
lua_setfield( L, -2, "value" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
{
|
||||
lua_createtable( L, 5, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.cbutton.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.cbutton.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
lua_pushinteger( L, event.cbutton.button );
|
||||
lua_setfield( L, -2, "button" );
|
||||
lua_pushinteger( L, event.cbutton.state );
|
||||
lua_setfield( L, -2, "state" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
case SDL_CONTROLLERDEVICEREMOVED:
|
||||
case SDL_CONTROLLERDEVICEREMAPPED:
|
||||
{
|
||||
lua_createtable( L, 3, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.cdevice.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.cdevice.which );
|
||||
lua_setfield( L, -2, "which" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_FINGERMOTION:
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_FINGERUP:
|
||||
{
|
||||
lua_createtable( L, 9, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.tfinger.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.tfinger.touchId );
|
||||
lua_setfield( L, -2, "touchId" );
|
||||
lua_pushinteger( L, event.tfinger.fingerId );
|
||||
lua_setfield( L, -2, "fingerId" );
|
||||
lua_pushnumber( L, event.tfinger.x );
|
||||
lua_setfield( L, -2, "x" );
|
||||
lua_pushnumber( L, event.tfinger.y );
|
||||
lua_setfield( L, -2, "y" );
|
||||
lua_pushnumber( L, event.tfinger.dx );
|
||||
lua_setfield( L, -2, "dx" );
|
||||
lua_pushnumber( L, event.tfinger.dy );
|
||||
lua_setfield( L, -2, "dy" );
|
||||
lua_pushnumber( L, event.tfinger.pressure );
|
||||
lua_setfield( L, -2, "pressure" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_MULTIGESTURE:
|
||||
{
|
||||
lua_createtable( L, 8, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.mgesture.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.mgesture.touchId );
|
||||
lua_setfield( L, -2, "touchId" );
|
||||
lua_pushnumber( L, event.mgesture.dTheta );
|
||||
lua_setfield( L, -2, "dTheta" );
|
||||
lua_pushnumber( L, event.mgesture.dDist );
|
||||
lua_setfield( L, -2, "dDist" );
|
||||
lua_pushnumber( L, event.mgesture.x );
|
||||
lua_setfield( L, -2, "x" );
|
||||
lua_pushnumber( L, event.mgesture.y );
|
||||
lua_setfield( L, -2, "y" );
|
||||
lua_pushinteger( L, event.mgesture.numFingers );
|
||||
lua_setfield( L, -2, "numFingers" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
case SDL_DOLLARGESTURE:
|
||||
case SDL_DOLLARRECORD:
|
||||
{
|
||||
lua_createtable( L, 8, 0 );
|
||||
lua_pushinteger( L, event.type );
|
||||
lua_setfield( L, -2, "type" );
|
||||
lua_pushinteger( L, event.dgesture.timestamp );
|
||||
lua_setfield( L, -2, "timestamp" );
|
||||
lua_pushinteger( L, event.dgesture.touchId );
|
||||
lua_setfield( L, -2, "touchId" );
|
||||
lua_pushinteger( L, event.dgesture.gestureId );
|
||||
lua_setfield( L, -2, "gestureId" );
|
||||
lua_pushinteger( L, event.dgesture.numFingers );
|
||||
lua_setfield( L, -2, "numFingers" );
|
||||
lua_pushnumber( L, event.dgesture.error );
|
||||
lua_setfield( L, -2, "error" );
|
||||
lua_pushnumber( L, event.dgesture.x );
|
||||
lua_setfield( L, -2, "x" );
|
||||
lua_pushnumber( L, event.dgesture.y );
|
||||
lua_setfield( L, -2, "y" );
|
||||
call = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ( call ) {
|
||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||
state->run = false;
|
||||
}
|
||||
lua_pop( L, -1 );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
lua_pop( L, -1 );
|
||||
}
|
||||
}
|
||||
|
||||
static void platformRegisterEvents() {
|
||||
/* Probably sould not use this since. SDL Warning:
|
||||
Be very careful of what you do in the event filter function, as it may run in a different thread!
|
||||
There has already being some undefined behavior with Lua! :o */
|
||||
// SDL_AddEventWatch( SDLEventFilter, NULL );
|
||||
state->SDL_eventQueueLen = 0;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
|
||||
for ( int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++ ) {
|
||||
state->RLGLcurrentShaderLocs[i] = defaultShaderLocs[i];
|
||||
}
|
||||
#ifdef PLATFORM_DESKTOP_SDL
|
||||
state->SDL_eventQueue = malloc( PLATFORM_SDL_EVENT_QUEUE_LEN * sizeof( SDL_Event ) );
|
||||
state->SDL_eventQueueLen = 0;
|
||||
#endif
|
||||
|
||||
return state->run;
|
||||
}
|
||||
@@ -56,6 +60,9 @@ void stateFree() {
|
||||
if ( state->hasWindow ) {
|
||||
CloseWindow();
|
||||
}
|
||||
#ifdef PLATFORM_DESKTOP_SDL
|
||||
free( state->SDL_eventQueue );
|
||||
#endif
|
||||
free( state->exePath );
|
||||
free( state->RLGLcurrentShaderLocs );
|
||||
free( state );
|
||||
|
||||
Reference in New Issue
Block a user