1
//------------------------------------------------------------------------
2
// PROGRESS : Unix/FLTK Progress display
3
//------------------------------------------------------------------------
5
// GL-Friendly Node Builder (C) 2000-2007 Andrew Apted
7
// Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
9
// This program is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
//------------------------------------------------------------------------
21
// this includes everything we need
25
#define TICKER_TIME 10
29
fl_color_cube(FL_NUM_RED-1, FL_NUM_GREEN-1, 0)
32
fl_color_cube(FL_NUM_RED-1, (FL_NUM_GREEN-1)*4/7, 0)
35
fl_color_cube(0, (FL_NUM_GREEN-1)*2/7, FL_NUM_BLUE-1)
39
// ProgressBox Constructor
41
Guix_ProgressBox::Guix_ProgressBox(int x, int y, int w, int h) :
42
Fl_Group(x, y, w, h, "Progress")
44
// cancel the automatic 'begin' in Fl_Group constructor
48
resizable(0); // no resizing the kiddies, please
50
labelfont(FL_HELVETICA | FL_BOLD);
51
labeltype(FL_NORMAL_LABEL);
52
align(FL_ALIGN_LEFT | FL_ALIGN_TOP | FL_ALIGN_INSIDE);
56
bars[0].lab_str = bars[1].lab_str = NULL;
59
// create the resizable
61
int len = w - 60 - 50;
63
group = new Fl_Group(x+60, y, len, h);
71
CreateOneBar(bars[0], x, y, w, h);
72
CreateOneBar(bars[1], x, y, w, h);
77
// ProgressBox Destructor
79
Guix_ProgressBox::~Guix_ProgressBox()
81
GlbspFree(bars[0].lab_str);
82
GlbspFree(bars[1].lab_str);
87
void Guix_ProgressBox::CreateOneBar(guix_bar_t& bar,
88
int x, int y, int w, int h)
90
bar.label = new Fl_Box(x+6, y+4, 50, 20);
91
bar.label->align(FL_ALIGN_RIGHT | FL_ALIGN_INSIDE);
95
bar.slide = new Fl_Slider(group->x(), y+6, group->w(), 16);
96
bar.slide->set_output();
97
bar.slide->slider(FL_FLAT_BOX);
98
bar.slide->type(FL_HOR_FILL_SLIDER);
100
group->add(bar.slide);
102
bar.perc = new Fl_Box(x + w - 50, y+4, 40, 20);
103
bar.perc->box(FL_FLAT_BOX);
104
bar.perc->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
110
void Guix_ProgressBox::SetupOneBar(guix_bar_t& bar, int y,
111
const char *label_short, Fl_Color col)
113
bar.label->label(label_short);
114
bar.label->position(bar.label->x(), y+4);
117
bar.slide->selection_color(col);
118
bar.slide->position(bar.slide->x(), y+6);
122
bar.perc->position(bar.perc->x(), y+4);
125
bar.perc_shown = -1; // invalid value, forces update.
129
void Guix_ProgressBox::SetBars(int num)
131
assert(num == 1 || num == 2);
140
// FILE loading/saving
142
SetupOneBar(bars[0], y() + 28, "File", BAR_ORANGEY);
148
SetupOneBar(bars[0], y() + 16, "Map", BAR_YELLOWY);
149
SetupOneBar(bars[1], y() + 40, "File", BAR_CYANISH);
154
void Guix_ProgressBox::ClearBars(void)
156
if (guix_win->progress->curr_bars == 0)
159
for (int i=0; i < 2; i++)
161
bars[i].label->hide();
162
bars[i].slide->hide();
163
bars[i].perc->hide();
168
void Guix_ProgressBox::SetBarName(int which, const char *label_short)
170
assert(0 <= which && which < 2);
172
bars[which].label->label(label_short);
178
//------------------------------------------------------------------------
183
void GUI_Ticker(void)
185
// this routine was causing a massive slow-down (under MacOSX at least,
186
// didn't have access to Win32/Linux to test). Seems that Fl::check()
187
// is pretty expensive (and the main glbsp code calls here a lot).
189
// By fixing this (and a optimisation in the progress bars), build time
190
// for DOOM2.WAD fell from 3m14s down to just 11 seconds !
192
static unsigned int last_millis = 0;
194
unsigned int cur_millis = HelperGetMillis();
196
if (cur_millis >= last_millis && cur_millis >= TICKER_TIME &&
197
cur_millis - TICKER_TIME < last_millis)
204
last_millis = cur_millis;
211
boolean_g GUI_DisplayOpen(displaytype_e type)
213
// shutdown any existing display
218
case DIS_BUILDPROGRESS:
219
guix_win->progress->SetBars(2);
222
case DIS_FILEPROGRESS:
223
guix_win->progress->SetBars(1);
227
return FALSE; // unknown display type
234
// GUI_DisplaySetTitle
236
void GUI_DisplaySetTitle(const char *str)
238
if (guix_win->progress->curr_bars == 0)
242
GlbspFree(guix_win->progress->title_str);
243
guix_win->progress->title_str = GlbspStrDup(str);
247
// GUI_DisplaySetBarText
249
void GUI_DisplaySetBarText(int barnum, const char *str)
251
if (guix_win->progress->curr_bars == 0)
254
// select the correct bar
255
if (barnum < 1 || barnum > guix_win->progress->curr_bars)
258
guix_bar_t *bar = guix_win->progress->bars + (barnum-1);
260
// we must copy the string, as the label() method only stores the
261
// pointer -- not good if we've been passed an on-stack buffer.
263
GlbspFree(bar->lab_str);
264
bar->lab_str = GlbspStrDup(str);
266
// for loading/saving, update short name
267
if (guix_win->progress->curr_bars == 1)
269
if (HelperCaseCmpLen(str, "Read", 4) == 0)
270
guix_win->progress->SetBarName(0, "Load");
272
if (HelperCaseCmpLen(str, "Writ", 4) == 0)
273
guix_win->progress->SetBarName(0, "Save");
277
guix_win->progress->redraw();
281
// GUI_DisplaySetBarLimit
283
void GUI_DisplaySetBarLimit(int barnum, int limit)
285
if (guix_win->progress->curr_bars == 0)
288
// select the correct bar
289
if (barnum < 1 || barnum > guix_win->progress->curr_bars)
292
guix_bar_t *bar = guix_win->progress->bars + (barnum-1);
294
bar->slide->range(0, limit);
300
void GUI_DisplaySetBar(int barnum, int count)
302
if (guix_win->progress->curr_bars == 0)
305
// select the correct bar
306
if (barnum < 1 || barnum > guix_win->progress->curr_bars)
309
guix_bar_t *bar = guix_win->progress->bars + (barnum-1);
311
// work out percentage
314
if (count >= 0 && count <= bar->slide->maximum() &&
315
bar->slide->maximum() > 0)
317
perc = (int)(count * 100.0 / bar->slide->maximum());
320
if (perc == bar->perc_shown)
323
bar->perc_shown = perc;
325
sprintf(bar->perc_buf, "%d%%", perc);
327
bar->perc->label(bar->perc_buf);
330
bar->slide->value(count);
331
bar->slide->redraw();
337
void GUI_DisplayClose(void)
339
guix_win->progress->ClearBars();