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

« back to all changes in this revision

Viewing changes to fltk/dialog.cpp

  • 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
 
// DIALOG : Unix/FLTK Pop-up dialogs
3
 
//------------------------------------------------------------------------
4
 
//
5
 
//  GL-Friendly Node Builder (C) 2000-2005 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
 
Fl_Image  *about_image;
26
 
Fl_Pixmap *pldie_image;
27
 
Fl_Pixmap *skull_image;
28
 
 
29
 
static unsigned char *about_image_rgb;
30
 
 
31
 
 
32
 
static Fl_Window *cur_diag;
33
 
static int cur_diag_result;
34
 
static boolean_g cur_diag_done;
35
 
static const char *cur_diag_guess_name;
36
 
 
37
 
 
38
 
static void UncompressAboutImage(unsigned char *& rgb)
39
 
{
40
 
  int rgb_size = ABOUT_IMG_W * ABOUT_IMG_H * 3;
41
 
 
42
 
  rgb = new unsigned char [rgb_size];
43
 
  assert(rgb);
44
 
 
45
 
  const unsigned char *src = about_image_data;
46
 
  unsigned char *dest = rgb;
47
 
 
48
 
  while (dest < (rgb + rgb_size))
49
 
  {
50
 
    int val = *src++;
51
 
 
52
 
    *dest++ = about_image_pal[val*3 + 0];  // red
53
 
    *dest++ = about_image_pal[val*3 + 1];  // green
54
 
    *dest++ = about_image_pal[val*3 + 2];  // blue
55
 
  }
56
 
}
57
 
 
58
 
 
59
 
//
60
 
// DialogLoadImages
61
 
//
62
 
// Should be called after WindowStartup.
63
 
//
64
 
void DialogLoadImages(void)
65
 
{
66
 
  pldie_image = new Fl_Pixmap(pldie_image_data);
67
 
  skull_image = new Fl_Pixmap(skull_image_data);
68
 
 
69
 
  // create about image
70
 
 
71
 
  UncompressAboutImage(about_image_rgb);
72
 
  
73
 
  about_image = new Fl_RGB_Image(about_image_rgb, 
74
 
      ABOUT_IMG_W, ABOUT_IMG_H, 3, (ABOUT_IMG_W * 3));
75
 
}
76
 
 
77
 
//
78
 
// DialogFreeImages
79
 
//
80
 
void DialogFreeImages(void)
81
 
{
82
 
  if (about_image_rgb)
83
 
    delete[] about_image_rgb;
84
 
 
85
 
  delete about_image;
86
 
  delete pldie_image;
87
 
  delete skull_image;
88
 
}
89
 
 
90
 
 
91
 
//------------------------------------------------------------------------
92
 
 
93
 
static void dialog_closed_CB(Fl_Widget *w, void *data)
94
 
{
95
 
  cur_diag_result = -1;
96
 
  cur_diag_done = TRUE;
97
 
}
98
 
 
99
 
static void dialog_left_button_CB(Fl_Widget *w, void *data)
100
 
{
101
 
  cur_diag_result = 0;
102
 
  cur_diag_done = TRUE;
103
 
}
104
 
 
105
 
static void dialog_middle_button_CB(Fl_Widget *w, void *data)
106
 
{
107
 
  cur_diag_result = 1;
108
 
  cur_diag_done = TRUE;
109
 
}
110
 
 
111
 
static void dialog_right_button_CB(Fl_Widget *w, void *data)
112
 
{
113
 
  cur_diag_result = 2;
114
 
  cur_diag_done = TRUE;
115
 
}
116
 
 
117
 
static void dialog_file_browse_CB(Fl_Widget *w, void *data)
118
 
{
119
 
  Fl_Input *inp_box = (Fl_Input *) data;
120
 
  const char *new_name; 
121
 
  
122
 
  new_name = fl_file_chooser("Select the log file", "*.log",
123
 
      inp_box->value());
124
 
 
125
 
  // cancelled ?
126
 
  if (! new_name)
127
 
    return;
128
 
 
129
 
  inp_box->value(new_name);
130
 
}
131
 
 
132
 
