2 * Simple Framebuffer Gfx/GUI lib
4 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
5 * Understanding is not required. Only obedience.
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 3 of the License ONLY.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 module iv
.egra
.gui
.widgets
.progbar
/*is aliced*/;
22 import arsd
.simpledisplay
;
32 import iv
.egra
.gui
.subwindows
;
33 import iv
.egra
.gui
.widgets
.base
;
34 import iv
.egra
.gui
.widgets
.labels
;
37 // ////////////////////////////////////////////////////////////////////////// //
38 public class ProgressBarWidget
: LabelWidget
{
43 int lastWidth
= int.min
;
44 int lastPxFull
= int.min
;
47 final bool updateLast () {
49 if (width
!= lastWidth
) {
54 if (lastPxFull
!= 0) {
63 pxFull
= cast(int)(cast(long)lastWidth
*cast(long)(mCurrent
-mMin
)/cast(long)(mMax
-mMin
));
65 if (pxFull
!= lastPxFull
) {
70 if (res
) widgetChanged();
75 this(T
:const(char)[]) (Widget aparent
, T atext
, HAlign horiz
=HAlign
.Center
, VAlign vert
=VAlign
.Center
) {
76 super(aparent
, atext
, horiz
, vert
);
80 this(T
:const(char)[]) (T atext
, HAlign horiz
=HAlign
.Center
, VAlign vert
=VAlign
.Center
) {
81 assert(creatorCurrentParent
!is null);
82 this(creatorCurrentParent
, atext
, horiz
, vert
);
85 final void setMinMax (int amin
, int amax
) {
86 if (amin
> amax
) { immutable int tmp
= amin
; amin
= amax
; amax
= tmp
; }
89 if (mCurrent
< mMin
) mCurrent
= mMin
;
90 if (mCurrent
> mMax
) mCurrent
= mMax
;
94 final @property int current () const nothrow @safe @nogc {
99 final @property void current (int val
) {
100 pragma(inline
, true);
101 if (val
< mMin
) val
= mMin
;
102 if (val
> mMax
) val
= mMax
;
107 // returns `true` if need to repaint
108 final bool setCurrentTotal (int val
, int total
) {
109 if (total
< 0) total
= 0;
111 if (val
< 0) val
= 0;
112 if (val
> total
) val
= total
;
117 protected void drawStripes (GxRect rect
, in bool asfull
) {
118 if (rect
.empty
) return;
120 immutable int sty
= rect
.pos
.y
;
121 immutable int sth
= rect
.size
.h
;
124 if (rect
.height
> 4) uprc
.size
.h
= 2;
125 else if (rect
.height
> 2) uprc
.size
.h
= 1;
126 else uprc
.size
.h
= 0;
127 if (uprc
.size
.h
> 0) {
128 rect
.pos
.y
+= uprc
.size
.h
;
129 rect
.size
.h
-= uprc
.size
.h
;
132 if (!uprc
.empty
) gxFillRect(uprc
, getColor(asfull ?
"back-full-hishade" : "back-hishade"));
133 gxFillRect(rect
, getColor(asfull ?
"back-full" : "back"));
135 immutable uint clrHi
= getColor(asfull ?
"stripe-full-hishade" : "stripe-hishade");
136 immutable uint clrOk
= getColor(asfull ?
"stripe-full" : "stripe");
138 foreach (int y0
; 0..sth
) {
139 gxHStripedLine(rect
.pos
.x
-y0
, sty
+y0
, rect
.size
.w
+y0
, 16, (y0
< uprc
.size
.h ? clrHi
: clrOk
));
143 protected override void doPaint (GxRect grect
) {
144 immutable uint clrRect
= getColor("rect");
146 gxDrawRect(grect
, clrRect
);
147 gxClipRect
.shrinkBy(1, 1);
148 grect
.shrinkBy(1, 1);
149 if (grect
.empty
) return;
151 if (lastWidth
!= width
) updateLast();
152 immutable int pxFull
= lastPxFull
;
156 GxRect rc
= GxRect(grect
.pos
, pxFull
, grect
.height
);
157 if (gxClipRect
.intersect(rc
)) drawStripes(rc
, asfull
:true);
161 if (pxFull
< grect
.width
) {
165 if (gxClipRect
.intersect(rc
)) drawStripes(grect
, asfull
:false);
169 if (grect
.height
> 2) grect
.moveLeftTopBy(0, 1);