File: menu.cc

package info (click to toggle)
glbsp 2.24-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,220 kB
  • sloc: cpp: 10,762; ansic: 6,953; makefile: 121; sh: 14
file content (338 lines) | stat: -rw-r--r-- 8,328 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
//------------------------------------------------------------------------
// MENU : Unix/FLTK Menu handling
//------------------------------------------------------------------------
//
//  GL-Friendly Node Builder (C) 2000-2007 Andrew Apted
//
//  Based on 'BSP 2.3' by Colin Reed, Lee Killough and others.
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//------------------------------------------------------------------------

// this includes everything we need
#include "local.h"


static boolean_g menu_want_to_quit;


static void menu_quit_CB(Fl_Widget *w, void *data)
{
  menu_want_to_quit = TRUE;
}

static void menu_do_clear_log(Fl_Widget *w, void * data)
{
  guix_win->text_box->ClearLog();
}

#ifndef MACOSX
static void menu_do_exit(Fl_Widget *w, void * data)
{
  guix_win->want_quit = TRUE;
}
#endif


//------------------------------------------------------------------------

static void menu_do_prefs(Fl_Widget *w, void * data)
{
  guix_pref_win = new Guix_PrefWin();

  // run the GUI until the user closes
  while (! guix_pref_win->want_quit)
    Fl::wait();

  delete guix_pref_win;
}


//------------------------------------------------------------------------

static const char *about_Info =
  "By Andrew Apted (C) 2000-2007\n"
  "\n"
  "Based on BSP 2.3 (C) 1998 Colin Reed, Lee Killough\n"
  "\n"
  "Additional credits to...\n"
  "    Andy Baker & Marc Pullen, for invaluable help\n"
  "    Janis Legzdinsh, for fixing up Hexen support\n"
  "    Matt Fell, for the Doom Specs\n"
  "    Raphael Quinet, for DEU and the original idea\n"
  "    ... and everyone else who deserves it !\n"
  "\n"
  "This program is free software, under the terms of\n"
  "the GNU General Public License, and comes with\n"
  "ABSOLUTELY NO WARRANTY.\n"
  "\n"
  "Website:  http://glbsp.sourceforge.net";


static void menu_do_about(Fl_Widget *w, void * data)
{
  menu_want_to_quit = FALSE;

  Fl_Window *ab_win = new Fl_Window(600, 340, "About glBSP");
  ab_win->end();

  // non-resizable
  ab_win->size_range(ab_win->w(), ab_win->h(), ab_win->w(), ab_win->h());
  ab_win->position(guix_prefs.manual_x, guix_prefs.manual_y);
  ab_win->callback((Fl_Callback *) menu_quit_CB);

  // add the about image
  Fl_Group *group = new Fl_Group(0, 0, 230, ab_win->h());
  group->box(FL_FLAT_BOX);
  group->color(FL_BLACK, FL_BLACK);
  ab_win->add(group);
  
  Fl_Box *box = new Fl_Box(20, 90, ABOUT_IMG_W+2, ABOUT_IMG_H+2);
  box->image(about_image);
  group->add(box); 


  // nice big logo text
  box = new Fl_Box(240, 5, 350, 50, "glBSPX  " GLBSP_VER);
  box->labelsize(24);
  ab_win->add(box);

  // about text
  box = new Fl_Box(240, 60, 350, 270, about_Info);
  box->align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_TOP);
  ab_win->add(box);
   
 
  // finally add an "OK" button
  Fl_Button *button = new Fl_Button(ab_win->w()-10-60, ab_win->h()-10-30, 
      60, 30, "OK");
  button->callback((Fl_Callback *) menu_quit_CB);
  ab_win->add(button);
    
  ab_win->set_modal();
  ab_win->show();
  
  // capture initial size
  WindowSmallDelay();
  int init_x = ab_win->x();
  int init_y = ab_win->y();
  
  // run the GUI until the user closes
  while (! menu_want_to_quit)
    Fl::wait();

  // check if the user moved/resized the window
  if (ab_win->x() != init_x || ab_win->y() != init_y)
  {
    guix_prefs.manual_x = ab_win->x();
    guix_prefs.manual_y = ab_win->y();
  }
 
  // this deletes all the child widgets too...
  delete ab_win;
}


//------------------------------------------------------------------------

static void menu_do_manual(Fl_Widget *w, void * data)
{
  guix_book_win = new Guix_Book();

  guix_book_win->LoadPage(guix_prefs.manual_page);

  // run the GUI until the user closes
  while (! guix_book_win->want_quit)
  {
    guix_book_win->Update();

    Fl::wait();
  }

  delete guix_book_win;
}


