fix some bugs
This commit is contained in:
parent
b0bde349e3
commit
efe1bd282b
45
src/external/RGFW.h
vendored
45
src/external/RGFW.h
vendored
|
|
@ -487,12 +487,14 @@ typedef struct RGFW_Event {
|
|||
|
||||
u8 lockState;
|
||||
|
||||
u8 button; /* !< which mouse button was pressed */
|
||||
u8 button; /* !< which mouse (or joystick) button was pressed */
|
||||
double scroll; /*!< the raw mouse scroll value */
|
||||
|
||||
u16 joystick; /*! which joystick this event applies to (if applicable to any) */
|
||||
u8 axisesCount; /*!< number of axises */
|
||||
RGFW_point axis[2]; /*!< x, y of axises (-100 to 100) */
|
||||
|
||||
u8 whichAxis; /* which axis was effected */
|
||||
RGFW_point axis[4]; /*!< x, y of axises (-100 to 100) */
|
||||
|
||||
u64 frameTime, frameTime2; /*!< this is used for counting the fps */
|
||||
} RGFW_Event;
|
||||
|
|
@ -2300,6 +2302,7 @@ This is where OS specific stuff starts
|
|||
win->event.axis[e.number / 2].y = yAxis;
|
||||
win->event.type = RGFW_jsAxisMove;
|
||||
win->event.joystick = i;
|
||||
win->event.whichAxis = e.number / 2;
|
||||
RGFW_jsAxisCallback(win, i, win->event.axis, win->event.axisesCount);
|
||||
return &win->event;
|
||||
|
||||
|
|
@ -5699,6 +5702,8 @@ RGFW_UNUSED(win); /*!< if buffer rendering is not being used */
|
|||
RGFW_point axis2 = RGFW_POINT(state.Gamepad.sThumbRX, state.Gamepad.sThumbRY);
|
||||
|
||||
if (axis1.x != e->axis[0].x || axis1.y != e->axis[0].y || axis2.x != e->axis[1].x || axis2.y != e->axis[1].y) {
|
||||
win->event.whichAxis = (axis1.x != e->axis[0].x || axis1.y != e->axis[0].y) ? 0 : 1;
|
||||
|
||||
e->type = RGFW_jsAxisMove;
|
||||
|
||||
e->axis[0] = axis1;
|
||||
|
|
@ -8401,7 +8406,7 @@ EM_BOOL Emscripten_on_wheel(int eventType, const EmscriptenWheelEvent* e, void*
|
|||
RGFW_events[RGFW_eventLen].type = RGFW_mouseButtonPressed;
|
||||
RGFW_events[RGFW_eventLen].point = RGFW_POINT(e->mouse.targetX, e->mouse.targetY);
|
||||
RGFW_events[RGFW_eventLen].button = RGFW_mouseScrollUp + (e->deltaY < 0);
|
||||
RGFW_events[RGFW_eventLen].scroll = e->deltaY;
|
||||
RGFW_events[RGFW_eventLen].scroll = e->deltaY < 0 ? 1 : -1;
|
||||
|
||||
RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].prev = RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current;
|
||||
RGFW_mouseButtons[RGFW_events[RGFW_eventLen].button].current = 1;
|
||||
|
|
@ -8534,8 +8539,7 @@ void EMSCRIPTEN_KEEPALIVE RGFW_makeSetValue(size_t index, char* file) {
|
|||
*/
|
||||
|
||||
RGFW_events[RGFW_eventLen].type = RGFW_dnd;
|
||||
char** arr = (char**)&RGFW_events[RGFW_eventLen].droppedFiles[index];
|
||||
*arr = file;
|
||||
strcpy((char*)RGFW_events[RGFW_eventLen].droppedFiles[index], file);
|
||||
}
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
|
@ -8689,14 +8693,15 @@ RGFW_window* RGFW_createWindow(const char* name, RGFW_rect rect, u16 args) {
|
|||
RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) {
|
||||
static u8 index = 0;
|
||||
|
||||
if (index == 0)
|
||||
if (index == 0) {
|
||||
RGFW_resetKey();
|
||||
}
|
||||
|
||||
emscripten_sample_gamepad_data();
|
||||
/* check gamepads */
|
||||
for (int i = 0; (i < emscripten_get_num_gamepads()) && (i < 4); i++) {
|
||||
if (RGFW_joysticks[i] == 0)
|
||||
continue;;
|
||||
|
||||
continue;
|
||||
EmscriptenGamepadEvent gamepadState;
|
||||
|
||||
if (emscripten_get_gamepad_status(i, &gamepadState) != EMSCRIPTEN_RESULT_SUCCESS)
|
||||
|
|
@ -8705,33 +8710,41 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) {
|
|||
// Register buttons data for every connected gamepad
|
||||
for (int j = 0; (j < gamepadState.numButtons) && (j < 16); j++) {
|
||||
u32 map[] = {
|
||||
RGFW_JS_A, RGFW_JS_X, RGFW_JS_B, RGFW_JS_Y,
|
||||
RGFW_JS_A, RGFW_JS_B, RGFW_JS_X, RGFW_JS_Y,
|
||||
RGFW_JS_L1, RGFW_JS_R1, RGFW_JS_L2, RGFW_JS_R2,
|
||||
RGFW_JS_SELECT, RGFW_JS_START,
|
||||
0, 0,
|
||||
404, 404,
|
||||
RGFW_JS_UP, RGFW_JS_DOWN, RGFW_JS_LEFT, RGFW_JS_RIGHT
|
||||
};
|
||||
|
||||
|
||||
u32 button = map[j];
|
||||
if (button == 404)
|
||||
continue;
|
||||
|
||||
if (RGFW_jsPressed[i][button] != gamepadState.digitalButton[j]) {
|
||||
if (gamepadState.digitalButton[j])
|
||||
win->event.type = RGFW_jsButtonPressed;
|
||||
else
|
||||
win->event.type = RGFW_jsButtonReleased;
|
||||
|
||||
win->event.joystick = i;
|
||||
win->event.button = map[j];
|
||||
RGFW_jsPressed[i][button] = gamepadState.digitalButton[j];
|
||||
return &win->event;
|
||||
}
|
||||
|
||||
RGFW_jsPressed[i][button] = gamepadState.digitalButton[j];
|
||||
}
|
||||
|
||||
for (int j = 0; (j < gamepadState.numAxes) && (j < 4); j += 2) {
|
||||
win->event.axisesCount = gamepadState.numAxes;
|
||||
if (win->event.axis[j].x != gamepadState.axis[j] ||
|
||||
win->event.axis[j].y != gamepadState.axis[j + 1]
|
||||
if (win->event.axis[j].x != (i8)(gamepadState.axis[j] * 100.0f) ||
|
||||
win->event.axis[j].y != (i8)(gamepadState.axis[j + 1] * 100.0f)
|
||||
) {
|
||||
win->event.axis[j].x = gamepadState.axis[j];
|
||||
win->event.axis[j].y = gamepadState.axis[j + 1];
|
||||
win->event.axis[j / 2].x = (i8)(gamepadState.axis[j] * 100.0f);
|
||||
win->event.axis[j / 2].y = (i8)(gamepadState.axis[j + 1] * 100.0f);
|
||||
win->event.type = RGFW_jsAxisMove;
|
||||
win->event.joystick = i;
|
||||
win->event.whichAxis = j / 2;
|
||||
return &win->event;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ static bool RGFW_disableCursor = false;
|
|||
|
||||
static const unsigned short keyMappingRGFW[] = {
|
||||
[RGFW_KEY_NULL] = KEY_NULL,
|
||||
[RGFW_Return] = KEY_ENTER,
|
||||
[RGFW_Quote] = KEY_APOSTROPHE,
|
||||
[RGFW_Comma] = KEY_COMMA,
|
||||
[RGFW_Minus] = KEY_MINUS,
|
||||
|
|
@ -949,8 +950,8 @@ void PollInputEvents(void)
|
|||
}
|
||||
|
||||
RGFW_Event *event = &platform.window->event;
|
||||
|
||||
// All input events can be processed after polling
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RGFW_quit: CORE.Window.shouldClose = true; break;
|
||||
|
|
@ -1001,7 +1002,6 @@ void PollInputEvents(void)
|
|||
case RGFW_keyPressed:
|
||||
{
|
||||
KeyboardKey key = ConvertScancodeToKey(event->keyCode);
|
||||
|
||||
if (key != KEY_NULL)
|
||||
{
|
||||
// If key was up, add it to the key pressed queue
|
||||
|
|
@ -1040,6 +1040,7 @@ void PollInputEvents(void)
|
|||
{
|
||||
if ((event->button == RGFW_mouseScrollUp) || (event->button == RGFW_mouseScrollDown))
|
||||
{
|
||||
|
||||
CORE.Input.Mouse.currentWheelMove.y = event->scroll;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1056,7 +1057,6 @@ void PollInputEvents(void)
|
|||
} break;
|
||||
case RGFW_mouseButtonReleased:
|
||||
{
|
||||
|
||||
if ((event->button == RGFW_mouseScrollUp) || (event->button == RGFW_mouseScrollDown))
|
||||
{
|
||||
CORE.Input.Mouse.currentWheelMove.y = event->scroll;
|
||||
|
|
@ -1161,28 +1161,31 @@ void PollInputEvents(void)
|
|||
case RGFW_jsAxisMove:
|
||||
{
|
||||
int axis = -1;
|
||||
for (int i = 0; i < event->axisesCount; i++)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
|
||||
float value = 0;
|
||||
switch(event->whichAxis) {
|
||||
case 0:
|
||||
{
|
||||
if (abs(event->axis[i].x) > abs(event->axis[i].y))
|
||||
if (abs(event->axis[0].x) > abs(event->axis[0].y))
|
||||
{
|
||||
axis = GAMEPAD_AXIS_LEFT_X;
|
||||
value = event->axis[0].x;
|
||||
break;
|
||||
}
|
||||
|
||||
value = event->axis[0].y;
|
||||
axis = GAMEPAD_AXIS_LEFT_Y;
|
||||
} break;
|
||||
case 1:
|
||||
{
|
||||
if (abs(event->axis[i].x) > abs(event->axis[i].y))
|
||||
if (abs(event->axis[1].x) > abs(event->axis[1].y))
|
||||
{
|
||||
axis = GAMEPAD_AXIS_RIGHT_X;
|
||||
value = event->axis[1].x;
|
||||
break;
|
||||
}
|
||||
|
||||
value = event->axis[1].y;
|
||||
axis = GAMEPAD_AXIS_RIGHT_Y;
|
||||
} break;
|
||||
case 2: axis = GAMEPAD_AXIS_LEFT_TRIGGER; break;
|
||||
|
|
@ -1191,9 +1194,9 @@ void PollInputEvents(void)
|
|||
}
|
||||
|
||||
#ifdef __linux__
|
||||
float value = (event->axis[i].x + event->axis[i].y)/(float)32767;
|
||||
value = (float)(value)/32767.0f;
|
||||
#else
|
||||
float value = (event->axis[i].x + -event->axis[i].y)/(float)32767;
|
||||
value = ((float)value / 100.0f);
|
||||
#endif
|
||||
CORE.Input.Gamepad.axisState[event->joystick][axis] = value;
|
||||
|
||||
|
|
@ -1207,7 +1210,6 @@ void PollInputEvents(void)
|
|||
if (pressed) CORE.Input.Gamepad.lastButtonPressed = button;
|
||||
else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
|
@ -1299,10 +1301,10 @@ int InitPlatform(void)
|
|||
I think this is needed by Raylib now ?
|
||||
If so, rcore_destkop_sdl should be updated too
|
||||
*/
|
||||
|
||||
SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
if (CORE.Window.flags & FLAG_VSYNC_HINT) RGFW_window_swapInterval(platform.window, 1);
|
||||
|
||||
RGFW_window_makeCurrent(platform.window);
|
||||
|
||||
// Check surface and context activation
|
||||
|
|
@ -1374,7 +1376,6 @@ int InitPlatform(void)
|
|||
#endif
|
||||
|
||||
TRACELOG(LOG_INFO, "PLATFORM: CUSTOM: Initialized successfully");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user