From 791960a1281afc3e4f1cf3dc156d94a8ca2878bb Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Fri, 17 Oct 2025 02:21:31 +0000 Subject: [PATCH] add tick_list git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@391 b9cfdab3-6d41-4d17-bbe4-086880011989 --- include/Mw/Core.h | 6 ++++++ include/Mw/TypeDefs.h | 1 + src/core.c | 26 +++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/Mw/Core.h b/include/Mw/Core.h index f9d0d4c..a0d48d4 100644 --- a/include/Mw/Core.h +++ b/include/Mw/Core.h @@ -231,6 +231,12 @@ MWDECL void MwForceRender(MwWidget handle); */ MWDECL void MwForceRender2(MwWidget handle, void* ptr); +/*! + * %brief Adds an widget to tick handler list + * %param handle Widget + */ +MWDECL void MwAddTickList(MwWidget handle); + #ifdef __cplusplus } #endif diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index bf0382e..be51a45 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -105,6 +105,7 @@ struct _MwWidget { MwVoidKeyValue* data; MwWidget* destroy_queue; + MwWidget* tick_list; }; #endif diff --git a/src/core.c b/src/core.c index 8e831e0..7a830a5 100644 --- a/src/core.c +++ b/src/core.c @@ -112,6 +112,9 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent, h->destroy_queue = NULL; h->prop_event = 1; h->draw_inject = NULL; + h->tick_list = NULL; + + if(parent == NULL) arrput(h->tick_list, h); if(h->lowlevel != NULL) { h->lowlevel->user = h; @@ -190,14 +193,25 @@ static void MwFreeWidget(MwWidget handle) { shfree(handle->data); arrfree(handle->destroy_queue); + arrfree(handle->tick_list); free(handle); } void MwDestroyWidget(MwWidget handle) { + int i; + MwWidget root = handle; if(handle->parent != NULL) { arrput(handle->parent->destroy_queue, handle); } + + while(root->parent != NULL) root = root->parent; + for(i = 0; i < arrlen(root->tick_list); i++) { + if(handle == root->tick_list[i]) { + arrdel(root->tick_list, i); + i--; + } + } } void MwStep(MwWidget handle) { @@ -235,10 +249,13 @@ int MwPending(MwWidget handle) { void MwLoop(MwWidget handle) { long tick = MwLLGetTick(); + int i; while(!handle->close) { while(MwPending(handle)) MwStep(handle); - MwDispatchUserHandler(handle, MwNtickHandler, NULL); + for(i = 0; i < arrlen(handle->tick_list); i++) { + MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL); + } tick = MwWaitMS - (MwLLGetTick() - tick); if(tick > 0) MwLLSleep(tick); tick = MwLLGetTick(); @@ -426,3 +443,10 @@ void MwForceRender2(MwWidget handle, void* ptr) { MwForceRender(handle); } + +void MwAddTickList(MwWidget handle) { + MwWidget root = handle; + while(root->parent != NULL) root = root->parent; + + arrput(root->tick_list, handle); +}