//------------------------------------------------------------------------

static void menu_do_license(Fl_Widget *w, void * data)
{
  guix_lic_win = new Guix_License();

  // run the GUI until the user closes
  while (! guix_lic_win->want_quit)
  {
    Fl::wait();
  }

  delete guix_lic_win;
}


//------------------------------------------------------------------------

static void menu_do_save_log(Fl_Widget *w, void * data)
{
  char guess_name[512];
    
  // compute the "guess" filename
  
  if (! guix_info.output_file ||
      ! HelperFilenameValid(guix_info.output_file) ||
      strlen(guix_info.output_file) > 500)
  {
    strcpy(guess_name, "glbsp.log");
  }
  else
  {
    strcpy(guess_name, HelperReplaceExt(guix_info.output_file, "log"));
  }

  int choice;
  char buffer[1024];

  for (;;)
  {
    choice = DialogQueryFilename(
        "Please select the file to save the log into:",
        & guix_prefs.save_log_file, guess_name);

    if (choice != 0)
      return;

    if (!guix_prefs.save_log_file || guix_prefs.save_log_file[0] == 0)
    {
      DialogShowAndGetChoice(ALERT_TXT, skull_image, 
          "Please choose a Log filename.");
      continue;
    }

    if (! HelperFilenameValid(guix_prefs.save_log_file))
    {
      sprintf(buffer,
          "Invalid Log filename:\n"
          "\n"
          "      %s\n"
          "\n"
          "Please check the filename and try again.",
          guix_prefs.save_log_file);

      DialogShowAndGetChoice(ALERT_TXT, skull_image, buffer);
      continue;
    }

    // check for missing extension

    if (! HelperHasExt(guix_prefs.save_log_file))
    {
      if (guix_prefs.lack_ext_warn)
      {
        sprintf(buffer,
            "The Log file you selected has no extension.\n"
            "\n"
            "Do you want to add \".LOG\" and continue ?");

        choice = DialogShowAndGetChoice(ALERT_TXT, skull_image,
            buffer, "OK", "Re-Select", "Cancel");

        if (choice < 0 || choice == 2)
          return;

        if (choice == 1)
          continue;
      }

      // choice == 0
      {
        char *new_log = HelperReplaceExt(guix_prefs.save_log_file, "log");

        GlbspFree(guix_prefs.save_log_file);
        guix_prefs.save_log_file = GlbspStrDup(new_log);
      }
    }

    // check if file already exists...
    
    if (guix_prefs.overwrite_warn && 
        HelperFileExists(guix_prefs.save_log_file))
    {
      sprintf(buffer,
          "Warning: the chosen Log file already exists:\n"
          "\n"
          "      %s\n"
          "\n"
          "Do you want to overwrite it ?",
          guix_prefs.save_log_file);

      choice = DialogShowAndGetChoice(ALERT_TXT, skull_image,
          buffer, "OK", "Re-Select", "Cancel");

      if (choice < 0 || choice == 2)
        return;

      if (choice == 1)
        continue;
    }

    guix_win->text_box->SaveLog(guix_prefs.save_log_file);
    return;
  }
}


//------------------------------------------------------------------------

#undef FCAL
#define FCAL  (Fl_Callback *)

static Fl_Menu_Item menu_items[] = 
{
  { "&File", 0, 0, 0, FL_SUBMENU },
    { "&Preferences...",    0, FCAL menu_do_prefs },
    { "&Save Log...",       0, FCAL menu_do_save_log },
#ifdef MACOSX
    { "&Clear Log",         0, FCAL menu_do_clear_log },
#else
    { "&Clear Log",         0, FCAL menu_do_clear_log, 0, FL_MENU_DIVIDER },
    { "E&xit",   FL_ALT + 'q', FCAL menu_do_exit },
#endif
    { 0 },

  { "&Help", 0, 0, 0, FL_SUBMENU },
    { "&About...",         0,  FCAL menu_do_about },
    { "&License...",       0,  FCAL menu_do_license },
    { "&Manual...",   FL_F+1,  FCAL menu_do_manual },
    { 0 },

  { 0 }
};


//
// MenuCreate
//
#ifdef MACOSX
Fl_Sys_Menu_Bar * MenuCreate(int x, int y, int w, int h)
{
  Fl_Sys_Menu_Bar *bar = new Fl_Sys_Menu_Bar(x, y, w, h);
  bar->menu(menu_items);
  return bar;
}
#else
Fl_Menu_Bar * MenuCreate(int x, int y, int w, int h)
{
  Fl_Menu_Bar *bar = new Fl_Menu_Bar(x, y, w, h);
  bar->menu(menu_items);
  return bar;
}
#endif