SDL Events.
This commit is contained in:
@@ -12,6 +12,7 @@ KEY CHANGES:
|
|||||||
- ADDED: Support for platforms.
|
- ADDED: Support for platforms.
|
||||||
- ADDED: Platform desktop SDL.
|
- ADDED: Platform desktop SDL.
|
||||||
- CHANGE: Renamed event enums. Events are now platform specific.
|
- CHANGE: Renamed event enums. Events are now platform specific.
|
||||||
|
- ADDED: SDL Events.
|
||||||
|
|
||||||
DETAILED CHANGES:
|
DETAILED CHANGES:
|
||||||
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
|
- REMOVED: DrawLineBezierQuad, DrawLineBezierCubic.
|
||||||
|
|||||||
6
devnotes
6
devnotes
@@ -2,11 +2,11 @@ Current {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Backlog {
|
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.
|
* Platform specific API documentation.
|
||||||
|
* Raylibgui.
|
||||||
|
* Fix textbox focus.
|
||||||
* Platform desktop SDL.
|
* Platform desktop SDL.
|
||||||
* Thread safe Lua RL.event calling.
|
* Text input not working on gui. Could this be Raylib issue?
|
||||||
* Haptic functions.
|
* Haptic functions.
|
||||||
* Text
|
* Text
|
||||||
* Text codepoints management functions (unicode characters)? Could be usefull for luajit.
|
* Text codepoints management functions (unicode characters)? Could be usefull for luajit.
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ function RL.init()
|
|||||||
RL.SetWindowTitle( "Events" )
|
RL.SetWindowTitle( "Events" )
|
||||||
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
|
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
|
||||||
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
||||||
|
|
||||||
|
RL.SetTextLineSpacing( 24 )
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getEventType( event )
|
local function getEventType( event )
|
||||||
@@ -33,6 +35,8 @@ local function getEventType( event )
|
|||||||
return "Cursor Enter"
|
return "Cursor Enter"
|
||||||
elseif event.type == RL.EVENT_JOYSTICK then
|
elseif event.type == RL.EVENT_JOYSTICK then
|
||||||
return "Joystick"
|
return "Joystick"
|
||||||
|
elseif event.type == RL.SDL_KEYBOARD_EVENT then
|
||||||
|
return "SDL_KEYBOARD_EVENT"
|
||||||
end
|
end
|
||||||
|
|
||||||
return "Unknown"
|
return "Unknown"
|
||||||
@@ -99,9 +103,29 @@ function RL.event( event )
|
|||||||
elseif event.event == RL.GLFW_DISCONNECTED then
|
elseif event.event == RL.GLFW_DISCONNECTED then
|
||||||
text = text.."\nDisconnected"
|
text = text.."\nDisconnected"
|
||||||
end
|
end
|
||||||
elseif event.type == RL.SDL_KEYBOARD_EVENT then
|
|
||||||
text = text.."state: "..event.state
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function RL.draw()
|
function RL.draw()
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ function RL.init()
|
|||||||
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
RL.SetWindowState( RL.FLAG_VSYNC_HINT )
|
||||||
RL.SetWindowSize( winSize )
|
RL.SetWindowSize( winSize )
|
||||||
RL.SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
|
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
|
end
|
||||||
|
|
||||||
function RL.draw()
|
function RL.draw()
|
||||||
@@ -74,8 +76,8 @@ function RL.draw()
|
|||||||
if result == 1 then
|
if result == 1 then
|
||||||
dropdownActive = not dropdownActive
|
dropdownActive = not dropdownActive
|
||||||
end
|
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" )
|
result = RL.GuiMessageBox( { 420, 400, 200, 100 }, "Message", "Are you sure about this?", "Yes;No" )
|
||||||
if 0 <= result then
|
if 0 <= result then
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "glfw3.h"
|
||||||
|
#include "glfw3native.h"
|
||||||
|
|
||||||
enum EventType {
|
enum EventType {
|
||||||
GLFW_WINDOW_SIZE_EVENT,
|
GLFW_WINDOW_SIZE_EVENT,
|
||||||
GLFW_WINDOW_MAXIMIZE_EVENT,
|
GLFW_WINDOW_MAXIMIZE_EVENT,
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// #include "SDL.h"
|
// #define SDL_EVENT_QUEUE_LEN 128
|
||||||
|
|
||||||
enum EventType {
|
#include "SDL.h"
|
||||||
SDL_WINDOW_EVENT,
|
|
||||||
SDL_KEYBOARD_EVENT
|
// typedef struct {
|
||||||
};
|
// int SDL_eventQueueLen;
|
||||||
|
// SDL_Event **SDL_eventQueue;
|
||||||
|
// } SDL_State;
|
||||||
|
|
||||||
|
// extern SDL_State *SDL_state;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define ALLOC_PAGE_SIZE 256
|
#ifdef PLATFORM_DESKTOP_SDL
|
||||||
|
#define PLATFORM_SDL_EVENT_QUEUE_LEN 128
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *exePath;
|
char *exePath;
|
||||||
@@ -14,7 +16,6 @@ typedef struct {
|
|||||||
Material defaultMaterial;
|
Material defaultMaterial;
|
||||||
int *RLGLcurrentShaderLocs;
|
int *RLGLcurrentShaderLocs;
|
||||||
/* Events. */
|
/* Events. */
|
||||||
/* GLFW events. */
|
|
||||||
#ifdef PLATFORM_DESKTOP
|
#ifdef PLATFORM_DESKTOP
|
||||||
/* Window events. */
|
/* Window events. */
|
||||||
GLFWwindowsizefun raylibWindowSizeCallback;
|
GLFWwindowsizefun raylibWindowSizeCallback;
|
||||||
@@ -30,8 +31,9 @@ typedef struct {
|
|||||||
GLFWscrollfun raylibMouseScrollCallback;
|
GLFWscrollfun raylibMouseScrollCallback;
|
||||||
GLFWcursorenterfun raylibCursorEnterCallback;
|
GLFWcursorenterfun raylibCursorEnterCallback;
|
||||||
GLFWjoystickfun raylibJoystickCallback;
|
GLFWjoystickfun raylibJoystickCallback;
|
||||||
// #elif PLATFORM_DESKTOP_SDL
|
#elif PLATFORM_DESKTOP_SDL
|
||||||
|
int SDL_eventQueueLen;
|
||||||
|
SDL_Event *SDL_eventQueue;
|
||||||
#endif
|
#endif
|
||||||
} State;
|
} State;
|
||||||
|
|
||||||
|
|||||||
@@ -983,7 +983,7 @@ bool luaInit( int argn, const char **argc ) {
|
|||||||
defineModelAnimation();
|
defineModelAnimation();
|
||||||
/* Define globals. */
|
/* Define globals. */
|
||||||
defineGlobals();
|
defineGlobals();
|
||||||
definePlatformGlobals();
|
platformDefineGlobals();
|
||||||
|
|
||||||
/* Register functions. */
|
/* Register functions. */
|
||||||
luaRegister();
|
luaRegister();
|
||||||
@@ -1078,6 +1078,9 @@ bool luaCallMain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void luaCallProcess() {
|
void luaCallProcess() {
|
||||||
|
#ifdef PLATFORM_DESKTOP_SDL
|
||||||
|
platformSendEvents();
|
||||||
|
#endif
|
||||||
lua_State *L = state->luaState;
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
lua_pushcfunction( L, luaTraceback );
|
lua_pushcfunction( L, luaTraceback );
|
||||||
@@ -1115,7 +1118,6 @@ void luaCallDraw() {
|
|||||||
state->run = false;
|
state->run = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ int main( int argn, const char **argc ) {
|
|||||||
else {
|
else {
|
||||||
printVersion();
|
printVersion();
|
||||||
stateInit( argn, argc, exePath );
|
stateInit( argn, argc, exePath );
|
||||||
// luaRegister();
|
|
||||||
state->run = luaCallMain();
|
state->run = luaCallMain();
|
||||||
|
|
||||||
while ( state->run ) {
|
while ( state->run ) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "platforms/core_desktop.h"
|
#include "platforms/core_desktop.h"
|
||||||
|
|
||||||
static void definePlatformGlobals() {
|
static void platformDefineGlobals() {
|
||||||
lua_State *L = state->luaState;
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
@@ -463,7 +463,7 @@ static void joystickInputEvent( int jid, int event ) {
|
|||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void platformRegisterEvents() {
|
static void platformRegisterEvents() {
|
||||||
/* Window events. */
|
/* Window events. */
|
||||||
state->raylibWindowSizeCallback = glfwSetWindowSizeCallback( GetWindowHandle(), windowSizeEvent );
|
state->raylibWindowSizeCallback = glfwSetWindowSizeCallback( GetWindowHandle(), windowSizeEvent );
|
||||||
#if !defined( PLATFORM_WEB )
|
#if !defined( PLATFORM_WEB )
|
||||||
|
|||||||
@@ -3,19 +3,74 @@
|
|||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "platforms/core_desktop_sdl.h"
|
#include "platforms/core_desktop_sdl.h"
|
||||||
|
|
||||||
static void definePlatformGlobals() {
|
static void platformDefineGlobals() {
|
||||||
lua_State *L = state->luaState;
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
|
|
||||||
/* KeyboardKey */
|
/* KeyboardEvents */
|
||||||
assignGlobalInt( SDL_KEYDOWN, "SDL_KEYDOWN" ); // key pressed
|
assignGlobalInt( SDL_KEYDOWN, "SDL_KEYDOWN" ); // Key pressed
|
||||||
assignGlobalInt( SDL_KEYUP, "SDL_KEYUP" ); // key released
|
assignGlobalInt( SDL_KEYUP, "SDL_KEYUP" ); // Key released
|
||||||
assignGlobalInt( SDL_PRESSED, "SDL_PRESSED" ); // key pressed
|
/* WindowEvents */
|
||||||
assignGlobalInt( SDL_RELEASED, "SDL_RELEASED" ); // key released
|
assignGlobalInt( SDL_WINDOWEVENT, "SDL_WINDOWEVENT" ); // Window state change
|
||||||
/* Keyboard Events. */
|
/* MouseEvents */
|
||||||
assignGlobalInt( SDL_WINDOW_EVENT, "SDL_WINDOW_EVENT" ); // SDL Window Event
|
assignGlobalInt( SDL_MOUSEMOTION, "SDL_MOUSEMOTION" ); // Mouse moved
|
||||||
assignGlobalInt( SDL_KEYBOARD_EVENT, "SDL_KEYBOARD_EVENT" ); // SDL Keyboard Event
|
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 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
@@ -69,59 +124,350 @@ static void luaPlatformRegister() {
|
|||||||
|
|
||||||
/* Events. */
|
/* 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 ) {
|
static int SDLEventFilter( void *userdata, SDL_Event *event ) {
|
||||||
/* Don't handle events if exiting. Prevent segfault. */
|
/* SDL_EVENT_POLL_SENTINEL = 0x7F00, /**< Signals the end of an event poll cycle */
|
||||||
if ( event->type == SDL_QUIT || !state->run ) {
|
if ( event->type != SDL_QUIT && event->type != 0x7F00 && state->SDL_eventQueueLen < PLATFORM_SDL_EVENT_QUEUE_LEN ) {
|
||||||
return 0;
|
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_State *L = state->luaState;
|
||||||
|
|
||||||
lua_pushcfunction( L, luaTraceback );
|
lua_pushcfunction( L, luaTraceback );
|
||||||
int tracebackidx = lua_gettop( L );
|
int tracebackidx = lua_gettop( L );
|
||||||
|
|
||||||
|
/* If RL.event is not defined, we don't need to proceed. */
|
||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( !lua_isfunction( L, -1 ) ) {
|
if ( !lua_isfunction( L, -1 ) ) {
|
||||||
return 0;
|
state->SDL_eventQueueLen = 0;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( event->type ) {
|
for ( int i = 0; i < state->SDL_eventQueueLen; i++ ) {
|
||||||
case SDL_KEYDOWN:
|
bool call = false;
|
||||||
case SDL_KEYUP:
|
lua_getglobal( L, "RL" );
|
||||||
{
|
lua_getfield( L, -1, "event" );
|
||||||
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" );
|
|
||||||
|
|
||||||
|
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 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
|
||||||
}
|
}
|
||||||
break;
|
lua_pop( L, -1 );
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
state->SDL_eventQueueLen = 0;
|
||||||
|
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
|
|||||||
for ( int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++ ) {
|
for ( int i = 0; i < RL_MAX_SHADER_LOCATIONS; i++ ) {
|
||||||
state->RLGLcurrentShaderLocs[i] = defaultShaderLocs[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;
|
return state->run;
|
||||||
}
|
}
|
||||||
@@ -56,6 +60,9 @@ void stateFree() {
|
|||||||
if ( state->hasWindow ) {
|
if ( state->hasWindow ) {
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
}
|
}
|
||||||
|
#ifdef PLATFORM_DESKTOP_SDL
|
||||||
|
free( state->SDL_eventQueue );
|
||||||
|
#endif
|
||||||
free( state->exePath );
|
free( state->exePath );
|
||||||
free( state->RLGLcurrentShaderLocs );
|
free( state->RLGLcurrentShaderLocs );
|
||||||
free( state );
|
free( state );
|
||||||
|
|||||||
Reference in New Issue
Block a user