smooth movement

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@587 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-04 01:52:44 +00:00
parent 0e78d6dee9
commit 83340f95a2
19 changed files with 79 additions and 35 deletions

View File

@@ -109,6 +109,8 @@ struct _MwViewport {
MwWidget hscroll; MwWidget hscroll;
MwWidget frame; MwWidget frame;
MwWidget inframe; MwWidget inframe;
int vchanged;
int hchanged;
}; };
struct _MwListBoxEntry { struct _MwListBoxEntry {
@@ -124,6 +126,7 @@ struct _MwListBox {
unsigned long click_time; unsigned long click_time;
int pressed; int pressed;
int* width; int* width;
int changed;
}; };
struct _MwDirectoryEntry { struct _MwDirectoryEntry {
@@ -150,7 +153,7 @@ struct _MwClass {
MwHandlerMouse mouse_down; MwHandlerMouse mouse_down;
MwHandlerKey key; MwHandlerKey key;
MwHandlerExecute execute; MwHandlerExecute execute;
void* reserved2; MwHandler tick;
void* reserved3; void* reserved3;
void* reserved4; void* reserved4;
void* reserved5; void* reserved5;

View File

@@ -166,6 +166,10 @@ MwWidget MwCreateWidget(MwClass widget_class, const char* name, MwWidget parent,
} }
h->prop_event = 1; h->prop_event = 1;
if(h->widget_class != NULL && h->widget_class->tick != NULL){
MwAddTickList(h);
}
return h; return h;
} }
@@ -302,6 +306,7 @@ void MwLoop(MwWidget handle) {
if(v != 0) break; if(v != 0) break;
for(i = 0; i < arrlen(handle->tick_list); i++) { for(i = 0; i < arrlen(handle->tick_list); i++) {
MwDispatch(handle->tick_list[i], tick);
MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL); MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL);
} }

View File

