fix some bugs
This commit is contained in:
parent
b0bde349e3
commit
efe1bd282b
57
src/external/RGFW.h
vendored
57
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;
|
||||
|
|
@ -8317,7 +8322,7 @@ EM_BOOL Emscripten_on_fullscreenchange(int eventType, const EmscriptenFullscreen
|
|||
|
||||
RGFW_events[RGFW_eventLen].type = RGFW_windowResized;
|
||||
RGFW_eventLen++;
|
||||
|
||||
|
||||
RGFW_root->r = RGFW_RECT(0, 0, e->elementWidth, e->elementHeight);
|
||||
RGFW_windowResizeCallback(RGFW_root, RGFW_root->r);
|
||||
return EM_TRUE;
|
||||
|
|
@ -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;
|
||||
|
|
@ -8474,7 +8479,7 @@ EM_BOOL Emscripten_on_gamepad(int eventType, const EmscriptenGamepadEvent *gamep
|
|||
|
||||
if (gamepadEvent->index >= 4)
|
||||
return 0;
|
||||
|
||||
|
||||
RGFW_joysticks[gamepadEvent->index] = gamepadEvent->connected;
|
||||
|
||||
return 1; // The event was consumed by the callback handler
|
||||
|
|
@ -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,49 +8693,58 @@ 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)
|
||||
break;
|
||||
|
||||
|
||||
// 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]) {
|
||||
win->event.type = RGFW_jsButtonPressed;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -8740,7 +8753,7 @@ RGFW_Event* RGFW_window_checkEvent(RGFW_window* win) {
|
|||
/* check queued events */
|
||||
if (RGFW_eventLen == 0)
|
||||
return NULL;
|
||||
|
||||
|
||||
RGFW_events[index].frameTime = win->event.frameTime;
|
||||
RGFW_events[index].frameTime2 = win->event.frameTime2;
|
||||
RGFW_events[index].inFocus = win->event.inFocus;
|
||||
|
|
|
|||
|
|
@ -124,7 +124,8 @@ static bool RGFW_disableCursor = false;
|
|||
|
||||
static const unsigned short keyMappingRGFW[] = {
|
||||
[RGFW_KEY_NULL] = KEY_NULL,
|
||||
[RGFW_Quote] = KEY_APOSTROPHE,
|
||||
[RGFW_Return] = KEY_ENTER,
|
||||
[RGFW_Quote] = KEY_APOSTROPHE,
|
||||
[RGFW_Comma] = KEY_COMMA,
|
||||
[RGFW_Minus] = KEY_MINUS,
|
||||
[RGFW_Period] = KEY_PERIOD,
|
||||
|
|
@ -872,7 +873,7 @@ void PollInputEvents(void)
|
|||
// because ProcessGestureEvent() is just called on an event, not every frame
|
||||
UpdateGestures();
|
||||
#endif
|
||||
|
||||
|
||||
// Reset keys/chars pressed registered
|
||||
CORE.Input.Keyboard.keyPressedQueueCount = 0;
|
||||
CORE.Input.Keyboard.charPressedQueueCount = 0;
|
||||
|
|
@ -949,9 +950,9 @@ void PollInputEvents(void)
|
|||
}
|
||||
|
||||
RGFW_Event *event = &platform.window->event;
|
||||
|
||||
// All input events can be processed after polling
|
||||
switch (event->type)
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RGFW_quit: CORE.Window.shouldClose = true; break;
|
||||
case RGFW_dnd: // Dropped file
|
||||
|
|
@ -967,7 +968,7 @@ void PollInputEvents(void)
|
|||
|
||||
CORE.Window.dropFilepaths[CORE.Window.dropFileCount] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
||||
strcpy(CORE.Window.dropFilepaths[CORE.Window.dropFileCount], event->droppedFiles[i]);
|
||||
|
||||
|
||||
CORE.Window.dropFileCount++;
|
||||
}
|
||||
else if (CORE.Window.dropFileCount < 1024)
|
||||
|
|
@ -1000,8 +1001,7 @@ void PollInputEvents(void)
|
|||
// Keyboard events
|
||||
case RGFW_keyPressed:
|
||||
{
|
||||
KeyboardKey key = ConvertScancodeToKey(event->keyCode);
|
||||
|
||||
KeyboardKey key = ConvertScancodeToKey(event->keyCode);
|
||||
if (key != KEY_NULL)
|
||||
{
|
||||
// If key was up, add it to the key pressed queue
|
||||
|
|
@ -1038,9 +1038,10 @@ void PollInputEvents(void)
|
|||
// Check mouse events
|
||||
case RGFW_mouseButtonPressed:
|
||||
{
|
||||
if ((event->button == RGFW_mouseScrollUp) || (event->button == RGFW_mouseScrollDown))
|
||||
if ((event->button == RGFW_mouseScrollUp) || (event->button == RGFW_mouseScrollDown))
|
||||
{
|
||||
CORE.Input.Mouse.currentWheelMove.y = event->scroll;
|
||||
|
||||
CORE.Input.Mouse.currentWheelMove.y = event->scroll;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1056,8 +1057,7 @@ void PollInputEvents(void)
|
|||
} break;
|
||||
case RGFW_mouseButtonReleased:
|
||||
{
|
||||
|
||||
if ((event->button == RGFW_mouseScrollUp) || (event->button == RGFW_mouseScrollDown))
|
||||
if ((event->button == RGFW_mouseScrollUp) || (event->button == RGFW_mouseScrollDown))
|
||||
{
|
||||
CORE.Input.Mouse.currentWheelMove.y = event->scroll;
|
||||
break;
|
||||
|
|
@ -1161,53 +1161,55 @@ void PollInputEvents(void)
|
|||
case RGFW_jsAxisMove:
|
||||
{
|
||||
int axis = -1;
|
||||
for (int i = 0; i < event->axisesCount; i++)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (abs(event->axis[i].x) > abs(event->axis[i].y))
|
||||
{
|
||||
axis = GAMEPAD_AXIS_LEFT_X;
|
||||
break;
|
||||
}
|
||||
|
||||
axis = GAMEPAD_AXIS_LEFT_Y;
|
||||
} break;
|
||||
case 1:
|
||||
{
|
||||
if (abs(event->axis[i].x) > abs(event->axis[i].y))
|
||||
{
|
||||
axis = GAMEPAD_AXIS_RIGHT_X;
|
||||
break;
|
||||
}
|
||||
float value = 0;
|
||||
switch(event->whichAxis) {
|
||||
case 0:
|
||||
{
|
||||
if (abs(event->axis[0].x) > abs(event->axis[0].y))
|
||||
{
|
||||
axis = GAMEPAD_AXIS_LEFT_X;
|
||||
value = event->axis[0].x;
|
||||
break;
|
||||
}
|
||||
|
||||
axis = GAMEPAD_AXIS_RIGHT_Y;
|
||||
} break;
|
||||
case 2: axis = GAMEPAD_AXIS_LEFT_TRIGGER; break;
|
||||
case 3: axis = GAMEPAD_AXIS_RIGHT_TRIGGER; break;
|
||||
default: break;
|
||||
}
|
||||
value = event->axis[0].y;
|
||||
axis = GAMEPAD_AXIS_LEFT_Y;
|
||||
} break;
|
||||
case 1:
|
||||
{
|
||||
if (abs(event->axis[1].x) > abs(event->axis[1].y))
|
||||
{
|
||||
axis = GAMEPAD_AXIS_RIGHT_X;
|
||||
value = event->axis[1].x;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
float value = (event->axis[i].x + event->axis[i].y)/(float)32767;
|
||||
#else
|
||||
float value = (event->axis[i].x + -event->axis[i].y)/(float)32767;
|
||||
#endif
|
||||
CORE.Input.Gamepad.axisState[event->joystick][axis] = value;
|
||||
value = event->axis[1].y;
|
||||
axis = GAMEPAD_AXIS_RIGHT_Y;
|
||||
} break;
|
||||
case 2: axis = GAMEPAD_AXIS_LEFT_TRIGGER; break;
|
||||
case 3: axis = GAMEPAD_AXIS_RIGHT_TRIGGER; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
value = (float)(value)/32767.0f;
|
||||
#else
|
||||
value = ((float)value / 100.0f);
|
||||
#endif
|
||||
CORE.Input.Gamepad.axisState[event->joystick][axis] = value;
|
||||
|
||||
// Register button state for triggers in addition to their axes
|
||||
if ((axis == GAMEPAD_AXIS_LEFT_TRIGGER) || (axis == GAMEPAD_AXIS_RIGHT_TRIGGER))
|
||||
{
|
||||
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
|
||||
int pressed = (value > 0.1f);
|
||||
CORE.Input.Gamepad.currentButtonState[event->joystick][button] = pressed;
|
||||
|
||||
if (pressed) CORE.Input.Gamepad.lastButtonPressed = button;
|
||||
else if (CORE.Input.Gamepad.lastButtonPressed == button) CORE.Input.Gamepad.lastButtonPressed = 0;
|
||||
}
|
||||
}
|
||||
// Register button state for triggers in addition to their axes
|
||||
if ((axis == GAMEPAD_AXIS_LEFT_TRIGGER) || (axis == GAMEPAD_AXIS_RIGHT_TRIGGER))
|
||||
{
|
||||
int button = (axis == GAMEPAD_AXIS_LEFT_TRIGGER)? GAMEPAD_BUTTON_LEFT_TRIGGER_2 : GAMEPAD_BUTTON_RIGHT_TRIGGER_2;
|
||||
int pressed = (value > 0.1f);
|
||||
CORE.Input.Gamepad.currentButtonState[event->joystick][button] = pressed;
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -1388,6 +1389,6 @@ void ClosePlatform(void)
|
|||
static KeyboardKey ConvertScancodeToKey(u32 keycode)
|
||||
{
|
||||
if (keycode > sizeof(keyMappingRGFW)/sizeof(unsigned short)) return 0;
|
||||
|
||||
return keyMappingRGFW[keycode];
|
||||
|
||||
return keyMappingRGFW[keycode];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3573,7 +3573,7 @@ void SetupViewport(int width, int height)
|
|||
// NOTE: Global variables CORE.Window.render.width/CORE.Window.render.height and CORE.Window.renderOffset.x/CORE.Window.renderOffset.y can be modified
|
||||
void SetupFramebuffer(int width, int height)
|
||||
{
|
||||
// Calculate CORE.Window.render.width and CORE.Window.render.height, we have the display size (input params) and the desired screen size (global var)
|
||||
// Calculate CORE.Window.render.width and CORE.Window.render.height, we have the display size (input params) and the desired screen size (global var)
|
||||
if ((CORE.Window.screen.width > CORE.Window.display.width) || (CORE.Window.screen.height > CORE.Window.display.height))
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "DISPLAY: Downscaling required: Screen size (%ix%i) is bigger than display size (%ix%i)", CORE.Window.screen.width, CORE.Window.screen.height, CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user