diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gwin/gwin_progressbar.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/src/gwin/gwin_progressbar.c b/src/gwin/gwin_progressbar.c index d06f8058..ce11934f 100644 --- a/src/gwin/gwin_progressbar.c +++ b/src/gwin/gwin_progressbar.c @@ -102,9 +102,17 @@ void gwinProgressbarSetRange(GHandle gh, int min, int max) { if (min == max) // prevent divide by 0 errors. max++; - gsw->min = min; - gsw->max = max; - gsw->pos = min; + if (min <= max) { + gsw->min = min; + gsw->max = max; + gsw->pos = min; + gsw->res = 1; + } else { + gsw->min = max; + gsw->max = min; + gsw->pos = min; + gsw->res = -1; + } PBResetDisplayPos(gsw); @@ -117,15 +125,9 @@ void gwinProgressbarSetPosition(GHandle gh, int pos) { if (gh->vmt != (gwinVMT *)&progressbarVMT) return; - if (gsw->min <= gsw->max) { - if (pos < gsw->min) gsw->pos = gsw->min; - else if (pos > gsw->max) gsw->pos = gsw->max; - else gsw->pos = pos; - } else { - if (pos > gsw->min) gsw->pos = gsw->min; - else if (pos < gsw->max) gsw->pos = gsw->max; - else gsw->pos = pos; - } + if (pos < gsw->min) gsw->pos = gsw->min; + else if (pos > gsw->max) gsw->pos = gsw->max; + else gsw->pos = pos; PBResetDisplayPos(gsw); _gwinUpdate(gh); @@ -139,9 +141,6 @@ void gwinProgressbarSetResolution(GHandle gh, int resolution) { if (gh->vmt != (gwinVMT *)&progressbarVMT) return; - if (resolution <= 0) - resolution = 1; - gsw->res = resolution; #undef gsw @@ -153,10 +152,9 @@ void gwinProgressbarIncrement(GHandle gh) { if (gh->vmt != (gwinVMT *)&progressbarVMT) return; - if (gsw->max - gsw->pos > gsw->res) - gsw->pos += gsw->res; - else - gsw->pos = gsw->max; + gsw->pos += gsw->res; + if (gsw->pos < gsw->min) gsw->pos = gsw->min; + else if (gsw->pos > gsw->max) gsw->pos = gsw->max; PBResetDisplayPos(gsw); _gwinUpdate(gh); @@ -170,12 +168,9 @@ void gwinProgressbarDecrement(GHandle gh) { if (gh->vmt != (gwinVMT *)&progressbarVMT) return; - if (gsw->pos > gsw->res) - gsw->pos -= gsw->min; - else - gsw->pos = gsw->min; - gsw->pos -= gsw->res; + if (gsw->pos < gsw->min) gsw->pos = gsw->min; + else if (gsw->pos > gsw->max) gsw->pos = gsw->max; PBResetDisplayPos(gsw); _gwinUpdate(gh); |