mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-09 10:53:27 +00:00
viewport seems to work
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@275 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -32,6 +32,7 @@ static int calc_length(MwWidget handle) {
|
||||
int max = MwScrollBarGetVisibleLength(handle);
|
||||
int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue);
|
||||
int area = MwGetInteger(handle, MwNareaShown);
|
||||
if(area > MwGetInteger(handle, MwNmaxValue)) area = MwGetInteger(handle, MwNmaxValue);
|
||||
|
||||
return max * (double)area / len;
|
||||
}
|
||||
@@ -55,6 +56,7 @@ static void add_value(MwWidget handle, int mul) {
|
||||
if(val > max) val = max;
|
||||
|
||||
MwSetInteger(handle, MwNvalue, val);
|
||||
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
|
||||
}
|
||||
|
||||
static void draw(MwWidget handle) {
|
||||
@@ -151,6 +153,7 @@ static void mouse_move(MwWidget handle) {
|
||||
if(len < 0) len = 0;
|
||||
if(len > 1) len = 1;
|
||||
MwSetInteger(handle, MwNvalue, (int)((max - min) * len - min));
|
||||
MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
|
||||
|
||||
MwForceRender(handle);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,88 @@
|
||||
/* $Id$ */
|
||||
#include <Mw/Milsko.h>
|
||||
|
||||
typedef struct viewport {
|
||||
MwWidget vscroll;
|
||||
MwWidget hscroll;
|
||||
MwWidget frame;
|
||||
MwWidget inframe;
|
||||
} viewport_t;
|
||||
|
||||
static void vscroll_changed(MwWidget handle, void* user, void* call) {
|
||||
viewport_t* vp = user;
|
||||
int v = MwGetInteger(handle, MwNvalue);
|
||||
MwVaApply(vp->inframe,
|
||||
MwNy, -v,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void hscroll_changed(MwWidget handle, void* user, void* call) {
|
||||
viewport_t* vp = user;
|
||||
int v = MwGetInteger(handle, MwNvalue);
|
||||
MwVaApply(vp->inframe,
|
||||
MwNx, -v,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void resize(MwWidget handle) {
|
||||
viewport_t* vp = handle->internal;
|
||||
int w = MwGetInteger(handle, MwNwidth);
|
||||
int h = MwGetInteger(handle, MwNheight);
|
||||
if(vp->vscroll == NULL) {
|
||||
vp->vscroll = MwVaCreateWidget(MwScrollBarClass, "vscroll", handle, w - 16, 0, 16, h - 16, NULL);
|
||||
MwAddUserHandler(vp->vscroll, MwNchangedHandler, vscroll_changed, vp);
|
||||
} else {
|
||||
MwVaApply(vp->vscroll,
|
||||
MwNx, w - 16,
|
||||
MwNy, 0,
|
||||
MwNwidth, 16,
|
||||
MwNheight, h - 16,
|
||||
NULL);
|
||||
}
|
||||
if(vp->hscroll == NULL) {
|
||||
vp->hscroll = MwVaCreateWidget(MwScrollBarClass, "hscroll", handle, 0, h - 16, w - 16, 16, MwNorientation, MwHORIZONTAL, NULL);
|
||||
MwAddUserHandler(vp->hscroll, MwNchangedHandler, hscroll_changed, vp);
|
||||
} else {
|
||||
MwVaApply(vp->hscroll,
|
||||
MwNx, 0,
|
||||
MwNy, h - 16,
|
||||
MwNwidth, w - 16,
|
||||
MwNheight, 16,
|
||||
NULL);
|
||||
}
|
||||
if(vp->frame == NULL) {
|
||||
vp->frame = MwCreateWidget(MwFrameClass, "frame", handle, 0, 0, w - 16, h - 16);
|
||||
} else {
|
||||
MwVaApply(vp->frame,
|
||||
MwNx, 0,
|
||||
MwNy, 0,
|
||||
MwNwidth, w - 16,
|
||||
MwNheight, h - 16,
|
||||
NULL);
|
||||
}
|
||||
if(vp->inframe == NULL) {
|
||||
vp->inframe = MwCreateWidget(MwFrameClass, "inframe", vp->frame, 0, 0, w - 16, h - 16);
|
||||
}
|
||||
|
||||
MwVaApply(vp->vscroll,
|
||||
MwNareaShown, h - 16,
|
||||
NULL);
|
||||
|
||||
MwVaApply(vp->hscroll,
|
||||
MwNareaShown, w - 16,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static int create(MwWidget handle) {
|
||||
viewport_t* vp = malloc(sizeof(*vp));
|
||||
memset(vp, 0, sizeof(*vp));
|
||||
|
||||
handle->internal = vp;
|
||||
|
||||
MwSetDefault(handle);
|
||||
|
||||
resize(handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,23 +100,47 @@ static void draw(MwWidget handle) {
|
||||
MwLLFreeColor(base);
|
||||
}
|
||||
|
||||
MwWidget MwViewportGetViewport(MwWidget widget) {
|
||||
static void prop_change(MwWidget handle, const char* prop) {
|
||||
if(strcmp(prop, MwNwidth) == 0 || strcmp(prop, MwNheight) == 0) resize(handle);
|
||||
}
|
||||
|
||||
MwClassRec MwViewportClassRec = {
|
||||
create, /* create */
|
||||
NULL, /* destroy */
|
||||
draw, /* draw */
|
||||
NULL, /* click */
|
||||
NULL, /* parent_resize */
|
||||
NULL, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
NULL, /* mouse_up */
|
||||
NULL, /* mouse_down */
|
||||
NULL, /* key */
|
||||
create, /* create */
|
||||
NULL, /* destroy */
|
||||
draw, /* draw */
|
||||
NULL, /* click */
|
||||
NULL, /* parent_resize */
|
||||
prop_change, /* prop_change */
|
||||
NULL, /* mouse_move */
|
||||
NULL, /* mouse_up */
|
||||
NULL, /* mouse_down */
|
||||
NULL, /* key */
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL};
|
||||
MwClass MwViewportClass = &MwViewportClassRec;
|
||||
|
||||
MwWidget MwViewportGetViewport(MwWidget handle) {
|
||||
viewport_t* vp = handle->internal;
|
||||
|
||||
return vp->inframe;
|
||||
}
|
||||
|
||||
void MwViewportSetSize(MwWidget handle, int w, int h) {
|
||||
viewport_t* vp = handle->internal;
|
||||
|
||||
MwVaApply(vp->vscroll,
|
||||
MwNmaxValue, h,
|
||||
NULL);
|
||||
|
||||
MwVaApply(vp->hscroll,
|
||||
MwNmaxValue, w,
|
||||
NULL);
|
||||
|
||||
MwVaApply(vp->inframe,
|
||||
MwNwidth, w,
|
||||
MwNheight, h,
|
||||
NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user