mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-19 22:01:14 +00:00
121 lines
3.2 KiB
C
121 lines
3.2 KiB
C
#pragma once
|
|
|
|
// https://wiki.libsdl.org/SDL3/README-migration#sdl_stdinch
|
|
#define SDL_bool bool
|
|
|
|
#include <SDL2/SDL.h>
|
|
#include "SDL_events.h"
|
|
#include "SDL_gamepad.h"
|
|
#include "SDL_iostream.h"
|
|
#include "SDL_keyboard.h"
|
|
#include "SDL_mutex.h"
|
|
#include "SDL_pixels.h"
|
|
#include "SDL_surface.h"
|
|
#include "SDL_timer.h"
|
|
|
|
// https://wiki.libsdl.org/SDL3/README-migration#sdl_logh
|
|
|
|
#define SDL_LogTrace SDL_LogVerbose
|
|
|
|
// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh
|
|
|
|
typedef Uint32 SDL_DisplayID;
|
|
inline SDL_DisplayID SDL_GetPrimaryDisplay()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
// Modified from 83bb0f9105922fd49282f0b931f7873a71877ac8 SDL_video.c#L1331
|
|
inline SDL_DisplayMode** SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count)
|
|
{
|
|
int i;
|
|
if (count) *count = 0;
|
|
|
|
const int num_modes = SDL_GetNumDisplayModes(displayID);
|
|
SDL_DisplayMode** result = static_cast<SDL_DisplayMode**>(SDL_malloc(sizeof(SDL_DisplayMode*) * num_modes));
|
|
if (result) {
|
|
SDL_DisplayMode *modes = (SDL_DisplayMode *)((Uint8 *)result + ((num_modes + 1) * sizeof(*result)));
|
|
for (i = 0; i < num_modes; ++i) {
|
|
if (SDL_GetDisplayMode(displayID, i, &modes[i]) == 0) {
|
|
result[i] = modes++;
|
|
}
|
|
}
|
|
result[i] = NULL;
|
|
|
|
if (count) {
|
|
*count = num_modes;
|
|
}
|
|
SDL_free(modes);
|
|
} else {
|
|
if (count) {
|
|
*count = 0;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
inline SDL_DisplayMode* SDL_GetCurrentDisplayMode(SDL_DisplayID displayID)
|
|
{
|
|
SDL_DisplayMode* mode = nullptr;
|
|
SDL_GetCurrentDisplayMode(displayID, mode);
|
|
return mode;
|
|
}
|
|
|
|
#define SDL_GetWindowSize(...) (SDL_GetWindowSize(__VA_ARGS__), true )
|
|
|
|
// https://wiki.libsdl.org/SDL3/README-migration#sdl_videoh
|
|
|
|
#define SDL_GL_DestroyContext SDL_GL_DeleteContext
|
|
|
|
// https://wiki.libsdl.org/SDL3/README-migration#sdl_renderh
|
|
|
|
// hardcode -1 as all uses are NULL or -1 (hacks out failure)
|
|
#define SDL_CreateRenderer(window, name) SDL_CreateRenderer(window, -1, 0)
|
|
|
|
#define SDL_RenderTexture SDL_RenderCopyF
|
|
|
|
// https://wiki.libsdl.org/SDL3/README-migration#sdl_haptich
|
|
// SDL_MouseID/SDL_KeyboardID are new
|
|
|
|
typedef int SDL_MouseID;
|
|
typedef int SDL_KeyboardID;
|
|
#define SDL_GetKeyboardState (const bool*)SDL_GetKeyboardState
|
|
typedef int SDL_HapticID;
|
|
|
|
|
|
#define SDL_CloseHaptic SDL_HapticClose
|
|
#define SDL_OpenHaptic SDL_HapticOpen
|
|
#define SDL_OpenHapticFromJoystick SDL_HapticOpenFromJoystick
|
|
#define SDL_OpenHapticFromMouse SDL_HapticOpenFromMouse
|
|
#define SDL_InitHapticRumble SDL_HapticRumbleInit
|
|
#define SDL_PlayHapticRumble SDL_HapticRumblePlay
|
|
|
|
#define SDL_GetHapticID SDL_HapticIndex
|
|
|
|
// Modified from cc9937201e421ec55b12ad3f07ff2268f15096e8 SDL_haptic.c#L150
|
|
inline SDL_HapticID* SDL_GetHaptics(int *count)
|
|
{
|
|
const int num_haptics = SDL_NumHaptics();
|
|
if (count) *count = 0;
|
|
|
|
SDL_HapticID* haptics = static_cast<SDL_HapticID*>(SDL_malloc((num_haptics + 1) * sizeof(*haptics)));
|
|
if (haptics) {
|
|
if (count) {
|
|
*count = num_haptics;
|
|
}
|
|
int haptic_index = 0;
|
|
for (int device_index = 0; device_index < num_haptics; ++device_index) {
|
|
SDL_Haptic* haptic = SDL_HapticOpen(device_index);
|
|
if (haptic) {
|
|
haptics[haptic_index] = SDL_GetHapticID(haptic);
|
|
SDL_HapticClose(haptic);
|
|
++haptic_index;
|
|
}
|
|
}
|
|
haptics[haptic_index] = 0;
|
|
} else { if (count) *count = 0; }
|
|
|
|
return haptics;
|
|
}
|
|
|