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

« back to all changes in this revision

Viewing changes to fltk/book.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
 
// BOOK : Unix/FLTK Manual Code
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
 
Guix_Book *guix_book_win;
26
 
 
27
 
 
28
 
static void book_quit_CB(Fl_Widget *w, void *data)
29
 
{
30
 
  if (guix_book_win)
31
 
    guix_book_win->want_quit = TRUE;
32
 
}
33
 
 
34
 
static void book_contents_CB(Fl_Widget *w, void *data)
35
 
{
36
 
  if (guix_book_win)
37
 
    guix_book_win->want_page = 0;
38
 
}
39
 
 
40
 
static void book_prev_CB(Fl_Widget *w, void *data)
41
 
{
42
 
  if (guix_book_win)
43
 
    guix_book_win->want_page = guix_book_win->cur_page - 1;
44
 
}
45
 
 
46
 
static void book_next_CB(Fl_Widget *w, void *data)
47
 
{
48
 
  if (guix_book_win)
49
 
    guix_book_win->want_page = guix_book_win->cur_page + 1;
50
 
}
51
 
 
52
 
static void book_selector_CB(Fl_Widget *w, void *data)
53
 
{
54
 
  if (guix_book_win)
55
 
    guix_book_win->FollowLink(guix_book_win->browser->value() - 1);
56
 
}
57
 
 
58
 
 
59
 
//------------------------------------------------------------------------
60
 
 
61
 
//
62
 
// Book Constructor
63
 
//
64
 
Guix_Book::Guix_Book() : Fl_Window(guix_prefs.manual_w,
65
 
    guix_prefs.manual_h, "glBSP Manual")
66
 
{
67
 
  // cancel the automatic 'begin' in Fl_Group constructor
68
 
  end();
69
 
 
70
 
  size_range(MANUAL_WINDOW_MIN_W, MANUAL_WINDOW_MIN_H);
71
 
  position(guix_prefs.manual_x, guix_prefs.manual_y);
72
 
  color(MAIN_BG_COLOR, MAIN_BG_COLOR);
73
 
 
74
 
  // allow manual closing of window
75
 
  callback((Fl_Callback *) book_quit_CB);
76
 
  
77
 
  want_quit = FALSE;
78
 
  want_page = BOOK_NO_PAGE;
79
 
  want_reformat = FALSE;
80
 
  cur_page = 0;
81
 
 
82
 
  // create buttons in top row
83
 
 
84
 
  group = new Fl_Group(0, h() - 34, w(), 34);
85
 
  add(group);
86
 
  
87
 
  int CX = 10;
88
 
  int CY = h() - 30;
89
 
 
90
 
  contents = new Fl_Button(CX, CY, 96, 26, "&Contents");
91
 
  contents->box(FL_ROUND_UP_BOX);
92
 
  contents->callback((Fl_Callback *) book_contents_CB);
93
 
  group->add(contents);
94
 
 
95
 
  CX += 126;
96
 
 
97
 
  prev = new Fl_Button(CX, CY, 96, 26, "<<  &Prev");
98
 
  prev->box(FL_ROUND_UP_BOX);
99
 
  prev->callback((Fl_Callback *) book_prev_CB);
100
 
  group->add(prev);
101
 
 
102
 
  CX += 106;
103
 
 
104
 
  next = new Fl_Button(CX, CY, 96, 26, "&Next  >>");
105
 
  next->box(FL_ROUND_UP_BOX);
106
 
  next->callback((Fl_Callback *) book_next_CB);
107
 
  group->add(next);
108
 
 
109
 
  CX += 106;
110
 
 
111
 
  quit = new Fl_Button(w() - 96 - 24, CY, 96, 26, "Close");
112
 
  quit->box(FL_ROUND_UP_BOX);
113
 
  quit->callback((Fl_Callback *) book_quit_CB);
114
 
  group->add(quit);
115
 
 
116
 
  Fl_Box *invis_2 = new Fl_Box(CX, 0, w() - 96 - 10 - CX, 20);
117
 
  add(invis_2);
118
 
 
119
 
  group->resizable(invis_2);
120
 
 
121
 
  // create the browser
122
 
 
123
 
  browser = new Fl_Hold_Browser(0, 0, w(), h() - 34);
124
 
  browser->callback((Fl_Callback *) book_selector_CB);
125
 
 
126
 
  add(browser);
127
 
  resizable(browser);
128
 
 
129
 
  // show the window
130
 
  set_modal();
131
 
  show();
132
 
 
133
 
  // read initial pos (same logic as in Guix_MainWin)
134
 
  WindowSmallDelay();
135
 
  
136
 
  init_x = x(); init_y = y();
137
 
  init_w = w(); init_h = h();
138
 
}
139
 
 
140
 
 
141
 
