mirror of
https://github.com/arnavbhatt288/sdl-2.30.3-kolibri.git
synced 2025-01-02 10:25:54 +01:00
add relative mouse support
Signed-off-by: Arnav Bhatt <arnav@ghativega.in>
This commit is contained in:
parent
9968fdb39d
commit
81226d4ea0
@ -236,8 +236,6 @@ void KOLIBRI_InitOSKeymap(void)
|
||||
_ksys_set_key_input_mode(KSYS_KEY_INPUT_MODE_SCANC);
|
||||
}
|
||||
|
||||
extern void kos_CheckMouseMode(_THIS);
|
||||
|
||||
void KOLIBRI_PumpEvents(_THIS)
|
||||
{
|
||||
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
|
||||
@ -310,18 +308,17 @@ void KOLIBRI_PumpEvents(_THIS)
|
||||
mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_WINDOW_POS);
|
||||
if (mouse_pos.x >= 0 && mouse_pos.x < window->w && mouse_pos.y >= 0 && mouse_pos.y < window->h || SDL_GetMouse()->relative_mode) {
|
||||
if (SDL_GetMouse()->relative_mode) {
|
||||
center_pos.x = mouse_pos.x - window->w / 2;
|
||||
center_pos.y = mouse_pos.y - window->h / 2;
|
||||
if (center_pos.x || center_pos.y) {
|
||||
SDL_SendMouseMotion(window, 0, SDL_TRUE, center_pos.x, center_pos.y);
|
||||
center_pos.x = mouse_pos.x - (window->w / 2);
|
||||
center_pos.y = mouse_pos.y - (window->h / 2);
|
||||
SDL_SendMouseMotion(window, 0, SDL_TRUE, center_pos.x, center_pos.y);
|
||||
|
||||
int top = _ksys_thread_info(&thread_info, KSYS_THIS_SLOT);
|
||||
if (top == thread_info.pos_in_window_stack) {
|
||||
int x = thread_info.winx_start + thread_info.clientx + window->w / 2;
|
||||
int y = thread_info.winy_start + thread_info.clienty + window->h / 2;
|
||||
_ksys_set_mouse_pos(x, y);
|
||||
}
|
||||
int top = _ksys_thread_info(&thread_info, KSYS_THIS_SLOT);
|
||||
if (top == thread_info.pos_in_window_stack) {
|
||||
int x = thread_info.winx_start + thread_info.clientx + (window->w / 2);
|
||||
int y = thread_info.winy_start + thread_info.clienty + (window->h / 2);
|
||||
_ksys_set_mouse_pos(x, y);
|
||||
}
|
||||
|
||||
} else
|
||||
SDL_SendMouseMotion(window, 0, SDL_FALSE, mouse_pos.x, mouse_pos.y);
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <sys/ksys.h>
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_surface.h"
|
||||
|
||||
@ -35,8 +36,11 @@ static SDL_Cursor *KOLIBRI_CreateDefaultCursor(void)
|
||||
|
||||
/* Convert default SDL cursor to 32x32 */
|
||||
temp = (Uint32 *)SDL_malloc(32 * 32 * 4);
|
||||
if (!temp)
|
||||
if (!temp) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(cursor);
|
||||
return NULL;
|
||||
}
|
||||
for (int i = 0; i < 32; i++) {
|
||||
for (int j = 0; j < 32; j++) {
|
||||
if (i >= 16 || j >= 16) {
|
||||
@ -95,18 +99,6 @@ static int KOLIBRI_ShowCursor(SDL_Cursor *cursor)
|
||||
KOLIBRI_CursorData *curdata;
|
||||
if (cursor) {
|
||||
curdata = (KOLIBRI_CursorData *)cursor->driverdata;
|
||||
if (!curdata->cursor) {
|
||||
if (!curdata->has_null_cursor) {
|
||||
unsigned *u = SDL_malloc(32 * 32 * 4);
|
||||
if (!u)
|
||||
return 0;
|
||||
SDL_memset(u, 0, 32 * 32 * 4);
|
||||
curdata->null_cursor = _ksys_load_cursor(u, KSYS_CURSOR_INDIRECT);
|
||||
free(u);
|
||||
curdata->has_null_cursor = 1;
|
||||
}
|
||||
curdata->cursor = curdata->null_cursor;
|
||||
}
|
||||
_ksys_set_cursor(curdata->cursor);
|
||||
}
|
||||
|
||||
@ -120,13 +112,52 @@ static void KOLIBRI_FreeCursor(SDL_Cursor *cursor)
|
||||
if (cursor) {
|
||||
curdata = (KOLIBRI_CursorData *)cursor->driverdata;
|
||||
if (curdata) {
|
||||
SDL_free(curdata->cursor);
|
||||
if (curdata->cursor)
|
||||
_ksys_delete_cursor(curdata->cursor);
|
||||
if (curdata->has_null_cursor)
|
||||
_ksys_delete_cursor(curdata->null_cursor);
|
||||
SDL_free(curdata);
|
||||
}
|
||||
SDL_free(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
static int KOLIBRI_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
SDL_Window *window = SDL_GetMouseFocus();
|
||||
SDL_Cursor *cursor = SDL_GetCursor();
|
||||
KOLIBRI_CursorData *curdata;
|
||||
|
||||
if (!window || !cursor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
ksys_thread_t thread_info;
|
||||
int top = _ksys_thread_info(&thread_info, KSYS_THIS_SLOT);
|
||||
unsigned *u = SDL_calloc(32 * 32, 1);
|
||||
|
||||
if (!u)
|
||||
return 0;
|
||||
|
||||
curdata->null_cursor = _ksys_load_cursor(u, KSYS_CURSOR_INDIRECT);
|
||||
SDL_free(u);
|
||||
curdata->has_null_cursor = 1;
|
||||
_ksys_set_cursor(curdata->null_cursor);
|
||||
|
||||
if (top == thread_info.pos_in_window_stack) {
|
||||
int x = thread_info.winx_start + thread_info.clientx + (window->w / 2);
|
||||
int y = thread_info.winy_start + thread_info.clienty + (window->h / 2);
|
||||
_ksys_set_mouse_pos(x, y);
|
||||
}
|
||||
} else {
|
||||
curdata->has_null_cursor = 0;
|
||||
_ksys_delete_cursor(curdata->null_cursor);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void KOLIBRI_InitMouse(void)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
@ -134,6 +165,7 @@ void KOLIBRI_InitMouse(void)
|
||||
mouse->CreateCursor = KOLIBRI_CreateCursor;
|
||||
mouse->ShowCursor = KOLIBRI_ShowCursor;
|
||||
mouse->FreeCursor = KOLIBRI_FreeCursor;
|
||||
mouse->SetRelativeMouseMode = KOLIBRI_SetRelativeMouseMode;
|
||||
|
||||
SDL_SetDefaultCursor(KOLIBRI_CreateDefaultCursor());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user