5 ** Copyright (C) 1998 Kurt Van den Branden
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software
19 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <FL/fl_ask.H>
28 #include <FileChooser.h>
30 #include <FL/fl_file_chooser.H>
33 #include "callbacks.h"
37 extern char versiontext
[];
38 int interrupt_computer
= 0;
39 char currentfilename
[100] = "";
41 void show_about (int flag
)
45 aboutw
= make_aboutwindow ();
46 box_versiontext
->label (versiontext
);
51 Fl::add_timeout (5.0, remove_about
, (void *) aboutw
);
58 void remove_about (void * aboutwindow
)
60 Fl_Window
* aboutw
= (Fl_Window
*) aboutwindow
;
62 Fl::remove_timeout (remove_about
, aboutwindow
);
69 void gf1_alert (const char * message
)
73 icon
= fl_message_icon ();
74 icon
->box (FL_ENGRAVED_BOX
);
75 icon
->color (FL_GRAY
);
85 ** 1 : yes was pressed
88 ** position of the window will be just under the gameboard
90 int gf1_question (const char * line1
, const char * line2
)
92 Fl_Window
* questionw
;
97 questionw
= make_questionwindow ();
98 mainwin
= gameboard
->parent ();
99 questionw
->position (mainwin
->x() + gameboard
->x(),
100 mainwin
->y() + mainwin
->h() - questionw
->h());
101 qtext1
->label (line1
);
102 qtext2
->label (line2
);
111 while ((x
= Fl::readqueue()))
113 if (x
== button_qyes
)
118 else if (x
== button_qno
)
134 ** 2 : save was pressed
135 ** 1 : yes was pressed
136 ** 0 : no was pressed
138 ** position of the window will be just under the gameboard
140 int gf1_questionsave (const char * line1
, const char * line2
)
142 Fl_Window
* questionw
;
147 questionw
= make_questionsavewindow ();
148 mainwin
= gameboard
->parent ();
149 questionw
->position (mainwin
->x() + gameboard
->x(),
150 mainwin
->y() + mainwin
->h() - questionw
->h());
151 qstext1
->label (line1
);
152 qstext2
->label (line2
);
161 while ((x
= Fl::readqueue()))
163 if (x
== button_qsyes
)
168 else if (x
== button_qsno
)
173 else if (x
== button_qssave
)
187 void changeinterface (int flag
, gamestruct
* curgame
)
189 listheader
* loglines
;
193 if (flag
== INTERFACE_PLAY
)
195 /* interface items for playing */
196 count_lostwhite
->hide();
197 count_lostblack
->hide();
198 choice_piecetype
->hide();
199 menu_piecetype
->hide();
203 button_execute
->show();
205 /* the browser widget for logging */
209 logbrowser
->color (FL_WHITE
);
210 loglines
= logtobrowser (curgame
->movelog
);
211 while ((line
= (char *) llrembynr (loglines
, 1)) != NULL
)
213 logbrowser
->add (line
);
219 logbrowser
->color (FL_GRAY
);
220 logbrowser
->bottomline (logbrowser
->size());
222 /* player names and timers */
225 whitename
->value (curgame
->player
[0].name
);
226 blackname
->value (curgame
->player
[1].name
);
227 if (curgame
->player
[0].fulltime
== -1)
229 whitetimer
->value ("-:--:--");
230 blacktimer
->value ("-:--:--");
234 timertostr (curgame
->player
[0].timer
, tempstr
);
235 whitetimer
->value (tempstr
);
236 timertostr (curgame
->player
[1].timer
, tempstr
);
237 blacktimer
->value (tempstr
);
239 /* background color for player-names shows whose turn it is */
240 if (curgame
->state
== GAME_GO
)
242 if (b_next_piece (curgame
->boards
[0]) == 'o')
244 whitename
->color (FL_RED
);
245 blackname
->color (FL_GRAY
);
249 whitename
->color (FL_GRAY
);
250 blackname
->color (FL_RED
);
255 whitename
->color (FL_GRAY
);
256 blackname
->color (FL_GRAY
);
258 whitename
->redraw ();
259 blackname
->redraw ();
263 whitename
->value ("");
264 blackname
->value ("");
265 whitetimer
->value ("");
266 blacktimer
->value ("");
267 whitename
->color (FL_GRAY
);
268 blackname
->color (FL_GRAY
);
269 whitename
->redraw ();
270 blackname
->redraw ();
273 /* menu items for playing */
274 menu_new
->activate();
275 menu_loadgame
->activate();
278 menu_savegame
->activate();
279 menu_savelog
->activate();
281 ** show the undo-button when there is a board to restore and
282 ** when we are not playing a timed game
284 if ((curgame
->boards
[2] != NULL
) &&
285 (curgame
->player
[0].fulltime
== -1) &
286 (curgame
->state
== GAME_GO
))
287 menu_undo
->activate();
289 menu_undo
->deactivate();
293 menu_savegame
->deactivate();
294 menu_savelog
->deactivate();
295 menu_undo
->deactivate();
297 menu_edit
->activate();
298 menu_start
->deactivate();
299 menu_compumove
->deactivate();
300 menu_clear
->deactivate();
301 menu_restore
->deactivate();
302 menu_loadboard
->deactivate();
305 menu_saveboard
->deactivate();
307 menu_saveboard
->activate();
310 menu_makedrawing
->deactivate();
312 menu_makedrawing
->activate();
314 menu_makedrawing
->deactivate();
317 /* state of the gameboard */
318 if ((curgame
== NULL
) ||
319 (curgame
->state
== GAME_STOP
))
321 gameboard
->setstate (BOARD_NONE
);
325 gameboard
->setstate (BOARD_PLAY
);
330 /* interface items for editing */
333 button_execute
->hide();
335 count_lostwhite
->show();
336 count_lostblack
->show();
337 choice_piecetype
->show();
338 menu_piecetype
->show();
340 /* the browser widget for logging */
342 logbrowser
->color (FL_GRAY
);
344 /* player names and timers */
345 whitename
->value ("");
346 blackname
->value ("");
347 whitetimer
->value ("");
348 blacktimer
->value ("");
349 whitename
->color (FL_GRAY
);
350 blackname
->color (FL_GRAY
);
351 whitename
->redraw ();
352 blackname
->redraw ();
354 /* menu items for editing */
355 menu_new
->deactivate();
356 menu_loadgame
->deactivate();
357 menu_savegame
->deactivate();
358 menu_savelog
->deactivate();
359 menu_edit
->deactivate();
360 menu_start
->activate();
361 menu_compumove
->activate();
362 menu_clear
->activate();
363 menu_restore
->activate();
364 menu_loadboard
->activate();
365 menu_saveboard
->activate();
366 menu_undo
->deactivate();
369 menu_makedrawing
->activate();
371 menu_makedrawing
->deactivate();
374 /* state of the gameboard */
375 gameboard
->setstate (BOARD_EDIT
);
378 /* always allowed menu items */
379 menu_setup
->activate();
380 menu_exit
->activate();
381 menu_help
->activate();
382 menu_about
->activate();
384 /* problems with the UNDO-button if I don't do this */
391 void setlostcounters (void)
395 tempboard
= gameboard
->getboard ();
397 if (tempboard
== NULL
)
399 count_lostwhite
->value (0);
400 count_lostblack
->value (0);
404 count_lostwhite
->value (b_white_lost (tempboard
));
405 count_lostblack
->value (b_black_lost (tempboard
));
412 void stop_thinking (Fl_Button
* stopbutton
, void * data
)
414 interrupt_computer
= 1;
420 Fl_Window
* create_thinkwindow (void)
422 Fl_Window
* thinkwindow
;
425 thinkwindow
= make_thinkwindow ();
426 mainwin
= logbrowser
->parent ();
427 thinkwindow
->position (logbrowser
->x() + mainwin
->x() + 10,
428 logbrowser
->y() + mainwin
->y() + 10);
429 thinkwindow
->show ();
432 return (thinkwindow
);
436 void timertostr (float newtimer
, char * tempstr
)
438 int thetimer
= (int) newtimer
;
442 sprintf (tempstr
, "YOULOSE");
446 sprintf (tempstr
, "%d:%02d:%02d",
448 (thetimer
% 3600) / 60,
456 Fl_Window
* gf1_help (void)
461 helpw
= make_helpwindow ();
463 for (i
= 0; i
< sizeof(helplines
)/sizeof(helplines
[0]); i
++)
465 browser_help
->add (helplines
[i
]);
467 browser_help
->topline (1);
469 for (i
= 0; i
< sizeof(sectionlines
)/sizeof(sectionlines
[0]); i
++)
471 browser_sections
->add (sectionlines
[i
].line
);
473 browser_sections
->topline (1);
478 void showhelpsection (void)
480 int val
= browser_sections
->value ();
483 browser_help
->topline (sectionlines
[val
-1].offset
);
490 void setcurrentfilename (const char * str
)
495 strcpy (currentfilename
, str
);
496 if (currentfilename
[0] == '\0')
498 sprintf (tempstr
, "Gipf for One");
503 if ((pos
= strrchr (currentfilename
, '\\')) != NULL
)
505 if ((pos
= strrchr (currentfilename
, '/')) != NULL
)
509 pos
= currentfilename
;
510 sprintf (tempstr
, "Gipf for One (%s)", pos
);
513 gf1_window
->label (tempstr
);
517 char * getcurrentfilename (void)
519 return (currentfilename
);
522 const char * file_chooser (const char * windowtitle
, const char * pattern
, const char * path
)
524 const char * filename
= NULL
;
526 #ifdef NEWFILECHOOSER
527 FileIcon::load_system_icons();
529 FileChooser
fc(path
, pattern
, FileChooser::CREATE
, windowtitle
);
536 filename
= fc
.value();
538 filename
= fl_file_chooser (windowtitle
, pattern
, path
);