//
142
 
// Book Destructor
143
 
//
144
 
Guix_Book::~Guix_Book()
145
 
{
146
 
  // update preferences if user moved the window
147
 
  if (x() != init_x || y() != init_y)
148
 
  {
149
 
    guix_prefs.manual_x = x();
150
 
    guix_prefs.manual_y = y();
151
 
  }
152
 
 
153
 
  if (w() != init_w || h() != init_h)
154
 
  {
155
 
    guix_prefs.manual_w = w();
156
 
    guix_prefs.manual_h = h();
157
 
  }
158
 
 
159
 
  guix_prefs.manual_page = cur_page;
160
 
}
161
 
 
162
 
 
163
 
void Guix_Book::resize(int X, int Y, int W, int H)
164
 
{
165
 
  if (W != w() || H != h())
166
 
    want_reformat = TRUE;
167
 
 
168
 
  Fl_Window::resize(X, Y, W, H);
169
 
}
170
 
 
171
 
 
172
 
int Guix_Book::PageCount()
173
 
{
174
 
  // we don't need anything super efficient
175
 
 
176
 
  int count;
177
 
  
178
 
  for (count=0; book_pages[count].text; count++)
179
 
  { /* nothing */ }
180
 
 
181
 
  return count;
182
 
}
183
 
 
184
 
 
185
 
void Guix_Book::LoadPage(int new_num)
186
 
{
187
 
  if (new_num < 0 || new_num >= PageCount())
188
 
    return;
189
 
 
190
 
  cur_page = new_num;
191
 
 
192
 
  want_page = BOOK_NO_PAGE;
193
 
  want_reformat = FALSE;
194
 
 
195
 
  if (cur_page == 0)
196
 
    prev->deactivate();
197
 
  else
198
 
    prev->activate();
199
 
 
200
 
  if (cur_page == PageCount() - 1)
201
 
    next->deactivate();
202
 
  else
203
 
    next->activate();
204
 
 
205
 
  // -- create browser text --
206
 
 
207
 
  browser->clear();
208
 
 
209
 
  int i;
210
 
  const char ** lines = book_pages[cur_page].text;
211
 
 
212
 
  ParaStart();
213
 
 
214
 
  for (i=0; lines[i]; i++)
215
 
  {
216
 
    ParaAddLine(lines[i]);
217
 
  }
218
 
 
219
 
  ParaEnd();
220
 
 
221
 
  browser->position(0);
222
 
}
223
 
 
224
 
 
225
 
void Guix_Book::FollowLink(int line)
226
 
{
227
 
  if (line < 0)
228
 
  {
229
 
    browser->deselect();
230
 
    return;
231
 
  }
232
 
 
233
 
  const char * L = book_pages[cur_page].text[line];
234
 
  
235
 
  if (L[0] == '#' && L[1] == 'L')
236
 
  {
237
 
    want_page = (L[2] - '0') * 10 + (L[3] - '0');
238
 
  }
239
 
  else
240
 
  {
241
 
    // for lines without links, the best we can do is just clear the
242
 
    // hold selection.
243
 
    //
244
 
    browser->deselect();
245
 
  }
246
 
}
247
 
 
248
 
 
249
 