static void dialog_file_guess_CB(Fl_Widget *w, void *data)
133
 
{
134
 
  Fl_Input *inp_box = (Fl_Input *) data;
135
 
 
136
 
  if (cur_diag_guess_name)
137
 
  {
138
 
    inp_box->value(cur_diag_guess_name);
139
 
  }
140
 
  
141
 
}
142
 
 
143
 
 
144
 
//------------------------------------------------------------------------
145
 
 
146
 
static void DialogRun()
147
 
{
148
 
  cur_diag->set_modal();
149
 
  cur_diag->show();
150
 
 
151
 
  // read initial pos (same logic as in Guix_MainWin)
152
 
  WindowSmallDelay();
153
 
  int init_x = cur_diag->x(); 
154
 
  int init_y = cur_diag->y();
155
 
 
156
 
  // run the GUI and let user make their choice
157
 
  while (! cur_diag_done)
158
 
  {
159
 
    Fl::wait();
160
 
  }
161
 
 
162
 
  // check if the user moved/resized the window
163
 
  if (cur_diag->x() != init_x || cur_diag->y() != init_y)
164
 
  {
165
 
    guix_prefs.dialog_x = cur_diag->x();
166
 
    guix_prefs.dialog_y = cur_diag->y();
167
 
  }
168
 
}
169
 
 
170
 
 
171
 
//
172
 
// DialogShowAndGetChoice
173
 
//
174
 
// The 'pic' parameter is the picture to show on the left, or NULL for
175
 
// none.  The message can contain newlines.  The right/middle/left
176
 
// parameters allow up to three buttons.
177
 
//
178
 
// Returns the button number pressed (0 for right, 1 for middle, 2 for
179
 
// left) or -1 if escape was pressed or window manually closed.
180
 
// 
181
 
int DialogShowAndGetChoice(const char *title, Fl_Pixmap *pic, 
182
 
    const char *message, const char *left, // = "OK", 
183
 
    const char *middle, // = NULL,
184
 
    const char *right)  // = NULL)
185
 
