diff options
Diffstat (limited to 'src/platforms')
| -rw-r--r-- | src/platforms/rcore_android.c | 16 | ||||
| -rw-r--r-- | src/platforms/rcore_desktop_rgfw.c | 6 | ||||
| -rw-r--r-- | src/platforms/rcore_desktop_sdl.c | 59 | ||||
| -rw-r--r-- | src/platforms/rcore_drm.c | 8 | ||||
| -rw-r--r-- | src/platforms/rcore_web.c | 6 |
5 files changed, 47 insertions, 48 deletions
diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c index dc8724d8..8fc51d0e 100644 --- a/src/platforms/rcore_android.c +++ b/src/platforms/rcore_android.c @@ -81,7 +81,7 @@ static PlatformData platform = { 0 }; // Platform specific data // Local Variables Definition //---------------------------------------------------------------------------------- #define KEYCODE_MAP_SIZE 162 -static const KeyboardKey KeycodeMap[KEYCODE_MAP_SIZE] = { +static const KeyboardKey mapKeycode[KEYCODE_MAP_SIZE] = { KEY_NULL, // AKEYCODE_UNKNOWN 0, // AKEYCODE_SOFT_LEFT 0, // AKEYCODE_SOFT_RIGHT @@ -1133,9 +1133,9 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) CORE.Input.Gamepad.axisState[0][GAMEPAD_AXIS_RIGHT_Y] = AMotionEvent_getAxisValue( event, AMOTION_EVENT_AXIS_RZ, 0); CORE.Input.Gamepad.axisState[0][GAMEPAD_AXIS_LEFT_TRIGGER] = AMotionEvent_getAxisValue( - event, AMOTION_EVENT_AXIS_BRAKE, 0) * 2.0f - 1.0f; + event, AMOTION_EVENT_AXIS_BRAKE, 0)*2.0f - 1.0f; CORE.Input.Gamepad.axisState[0][GAMEPAD_AXIS_RIGHT_TRIGGER] = AMotionEvent_getAxisValue( - event, AMOTION_EVENT_AXIS_GAS, 0) * 2.0f - 1.0f; + event, AMOTION_EVENT_AXIS_GAS, 0)*2.0f - 1.0f; // dpad is reported as an axis on android float dpadX = AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_HAT_X, 0); @@ -1201,7 +1201,7 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) return 1; // Handled gamepad button } - KeyboardKey key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE) ? KeycodeMap[keycode] : KEY_NULL; + KeyboardKey key = (keycode > 0 && keycode < KEYCODE_MAP_SIZE)? mapKeycode[keycode] : KEY_NULL; if (key != KEY_NULL) { // Save current key and its state @@ -1252,10 +1252,10 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) CORE.Input.Touch.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) }; // Normalize CORE.Input.Touch.position[i] for CORE.Window.screen.width and CORE.Window.screen.height - float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x) / (float)CORE.Window.display.width; - float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y) / (float)CORE.Window.display.height; - CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x * widthRatio - (float)CORE.Window.renderOffset.x / 2; - CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y * heightRatio - (float)CORE.Window.renderOffset.y / 2; + float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x)/(float)CORE.Window.display.width; + float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y)/(float)CORE.Window.display.height; + CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x*widthRatio - (float)CORE.Window.renderOffset.x/2; + CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y*heightRatio - (float)CORE.Window.renderOffset.y/2; } int32_t action = AMotionEvent_getAction(event); diff --git a/src/platforms/rcore_desktop_rgfw.c b/src/platforms/rcore_desktop_rgfw.c index dbbbe10c..d53237fc 100644 --- a/src/platforms/rcore_desktop_rgfw.c +++ b/src/platforms/rcore_desktop_rgfw.c @@ -1097,16 +1097,16 @@ void PollInputEvents(void) }
#ifdef __linux__
- float value = (event->axis[i].x + event->axis[i].y) / (float) 32767;
+ 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;
+ float value = (event->axis[i].x + -event->axis[i].y)/(float)32767;
#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 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;
diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 8a0fea81..d9637f70 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -80,7 +80,7 @@ static PlatformData platform = { 0 }; // Platform specific data // Local Variables Definition //---------------------------------------------------------------------------------- #define SCANCODE_MAPPED_NUM 232 -static const KeyboardKey ScancodeToKey[SCANCODE_MAPPED_NUM] = { +static const KeyboardKey mapScancodeToKey[SCANCODE_MAPPED_NUM] = { KEY_NULL, // SDL_SCANCODE_UNKNOWN 0, 0, @@ -476,9 +476,9 @@ void ClearWindowState(unsigned int flags) // Set icon for window void SetWindowIcon(Image image) { - SDL_Surface* iconSurface = NULL; + SDL_Surface *iconSurface = NULL; - Uint32 rmask, gmask, bmask, amask; + unsigned int rmask = 0, gmask = 0, bmask = 0, amask = 0; int depth = 0; // Depth in bits int pitch = 0; // Pixel spacing (pitch) in bytes @@ -492,72 +492,67 @@ void SetWindowIcon(Image image) case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: rmask = 0xFF, gmask = 0xFF00; bmask = 0, amask = 0; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R5G6B5: rmask = 0xF800, gmask = 0x07E0; bmask = 0x001F, amask = 0; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R8G8B8: // Uses BGR for 24-bit rmask = 0x0000FF, gmask = 0x00FF00; bmask = 0xFF0000, amask = 0; - depth = 24, pitch = image.width * 3; + depth = 24, pitch = image.width*3; break; case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: rmask = 0xF800, gmask = 0x07C0; bmask = 0x003E, amask = 0x0001; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: rmask = 0xF000, gmask = 0x0F00; bmask = 0x00F0, amask = 0x000F; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: rmask = 0xFF000000, gmask = 0x00FF0000; bmask = 0x0000FF00, amask = 0x000000FF; - depth = 32, pitch = image.width * 4; + depth = 32, pitch = image.width*4; break; case PIXELFORMAT_UNCOMPRESSED_R32: rmask = 0xFFFFFFFF, gmask = 0; bmask = 0, amask = 0; - depth = 32, pitch = image.width * 4; + depth = 32, pitch = image.width*4; break; case PIXELFORMAT_UNCOMPRESSED_R32G32B32: rmask = 0xFFFFFFFF, gmask = 0xFFFFFFFF; bmask = 0xFFFFFFFF, amask = 0; - depth = 96, pitch = image.width * 12; + depth = 96, pitch = image.width*12; break; case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: rmask = 0xFFFFFFFF, gmask = 0xFFFFFFFF; bmask = 0xFFFFFFFF, amask = 0xFFFFFFFF; - depth = 128, pitch = image.width * 16; + depth = 128, pitch = image.width*16; break; case PIXELFORMAT_UNCOMPRESSED_R16: rmask = 0xFFFF, gmask = 0; bmask = 0, amask = 0; - depth = 16, pitch = image.width * 2; + depth = 16, pitch = image.width*2; break; case PIXELFORMAT_UNCOMPRESSED_R16G16B16: rmask = 0xFFFF, gmask = 0xFFFF; bmask = 0xFFFF, amask = 0; - depth = 48, pitch = image.width * 6; + depth = 48, pitch = image.width*6; break; case PIXELFORMAT_UNCOMPRESSED_R16G16B16A16: rmask = 0xFFFF, gmask = 0xFFFF; bmask = 0xFFFF, amask = 0xFFFF; - depth = 64, pitch = image.width * 8; + depth = 64, pitch = image.width*8; break; - default: - // Compressed formats are not supported - return; + default: return; // Compressed formats are not supported } - iconSurface = SDL_CreateRGBSurfaceFrom( - image.data, image.width, image.height, depth, pitch, - rmask, gmask, bmask, amask - ); + iconSurface = SDL_CreateRGBSurfaceFrom( image.data, image.width, image.height, depth, pitch, rmask, gmask, bmask, amask ); if (iconSurface) { @@ -599,7 +594,7 @@ void SetWindowMonitor(int monitor) // 1. SDL started supporting moving exclusive fullscreen windows between displays on SDL3, // see commit https://github.com/libsdl-org/SDL/commit/3f5ef7dd422057edbcf3e736107e34be4b75d9ba // 2. A workaround for SDL2 is leaving fullscreen, moving the window, then entering full screen again. - const bool wasFullscreen = ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) ? true : false; + const bool wasFullscreen = ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0)? true : false; const int screenWidth = CORE.Window.screen.width; const int screenHeight = CORE.Window.screen.height; @@ -941,11 +936,11 @@ int SetGamepadMappings(const char *mappings) // Set gamepad vibration void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor) { - //Limit input values to between 0.0f and 1.0f - leftMotor = (0.0f > leftMotor) ? 0.0f : leftMotor; - rightMotor = (0.0f > rightMotor) ? 0.0f : rightMotor; - leftMotor = (1.0f < leftMotor) ? 1.0f : leftMotor; - rightMotor = (1.0f < rightMotor) ? 1.0f : rightMotor; + // Limit input values to between 0.0f and 1.0f + leftMotor = (0.0f > leftMotor)? 0.0f : leftMotor; + rightMotor = (0.0f > rightMotor)? 0.0f : rightMotor; + leftMotor = (1.0f < leftMotor)? 1.0f : leftMotor; + rightMotor = (1.0f < rightMotor)? 1.0f : rightMotor; if (IsGamepadAvailable(gamepad)) { @@ -1365,13 +1360,13 @@ void PollInputEvents(void) if (axis >= 0) { // SDL axis value range is -32768 to 32767, we normalize it to RayLib's -1.0 to 1.0f range - float value = event.jaxis.value / (float) 32767; + float value = event.jaxis.value/(float)32767; CORE.Input.Gamepad.axisState[event.jaxis.which][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 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.jaxis.which][button] = pressed; if (pressed) CORE.Input.Gamepad.lastButtonPressed = button; @@ -1554,6 +1549,7 @@ int InitPlatform(void) for (int i = 0; (i < SDL_NumJoysticks()) && (i < MAX_GAMEPADS); i++) { platform.gamepad[i] = SDL_JoystickOpen(i); + if (platform.gamepad[i]) { CORE.Input.Gamepad.ready[i] = true; @@ -1608,8 +1604,9 @@ static KeyboardKey ConvertScancodeToKey(SDL_Scancode sdlScancode) { if (sdlScancode >= 0 && sdlScancode < SCANCODE_MAPPED_NUM) { - return ScancodeToKey[sdlScancode]; + return mapScancodeToKey[sdlScancode]; } + return KEY_NULL; // No equivalent key in Raylib } // EOF diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index 17a8e4d0..f888d0e4 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -1028,7 +1028,7 @@ int InitPlatform(void) // If graphic device is no properly initialized, we end program if (!CORE.Window.ready) { TRACELOG(LOG_FATAL, "PLATFORM: Failed to initialize graphic device"); return -1; } - else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor()) / 2 - CORE.Window.screen.width / 2, GetMonitorHeight(GetCurrentMonitor()) / 2 - CORE.Window.screen.height / 2); + else SetWindowPosition(GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2, GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2); // Set some default window flags CORE.Window.flags &= ~FLAG_WINDOW_HIDDEN; // false @@ -1614,7 +1614,7 @@ static void PollKeyboardEvents(void) } } - TRACELOG(LOG_DEBUG, "INPUT: KEY_%s Keycode(linux): %4i KeyCode(raylib): %4i", (event.value == 0) ? "UP " : "DOWN", event.code, keycode); + TRACELOG(LOG_DEBUG, "INPUT: KEY_%s Keycode(linux): %4i KeyCode(raylib): %4i", (event.value == 0)? "UP " : "DOWN", event.code, keycode); } } } @@ -1641,7 +1641,7 @@ static void PollGamepadEvents(void) { short keycodeRaylib = linuxToRaylibMap[event.code]; - TRACELOG(LOG_DEBUG, "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i", i, (event.value == 0) ? "UP " : "DOWN", event.code, keycodeRaylib); + TRACELOG(LOG_DEBUG, "INPUT: Gamepad %2i: KEY_%s Keycode(linux): %4i Keycode(raylib): %4i", i, (event.value == 0)? "UP" : "DOWN", event.code, keycodeRaylib); if ((keycodeRaylib != 0) && (keycodeRaylib < MAX_GAMEPAD_BUTTONS)) { @@ -1666,7 +1666,7 @@ static void PollGamepadEvents(void) int range = platform.gamepadAbsAxisRange[i][event.code][1]; // NOTE: Scaling of event.value to get values between -1..1 - CORE.Input.Gamepad.axisState[i][axisRaylib] = (2 * (float)(event.value - min) / range) - 1; + CORE.Input.Gamepad.axisState[i][axisRaylib] = (2*(float)(event.value - min)/range) - 1; } } } diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index afe8adfb..47b8d42d 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -190,7 +190,8 @@ void ToggleFullscreen(void) if (enterFullscreen) { // NOTE: The setTimeouts handle the browser mode change delay - EM_ASM( + EM_ASM + ( setTimeout(function() { Module.requestFullscreen(false, false); @@ -298,7 +299,8 @@ void ToggleBorderlessWindowed(void) { // NOTE: 1. The setTimeouts handle the browser mode change delay // 2. The style unset handles the possibility of a width="value%" like on the default shell.html file - EM_ASM( + EM_ASM + ( setTimeout(function() { Module.requestFullscreen(false, true); |
