vinci_run -> vinci_hidle now only implements 1 tick non blocking event handling

This commit is contained in:
Paolo Marrone 2025-03-19 19:35:51 +01:00
parent 8d3d429101
commit 96b15113a5
2 changed files with 36 additions and 51 deletions

View File

@ -37,9 +37,8 @@ struct window {
};
struct vinci {
char keep_running;
window *windows;
char className[20];
char className[66];
};
static uint32_t get_mouse_state(WPARAM wParam) {
@ -146,7 +145,7 @@ vinci* vinci_new(void) {
vinci *g = (vinci*)malloc(sizeof(vinci));
if (!g)
return NULL;
snprintf(g->className, 20, "vinClass%p", (void*)g); // Nice random name
snprintf(g->className, 66, "vc%p", (void*)g); // Nice random name
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
@ -165,7 +164,6 @@ vinci* vinci_new(void) {
free(g);
return NULL;
}
g->keep_running = 0;
g->windows = NULL;
return g;
}
@ -175,32 +173,20 @@ void vinci_destroy(vinci *g) {
free(g);
}
void vinci_run(vinci *g, char single) {
g->keep_running = 1;
void vinci_idle(vinci *g) {
(void) g;
MSG msg;
while (g->keep_running) {
if (single) {
BOOL b = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
if (!b)
break;
} else {
BOOL b = GetMessage(&msg, NULL, 0, 0);
if (b <= 0)
break;
}
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
void vinci_stop(vinci *g) {
g->keep_running = 0;
}
window* window_new(vinci *g, void* parent, uint32_t width, uint32_t height, window_cbs *cbs) {
window *w = (window*)malloc(sizeof(window));
if (w == NULL)
return NULL;
memset((void*) w, 0, sizeof(window));
w->g = g;
w->handle = CreateWindowEx(0, g->className, NULL, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, NULL, NULL, NULL);
@ -226,7 +212,7 @@ window* window_new(vinci *g, void* parent, uint32_t width, uint32_t height, wind
}
if (parent) {
SetParent(w->handle, *((HWND *)parent));
SetParent(w->handle, (HWND)parent);
SetWindowLong(w->handle, GWL_STYLE, GetWindowLong(w->handle, GWL_STYLE) & ~(WS_BORDER | WS_SIZEBOX | WS_DLGFRAME));
SetWindowPos(w->handle, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); // SWP_FRAMECHANGED triggers WndProc call with WM_SIZE right here. May they die hard
}

View File

@ -44,8 +44,7 @@ typedef struct window_cbs {
vinci* vinci_new (void);
void vinci_destroy (vinci *g);
void vinci_run (vinci *g, char single);
void vinci_stop (vinci *g);
void vinci_idle (vinci *g);
window* window_new (vinci *g, void* p, uint32_t width, uint32_t height, window_cbs *cbs);
void window_free (window *w);
void window_draw (window *w, unsigned char *data, int32_t dx, int32_t dy, int32_t dw, int32_t dh, int32_t wx, int32_t wy, int32_t width, int32_t height);