Support for g++-4.1.
[gf1.git] / fl_board.cxx
blob57b3a01a924320f128c7d8eb291592770c6d9a77
1 /*
2 ** $Id$
3 **
4 ** all that is necessary for drawing a gipf-board and the pieces on it
5 */
6 /*
7 ** Copyright (C) 1998 Kurt Van den Branden
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (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 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <string.h>
25 #include <FL/Fl.H>
26 #include <FL/fl_draw.H>
27 #include "fl_board.h"
29 #ifndef min
30 #define min(x,y) (x < y ? x : y)
31 #endif
33 #ifndef max
34 #define max(x,y) (x > y ? x : y)
35 #endif
37 #define round(x) (int)(x + 0.5)
39 void shmpos (void * data);
42 ** all measurements are based on a square of 2 * 2.5
44 // x and y-position of each first point of a column
45 const double rowbase[9][2] = {
46 {.134, 2}, // row a
47 {.3505, 2.125}, // row b
48 {.567, 2.25}, // row c
49 {.7835, 2.375}, // row d
50 {1, 2.5}, // row e
51 {1.2165, 2.375}, // row f
52 {1.433, 2.25}, // row g
53 {1.6495, 2.125}, // row h
54 {1.866, 2} // row i
57 /* lines on the board */
58 const position linetable[21][2] = {
59 {{0, 4}, {5, 8}}, {{0, 3}, {6, 7}}, {{0, 2}, {7, 6}},
60 {{0, 1}, {8, 5}}, {{1, 1}, {8, 4}}, {{2, 1}, {8, 3}},
61 {{3, 1}, {8, 2}}, {{0, 2}, {5, 1}}, {{0, 3}, {6, 1}},
62 {{0, 4}, {7, 1}}, {{0, 5}, {8, 1}}, {{1, 6}, {8, 2}},
63 {{2, 7}, {8, 3}}, {{3, 8}, {8, 4}}, {{1, 6}, {1, 1}},
64 {{2, 7}, {2, 1}}, {{3, 8}, {3, 1}}, {{4, 9}, {4, 1}},
65 {{5, 8}, {5, 1}}, {{6, 7}, {6, 1}}, {{7, 6}, {7, 1}}
68 /* possible from-points */
69 const position fromtable[24] = {
70 {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {1, 6},
71 {2, 7}, {3, 8}, {4, 9}, {5, 8}, {6, 7}, {7, 6},
72 {8, 5}, {8, 4}, {8, 3}, {8, 2}, {8, 1}, {7, 1},
73 {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1},
76 /* possible to-points */
77 const position totable[18] = {
78 {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 6}, {3, 7},
79 {4, 8}, {5, 7}, {6, 6}, {7, 5}, {7, 4}, {7, 3},
80 {7, 2}, {6, 2}, {5, 2}, {4, 2}, {3, 2}, {2, 2}
83 /* white hexagon */
84 const position hexagon[7] = {
85 {1, 2}, {1, 5}, {4, 8}, {7, 5}, {7, 2}, {4, 2}, {1, 2}
89 ** constructor
91 fl_board::fl_board(int X,int Y,int W,int H,const char *l)
92 : Fl_Widget (X, Y, W, H, l)
94 theboard = NULL;
95 from = NULL;
96 to = NULL;
97 row = NULL;
98 fromtype = 0;
99 gipfpossible = 0;
100 state = BOARD_NONE;
101 editpiece = 'o';
102 positionhints = 1;
103 showpos = NULL;
104 showflag = 0;
105 animlist = NULL;
107 wpieces = NULL;
108 wlost = NULL;
109 wpile = NULL;
110 bpieces = NULL;
111 blost = NULL;
112 bpile = NULL;
113 execbutton = NULL;
115 calcsizes ();
117 // I don't know if this is a good solution
118 // lyellow = FL_COLOR_CUBE +
119 // FL_RED_MULTIPLY * 4 +
120 // FL_GREEN_MULTIPLY * 7 +
121 // FL_BLUE_MULTIPLY * 3;
122 lyellow = fl_color_cube(255 * FL_NUM_RED/256,
123 255 * FL_NUM_GREEN/256,
124 200 * FL_NUM_BLUE/256);
125 return;
130 ** destructor
132 fl_board::~fl_board ()
134 b_del (theboard);
136 if (row != NULL)
138 emptyll (row, del_position_f);
139 free (row);
142 if (from != NULL)
143 free (from);
144 if (to != NULL)
145 free (to);
147 return;
152 ** the fl_board class should only handle one event on its own
153 ** when an FL_PUSH occurs, the widget must check in what state it is
154 ** and where a push can have effect in this state
156 int fl_board::handle (int event)
158 ::position * temppos;
160 switch (event)
162 case FL_PUSH:
163 /* check what was pushed */
164 if (theboard == NULL)
165 return (1);
167 if (state == BOARD_PLAY)
169 if (checkfrompush ())
171 return (1);
173 checktopush ();
176 else if (state == BOARD_EDIT)
178 checkeditpush ();
181 // state = BOARD_NONE
182 return (1);
184 case FL_ENTER:
185 case FL_MOVE:
186 if (positionhints == 0)
187 return (0);
189 temppos = getmousepos ();
191 // mouse was moved to an unrecognized position
192 if (temppos == NULL)
194 // stop timer, even if it is not running
195 Fl::remove_timeout (shmpos, (void *) this);
197 if (showpos != NULL)
199 del_position (showpos);
200 showpos = NULL;
201 if (showflag != 0)
203 showflag = 0;
204 redraw ();
207 return (1);
210 // mouse was moved to a known position
211 // previous position was NULL
212 if (showpos == NULL)
214 // start timer
215 Fl::add_timeout (.5, shmpos, (void *) this);
217 showpos = temppos;
218 return (1);
221 // check if mouse was moved to a different position
222 if ((showpos->row == temppos->row) &&
223 (showpos->col == temppos->col))
224 { // do nothing
225 del_position (temppos);
226 return (1);
229 // new known position
231 // stop timer, even if it is not running
232 Fl::remove_timeout (shmpos, (void *) this);
234 del_position (showpos);
235 showpos = NULL;
236 if (showflag != 0)
238 showflag = 0;
239 redraw ();
241 showpos = temppos;
243 // start timer
244 Fl::add_timeout (.5, shmpos, (void *) this);
246 return (1);
247 break;
249 case FL_LEAVE:
250 if (positionhints == 0)
251 return (0);
253 Fl::remove_timeout (shmpos, (void *) this);
255 if (showpos != NULL)
257 del_position (showpos);
258 showpos = NULL;
259 if (showflag != 0)
261 showflag = 0;
262 redraw ();
265 break;
267 default:
268 return (0);
271 return (0);
276 ** check if one of the from-points was pushed
278 int fl_board::checkfrompush ()
280 int pushx,
281 pushy,
283 x, y,
284 box;
286 pushx = Fl::event_x ();
287 pushy = Fl::event_y ();
288 box = base / 15;
290 for (i = 0; i < 24; i++)
292 pos2coor (&(fromtable[i]), x, y);
294 if ((pushx > (x - box)) &&
295 (pushy > (y - box)) &&
296 (pushx < (x + box)) &&
297 (pushy < (y + box)))
299 if ((from == NULL) ||
300 (from->col != fromtable[i].col) ||
301 (from->row != fromtable[i].row))
303 setfrom (& fromtable[i]);
304 redraw ();
306 else if (gipfpossible == 1)
308 fromtype = (fromtype == 1 ? 0 : 1);
309 redraw ();
311 return (1);
315 return (0);
320 ** check if one of the to-points was pushed
322 int fl_board::checktopush ()
324 int pushx,
325 pushy,
327 x, y,
328 box;
330 pushx = Fl::event_x ();
331 pushy = Fl::event_y ();
332 box = base / 15;
334 for (i = 0; i < 18; i++)
336 pos2coor (&(totable[i]), x, y);
338 if ((pushx > (x - box)) &&
339 (pushy > (y - box)) &&
340 (pushx < (x + box)) &&
341 (pushy < (y + box)))
343 setto (& totable[i]);
344 redraw ();
345 return (1);
349 return (0);
354 ** check if any point on the board was pushed
356 int fl_board::checkeditpush ()
358 int pushx,
359 pushy,
360 i, j,
361 x, y,
362 box;
363 ::position * temppos;
364 board * nboard;
366 pushx = Fl::event_x ();
367 pushy = Fl::event_y ();
368 box = base / 15;
370 temppos = new_position ();
371 /* check all board positions */
372 for (i = 1; i < 8; i++)
374 temppos->col = i;
375 for (j = 2; j <= b_colsize (i); j++)
377 temppos->row = j;
379 pos2coor (temppos, x, y);
380 if ((pushx > (x - box)) &&
381 (pushy > (y - box)) &&
382 (pushx < (x + box)) &&
383 (pushy < (y + box)))
385 if (b_ppiece (theboard, temppos) != '.')
387 if ((nboard = b_edit_piece (theboard, temppos, '.'))
388 != NULL)
390 b_del (theboard);
391 theboard = nboard;
394 else
396 if ((nboard = b_edit_piece (theboard, temppos, editpiece))
397 != NULL)
399 b_del (theboard);
400 theboard = nboard;
404 changecountervalues ();
405 redraw ();
406 return (1);
410 free (temppos);
412 return (0);
416 position * fl_board::getmousepos ()
418 int pushx,
419 pushy,
420 i, j,
421 x, y,
422 box;
423 ::position * temppos;
424 int colsize[] = {5, 6, 7, 8, 9, 8, 7, 6, 5};
426 pushx = Fl::event_x ();
427 pushy = Fl::event_y ();
428 box = base / 10;
430 temppos = new_position ();
431 /* draw pieces */
432 for (i = 0; i < 9; i++)
434 temppos->col = i;
435 for (j = 1; j <= colsize [i]; j++)
437 temppos->row = j;
439 pos2coor (temppos, x, y);
440 if ((pushx > (x - box)) &&
441 (pushy > (y - box)) &&
442 (pushx < (x + box)) &&
443 (pushy < (y + box)))
445 return (temppos);
449 free (temppos);
451 return (NULL);
455 void fl_board::draw ()
457 int i, j, nr,
458 x1, y1,
459 x2, y2,
460 width, height,
461 diam, straal;
462 char tempstr[10],
463 piece,
464 * posstr;
465 ::position * temppos;
466 uchar dam;
468 dam = damage();
469 if (!(dam & FL_DAMAGE_ALL) &&
470 (dam & FL_DAMAGE_ANIM))
471 { /* draw for move-animation */
472 /* maybe things can be speeded up by using clipping */
473 /* calculate clipping-region */
474 calc_clipping ();
476 else
478 clip_x = x();
479 clip_y = y();
480 clip_w = w();
481 clip_h = h();
483 fl_clip (clip_x, clip_y, clip_w, clip_h);
485 /* set everything to background color */
486 // fl_color (Fl_Widget::color());
487 fl_color (FL_GRAY);
488 fl_rectf (clip_x, clip_y, clip_w, clip_h);
490 draw_box ();
492 fl_color (FL_WHITE); // white
494 // hexagon
495 fl_begin_polygon ();
496 for (i = 0; i < 7; i++)
498 pos2coor (&(hexagon[i]), x1, y1);
499 #ifdef MSWIN
500 /* didn't look nice on mswin */
501 if ((i > 0) && (i < 4))
502 y1 += 1;
503 else
504 y1 -= 1;
505 #endif
506 fl_vertex (x1, y1);
508 fl_end_polygon ();
510 fl_color (FL_BLACK); // black
512 // lines
513 for (i = 0; i < 21; i++)
515 pos2coor (&(linetable[i][0]), x1, y1);
516 pos2coor (&(linetable[i][1]), x2, y2);
518 /* I have to add 1 to the third parameter, or
519 ** vertical lines don't get drawn on ms windows */
520 if (fl_not_clipped (min (x1, x2), min (y1, y2),
521 max (x1, x2) - min (x1, x2) + 1,
522 max (y1, y2) - min (y1, y2)))
523 fl_line (x1, y1, x2, y2);
526 // from-positions
527 straal = base / 24;
528 diam = straal * 2;
529 for (i = 0; i < 24; i++)
531 pos2coor (&(fromtable[i]), x1, y1);
532 if (fl_not_clipped (x1 - straal, y1 - straal,
533 x1 + straal, y1 + straal))
535 fl_begin_polygon ();
536 fl_circle (x1, y1, straal);
537 fl_end_polygon ();
539 #if 0
540 fl_pie (x1 - straal, y1 - straal, diam, diam, 0, 360);
541 #endif
544 /* position names */
545 fl_font (FL_HELVETICA, base/12);
547 height = fl_height () / 2 - fl_descent ();
548 for (i = 0; i < 9; i++)
550 sprintf (tempstr, "%c1", i+'a');
551 width = round (fl_width (tempstr) / 2);
552 x1 = xoffset + round (rowbase[i][0] * base);
553 y1 = yoffset + round ((rowbase[i][1] - .5 * .25) * base);
554 fl_draw (tempstr, x1 - width, y1 + height);
556 nr = (i < 5 ? i + 5 : 13 - i);
557 sprintf (tempstr, "%c%d", i+'a', nr);
558 width = round (fl_width (tempstr) / 2);
559 y1 = yoffset + round ((rowbase[i][1] - (nr + .5) * .25) * base);
560 fl_draw (tempstr, x1 - width, y1 + height);
563 /* draw pieces if there is a board */
564 if (theboard != NULL)
566 temppos = new_position ();
567 /* draw pieces */
568 for (i = 1; i < 8; i++)
570 temppos->col = i;
571 for (j = 2; j <= b_colsize (i); j++)
573 temppos->row = j;
574 if (b_ppiece (theboard, temppos) != '.')
576 drawpiece (temppos, b_ppiece (theboard, temppos));
580 free (temppos);
582 /* draw from and to (if necessary) */
583 if (state == BOARD_PLAY)
585 if (from != NULL)
587 piece = b_next_piece (theboard);
588 if (fromtype == 1)
590 piece = b_otherpiece (piece);
592 drawpiece (from, piece);
595 if (to != NULL)
597 drawcross (to->col, to->row);
601 /* draw crosses on row of pieces, if necessary */
602 if (row != NULL)
604 int counter = 1;
605 ::position * posp;
606 while ((posp = (::position *) llitembynr (row, counter)) != NULL)
608 drawcross (posp->col, posp->row);
609 counter++;
613 if (animlist != NULL)
615 drawanimpieces ();
619 // draw position-box
620 if ((positionhints != 0) && (showpos != NULL) && (showflag == 1))
622 posstr = postostr (showpos);
624 pos2coor (showpos, x1, y1);
625 width = 8 + (int) fl_width (posstr);
626 height = 4 + fl_height ();
627 y1 -= height + 2;
628 x1 -= 2;
630 if (fl_not_clipped (x1, y1, width + 2, height + 2))
632 fl_color (FL_DARK2); // 125,125,125
633 fl_rectf (x1 + 2, y1 + 2, width, height);
634 fl_color (lyellow); // 255,255,200
635 fl_rectf (x1, y1, width, height);
636 fl_color (FL_BLACK);
637 fl_rect (x1, y1, width, height);
638 fl_draw (posstr, x1 + 4, y1 + height - fl_descent () - 2);
641 free (posstr);
644 fl_pop_clip ();
646 return;
650 void fl_board::drawpiece (::position * pos, char piece)
652 int counter,
653 x, y;
654 struct movepiece {
655 char piece;
656 ::position * from;
657 ::position * to;
658 } * mpiece;
660 /* don't draw piece if in animation-list */
661 counter = 2;
662 while ((mpiece = (struct movepiece *) llitembynr (animlist, counter))
663 != NULL)
665 counter++;
666 if ((posp_col (pos) == posp_col (mpiece->from)) &&
667 (posp_row (pos) == posp_row (mpiece->from)))
668 return;
671 /* calculate position of center of the piece */
672 pos2coor (pos, x, y);
674 drawpiece (x, y, piece);
676 return;
679 void fl_board::drawpiece (int x, int y, char piece)
681 int straal, diam,
682 straal2, diam2,
683 straal3,
684 counter;
686 /* calculate size of piece */
687 straal = base / 12;
688 diam = straal * 2;
689 straal2 = base / 18;
690 diam2 = straal2 * 2;
691 straal3 = base / 22;
692 if (straal3 > (straal2 - 2))
693 straal3 = straal2 - 2;
695 if (!fl_not_clipped (x - straal, y - straal, diam, diam))
696 return;
698 if ((piece == 'o') ||
699 (piece == 'O'))
701 fl_color (lyellow);
703 else
705 fl_color (FL_BLACK);
708 fl_begin_polygon ();
709 fl_circle (x, y, straal);
710 fl_end_polygon ();
712 fl_color (FL_BLACK);
713 fl_begin_loop ();
714 fl_circle (x, y, straal);
715 fl_end_loop ();
717 if ((piece == 'O') ||
718 (piece == 'X'))
720 fl_color (FL_DARK1);
721 // fl_begin_complex_polygon ();
722 // fl_arc (x, y, straal2, 0, 360);
723 // fl_gap ();
724 // fl_arc (x, y, straal3, 0, 360);
725 // fl_end_complex_polygon ();
726 fl_begin_polygon ();
727 fl_circle (x, y, straal2);
728 fl_end_polygon ();
730 if (piece == 'O')
731 fl_color (lyellow);
732 else
733 fl_color (FL_BLACK);
734 fl_begin_polygon ();
735 fl_circle (x, y, straal3);
736 fl_end_polygon ();
739 #if 0
740 #ifdef MSWIN
741 fl_pie (x - straal + 1, y - straal + 1, diam - 2, diam - 2, 0, 360);
742 #else
743 fl_pie (x - straal, y - straal, diam - 1, diam - 1, 0, 360);
744 #endif
746 fl_color (FL_BLACK);
747 fl_arc (x - straal, y - straal, diam, diam, 0, 360);
749 if ((piece == 'O') ||
750 (piece == 'X'))
752 fl_color (FL_DARK1);
753 fl_arc (x - straal2, y - straal2, diam2, diam2, 0, 360);
754 fl_arc (x - straal2 + 1, y - straal2 + 1, diam2-2, diam2-2, 0, 360);
756 #endif
758 return;
762 void fl_board::drawanimpieces (void)
764 int counter;
765 struct movepiece {
766 char piece;
767 ::position * from;
768 ::position * to;
769 } * mpiece;
770 int x, y, x1, y1, x2, y2;
772 counter = 1;
773 while ((mpiece = (struct movepiece *) llitembynr (animlist, counter))
774 != NULL)
776 counter++;
778 /* calculate position of center of the piece */
779 pos2coor (mpiece->from, x1, y1);
780 pos2coor (mpiece->to, x2, y2);
781 x = x1 + (x2 - x1) * step / maxstep;
782 y = y1 + (y2 - y1) * step / maxstep;
784 drawpiece (x, y, mpiece->piece);
787 if (step == maxstep)
789 while ((mpiece = (struct movepiece *) llrembynr (animlist, 1)) != NULL)
791 free (mpiece->from);
792 free (mpiece->to);
793 free (mpiece);
795 free (animlist);
797 animlist = NULL;
799 return;
803 void fl_board::drawcross (int col, int row)
805 ::position temppos;
806 int x, y,
807 straal;
809 /* calculate position of center of the piece */
810 temppos.col = col;
811 temppos.row = row;
812 pos2coor (&temppos, x, y);
814 straal = base / 16;
816 if (!fl_not_clipped (x - straal, y - straal, straal * 2, straal * 2))
817 return;
819 fl_color (FL_RED);
822 ** I draw a lot of lines here to get the impression of a
823 ** thick cross
825 fl_line (x - straal, y - straal, x + straal, y + straal);
826 fl_line (x - straal + 1, y - straal, x + straal, y + straal - 1);
827 fl_line (x - straal, y - straal + 1, x + straal - 1, y + straal);
829 fl_line (x + straal, y - straal, x - straal, y + straal);
830 fl_line (x + straal - 1, y - straal, x - straal, y + straal - 1);
831 fl_line (x + straal, y - straal + 1, x - straal + 1, y + straal);
833 return;
837 void fl_board::resize (int x, int y, int w, int h)
839 Fl_Widget::resize (x, y, w, h);
841 calcsizes ();
843 if (showpos != NULL)
845 del_position (showpos);
846 showpos = NULL;
847 showflag = 0;
850 return;
855 ** calculate
856 ** xoffset
857 ** yoffset
858 ** base
860 ** to be used at every resize-event and at class-creation
862 void fl_board::calcsizes ()
864 int height,
865 width;
867 width = round (w() / 2.0);
868 height = round (h() / 2.5);
869 base = min (width, height);
871 xoffset = round((w() - base * 2.0) / 2) + x();
872 yoffset = round((h() - base * 2.5) / 2) + y();
874 return;
879 ** calculate screen-coordinates starting from a board-position
881 // solution: Fl_Input_ has a 'position' member function
882 inline void fl_board::pos2coor (const ::position *pos, int& x, int& y)
884 x = xoffset + round (rowbase[pos->col][0] * base);
885 y = yoffset + round ((rowbase[pos->col][1] - pos->row * .25) * base);
887 return;
891 void fl_board::setoutputwidgets (Fl_Output * wp, Fl_Output * wl,
892 fl_pile * wpi, Fl_Output * bp,
893 Fl_Output * bl, fl_pile * bpi,
894 Fl_Output * from_o, Fl_Output * to_o)
896 wpieces = wp;
897 wlost = wl;
898 wpile = wpi;
899 wpile->setcolor ('o');
901 bpieces = bp;
902 blost = bl;
903 bpile = bpi;
904 bpile->setcolor ('x');
906 t_from = from_o;
907 t_to = to_o;
909 changecountervalues ();
910 changefromtovalues ();
912 return;
915 void fl_board::changefromtovalues ()
917 char * tempstr;
919 if (from != NULL)
921 tempstr = postostr (from);
922 t_from->value (tempstr);
923 free (tempstr);
925 else
927 t_from->value (NULL);
930 if (to != NULL)
932 tempstr = postostr (to);
933 t_to->value (tempstr);
934 free (tempstr);
936 else
938 t_to->value (NULL);
941 redraw ();
943 return;
947 void fl_board::changecountervalues ()
949 char tempstr[20];
951 if (wpieces != NULL)
953 if (theboard != NULL)
955 sprintf (tempstr, "%d", b_white (theboard));
956 wpieces->value (tempstr);
957 sprintf (tempstr, "lost: %d", b_white_lost (theboard));
958 wlost->value (tempstr);
959 wpile->setvalue (b_white (theboard));
961 sprintf (tempstr, "%d", b_black (theboard));
962 bpieces->value (tempstr);
963 sprintf (tempstr, "lost: %d", b_black_lost (theboard));
964 blost->value (tempstr);
965 bpile->setvalue (b_black (theboard));
967 else
969 wpieces->value (NULL);
970 wlost->value (NULL);
971 wpile->setvalue (-1);
972 bpieces->value (NULL);
973 blost->value (NULL);
974 bpile->setvalue (-1);
978 return;
982 void fl_board::setboard (board * newboard)
984 if (b_compare (newboard, theboard) == 0)
985 { /* the new is the same as the old */
986 return;
989 if (theboard != NULL)
991 b_del (theboard);
993 theboard = b_copy (newboard);
995 changecountervalues ();
996 redraw ();
998 return;
1002 void fl_board::setfrom (const ::position * newfrom)
1004 if (from != NULL)
1006 free (from);
1008 from = (::position *) copy_position ((void *) newfrom);
1010 changefromtovalues ();
1012 return;
1016 void fl_board::setto (const ::position * newto)
1018 if ((newto != NULL) && (from != NULL) && (to != NULL) &&
1019 (execbutton != NULL) &&
1020 (posp_col (to) == posp_col (newto)) &&
1021 (posp_row (to) == posp_row (newto)))
1023 execbutton->do_callback ();
1024 return;
1026 if (to != NULL)
1028 free (to);
1030 to = (::position *) copy_position ((void *) newto);
1032 changefromtovalues ();
1034 return;
1038 void fl_board::seteditpiece (char newpiece)
1040 editpiece = newpiece;
1044 int fl_board::setlostwhite (int val)
1046 board * nboard;
1048 if (theboard == NULL)
1049 return (0);
1051 if ((nboard = b_edit_lostwhite (theboard, val)) != NULL)
1053 b_del (theboard);
1054 theboard = nboard;
1056 changecountervalues ();
1058 return (b_white_lost (theboard));
1062 int fl_board::setlostblack (int val)
1064 board * nboard;
1066 if (theboard == NULL)
1067 return (0);
1069 if ((nboard = b_edit_lostblack (theboard, val)) != NULL)
1071 b_del (theboard);
1072 theboard = nboard;
1074 changecountervalues ();
1076 return (b_black_lost (theboard));
1080 void fl_board::setstate (int newstate)
1082 state = newstate;
1084 if (state != BOARD_PLAY)
1086 setfrom (NULL);
1087 setto (NULL);
1092 void fl_board::showmousepos ()
1094 if (showpos != NULL)
1096 showflag = 1;
1097 redraw ();
1100 return;
1104 void shmpos (void * data)
1106 fl_board * boardobject = (fl_board *) data;
1108 boardobject->showmousepos ();
1110 return;
1114 void fl_board::setgipfpossible (int flag)
1116 if (flag == 1)
1118 gipfpossible = 1;
1119 fromtype = 1;
1121 else
1123 gipfpossible = 0;
1124 fromtype = 0;
1126 return;
1129 void fl_board::setrow (listheader * rowp)
1131 if (row != NULL)
1133 emptyll (row, del_position_f);
1134 free (row);
1136 if (rowp != NULL)
1137 row = copy_position_row (rowp);
1138 else
1139 row = NULL;
1141 redraw ();
1142 return;
1146 void fl_board::initanim (int st, listheader * al)
1148 int counter;
1149 struct movepiece {
1150 char piece;
1151 ::position * from;
1152 ::position * to;
1153 } * mpiece, * npiece;
1154 listheader * newl;
1156 maxstep = st;
1158 newl = (listheader *) malloc (sizeof (listheader));
1159 newlist (newl);
1161 counter = 1;
1162 while ((mpiece = (struct movepiece *) llitembynr (al, counter))
1163 != NULL)
1165 counter++;
1167 npiece = (struct movepiece *) malloc (sizeof (struct movepiece));
1168 npiece->piece = mpiece->piece;
1169 npiece->from = (::position *) copy_position ((void *) mpiece->from);
1170 npiece->to = (::position *) copy_position ((void *) mpiece->to);
1172 pushll (newl, npiece);
1175 if (animlist != NULL)
1177 while ((mpiece = (struct movepiece *) llrembynr (animlist, 1)) != NULL)
1179 free (mpiece->from);
1180 free (mpiece->to);
1181 free (mpiece);
1183 free (animlist);
1186 animlist = newl;
1188 return;
1192 void fl_board::calc_clipping ()
1194 int counter;
1195 struct movepiece {
1196 char piece;
1197 ::position * from;
1198 ::position * to;
1199 } * mpiece;
1200 int x1, y1,
1201 x2, y2,
1202 straal;
1204 mpiece = (struct movepiece *) llitembynr (animlist, 1);
1205 pos2coor (mpiece->from, x1, y1);
1206 counter = 1;
1207 while ((mpiece = (struct movepiece *) llitembynr (animlist, counter))
1208 != NULL)
1210 counter++;
1211 pos2coor (mpiece->to, x2, y2);
1213 straal = base / 12;
1215 /* the -2 and +2 are used for a little security */
1216 clip_x = min (x1, x2) - straal - 2;
1217 clip_y = min (y1, y2) - straal - 2;
1218 clip_w = max (x1, x2) - clip_x + straal + 2;
1219 clip_h = max (y1, y2) - clip_y + straal + 2;
1221 return;