void Guix_Book::Update()
250
 
{
251
 
  if (want_page != BOOK_NO_PAGE)
252
 
    LoadPage(want_page);
253
 
  else if (want_reformat)
254
 
    LoadPage(cur_page);
255
 
}
256
 
 
257
 
 
258
 
//
259
 
//  PARAGRAPH CODE
260
 
//
261
 
 
262
 
void Guix_Book::ParaStart()
263
 
{
264
 
  in_paragraph = FALSE;
265
 
}
266
 
 
267
 
 
268
 
void Guix_Book::ParaEnd()
269
 
{
270
 
  if (in_paragraph && para_buf[0] != 0)
271
 
  {
272
 
    browser->add(para_buf);
273
 
  }
274
 
 
275
 
  in_paragraph = FALSE;
276
 
}
277
 
 
278
 
 
279
 
void Guix_Book::ParaAddWord(const char *word)
280
 
{
281
 
  // set current font for fl_width()
282
 
  fl_font(browser->textfont(), browser->textsize());
283
 
 
284
 
  // need to wrap ?
285
 
  if (para_buf[0] != 0 && (fl_width(para_buf) + fl_width(' ') +
286
 
      fl_width(word) > para_width))
287
 
  {
288
 
    browser->add(para_buf);
289
 
    para_buf[0] = 0;
290
 
    first_line = FALSE;
291
 
  }
292
 
 
293
 
  if (para_buf[0] == 0)
294
 
  {
295
 
    // prefix with spaces to indent paragraph
296
 
    int count = major_indent + (first_line ? 0 : minor_indent);
297
 
 
298
 
    para_buf[count] = 0;
299
 
 
300
 
    for (count--; count >= 0; count--)
301
 
      para_buf[count] = ' ';
302
 
  }
303
 
  else
304
 
    strcat(para_buf, " ");
305
 
 
306
 
  strcat(para_buf, word);
307
 
}
308
 
 
309
 
 
310
 
void Guix_Book::ParaAddLine(const char *line)
311
 
{
312
 
  if (line[0] == 0 || line[0] == '#' || line[0] == '@')
313
 
    ParaEnd();
314
 
 
315
 
  if (line[0] == '#' && line[1] == 'L')
316
 
  {
317
 
    browser->add(line + 4);
318
 
    return;
319
 
  }
320
 
 
321
 
  if (! in_paragraph)
322
 
  {
323
 
    if (! (line[0] == '#' && line[1] == 'P'))
324
 
    {
325
 
      browser->add(line);
326
 
      return;
327
 
    }
328
 
    
329
 
    major_indent = (line[2] - '0') * 6 + 1;
330
 
    minor_indent = (line[3] - '0');
331
 
 
332
 
    line += 4;
333
 
 
334
 
    in_paragraph = TRUE;
335
 
    first_line = TRUE;
336
 
 
337
 
    para_buf[0] = 0;
338
 
    para_width = browser->w() - 24 - (int)fl_width(' ') * major_indent;
339
 
  }
340
 
 
341
 
  // OK, we must be in paragraph mode here
342
 
 
343
 
  for (;;)
344
 
  {
345
 
    while (isspace(*line))
346
 
      line++;
347
 
 
348
 
    if (line[0] == 0)
349
 
      return;
350
 
 
351
 
    char word_buf[100];
352
 
    int word_len = 0;
353
 
 
354
 
    while (*line && word_len < 98)
355
 
    {
356
 
      // handle escapes:
357
 
      //  '#-'  : non-break space.
358
 
      //  '. '  : add a non-break space after dot
359
 
 
360
 
      if (line[0] == '#' && line[1] == '-')
361
 
      {
362
 
        word_buf[word_len++] = ' ';
363
 
        line += 2;
364
 
        continue;
365
 
      }
366
 
      else if (line[0] == '.' && line[1] == ' ')
367
 
      {
368
 
        word_buf[word_len++] = '.';
369
 
        word_buf[word_len++] = ' ';
370
 
        word_buf[word_len++] = ' ';
371
 
        line += 2;
372
 
        continue;
373
 
      }
374
 
 
375
 
      if (isspace(*line))
376
 
        break;
377
 
 
378
 
      word_buf[word_len++] = *line++;
379
 
    }
380
 
 
381
 
    word_buf[word_len] = 0;
382
 
    
383
 
    ParaAddWord(word_buf);
384
 
  }
385
 
}
386
 
 
387
 
 
388
 