{
186
 
  cur_diag_result = -1;
187
 
  cur_diag_done = FALSE;
188
 
 
189
 
  int but_width = right ? (120*3) : middle ? (120*2) : (120*1);
190
 
 
191
 
  // determine required size
192
 
  int width = 120 * 3;
193
 
  int height;
194
 
 
195
 
  // set current font for fl_measure()
196
 
  fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
197
 
 
198
 
  fl_measure(message, width, height);
199
 
 
200
 
  if (width < but_width)
201
 
    width = but_width;
202
 
 
203
 
  if (height < 16)
204
 
    height = 16;
205
 
 
206
 
  width  += 60 + 20 + 16;  // 16 extra, just in case
207
 
  height += 10 + 40 + 16;  // 
208
 
 
209
 
  // create window
210
 
  cur_diag = new Fl_Window(0, 0, width, height, title);
211
 
  cur_diag->end();
212
 
  cur_diag->size_range(width, height, width, height);
213
 
  cur_diag->callback((Fl_Callback *) dialog_closed_CB);
214
 
  
215
 
  cur_diag->position(guix_prefs.dialog_x, guix_prefs.dialog_y);
216
 
 
217
 
  // set the resizable
218
 
  Fl_Box *box = new Fl_Box(60, 0, width - 3*120, height);
219
 
  cur_diag->add(box);
220
 
  cur_diag->resizable(box); 
221
 
 
222
 
  // create the image, if any
223
 
  if (pic)
224
 
  {
225
 
    box = new Fl_Box(5, 10, 50, 50);
226
 
    pic->label(box);
227
 
    cur_diag->add(box);
228
 
  }
229
 
 
230
 
  // create the message area
231
 
  box = new Fl_Box(60, 10, width-60 - 20, height-10 - 40, message);
232
 
  box->align(FL_ALIGN_LEFT | FL_ALIGN_TOP | FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
233
 
  cur_diag->add(box);
234
 
  
235
 
  // create buttons
236
 
  Fl_Button *button;
237
 
  
238
 
  int CX = width - 120;
239
 
  int CY = height - 40;
240
 
 
241
 
  if (right)
242
 
  {
243
 
    button = new Fl_Return_Button(CX, CY, 104, 30, right);
244
 
    button->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
245
 
    button->callback((Fl_Callback *) dialog_right_button_CB);
246
 
    cur_diag->add(button);
247
 
 
248
 
    CX -= 120;
249
 
  }
250
 
 
251
 
  if (middle)
252
 
  {
253
 
    button = new Fl_Button(CX, CY, 104, 30, middle);
254
 
    button->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
255
 
    button->callback((Fl_Callback *) dialog_middle_button_CB);
256
 
    cur_diag->add(button);
257
 
 
258
 
    CX -= 120;
259
 
  }
260
 
 
261
 
  if (left)
262
 
  {
263
 
    button = new Fl_Button(CX, CY, 104, 30, left);
264
 
    button->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
265
 
    button->callback((Fl_Callback *) dialog_left_button_CB);
266
 
    cur_diag->add(button);
267
 
 
268
 
    CX -= 120;
269
 
  }
270
 
 
271
 
  // show time !
272
 
  DialogRun();
273
 
 
274
 
  // delete window (automatically deletes child widgets)
275
 
  delete cur_diag;
276
 
  cur_diag = NULL;
277
 
 
278
 
  return cur_diag_result;
279
 
}
280
 
 
281
 
 
282
 
//
283
 
// DialogQueryFilename
284
 
// 
285
 
// Shows the current filename (name_ptr) in an input box, and provides
286
 
// a browse button to choose a new filename, and an optional button to
287
 
// guess the new filename (if 'guess_name' is NULL, then the button is
288
 
// disabled).
289
 
//
290
 
// This routine does NOT ensure that the filename is valid (or any
291
 
// other requirement, e.g. has a certain extension).
292
 
// 
293
 
// Returns 0 if "OK" was pressed, 1 if "Cancel" was pressed, or -1 if
294
 
// escape was pressed or the window was manually closed.
295
 
// 
296
 
int DialogQueryFilename(const char *message,
297
 
        const char ** name_ptr, const char *guess_name)
298
 
{
299
 
  cur_diag_result = -1;
300
 
  cur_diag_done = FALSE;
301
 
  cur_diag_guess_name = guess_name;
302
 
 
303
 
  // determine required size
304
 
  int width = 400;
305
 
  int height;
306
 
 
307
 
  // set current font for fl_measure()
308
 
  fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
309
 
 
310
 
  fl_measure(message, width, height);
311
 
 
312
 
  if (width < 400)
313
 
    width = 400;
314
 
 
315
 
  if (height < 16)
316
 
    height = 16;
317
 
 
318
 
  width  += 60 + 20 + 16;  // 16 extra, just in case
319
 
  height += 60 + 50 + 16;  // 
320
 
 
321
 
  // create window
322
 
  cur_diag = new Fl_Window(0, 0, width, height, "glBSP Query");
323
 
  cur_diag->end();
324
 
  cur_diag->size_range(width, height, width, height);
325
 
  cur_diag->callback((Fl_Callback *) dialog_closed_CB);
326
 
  
327
 
  cur_diag->position(guix_prefs.dialog_x, guix_prefs.dialog_y);
328
 
 
329
 
  // set the resizable
330
 
  Fl_Box *box = new Fl_Box(0, height-1, width, 1);
331
 
  cur_diag->add(box);
332
 
  cur_diag->resizable(box); 
333
 
 
334
 
  // create the message area
335
 
  box = new Fl_Box(14, 10, width-20 - 20, height-10 - 100, message);
336
 
  box->align(FL_ALIGN_LEFT | FL_ALIGN_TOP | FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
337
 
  cur_diag->add(box);
338
 
  
339
 
  // create buttons
340
 
  
341
 
  int CX = width - 120;
342
 
  int CY = height - 50;
343
 
 
344
 
  Fl_Button *b_ok;
345
 
  Fl_Button *b_cancel;
346
 
  
347
 
  b_cancel = new Fl_Button(CX, CY, 104, 30, "Cancel");
348
 
  b_cancel->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
349
 
  b_cancel->callback((Fl_Callback *) dialog_middle_button_CB);
350
 
  cur_diag->add(b_cancel);
351
 
 
352
 
  CX -= 120;
353
 
 
354
 
  b_ok = new Fl_Return_Button(CX, CY, 104, 30, "OK");
355
 
  b_ok->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
356
 
  b_ok->callback((Fl_Callback *) dialog_left_button_CB);
357
 
  cur_diag->add(b_ok);
358
 
 
359
 
  // create input box
360
 
  Fl_Input *inp_box;
361
 
  
362
 
  CX = width - 120;
363
 
  CY = height - 100;
364
 
 
365
 
  inp_box = new Fl_Input(20, CY, CX - 20 - 90, 26);
366
 
  inp_box->value(*name_ptr);
367
 
  cur_diag->add(inp_box);
368
 
 
369
 
  // create the browse and guess button
370
 
  Fl_Button *b_browse;
371
 
  Fl_Button *b_guess;
372
 
 
373
 
  b_guess = new Fl_Button(CX, CY, 70, 26, "Guess");
374
 
  b_guess->align(FL_ALIGN_INSIDE);
375
 
  b_guess->callback((Fl_Callback *) dialog_file_guess_CB, inp_box);
376
 
  cur_diag->add(b_guess);
377
 
 
378
 
  CX -= 85;
379
 
 
380
 
  b_browse = new Fl_Button(CX, CY, 80, b_guess->h(), "Browse");
381
 
  b_browse->align(FL_ALIGN_INSIDE);
382
 
  b_browse->callback((Fl_Callback *) dialog_file_browse_CB, inp_box);
383
 
  cur_diag->add(b_browse);
384
 
 
385
 
  // show time !
386
 
  DialogRun();
387
 
 
388
 
  if (cur_diag_result == 0)
389
 
  {
390
 
    GlbspFree(*name_ptr);
391
 
 
392
 
    *name_ptr = GlbspStrDup(inp_box->value());
393
 
  }
394
 
 
395
 
  // delete window (automatically deletes child widgets)
396
 
  delete cur_diag;
397
 
  cur_diag = NULL;
398
 
 
399
 
  return cur_diag_result;
400
 
}
401
 
 
402
 
 
403
 
//
404
 
// GUI_FatalError
405
 
//
406
 
// Terminates the program reporting an error.
407
 
//
408
 
void GUI_FatalError(const char *str, ...)
409
 
{
410
 
  char buffer[2048];
411
 
  char main_err[2048];
412
 
  char *m_ptr;
413
 
 
414
 
  // create message
415
 
  va_list args;
416
 
 
417
 
  va_start(args, str);
418
 
  vsprintf(main_err, str, args);
419
 
  va_end(args);
420
 
 
421
 
  // remove leading and trailing whitespace
422
 
  int len = strlen(main_err);
423
 
 
424
 
  for (; len > 0 && isspace(main_err[len-1]); len--)
425
 
  {
426
 
    main_err[len-1] = 0;
427
 
  }
428
 
  
429
 
  for (m_ptr = main_err; isspace(*m_ptr); m_ptr++)
430
 
  { /* nothing else needed */ }
431
 
 
432
 
  if (HelperCaseCmpLen(m_ptr, "Error: ", 7) == 0)
433
 
    m_ptr += 7;
434
 
 
435
 
  sprintf(buffer,
436
 
      "The following unexpected error occurred:\n"
437
 
      "\n"
438
 
      "      %s\n"
439
 
      "\n"
440
 
      "This may indicate a serious problem within the WAD you "
441
 
      "were trying to build the nodes for.  Check that the WAD "
442
 
      "file isn't corrupt.\n"
443
 
      "\n"
444
 
      "glBSPX will now shut down.",
445
 
      m_ptr);
446
 
   
447
 
  DialogShowAndGetChoice("glBSP Fatal Error", pldie_image, buffer);
448
 
 
449
 
  // Q/ save cookies ?  
450
 
  // A/ no, we save them before each build begins.
451
 
 
452
 
  exit(5);
453
 
}
454