~ubuntu-branches/ubuntu/quantal/glbsp/quantal

« back to all changes in this revision

Viewing changes to fltk/menu.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
 
// MENU : Unix/FLTK Menu handling
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
 
static boolean_g menu_want_to_quit;
26
 
 
27
 
 
28
 
static void menu_quit_CB(Fl_Widget *w, void *data)
29
 
{
30
 
  menu_want_to_quit = TRUE;
31
 
}
32
 
 
33
 
static void menu_do_clear_log(Fl_Widget *w, void * data)
34
 
{
35
 
  guix_win->text_box->ClearLog();
36
 
}
37
 
 
38
 
#ifndef MACOSX
39
 
static void menu_do_exit(Fl_Widget *w, void * data)
40
 
{
41
 
  guix_win->want_quit = TRUE;
42
 
}
43
 
#endif
44
 
 
45
 
 
46
 
//------------------------------------------------------------------------
47
 
 
48
 
static void menu_do_prefs(Fl_Widget *w, void * data)
49
 
{
50
 
  guix_pref_win = new Guix_PrefWin();
51
 
 
52
 
  // run the GUI until the user closes
53
 
  while (! guix_pref_win->want_quit)
54
 
    Fl::wait();
55
 
 
56
 
  delete guix_pref_win;
57
 
}
58
 
 
59
 
 
60
 
//------------------------------------------------------------------------
61
 
 
62
 
static const char *about_Info =
63
 
  "By Andrew Apted (C) 2000-2005\n"
64
 
  "\n"
65
 
  "Based on BSP 2.3 (C) 1998 Colin Reed, Lee Killough\n"
66
 
  "\n"
67
 
  "Additional credits to...\n"
68
 
  "    Andy Baker & Marc Pullen, for invaluable help\n"
69
 
  "    Janis Legzdinsh, for fixing up Hexen support\n"
70
 
  "    Matt Fell, for the Doom Specs\n"
71
 
  "    Raphael Quinet, for DEU and the original idea\n"
72
 
  "    ... and everyone else who deserves it !\n"
73
 
  "\n"
74
 
  "This program is free software, under the terms of\n"
75
 
  "the GNU General Public License, and comes with\n"
76
 
  "ABSOLUTELY NO WARRANTY.\n"
77
 
  "\n"
78
 
  "Website:  http://glbsp.sourceforge.net";
79
 
 
80
 
 
81
 
static void menu_do_about(Fl_Widget *w, void * data)
82
 
{
83
 
  menu_want_to_quit = FALSE;
84
 
 
85
 
  Fl_Window *ab_win = new Fl_Window(600, 340, "About glBSP");
86
 
  ab_win->end();
87
 
 
88
 
  // non-resizable
89
 
  ab_win->size_range(ab_win->w(), ab_win->h(), ab_win->w(), ab_win->h());
90
 
  ab_win->position(guix_prefs.manual_x, guix_prefs.manual_y);
91
 
  ab_win->callback((Fl_Callback *) menu_quit_CB);
92
 
 
93
 
  // add the about image
94
 
  Fl_Group *group = new Fl_Group(0, 0, 230, ab_win->h());
95
 
  group->box(FL_FLAT_BOX);
96
 
  group->color(FL_BLACK, FL_BLACK);
97
 
  ab_win->add(group);
98
 
  
99
 
  Fl_Box *box = new Fl_Box(20, 90, ABOUT_IMG_W+2, ABOUT_IMG_H+2);
100
 
  box->image(about_image);
101
 
  group->add(box); 
102
 
 
103
 
 
104
 
  // nice big logo text
105
 
  box = new Fl_Box(240, 5, 350, 50, "glBSPX  " GLBSP_VER);
106
 
  box->labelsize(24);
107
 
  ab_win->add(box);
108
 
 
109
 
  // about text
110
 
  box = new Fl_Box(240, 60, 350, 270, about_Info);
111
 
  box->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_TOP);
112
 
  ab_win->add(box);
113
 
   
114
 
 
115
 
  // finally add an "OK" button
116
 
  Fl_Button *button = new Fl_Button(ab_win->w()-10-60, ab_win->h()-10-30, 
117
 
      60, 30, "OK");
