mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-03 16:10:50 +00:00
it works
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@169 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -3,17 +3,23 @@
|
||||
|
||||
typedef struct scrollbar {
|
||||
MwPoint point;
|
||||
int point_set;
|
||||
int drag;
|
||||
int pos;
|
||||
} scrollbar_t;
|
||||
|
||||
static int create(MwWidget handle) {
|
||||
scrollbar_t* scr = malloc(sizeof(*scr));
|
||||
|
||||
scr->point_set = 0;
|
||||
|
||||
handle->internal = scr;
|
||||
|
||||
MwSetDefault(handle);
|
||||
MwVaApply(handle,
|
||||
MwNminValue, 0,
|
||||
MwNmaxValue, 100,
|
||||
MwNvalue, 0,
|
||||
MwNareaShown, 25,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -22,8 +28,24 @@ static void destroy(MwWidget handle) {
|
||||
free(handle->internal);
|
||||
}
|
||||
|
||||
static int calc_length(MwWidget handle) {
|
||||
int max = MwScrollBarGetVisibleLength(handle);
|
||||
int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue);
|
||||
int area = MwGetInteger(handle, MwNareaShown);
|
||||
|
||||
return max * (double)area / len;
|
||||
}
|
||||
|
||||
static int calc_positition(MwWidget handle) {
|
||||
int max = MwScrollBarGetVisibleLength(handle);
|
||||
int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue);
|
||||
int val = MwGetInteger(handle, MwNvalue);
|
||||
|
||||
return (max - calc_length(handle)) * (double)val / len;
|
||||
}
|
||||
|
||||
static void draw(MwWidget handle) {
|
||||
MwRect r, rt;
|
||||
MwRect r, rt, rbar;
|
||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||
MwLLColor dark = MwLightenColor(handle, base, -64, -64, -64);
|
||||
scrollbar_t* scr = handle->internal;
|
||||
@@ -44,45 +66,127 @@ static void draw(MwWidget handle) {
|
||||
MwDrawFrame(handle, &r, dark, 1);
|
||||
MwDrawRect(handle, &r, dark);
|
||||
|
||||
if(handle->pressed && !scr->point_set) {
|
||||
scr->point = handle->mouse_point;
|
||||
scr->point_set = 1;
|
||||
} else if(!handle->pressed && scr->point_set) {
|
||||
scr->point_set = 0;
|
||||
}
|
||||
|
||||
rt = r;
|
||||
|
||||
if((or = MwGetInteger(handle, MwNorientation)) == -1 || or == MwVERTICAL) {
|
||||
or = MwGetInteger(handle, MwNorientation);
|
||||
if(or == MwVERTICAL) {
|
||||
rt.height = rt.width;
|
||||
|
||||
rt.y = r.y;
|
||||
MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.y <= uy) ? 1 : 0, MwNORTH);
|
||||
|
||||
rbar.width = r.width;
|
||||
rbar.height = calc_length(handle);
|
||||
rbar.x = r.x;
|
||||
rbar.y = r.y + rt.height + calc_positition(handle);
|
||||
|
||||
rt.y = r.y + r.height - rt.height;
|
||||
MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.y >= dy) ? 1 : 0, MwSOUTH);
|
||||
} else if((or = MwGetInteger(handle, MwNorientation)) == -1 || or == MwHORIZONTAL) {
|
||||
} else if(or == MwHORIZONTAL) {
|
||||
rt.width = rt.height;
|
||||
|
||||
rt.x = r.x;
|
||||
MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.x <= ux) ? 1 : 0, MwWEST);
|
||||
|
||||
rbar.width = calc_length(handle);
|
||||
rbar.height = r.height;
|
||||
rbar.x = r.x + rt.width + calc_positition(handle);
|
||||
rbar.y = r.y;
|
||||
|
||||
rt.x = r.x + r.width - rt.width;
|
||||
MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.x >= dx) ? 1 : 0, MwEAST);
|
||||
}
|
||||
|
||||
MwDrawFrame(handle, &rbar, base, 0);
|
||||
MwDrawRect(handle, &rbar, base);
|
||||
|
||||
MwLLFreeColor(dark);
|
||||
MwLLFreeColor(base);
|
||||
}
|
||||
|
||||
static void mouse_move(MwWidget handle) {
|
||||
int ww = MwGetInteger(handle, MwNwidth);
|
||||
int wh = MwGetInteger(handle, MwNheight);
|
||||
int or = MwGetInteger(handle, MwNorientation);
|
||||
scrollbar_t* scr = handle->internal;
|
||||
|
||||
if(!handle->pressed) return;
|
||||
|
||||
if(scr->drag) {
|
||||
int l = 0;
|
||||
double len = MwScrollBarGetVisibleLength(handle) - calc_length(handle);
|
||||
int min = MwGetInteger(handle, MwNminValue);
|
||||
int max = MwGetInteger(handle, MwNmaxValue);
|
||||
|
||||
if(or == MwVERTICAL) {
|
||||
int tri = (ww - MwDefaultBorderWidth * 2) + MwDefaultBorderWidth;
|
||||
l = handle->mouse_point.y - tri + scr->pos;
|
||||
len -= tri * 2;
|
||||
} else if(or == MwHORIZONTAL) {
|
||||
int tri = (wh - MwDefaultBorderWidth * 2) + MwDefaultBorderWidth;
|
||||
l = handle->mouse_point.x - tri + scr->pos;
|
||||
len -= tri * 2;
|
||||
}
|
||||
|
||||
len = l / len;
|
||||
if(len < 0) len = 0;
|
||||
if(len > 1) len = 1;
|
||||
MwSetInteger(handle, MwNvalue, (max - min) * len - min);
|
||||
|
||||
MwForceRender(handle);
|
||||
}
|
||||
}
|
||||
|
||||
static void mouse_down(MwWidget handle) {
|
||||
int ww = MwGetInteger(handle, MwNwidth);
|
||||
int wh = MwGetInteger(handle, MwNheight);
|
||||
int or = MwGetInteger(handle, MwNorientation);
|
||||
scrollbar_t* scr = handle->internal;
|
||||
|
||||
scr->point = handle->mouse_point;
|
||||
scr->drag = 0;
|
||||
if(or == MwVERTICAL) {
|
||||
int tri = (ww - MwDefaultBorderWidth * 2) + MwDefaultBorderWidth;
|
||||
if(tri <= scr->point.y && scr->point.y <= (wh - tri)) {
|
||||
scr->drag = 1;
|
||||
scr->pos = calc_positition(handle) - scr->point.y;
|
||||
}
|
||||
} else if(or == MwHORIZONTAL) {
|
||||
int tri = (wh - MwDefaultBorderWidth * 2) + MwDefaultBorderWidth;
|
||||
if(tri <= scr->point.x && scr->point.x <= (ww - tri)) {
|
||||
scr->drag = 1;
|
||||
scr->pos = calc_positition(handle) - scr->point.x;
|
||||
}
|
||||
}
|
||||
|
||||
MwForceRender(handle);
|
||||
}
|
||||
|
||||
MwClassRec MwScrollBarClassRec = {
|
||||
create, /* create */
|
||||
destroy, /* destroy */
|
||||
draw, /* draw */
|
||||
NULL, /* click */
|
||||
NULL, /* parent_resize */
|
||||
NULL, /* mouse_move */
|
||||
mouse_move, /* mouse_move */
|
||||
MwForceRender, /* mouse_up */
|
||||
MwForceRender /* mouse_down */
|
||||
mouse_down /* mouse_down */
|
||||
};
|
||||
MwClass MwScrollBarClass = &MwScrollBarClassRec;
|
||||
|
||||
int MwScrollBarGetVisibleLength(MwWidget handle) {
|
||||
int ww = MwGetInteger(handle, MwNwidth);
|
||||
int wh = MwGetInteger(handle, MwNheight);
|
||||
int or = MwGetInteger(handle, MwNorientation);
|
||||
int tri = 0;
|
||||
int s = 0;
|
||||
|
||||
if(or == MwVERTICAL) {
|
||||
tri = (ww - MwDefaultBorderWidth * 2) * 2;
|
||||
s = wh;
|
||||
} else if(or == MwHORIZONTAL) {
|
||||
tri = (wh - MwDefaultBorderWidth * 2) * 2;
|
||||
s = ww;
|
||||
}
|
||||
return s - tri - MwDefaultBorderWidth * 2;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ static void click(MwWidget handle) {
|
||||
MwDestroyWidget(menu->sub[i]->wsub);
|
||||
menu->sub[i]->wsub = NULL;
|
||||
|
||||
MwLLForceRender(handle->lowlevel);
|
||||
MwForceRender(handle);
|
||||
} else if(arrlen(menu->sub[i]->sub) == 0) {
|
||||
MwWidget p;
|
||||
|
||||
@@ -136,7 +136,7 @@ static void click(MwWidget handle) {
|
||||
|
||||
MwDestroyWidget(w);
|
||||
|
||||
MwLLForceRender(p->lowlevel);
|
||||
MwForceRender(p);
|
||||
|
||||
MwDispatchUserHandler(p, MwNmenuHandler, menu->sub[i]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user