~ubuntu-branches/ubuntu/precise/glbsp/precise

« back to all changes in this revision

Viewing changes to gui/progress.cc

  • Committer: Bazaar Package Importer
  • Author(s): Darren Salt
  • Date: 2008-01-30 13:33:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080130133349-kgojg33vyiu8xbvp
Tags: 2.24-1
* New upstream release.
* Bumped the lib soname and the library package name due to one silly
  little binary incompatibility caused by changes in an exported struct.
  (Safe; nothing else currently in the archive has ever used libglbsp2.)
* Removed my patches since they're all applied upstream.
* Updated the list of documentation files.
* Build-time changes:
  - Switched from dh_movefiles to dh_install.
  - Updated my makefile to cope with upstream changes.
  - Corrected for debian-rules-ignores-make-clean-error.
  - Corrected for substvar-source-version-is-deprecated.
  - Link libglbsp, rather than glbsp, with libm and libz.
* Fixed shlibdeps. (Closes: #460387)
* Bumped standards version to 3.7.3 (no other changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//------------------------------------------------------------------------
 
2
// PROGRESS : Unix/FLTK Progress display
 
3
//------------------------------------------------------------------------
 
4
//
 
5
//  GL-Friendly Node Builder (C) 2000-2007 Andrew Apted
 
6
//
 
7
//  Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
19
//------------------------------------------------------------------------
 
20
 
 
21
// this includes everything we need
 
22
#include "local.h"
 
23
 
 
24
 
 
25
#define TICKER_TIME  10
 
26
 
 
27
 
 
28
#define BAR_YELLOWY  \
 
29
      fl_color_cube(FL_NUM_RED-1, FL_NUM_GREEN-1, 0)
 
30
 
 
31
#define BAR_ORANGEY  \
 
32
      fl_color_cube(FL_NUM_RED-1, (FL_NUM_GREEN-1)*4/7, 0)
 
33
 
 
34
#define BAR_CYANISH  \
 
35
      fl_color_cube(0, (FL_NUM_GREEN-1)*2/7, FL_NUM_BLUE-1)
 
36
 
 
37
 
 
38
//
 
39
// ProgressBox Constructor
 
40
//
 
41
Guix_ProgressBox::Guix_ProgressBox(int x, int y, int w, int h) :
 
42
    Fl_Group(x, y, w, h, "Progress")
 
43
{
 
44
  // cancel the automatic 'begin' in Fl_Group constructor
 
45
  end();
 
46
 
 
47
  box(FL_THIN_UP_BOX);
 
48
  resizable(0);  // no resizing the kiddies, please
 
49
  
 
50
  labelfont(FL_HELVETICA | FL_BOLD);
 
51
  labeltype(FL_NORMAL_LABEL);
 
52
  align(FL_ALIGN_LEFT | FL_ALIGN_TOP | FL_ALIGN_INSIDE);
 
53
 
 
54
  curr_bars = 0;
 
55
 
 
56
  bars[0].lab_str = bars[1].lab_str = NULL;
 
57
  title_str = NULL;
 
58
 
 
59
  // create the resizable
 
60
 
 
61
  int len = w - 60 - 50;
 
62
 
 
63
  group = new Fl_Group(x+60, y, len, h);
 
64
  group->end();
 
65
 
 
66
  add(group);
 
67
  resizable(group);
 
68
      
 
69
  // create bars
 
70
 
 
71
  CreateOneBar(bars[0], x, y, w, h);
 
72
  CreateOneBar(bars[1], x, y, w, h);
 
73
}
 
74
 
 
75
 
 
76
//
 
77
// ProgressBox Destructor
 
78
//
 
79
Guix_ProgressBox::~Guix_ProgressBox()
 
80
{
 
81
  GlbspFree(bars[0].lab_str);
 
82
  GlbspFree(bars[1].lab_str);
 
83
  GlbspFree(title_str);
 
84
}
 
85
 
 
86
 
 
87
void Guix_ProgressBox::CreateOneBar(guix_bar_t& bar,
 
88
    int x, int y, int w, int h)
 
89
{
 
90
  bar.label = new Fl_Box(x+6, y+4, 50, 20);
 
91
  bar.label->align(FL_ALIGN_RIGHT | FL_ALIGN_INSIDE);
 
92
  bar.label->hide();
 
93
  add(bar.label);
 
94
 
 
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);
 
99
  bar.slide->hide();
 
100
  group->add(bar.slide);
 
101
 
 
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);
 
105
  bar.perc->hide();
 
106
  add(bar.perc);
 
107
}
 