118
 
  button->callback((Fl_Callback *) menu_quit_CB);
119
 
  ab_win->add(button);
120
 
    
121
 
  ab_win->set_modal();
122
 
  ab_win->show();
123
 
  
124
 
  // capture initial size
125
 
  WindowSmallDelay();
126
 
  int init_x = ab_win->x();
127
 
  int init_y = ab_win->y();
128
 
  
129
 
  // run the GUI until the user closes
130
 
  while (! menu_want_to_quit)
131
 
    Fl::wait();
132
 
 
133
 
  // check if the user moved/resized the window
134
 
  if (ab_win->x() != init_x || ab_win->y() != init_y)
135
 
  {
136
 
    guix_prefs.manual_x = ab_win->x();
137
 
    guix_prefs.manual_y = ab_win->y();
138
 
  }
139
 
 
140
 
  // this deletes all the child widgets too...
141
 
  delete ab_win;
142
 
}
143
 
 
144
 
 
145
 
//------------------------------------------------------------------------
146
 
 
147
 
static void menu_do_manual(Fl_Widget *w, void * data)
148
 
{
149
 
  guix_book_win = new Guix_Book();
150
 
 
151
 
  guix_book_win->LoadPage(guix_prefs.manual_page);
152
 
 
153
 
  // run the GUI until the user closes
154
 
  while (! guix_book_win->want_quit)
155
 
  {
156
 
    guix_book_win->Update();
157
 
 
158
 
    Fl::wait();
159
 
  }
160
 
 
161
 
  delete guix_book_win;
162
 
}
163
 
 
164
 
 
165
 
//------------------------------------------------------------------------
166
 
 
167
 
static void menu_do_license(Fl_Widget *w, void * data)
168
 
{
169
 
  guix_lic_win = new Guix_License();
170
 
 
171
 
  // run the GUI until the user closes
172
 
  while (! guix_lic_win->want_quit)
173
 
  {
174
 
    Fl::wait();
175
 
  }
176
 
 
177
 
  delete guix_lic_win;
178
 
}
179
 
 
180
 
 
181
 
//------------------------------------------------------------------------
182
 
 
183
 
static void menu_do_save_log(Fl_Widget *w, void * data)
184
 