@@ -76,7 +76,7 @@ MwClassRec MwButtonClassRec = {
MwForceRender2, /* mouse_down */ MwForceRender2, /* mouse_down */
NULL, /* key */ NULL, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -48,7 +48,7 @@ MwClassRec MwCheckBoxClassRec = {
MwForceRender2, /* mouse_down */ MwForceRender2, /* mouse_down */
NULL, /* key */ NULL, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -139,7 +139,7 @@ MwClassRec MwEntryClassRec = {
MwForceRender2, /* mouse_down */ MwForceRender2, /* mouse_down */
key, /* key */ key, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -52,7 +52,7 @@ MwClassRec MwFrameClassRec = {
NULL, /* mouse_down */ NULL, /* mouse_down */
NULL, /* key */ NULL, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -40,7 +40,7 @@ MwClassRec MwImageClassRec = {
NULL, /* mouse_down */ NULL, /* mouse_down */
NULL, /* key */ NULL, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -57,7 +57,7 @@ MwClassRec MwLabelClassRec = {
NULL, /* mouse_down */ NULL, /* mouse_down */
NULL, /* key */ NULL, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -112,7 +112,7 @@ static void vscroll_changed(MwWidget handle, void* user, void* call) {
(void)user; (void)user;
(void)call; (void)call;
MwForceRender(lb->frame); lb->changed = 1;
} }
static void frame_mouse_down(MwWidget handle, void* user, void* call) { static void frame_mouse_down(MwWidget handle, void* user, void* call) {
@@ -312,6 +312,7 @@ static int create(MwWidget handle) {
lb->selected = -1; lb->selected = -1;
lb->click_time = 0; lb->click_time = 0;
lb->width = NULL; lb->width = NULL;
lb->changed = 0;
MwSetInteger(handle, MwNleftPadding, 0); MwSetInteger(handle, MwNleftPadding, 0);
MwSetInteger(handle, MwNhasHeading, 0); MwSetInteger(handle, MwNhasHeading, 0);
@@ -505,6 +506,15 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
} }
} }
static void tick(MwWidget handle){
MwListBox lb = handle->internal;
if(lb->changed){
lb->changed = 0;
MwForceRender(lb->frame);
}
}
MwClassRec MwListBoxClassRec = { MwClassRec MwListBoxClassRec = {
create, /* create */ create, /* create */
destroy, /* destroy */ destroy, /* destroy */
@@ -517,7 +527,7 @@ MwClassRec MwListBoxClassRec = {
NULL, /* mouse_down */ NULL, /* mouse_down */
NULL, /* key */ NULL, /* key */
func_handler, /* execute */ func_handler, /* execute */
NULL, tick, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -209,7 +209,7 @@ MwClassRec MwMenuClassRec = {
mouse_down, /* mouse_down */ mouse_down, /* mouse_down */
NULL, /* key */ NULL, /* key */
func_handler, /* execute */ func_handler, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -140,7 +140,7 @@ MwClassRec MwNumberEntryClassRec = {
mouse_down, /* mouse_down */ mouse_down, /* mouse_down */
key, /* key */ key, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -180,7 +180,7 @@ MwClassRec MwOpenGLClassRec = {
NULL, /* mouse_down */ NULL, /* mouse_down */
NULL, /* key */ NULL, /* key */
func_handler, /* execute */ func_handler, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -56,7 +56,7 @@ MwClassRec MwProgressBarClassRec = {
NULL, /* mouse_down */ NULL, /* mouse_down */
NULL, /* key */ NULL, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -57,7 +57,7 @@ MwClassRec MwRadioBoxClassRec = {
MwForceRender2, /* mouse_down */ MwForceRender2, /* mouse_down */
NULL, /* key */ NULL, /* key */
NULL, /* execute */ NULL, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -254,7 +254,7 @@ MwClassRec MwScrollBarClassRec = {
mouse_down, /* mouse_down */ mouse_down, /* mouse_down */
NULL, /* key */ NULL, /* key */
func_handler, /* execute */ func_handler, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -208,7 +208,7 @@ MwClassRec MwSubMenuClassRec = {
MwForceRender2, /* mouse_down */ MwForceRender2, /* mouse_down */
NULL, /* key */ NULL, /* key */
func_handler, /* execute */ func_handler, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -3,28 +3,20 @@
static void vscroll_changed(MwWidget handle, void* user, void* call) { static void vscroll_changed(MwWidget handle, void* user, void* call) {
MwViewport vp = user; MwViewport vp = user;
int v = MwGetInteger(handle, MwNvalue);
int mv = MwGetInteger(handle, MwNmaxValue); (void)handle;
int l = MwGetInteger(vp->frame, MwNheight);
v = (mv - l) * (double)v / mv;
(void)call; (void)call;
if(v < 0) v = 0;
MwVaApply(vp->inframe, vp->vchanged = 1;
MwNy, -v,
NULL);
} }
static void hscroll_changed(MwWidget handle, void* user, void* call) { static void hscroll_changed(MwWidget handle, void* user, void* call) {
MwViewport vp = user; MwViewport vp = user;
int v = MwGetInteger(handle, MwNvalue);
int mv = MwGetInteger(handle, MwNmaxValue); (void)handle;
int l = MwGetInteger(vp->frame, MwNwidth);
v = (mv - l) * (double)v / mv;
(void)call; (void)call;
if(v < 0) v = 0;
MwVaApply(vp->inframe, vp->hchanged = 1;
MwNx, -v,
NULL);
} }
static void resize(MwWidget handle) { static void resize(MwWidget handle) {
@@ -91,6 +83,9 @@ static int create(MwWidget handle) {
MwSetDefault(handle); MwSetDefault(handle);
vp->vchanged = 0;
vp->hchanged = 0;
resize(handle); resize(handle);
return 0; return 0;
@@ -146,6 +141,37 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
} }
} }
static void tick(MwWidget handle){
MwViewport vp = handle->internal;
if(vp->vchanged){
vp->vchanged = 0;
int v = MwGetInteger(vp->vscroll, MwNvalue);
int mv = MwGetInteger(vp->vscroll, MwNmaxValue);
int l = MwGetInteger(vp->frame, MwNheight);
v = (mv - l) * (double)v / mv;
if(v < 0) v = 0;
MwVaApply(vp->inframe,
MwNy, -v,
NULL);
}
if(vp->hchanged){
vp->vchanged = 0;
int v = MwGetInteger(vp->hscroll, MwNvalue);
int mv = MwGetInteger(vp->hscroll, MwNmaxValue);
int l = MwGetInteger(vp->frame, MwNwidth);
v = (mv - l) * (double)v / mv;
if(v < 0) v = 0;
MwVaApply(vp->inframe,
MwNx, -v,
NULL);
}
}
MwClassRec MwViewportClassRec = { MwClassRec MwViewportClassRec = {
create, /* create */ create, /* create */
destroy, /* destroy */ destroy, /* destroy */
@@ -158,7 +184,7 @@ MwClassRec MwViewportClassRec = {
NULL, /* mouse_down */ NULL, /* mouse_down */
NULL, /* key */ NULL, /* key */
func_handler, /* execute */ func_handler, /* execute */
NULL, tick, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -524,7 +524,7 @@ MwClassRec MwVulkanClassRec = {
NULL, /* mouse_down */ NULL, /* mouse_down */
NULL, /* key */ NULL, /* key */
func_handler, /* execute */ func_handler, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};

View File

@@ -44,7 +44,7 @@ MwClassRec MwWindowClassRec = {
NULL, /* mouse_down */ NULL, /* mouse_down */
NULL, /* key */ NULL, /* key */
func_handler, /* execute */ func_handler, /* execute */
NULL, NULL, /* tick */
NULL, NULL,
NULL, NULL,
NULL}; NULL};