add MwNshowArrows

git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@789 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
NishiOwO
2025-11-23 12:10:27 +00:00
parent f70c201ae5
commit c7581d42c7
2 changed files with 38 additions and 18 deletions

View File

@@ -542,6 +542,7 @@
</widget> </widget>
<widget name="ScrollBar"> <widget name="ScrollBar">
<properties> <properties>
<property name="showArrows" />
<property name="areaShown" /> <property name="areaShown" />
<property name="value" /> <property name="value" />
<property name="minValue" /> <property name="minValue" />

View File

@@ -19,6 +19,7 @@ static int create(MwWidget handle) {
MwNvalue, 0, MwNvalue, 0,
MwNareaShown, 50, MwNareaShown, 50,
MwNorientation, MwVERTICAL, MwNorientation, MwVERTICAL,
MwNshowArrows, 1,
NULL); NULL);
return 0; return 0;
@@ -37,7 +38,7 @@ static int calc_length(MwWidget handle) {
return max * (double)area / len; return max * (double)area / len;
} }
static int calc_positition(MwWidget handle) { static int calc_position(MwWidget handle) {
int max = MwScrollBarGetVisibleLength(handle); int max = MwScrollBarGetVisibleLength(handle);
int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue); int len = MwGetInteger(handle, MwNmaxValue) - MwGetInteger(handle, MwNminValue);
int val = MwGetInteger(handle, MwNvalue); int val = MwGetInteger(handle, MwNvalue);
@@ -87,39 +88,51 @@ static void draw(MwWidget handle) {
rt.height = rt.width; rt.height = rt.width;
rt.y = r.y; rt.y = r.y;
MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.y <= uy) ? 1 : 0, MwNORTH); if(MwGetInteger(handle, MwNshowArrows)){
if(handle->pressed && scr->point.y <= uy) { MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.y <= uy) ? 1 : 0, MwNORTH);
add_value(handle, -1); if(handle->pressed && scr->point.y <= uy) {
add_value(handle, -1);
}
}else{
rt.height = 0;
} }
rbar.width = r.width; rbar.width = r.width;
rbar.height = calc_length(handle); rbar.height = calc_length(handle);
rbar.x = r.x; rbar.x = r.x;
rbar.y = r.y + rt.height + calc_positition(handle); rbar.y = r.y + rt.height + calc_position(handle);
rt.y = r.y + r.height - rt.height; rt.y = r.y + r.height - rt.height;
MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.y >= dy) ? 1 : 0, MwSOUTH); if(MwGetInteger(handle, MwNshowArrows)){
if(handle->pressed && scr->point.y >= dy) { MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.y >= dy) ? 1 : 0, MwSOUTH);
add_value(handle, 1); if(handle->pressed && scr->point.y >= dy) {
add_value(handle, 1);
}
} }
} else if(or == MwHORIZONTAL) { } else if(or == MwHORIZONTAL) {
rt.width = rt.height; rt.width = rt.height;
rt.x = r.x; rt.x = r.x;
MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.x <= ux) ? 1 : 0, MwWEST); if(MwGetInteger(handle, MwNshowArrows)){
if(handle->pressed && scr->point.x <= ux) { MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.x <= ux) ? 1 : 0, MwWEST);
add_value(handle, -1); if(handle->pressed && scr->point.x <= ux) {
add_value(handle, -1);
}
}else{
rt.width = 0;
} }
rbar.width = calc_length(handle); rbar.width = calc_length(handle);
rbar.height = r.height; rbar.height = r.height;
rbar.x = r.x + rt.width + calc_positition(handle); rbar.x = r.x + rt.width + calc_position(handle);
rbar.y = r.y; rbar.y = r.y;
rt.x = r.x + r.width - rt.width; rt.x = r.x + r.width - rt.width;
MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.x >= dx) ? 1 : 0, MwEAST); if(MwGetInteger(handle, MwNshowArrows)){
if(handle->pressed && scr->point.x >= dx) { MwDrawTriangle(handle, &rt, base, (handle->pressed && scr->point.x >= dx) ? 1 : 0, MwEAST);
add_value(handle, 1); if(handle->pressed && scr->point.x >= dx) {
add_value(handle, 1);
}
} }
} }
@@ -195,15 +208,17 @@ static void mouse_down(MwWidget handle, void* ptr) {
scr->drag = 0; scr->drag = 0;
if(or == MwVERTICAL) { if(or == MwVERTICAL) {
int tri = (ww - MwDefaultBorderWidth(handle) * 2) + MwDefaultBorderWidth(handle); int tri = (ww - MwDefaultBorderWidth(handle) * 2) + MwDefaultBorderWidth(handle);
if(!MwGetInteger(handle, MwNshowArrows)) tri = 0;
if(tri <= scr->point.y && scr->point.y <= (wh - tri)) { if(tri <= scr->point.y && scr->point.y <= (wh - tri)) {
scr->drag = 1; scr->drag = 1;
scr->pos = calc_positition(handle) - scr->point.y; scr->pos = calc_position(handle) - scr->point.y;
} }
} else if(or == MwHORIZONTAL) { } else if(or == MwHORIZONTAL) {
int tri = (wh - MwDefaultBorderWidth(handle) * 2) + MwDefaultBorderWidth(handle); int tri = (wh - MwDefaultBorderWidth(handle) * 2) + MwDefaultBorderWidth(handle);
if(!MwGetInteger(handle, MwNshowArrows)) tri = 0;
if(tri <= scr->point.x && scr->point.x <= (ww - tri)) { if(tri <= scr->point.x && scr->point.x <= (ww - tri)) {
scr->drag = 1; scr->drag = 1;
scr->pos = calc_positition(handle) - scr->point.x; scr->pos = calc_position(handle) - scr->point.x;
} }
} }
@@ -211,11 +226,14 @@ static void mouse_down(MwWidget handle, void* ptr) {
} }
static void prop_change(MwWidget handle, const char* key) { static void prop_change(MwWidget handle, const char* key) {
if(strcmp(key, MwNminValue) == 0 || strcmp(key, MwNvalue) == 0 || strcmp(key, MwNmaxValue) == 0 || strcmp(key, MwNareaShown) == 0) { if(strcmp(key, MwNminValue) == 0 || strcmp(key, MwNvalue) == 0 || strcmp(key, MwNmaxValue) == 0) {
if(MwGetInteger(handle, MwNvalue) > MwGetInteger(handle, MwNmaxValue)) MwSetInteger(handle, MwNvalue, MwGetInteger(handle, MwNmaxValue)); if(MwGetInteger(handle, MwNvalue) > MwGetInteger(handle, MwNmaxValue)) MwSetInteger(handle, MwNvalue, MwGetInteger(handle, MwNmaxValue));
if(handle->prop_event) MwDispatchUserHandler(handle, MwNchangedHandler, NULL); if(handle->prop_event) MwDispatchUserHandler(handle, MwNchangedHandler, NULL);
MwForceRender(handle); MwForceRender(handle);
} }
if(strcmp(key, MwNshowArrows) == 0 || strcmp(key, MwNareaShown) == 0){
MwForceRender(handle);
}
} }
static int mwScrollBarGetVisibleLengthImpl(MwWidget handle) { static int mwScrollBarGetVisibleLengthImpl(MwWidget handle) {
@@ -232,6 +250,7 @@ static int mwScrollBarGetVisibleLengthImpl(MwWidget handle) {
tri = (wh - MwDefaultBorderWidth(handle) * 2) * 2; tri = (wh - MwDefaultBorderWidth(handle) * 2) * 2;
s = ww; s = ww;
} }
if(!MwGetInteger(handle, MwNshowArrows)) tri = 0;
return s - tri - MwDefaultBorderWidth(handle) * 2; return s - tri - MwDefaultBorderWidth(handle) * 2;
} }