{
185
 
  char guess_name[512];
186
 
    
187
 
  // compute the "guess" filename
188
 
  
189
 
  if (! guix_info.output_file ||
190
 
      ! HelperFilenameValid(guix_info.output_file) ||
191
 
      strlen(guix_info.output_file) > 500)
192
 
  {
193
 
    strcpy(guess_name, "glbsp.log");
194
 
  }
195
 
  else
196
 
  {
197
 
    strcpy(guess_name, HelperReplaceExt(guix_info.output_file, "log"));
198
 
  }
199
 
 
200
 
  int choice;
201
 
  char buffer[1024];
202
 
 
203
 
  for (;;)
204
 
  {
205
 
    choice = DialogQueryFilename(
206
 
        "Please select the file to save the log into:",
207
 
        & guix_prefs.save_log_file, guess_name);
208
 
 
209
 
    if (choice != 0)
210
 
      return;
211
 
 
212
 
    if (!guix_prefs.save_log_file || guix_prefs.save_log_file[0] == 0)
213
 
    {
214
 
      DialogShowAndGetChoice(ALERT_TXT, skull_image, 
215
 
          "Please choose a Log filename.");
216
 
      continue;
217
 
    }
218
 
 
219
 
    if (! HelperFilenameValid(guix_prefs.save_log_file))
220
 
    {
221
 
      sprintf(buffer,
222
 
          "Invalid Log filename:\n"
223
 
          "\n"
224
 
          "      %s\n"
225
 
          "\n"
226
 
          "Please check the filename and try again.",
227
 
          guix_prefs.save_log_file);
228
 
 
229
 
      DialogShowAndGetChoice(ALERT_TXT, skull_image, buffer);
230
 
      continue;
231
 
    }
232
 
 
233
 
    // check for missing extension
234
 
 
235
 
    if (! HelperHasExt(guix_prefs.save_log_file))
236
 
    {
237
 
      if (guix_prefs.lack_ext_warn)
238
 
      {
239
 
        sprintf(buffer,
240
 
            "The Log file you selected has no extension.\n"
241
 
            "\n"
242
 
            "Do you want to add \".LOG\" and continue ?");
243
 
 
244
 
        choice = DialogShowAndGetChoice(ALERT_TXT, skull_image,
245
 
            buffer, "OK", "Re-Select", "Cancel");
246
 
 
247
 
        if (choice < 0 || choice == 2)
248
 
          return;
249
 
 
250
 
        if (choice == 1)
251
 
          continue;
252
 
      }
253
 
 
254
 
      // choice == 0
255
 
      {
256
 
        char *new_log = HelperReplaceExt(guix_prefs.save_log_file, "log");
257
 
 
258
 
        GlbspFree(guix_prefs.save_log_file);
259
 
        guix_prefs.save_log_file = GlbspStrDup(new_log);
260
 
      }
261
 
    }
262
 
 
263
 
    // check if file already exists...
264
 
    
265
 
    if (guix_prefs.overwrite_warn && 
266
 
        HelperFileExists(guix_prefs.save_log_file))
267
 
    {
268
 
      sprintf(buffer,
269
 
          "Warning: the chosen Log file already exists:\n"
270
 
          "\n"
271
 
          "      %s\n"
272
 
          "\n"
273
 
          "Do you want to overwrite it ?",
274
 
          guix_prefs.save_log_file);
275
 
 
276
 
      choice = DialogShowAndGetChoice(ALERT_TXT, skull_image,
277
 
          buffer, "OK", "Re-Select", "Cancel");
278
 
 
279
 
      if (choice < 0 || choice == 2)
280
 
        return;
281
 
 
282
 
      if (choice == 1)
283
 
        continue;
284
 
    }
285
 
 
286
 
    guix_win->text_box->SaveLog(guix_prefs.save_log_file);
287
 
    return;
288
 
  }
289
 
}
290
 
 
291
 
 
292
 
//------------------------------------------------------------------------
293
 
 
294
 
#undef FCAL
295
 
#define FCAL  (Fl_Callback *)
296
 
 
297
 
static Fl_Menu_Item menu_items[] = 
298
 
{
299
 
  { "&File", 0, 0, 0, FL_SUBMENU },
300
 
    { "&Preferences...",    0, FCAL menu_do_prefs },
301
 
    { "&Save Log...",       0, FCAL menu_do_save_log },
302
 
#ifdef MACOSX
303
 
    { "&Clear Log",         0, FCAL menu_do_clear_log },
304
 
#else
305
 
    { "&Clear Log",         0, FCAL menu_do_clear_log, 0, FL_MENU_DIVIDER },
306
 
    { "E&xit",   FL_ALT + 'q', FCAL menu_do_exit },
307
 
#endif
308
 
    { 0 },
309
 
 
310
 
  { "&Help", 0, 0, 0, FL_SUBMENU },
311
 
    { "&About...",         0,  FCAL menu_do_about },
312
 
    { "&License...",       0,  FCAL menu_do_license },
313
 
    { "&Manual...",   FL_F+1,  FCAL menu_do_manual },
314
 
    { 0 },
315
 
 
316
 
  { 0 }
317
 
};
318
 
 
319
 
 
320
 
//
321
 
// MenuCreate
322
 
//
323
 
#ifdef MACOSX
324
 
Fl_Sys_Menu_Bar * MenuCreate(int x, int y, int w, int h)
325
 
{
326
 
  Fl_Sys_Menu_Bar *bar = new Fl_Sys_Menu_Bar(x, y, w, h);
327
 
  bar->menu(menu_items);
328
 
  return bar;
329
 
}
330
 
#else
331
 
Fl_Menu_Bar * MenuCreate(int x, int y, int w, int h)
332
 
{
333
 
  Fl_Menu_Bar *bar = new Fl_Menu_Bar(x, y, w, h);
334
 
  bar->menu(menu_items);
335
 
  return bar;
336
 
}
337
 
#endif
338