2
0
mirror of https://github.com/arnavbhatt288/sdl-2.30.3-kolibri.git synced 2025-02-07 03:26:49 +01:00

handle window events

Signed-off-by: Arnav Bhatt <arnav@ghativega.in>
This commit is contained in:
Arnav Bhatt 2024-07-05 02:29:14 +05:30
parent 81226d4ea0
commit 6ffbce2cd7
No known key found for this signature in database
GPG Key ID: 2F49C4D36103865D
4 changed files with 54 additions and 13 deletions

View File

@ -240,10 +240,12 @@ void KOLIBRI_PumpEvents(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
SDL_Window *window = SDL_GetWindowFromID(data->window_id);
SDL_WindowData *wdata = (SDL_WindowData *)window->driverdata;
uint32_t kos_event;
ksys_pos_t mouse_pos;
ksys_pos_t center_pos;
ksys_thread_t thread_info;
int top = 0;
int scancode = 0;
int pressed = 0;
SDL_Keycode keycode = SDLK_UNKNOWN;
@ -251,6 +253,7 @@ void KOLIBRI_PumpEvents(_THIS)
static int ext_code = 0;
static uint8_t old_mode = 0;
static uint32_t old_mouse_but = 0;
static SDL_bool restored = SDL_TRUE;
while (1) {
kos_event = _ksys_check_event();
@ -258,8 +261,40 @@ void KOLIBRI_PumpEvents(_THIS)
case KSYS_EVENT_NONE:
return;
case KSYS_EVENT_REDRAW:
{
top = _ksys_thread_info(&thread_info, KSYS_THIS_SLOT);
if (top == thread_info.pos_in_window_stack) {
int win_size_w = thread_info.winx_size;
int win_size_h = thread_info.winy_size;
if (wdata->skin == 0x01) {
win_size_w++;
win_size_h++;
} else {
win_size_w -= (TRUE_WIN_WIDTH + 1);
win_size_h -= (TRUE_WIN_HEIGHT + 1);
}
if (thread_info.winx_start != window->x || thread_info.winy_start != window->y)
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, thread_info.winx_start, thread_info.winy_start);
if (win_size_w != window->w || win_size_h != window->h)
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, win_size_w, win_size_h);
}
if (thread_info.window_state & 0x01) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
restored = SDL_FALSE;
} else if (thread_info.window_state & 0x02) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
restored = SDL_FALSE;
} else if (!restored) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
restored = SDL_TRUE;
}
KOLIBRI_RepaintWnd(_this);
break;
}
case KSYS_EVENT_KEY:
scancode = _ksys_get_key().code;
if (scancode == 0xE0 || scancode == 0xE1) {
@ -300,8 +335,10 @@ void KOLIBRI_PumpEvents(_THIS)
SDL_SendKeyboardKey(pressed, SDL_GetScancodeFromKey(keycode));
break;
case KSYS_EVENT_BUTTON:
if (_ksys_get_button() == 1)
if (_ksys_get_button() == 1) {
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_CLOSE, 0, 0);
exit(0);
}
break;
case KSYS_EVENT_MOUSE:
{
@ -312,7 +349,7 @@ void KOLIBRI_PumpEvents(_THIS)
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);
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);

View File

@ -35,9 +35,9 @@ int KOLIBRI_VideoInit(_THIS)
/* Use 24-bpp desktop mode */
mode.format = SDL_PIXELFORMAT_RGB24;
mode.w = screen_size.x;
mode.h = screen_size.y;
mode.refresh_rate = 0;
mode.w = screen_size.x + 1;
mode.h = screen_size.y + 1;
mode.refresh_rate = 60;
mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0)
return -1;

View File

@ -12,9 +12,6 @@
#include "SDL_kolibrivideo.h"
#include "SDL_kolibriwindow.h"
#define WINDOW_BORDER_H 4
#define WINDOW_BORDER_W 9
void KOLIBRI_RepaintWnd(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
@ -23,8 +20,8 @@ void KOLIBRI_RepaintWnd(_THIS)
int win_pos_x, win_pos_y;
int win_size_w, win_size_h;
win_size_w = window->w + WINDOW_BORDER_W;
win_size_h = window->h + _ksys_get_skin_height() + WINDOW_BORDER_H;
win_size_w = window->w + TRUE_WIN_WIDTH;
win_size_h = window->h + TRUE_WIN_HEIGHT;
_ksys_start_draw();
_ksys_create_window(window->x, window->y, win_size_w, win_size_h, window->title, 0, 0x34);
@ -35,8 +32,8 @@ void KOLIBRI_RepaintWnd(_THIS)
void KOLIBRI_change_window_size_and_pos(int w, int h, int x, int y)
{
w += WINDOW_BORDER_W;
h += _ksys_get_skin_height() + WINDOW_BORDER_H;
w += TRUE_WIN_WIDTH;
h += TRUE_WIN_HEIGHT;
_ksys_change_window(x, y, w, h);
}

View File

@ -5,13 +5,20 @@
#ifndef SDL_kolibriwindow_h_
#define SDL_kolibriwindow_h_
#define WINDOW_BORDER_H 4
#define WINDOW_BORDER_W 9
#define TRUE_WIN_HEIGHT _ksys_get_skin_height() + WINDOW_BORDER_H;
#define TRUE_WIN_WIDTH WINDOW_BORDER_W
typedef struct SDL_WindowData
{
SDL_Surface *surface;
unsigned char skin;
} SDL_WindowData;
extern int KOLIBRI_CreateWindow(_THIS, SDL_Window *window);
extern void KOLIBRI_RepaintWnd(_THIS);
extern int KOLIBRI_CreateWindow(_THIS, SDL_Window *window);
extern void KOLIBRI_SetWindowTitle(_THIS, SDL_Window *window);
extern void KOLIBRI_DestroyWindow(_THIS, SDL_Window *window);