mirror of
https://github.com/raysan5/raylib.git
synced 2026-01-31 03:09:17 -05:00
[core] Add more missing implementations to SDL (#3436)
* Add more missing implementations 1 * Add more missing implementations 2 * Add more missing implementations 3 * Add more missing implementations 4 * Add more missing implementations 5 * Add more missing implementations 6
This commit is contained in:
@ -62,6 +62,7 @@ typedef struct {
|
|||||||
SDL_GLContext glContext;
|
SDL_GLContext glContext;
|
||||||
|
|
||||||
SDL_Joystick *gamepad;
|
SDL_Joystick *gamepad;
|
||||||
|
SDL_Cursor *cursor;
|
||||||
} PlatformData;
|
} PlatformData;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -178,6 +179,22 @@ static const KeyboardKey ScancodeToKey[SCANCODE_MAPPED_NUM] = {
|
|||||||
KEY_KP_DECIMAL // SDL_SCANCODE_KP_PERIOD
|
KEY_KP_DECIMAL // SDL_SCANCODE_KP_PERIOD
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const int CursorsLUT[] = {
|
||||||
|
SDL_SYSTEM_CURSOR_ARROW, // 0 MOUSE_CURSOR_DEFAULT
|
||||||
|
SDL_SYSTEM_CURSOR_ARROW, // 1 MOUSE_CURSOR_ARROW
|
||||||
|
SDL_SYSTEM_CURSOR_IBEAM, // 2 MOUSE_CURSOR_IBEAM
|
||||||
|
SDL_SYSTEM_CURSOR_CROSSHAIR, // 3 MOUSE_CURSOR_CROSSHAIR
|
||||||
|
SDL_SYSTEM_CURSOR_HAND, // 4 MOUSE_CURSOR_POINTING_HAND
|
||||||
|
SDL_SYSTEM_CURSOR_SIZEWE, // 5 MOUSE_CURSOR_RESIZE_EW
|
||||||
|
SDL_SYSTEM_CURSOR_SIZENS, // 6 MOUSE_CURSOR_RESIZE_NS
|
||||||
|
SDL_SYSTEM_CURSOR_SIZENWSE, // 7 MOUSE_CURSOR_RESIZE_NWSE
|
||||||
|
SDL_SYSTEM_CURSOR_SIZENESW, // 8 MOUSE_CURSOR_RESIZE_NESW
|
||||||
|
SDL_SYSTEM_CURSOR_SIZEALL, // 9 MOUSE_CURSOR_RESIZE_ALL
|
||||||
|
SDL_SYSTEM_CURSOR_NO // 10 MOUSE_CURSOR_NOT_ALLOWED
|
||||||
|
//SDL_SYSTEM_CURSOR_WAIT, // No equivalent implemented on MouseCursor enum on raylib.h
|
||||||
|
//SDL_SYSTEM_CURSOR_WAITARROW, // No equivalent implemented on MouseCursor enum on raylib.h
|
||||||
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Internal Functions Declaration
|
// Module Internal Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@ -315,14 +332,13 @@ void SetWindowOpacity(float opacity)
|
|||||||
// Set window focused
|
// Set window focused
|
||||||
void SetWindowFocused(void)
|
void SetWindowFocused(void)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "SetWindowFocused() not available on target platform");
|
SDL_RaiseWindow(platform.window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get native window handle
|
// Get native window handle
|
||||||
void *GetWindowHandle(void)
|
void *GetWindowHandle(void)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetWindowHandle() not implemented on target platform");
|
return (void *)platform.window;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get number of monitors
|
// Get number of monitors
|
||||||
@ -389,15 +405,45 @@ int GetMonitorHeight(int monitor)
|
|||||||
// Get selected monitor physical width in millimetres
|
// Get selected monitor physical width in millimetres
|
||||||
int GetMonitorPhysicalWidth(int monitor)
|
int GetMonitorPhysicalWidth(int monitor)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetMonitorPhysicalWidth() not implemented on target platform");
|
int width = 0;
|
||||||
return 0;
|
|
||||||
|
int monitorCount = 0;
|
||||||
|
monitorCount = SDL_GetNumVideoDisplays();
|
||||||
|
|
||||||
|
if ((monitor >= 0) && (monitor < monitorCount))
|
||||||
|
{
|
||||||
|
float vdpi = 0.0f;
|
||||||
|
SDL_GetDisplayDPI(monitor, NULL, NULL, &vdpi);
|
||||||
|
SDL_DisplayMode mode;
|
||||||
|
SDL_GetCurrentDisplayMode(monitor, &mode);
|
||||||
|
// Calculate size on inches, then convert to millimeter
|
||||||
|
if (vdpi > 0.0f) width = (mode.w/vdpi)*25.4f;
|
||||||
|
}
|
||||||
|
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
|
||||||
|
|
||||||
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get selected monitor physical height in millimetres
|
// Get selected monitor physical height in millimetres
|
||||||
int GetMonitorPhysicalHeight(int monitor)
|
int GetMonitorPhysicalHeight(int monitor)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetMonitorPhysicalHeight() not implemented on target platform");
|
int height = 0;
|
||||||
return 0;
|
|
||||||
|
int monitorCount = 0;
|
||||||
|
monitorCount = SDL_GetNumVideoDisplays();
|
||||||
|
|
||||||
|
if ((monitor >= 0) && (monitor < monitorCount))
|
||||||
|
{
|
||||||
|
float vdpi = 0.0f;
|
||||||
|
SDL_GetDisplayDPI(monitor, NULL, NULL, &vdpi);
|
||||||
|
SDL_DisplayMode mode;
|
||||||
|
SDL_GetCurrentDisplayMode(monitor, &mode);
|
||||||
|
// Calculate size on inches, then convert to millimeter
|
||||||
|
if (vdpi > 0.0f) height = (mode.h/vdpi)*25.4f;
|
||||||
|
}
|
||||||
|
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
|
||||||
|
|
||||||
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get selected monitor refresh rate
|
// Get selected monitor refresh rate
|
||||||
@ -452,34 +498,37 @@ Vector2 GetWindowScaleDPI(void)
|
|||||||
// Set clipboard text content
|
// Set clipboard text content
|
||||||
void SetClipboardText(const char *text)
|
void SetClipboardText(const char *text)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "SetClipboardText() not implemented on target platform");
|
SDL_SetClipboardText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get clipboard text content
|
// Get clipboard text content
|
||||||
// NOTE: returned string is allocated and freed by GLFW
|
// NOTE: returned string must be freed with SDL_free()
|
||||||
const char *GetClipboardText(void)
|
const char *GetClipboardText(void)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "GetClipboardText() not implemented on target platform");
|
return SDL_GetClipboardText();
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show mouse cursor
|
// Show mouse cursor
|
||||||
void ShowCursor(void)
|
void ShowCursor(void)
|
||||||
{
|
{
|
||||||
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
|
||||||
CORE.Input.Mouse.cursorHidden = false;
|
CORE.Input.Mouse.cursorHidden = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hides mouse cursor
|
// Hides mouse cursor
|
||||||
void HideCursor(void)
|
void HideCursor(void)
|
||||||
{
|
{
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
|
||||||
CORE.Input.Mouse.cursorHidden = true;
|
CORE.Input.Mouse.cursorHidden = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enables cursor (unlock cursor)
|
// Enables cursor (unlock cursor)
|
||||||
void EnableCursor(void)
|
void EnableCursor(void)
|
||||||
{
|
{
|
||||||
// Set cursor position in the middle
|
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||||
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
|
||||||
CORE.Input.Mouse.cursorHidden = false;
|
CORE.Input.Mouse.cursorHidden = false;
|
||||||
}
|
}
|
||||||
@ -487,8 +536,7 @@ void EnableCursor(void)
|
|||||||
// Disables cursor (lock cursor)
|
// Disables cursor (lock cursor)
|
||||||
void DisableCursor(void)
|
void DisableCursor(void)
|
||||||
{
|
{
|
||||||
// Set cursor position in the middle
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
SetMousePosition(CORE.Window.screen.width/2, CORE.Window.screen.height/2);
|
|
||||||
|
|
||||||
CORE.Input.Mouse.cursorHidden = true;
|
CORE.Input.Mouse.cursorHidden = true;
|
||||||
}
|
}
|
||||||
@ -524,8 +572,7 @@ void OpenURL(const char *url)
|
|||||||
// Set internal gamepad mappings
|
// Set internal gamepad mappings
|
||||||
int SetGamepadMappings(const char *mappings)
|
int SetGamepadMappings(const char *mappings)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "SetGamepadMappings() not implemented on target platform");
|
SDL_GameControllerAddMapping(mappings);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set mouse position XY
|
// Set mouse position XY
|
||||||
@ -538,7 +585,10 @@ void SetMousePosition(int x, int y)
|
|||||||
// Set mouse cursor
|
// Set mouse cursor
|
||||||
void SetMouseCursor(int cursor)
|
void SetMouseCursor(int cursor)
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "SetMouseCursor() not implemented on target platform");
|
platform.cursor = SDL_CreateSystemCursor(CursorsLUT[cursor]);
|
||||||
|
SDL_SetCursor(platform.cursor);
|
||||||
|
|
||||||
|
CORE.Input.Mouse.cursor = cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register all input events
|
// Register all input events
|
||||||
@ -794,6 +844,7 @@ static int InitPlatform(void)
|
|||||||
|
|
||||||
static void ClosePlatform(void)
|
static void ClosePlatform(void)
|
||||||
{
|
{
|
||||||
|
SDL_FreeCursor(platform.cursor); // Free cursor
|
||||||
SDL_GL_DeleteContext(platform.glContext); // Deinitialize OpenGL context
|
SDL_GL_DeleteContext(platform.glContext); // Deinitialize OpenGL context
|
||||||
SDL_DestroyWindow(platform.window);
|
SDL_DestroyWindow(platform.window);
|
||||||
SDL_Quit(); // Deinitialize SDL internal global state
|
SDL_Quit(); // Deinitialize SDL internal global state
|
||||||
|
|||||||
Reference in New Issue
Block a user