add tick_list

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@391 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-10-17 02:21:31 +00:00
parent 92e7f13897
commit 791960a128
3 changed files with 32 additions and 1 deletions

View File

@@ -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

View File

@@ -105,6 +105,7 @@ struct _MwWidget {
MwVoidKeyValue* data;
MwWidget* destroy_queue;
MwWidget* tick_list;
};
#endif

View File

@@ -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);
}