2 * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies of the Software, its documentation and marketing & publicity
13 * materials, and acknowledgment shall be given in the documentation, materials
14 * and software packages that this Software was used.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 static Progressbar **plist = NULL;
44 ProgressbarCreate(const char *name, int w, int h)
50 p = ECALLOC(Progressbar, 1);
52 plist = EREALLOC(Progressbar *, plist, pnum);
55 p->ic = ImageclassAlloc("PROGRESS_BAR", 1);
56 p->tc = TextclassAlloc("PROGRESS_TEXT", 1);
57 p->tnc = TextclassAlloc("PROGRESS_TEXT_NUMBER", 1);
59 pad = ImageclassGetPadding(p->ic);
60 TextSize(p->tc, 0, 0, 0, name, &tw, &th, 0);
61 if (h < th + pad->top + pad->bottom)
62 h = th + pad->top + pad->bottom;
68 x = (WinGetW(VROOT) - w) / 2;
69 y = 32 + (pnum * h * 2);
71 p->win = EobjWindowCreate(EOBJ_TYPE_MISC, x, y, w - (h * 5), h, 1, name);
73 EobjWindowCreate(EOBJ_TYPE_MISC, x + w - (h * 5), y, (h * 5), h, 1, "pn");
74 p->p_win = EobjWindowCreate(EOBJ_TYPE_MISC, x, y + h, 1, h, 1, "pp");
75 if (!p->win || !p->n_win || !p->p_win)
77 ProgressbarDestroy(p);
88 ProgressbarDestroy(Progressbar * p)
95 EobjWindowDestroy(p->win);
96 EobjWindowDestroy(p->n_win);
97 EobjWindowDestroy(p->p_win);
99 for (i = 0; i < pnum; i++)
104 for (j = i; j < pnum - 1; j++)
110 EobjMove(pp->win, EobjGetX(pp->win), EobjGetY(pp->win) - dy);
111 EobjMove(pp->n_win, EobjGetX(pp->n_win), EobjGetY(pp->n_win) - dy);
112 EobjMove(pp->p_win, EobjGetX(pp->p_win), EobjGetY(pp->p_win) - dy);
117 ImageclassFree(p->ic);
118 TextclassFree(p->tc);
119 TextclassFree(p->tnc);
131 plist = EREALLOC(Progressbar *, plist, pnum);
136 ProgressbarSet(Progressbar * p, int progress)
142 if (progress == p->value)
146 w = (p->value * p->w) / 100;
151 Esnprintf(s, sizeof(s), "%i%%", p->value);
153 EobjResize(p->p_win, w, p->h);
154 ImageclassApply(p->ic, EobjGetWin(p->p_win), 1, 0, STATE_NORMAL, ST_SOLID);
155 EobjShapeUpdate(p->p_win, 0);
157 pad = ImageclassGetPadding(p->ic);
158 EClearWindow(EobjGetWin(p->n_win));
159 TextDraw(p->tnc, EobjGetWin(p->n_win), None, 0, 0, STATE_CLICKED, s,
160 pad->left, pad->top, p->h * 5 - (pad->left + pad->right),
161 p->h - (pad->top + pad->bottom), p->h - (pad->top + pad->bottom),
162 TextclassGetJustification(p->tnc));
163 /* Hack - We may not be running in the event loop here */
164 EobjDamage(p->n_win);
170 ProgressbarShow(Progressbar * p)
174 ImageclassApply(p->ic, EobjGetWin(p->win), 0, 0, STATE_NORMAL, ST_SOLID);
175 ImageclassApply(p->ic, EobjGetWin(p->n_win), 0, 0, STATE_CLICKED, ST_SOLID);
176 ImageclassApply(p->ic, EobjGetWin(p->p_win), 1, 0, STATE_NORMAL, ST_SOLID);
179 EobjMap(p->n_win, 0);
180 EobjMap(p->p_win, 0);
182 pad = ImageclassGetPadding(p->ic);
183 TextDraw(p->tc, EobjGetWin(p->win), None, 0, 0, STATE_NORMAL,
184 EobjGetName(p->win), pad->left, pad->top,
185 p->w - (p->h * 5) - (pad->left + pad->right),
186 p->h - (pad->top + pad->bottom), p->h - (pad->top + pad->bottom),
187 TextclassGetJustification(p->tnc));
193 ProgressbarHide(Progressbar * p)