108
 
 
109
 
 
110
void Guix_ProgressBox::SetupOneBar(guix_bar_t& bar, int y,
 
111
    const char *label_short, Fl_Color col)
 
112
{
 
113
  bar.label->label(label_short);
 
114
  bar.label->position(bar.label->x(), y+4);
 
115
  bar.label->show();
 
116
 
 
117
  bar.slide->selection_color(col);
 
118
  bar.slide->position(bar.slide->x(), y+6);
 
119
  bar.slide->value(0);
 
120
  bar.slide->show();
 
121
 
 
122
  bar.perc->position(bar.perc->x(), y+4);
 
123
  bar.perc->show();
 
124
 
 
125
  bar.perc_shown = -1;  // invalid value, forces update.
 
126
}
 
127
 
 
128
 
 
129
void Guix_ProgressBox::SetBars(int num)
 
130
{
 
131
  assert(num == 1 || num == 2);
 
132
 
 
133
  if (curr_bars != 0)
 
134
    ClearBars();
 
135
 
 
136
  curr_bars = num;
 
137
 
 
138
  if (curr_bars == 1)
 
139
  {
 
140
    // FILE loading/saving
 
141
    
 
142
    SetupOneBar(bars[0], y() + 28, "File", BAR_ORANGEY);
 
143
  }
 
144
  else
 
145
  {
 
146
    // MAP building
 
147
    
 
148
    SetupOneBar(bars[0], y() + 16, "Map",  BAR_YELLOWY);
 
149
    SetupOneBar(bars[1], y() + 40, "File", BAR_CYANISH);
 
150
  }
 
151
}
 
152
 
 
153
 
 
154
void Guix_ProgressBox::ClearBars(void)
 
155
{
 
156
  if (guix_win->progress->curr_bars == 0)
 
157
    return;
 
158
 
 
159
  for (int i=0; i < 2; i++)
 
160
  {
 
161
    bars[i].label->hide();
 
162
    bars[i].slide->hide();
 
163
    bars[i].perc->hide();
 
164
  }
 
165
}
 
166
 
 
167
 
 
168
void Guix_ProgressBox::SetBarName(int which, const char *label_short)
 
169
{
 
170
  assert(0 <= which && which < 2);
 
171
 
 
172
  bars[which].label->label(label_short);
 
173
 
 
174
  redraw();
 
175
}
 
176
 
 
177
 
 
178
//------------------------------------------------------------------------
 
179
 
 
180
//
 
181
// GUI_Ticker
 
182
//
 
183
void GUI_Ticker(void)
 
184
{
 
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).
 
188
  //
 
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 !
 
191
 
 
192
  static unsigned int last_millis = 0;
 
193
 
 
194
  unsigned int cur_millis = HelperGetMillis();
 
195
 
 
196
  if (cur_millis >= last_millis && cur_millis >= TICKER_TIME &&
 
197
      cur_millis - TICKER_TIME < last_millis)
 
198
  {
 
199
    return;
 
200
  }
 
201
 
 
202
  Fl::check();
 
203
 
 
204
  last_millis = cur_millis;
 
205
}
 
206
 
 
207
 
 
208
//
 
209
// GUI_DisplayOpen
 
210
//
 
211
boolean_g GUI_DisplayOpen(displaytype_e type)
 
212
{
 
213
  // shutdown any existing display
 
214
  GUI_DisplayClose();
 
215
 
 
216
  switch (type)
 
217
  {
 
218
    case DIS_BUILDPROGRESS:
 
219
      guix_win->progress->SetBars(2);
 
220
      break;
 
221
 
 
222
    case DIS_FILEPROGRESS:
 
223
      guix_win->progress->SetBars(1);
 
224
      break;
 
225
 
 
226
    default:
 
227
      return FALSE;  // unknown display type
 
228
  }
 
229
 
 
230
  return TRUE;
 
231
}
 