//------------------------------------------------------------------------
389
 
 
390
 
 
391
 
Guix_License *guix_lic_win;
392
 
 
393
 
static void license_quit_CB(Fl_Widget *w, void *data)
394
 
{
395
 
  if (guix_lic_win)
396
 
    guix_lic_win->want_quit = TRUE;
397
 
}
398
 
 
399
 
//
400
 
// License Constructor
401
 
//
402
 
Guix_License::Guix_License() : Fl_Window(guix_prefs.manual_w,
403
 
    guix_prefs.manual_h, "glBSP License")
404
 
{
405
 
  // cancel the automatic 'begin' in Fl_Group constructor
406
 
  end();
407
 
 
408
 
  size_range(MANUAL_WINDOW_MIN_W, MANUAL_WINDOW_MIN_H);
409
 
  position(guix_prefs.manual_x, guix_prefs.manual_y);
410
 
  color(MAIN_BG_COLOR, MAIN_BG_COLOR);
411
 
 
412
 
  // allow manual closing of window
413
 
  callback((Fl_Callback *) license_quit_CB);
414
 
 
415
 
  want_quit = FALSE;
416
 
 
417
 
  // create close button in bottom row
418
 
 
419
 
  Fl_Box *invis_1 = new Fl_Box(0, 0, 30, 30);
420
 
  add(invis_1);
421
 
  
422
 
  group = new Fl_Group(0, h() - 34, w(), 34);
423
 
  group->resizable(invis_1);
424
 
  add(group);
425
 
  
426
 
  quit = new Fl_Button(w() - 96 - 24, h() - 30, 96, 26, "Close");
427
 
  quit->box(FL_ROUND_UP_BOX);
428
 
  quit->callback((Fl_Callback *) license_quit_CB);
429
 
  group->add(quit);
430
 
 
431
 
  // create the browser
432
 
 
433
 
  int i;
434
 
 
435
 
  browser = new Fl_Browser(0, 0, w(), h() - 34);
436
 
 
437
 
  for (i=0; license_text[i]; i++)
438
 
    browser->add(license_text[i]);
439
 
 
440
 
  browser->position(0);
441
 
 
442
 
  add(browser);
443
 
  resizable(browser);
444
 
 
445
 
  // show the window
446
 
  set_modal();
447
 
  show();
448
 
 
449
 
  // read initial pos (same logic as in Guix_MainWin)
450
 
  WindowSmallDelay();
451
 
  
452
 
  init_x = x(); init_y = y();
453
 
  init_w = w(); init_h = h();
454
 
}
455
 
 
456
 
 
457
 
//
458
 
// License Destructor
459
 
//
460
 
Guix_License::~Guix_License()
461
 
{
462
 
  // update preferences if user moved the window
463
 
  if (x() != init_x || y() != init_y)
464
 
  {
465
 
    guix_prefs.manual_x = x();
466
 
    guix_prefs.manual_y = y();
467
 
  }
468
 
 
469
 
  if (w() != init_w || h() != init_h)
470
 
  {
471
 
    guix_prefs.manual_w = w();
472
 
    guix_prefs.manual_h = h();
473
 
  }
474
 
}
475