232
 
 
233
//
 
234
// GUI_DisplaySetTitle
 
235
//
 
236
void GUI_DisplaySetTitle(const char *str)
 
237
{
 
238
  if (guix_win->progress->curr_bars == 0)
 
239
    return;
 
240
 
 
241
  // copy the string
 
242
  GlbspFree(guix_win->progress->title_str);
 
243
  guix_win->progress->title_str = GlbspStrDup(str);
 
244
}
 
245
 
 
246
//
 
247
// GUI_DisplaySetBarText
 
248
//
 
249
void GUI_DisplaySetBarText(int barnum, const char *str)
 
250
{
 
251
  if (guix_win->progress->curr_bars == 0)
 
252
    return;
 
253
 
 
254
  // select the correct bar
 
255
  if (barnum < 1 || barnum > guix_win->progress->curr_bars)
 
256
    return;
 
257
 
 
258
  guix_bar_t *bar = guix_win->progress->bars + (barnum-1);
 
259
 
 
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.
 
262
 
 
263
  GlbspFree(bar->lab_str);
 
264
  bar->lab_str = GlbspStrDup(str);
 
265
 
 
266
  // for loading/saving, update short name
 
267
  if (guix_win->progress->curr_bars == 1)
 
268
  {
 
269
    if (HelperCaseCmpLen(str, "Read", 4) == 0)
 
270
      guix_win->progress->SetBarName(0, "Load");
 
271
 
 
272
    if (HelperCaseCmpLen(str, "Writ", 4) == 0)
 
273
      guix_win->progress->SetBarName(0, "Save");
 
274
  }
 
275
 
 
276
  // redraw window too 
 
277
  guix_win->progress->redraw();
 
278
}
 
279
 
 
280
//
 
281
// GUI_DisplaySetBarLimit
 
282
//
 
283
void GUI_DisplaySetBarLimit(int barnum, int limit)
 
284
{
 
285
  if (guix_win->progress->curr_bars == 0)
 
286
    return;
 
287
 
 
288
  // select the correct bar
 
289
  if (barnum < 1 || barnum > guix_win->progress->curr_bars)
 
290
    return;
 
291
 
 
292
  guix_bar_t *bar = guix_win->progress->bars + (barnum-1);
 
293
 
 
294
  bar->slide->range(0, limit);
 
295
}
 
296
 
 
297
//
 
298
// GUI_DisplaySetBar
 
299
//
 
300
void GUI_DisplaySetBar(int barnum, int count)
 
301
{
 
302
  if (guix_win->progress->curr_bars == 0)
 
303
    return;
 
304
 
 
305
  // select the correct bar
 
306
  if (barnum < 1 || barnum > guix_win->progress->curr_bars)
 
307
    return;
 
308
 
 
309
  guix_bar_t *bar = guix_win->progress->bars + (barnum-1);
 
310
 
 
311
  // work out percentage
 
312
  int perc = 0;
 
313
 
 
314
  if (count >= 0 && count <= bar->slide->maximum() && 
 
315
      bar->slide->maximum() > 0)
 
316
  {
 
317
    perc = (int)(count * 100.0 / bar->slide->maximum());
 
318
  }
 
319
 
 
320
  if (perc == bar->perc_shown)
 
321
    return;
 
322
 
 
323
  bar->perc_shown = perc;
 
324
 
 
325
  sprintf(bar->perc_buf, "%d%%", perc);
 
326
 
 
327
  bar->perc->label(bar->perc_buf);
 
328
  bar->perc->redraw();
 
329
 
 
330
  bar->slide->value(count);
 
331
  bar->slide->redraw();
 
332
}
 
333
 
 
334
//
 
335
// GUI_DisplayClose
 
336
//
 
337
void GUI_DisplayClose(void)
 
338
{
 
339
  guix_win->progress->ClearBars();
 
340
}
 
341