(Temporarily) set "animate" to "none" by default (broken feature).
[gf1.git] / fl_board.cxx
blobcaf76ade7b1224485743b7ce7dccfdb0af601c33
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 #define round(x) (int)(x + 0.5)
31 void shmpos (void * data);
34 ** all measurements are based on a square of 2 * 2.5
36 // x and y-position of each first point of a column
37 const double rowbase[9][2] = {
38 {.134, 2}, // row a
39 {.3505, 2.125}, // row b
40 {.567, 2.25}, // row c
41 {.7835, 2.375}, // row d
42 {1, 2.5}, // row e
43 {1.2165, 2.375}, // row f
44 {1.433, 2.25}, // row g
45 {1.6495, 2.125}, // row h
46 {1.866, 2} // row i
49 /* lines on the board */
50 const position linetable[21][2] = {
51 {{0, 4}, {5, 8}}, {{0, 3}, {6, 7}}, {{0, 2}, {7, 6}},
52 {{0, 1}, {8, 5}}, {{1, 1}, {8, 4}}, {{2, 1}, {8, 3}},
53 {{3, 1}, {8, 2}}, {{0, 2}, {5, 1}}, {{0, 3}, {6, 1}},
54 {{0, 4}, {7, 1}}, {{0, 5}, {8, 1}}, {{1, 6}, {8, 2}},
55 {{2, 7}, {8, 3}}, {{3, 8}, {8, 4}}, {{1, 6}, {1, 1}},
56 {{2, 7}, {2, 1}}, {{3, 8}, {3, 1}}, {{4, 9}, {4, 1}},
57 {{5, 8}, {5, 1}}, {{6, 7}, {6, 1}}, {{7, 6}, {7, 1}}
60 /* possible from-points */
61 const position fromtable[24] = {
62 {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {1, 6},
63 {2, 7}, {3, 8}, {4, 9}, {5, 8}, {6, 7}, {7, 6},
64 {8, 5}, {8, 4}, {8, 3}, {8, 2}, {8, 1}, {7, 1},
65 {6, 1}, {5, 1}, {4, 1}, {3, 1}, {2, 1}, {1, 1},
68 /* possible to-points */
69 const position totable[18] = {
70 {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 6}, {3, 7},
71 {4, 8}, {5, 7}, {6, 6}, {7, 5}, {7, 4}, {7, 3},
72 {7, 2}, {6, 2}, {5, 2}, {4, 2}, {3, 2}, {2, 2}
75 /* white hexagon */
76 const position hexagon[7] = {
77 {1, 2}, {1, 5}, {4, 8}, {7, 5}, {7, 2}, {4, 2}, {1, 2}
81 ** constructor
83 fl_board::fl_board(int X,int Y,int W,int H,const char *l)
84 : Fl_Widget (X, Y, W, H, l)
86 theboard = NULL;
87 from = NULL;
88 to = NULL;
89 row = NULL;
90 fromtype = 0;
91 gipfpossible = 0;
92 state = BOARD_NONE;
93 editpiece = 'o';
94 positionhints = 1;
95 showpos = NULL;
96 showflag = 0;
97 animlist = NULL;
99 wpieces = NULL;
100 wlost = NULL;
101 wpile = NULL;
102 bpieces = NULL;
103 blost = NULL;
104 bpile = NULL;
105 execbutton = NULL;
107 calcsizes ();
109 // I don't know if this is a good solution
110 // lyellow = FL_COLOR_CUBE +
111 // FL_RED_MULTIPLY * 4 +
112 // FL_GREEN_MULTIPLY * 7 +
113 // FL_BLUE_MULTIPLY * 3;
114 lyellow = fl_color_cube(255 * FL_NUM_RED/256,
115 255 * FL_NUM_GREEN/256,
116 200 * FL_NUM_BLUE/256);
117 return;
122 ** destructor
124 fl_board::~fl_board ()
126 b_del (theboard);
128 if (row != NULL)
130 emptyll (row, del_position_f);
131 free (row);
134 if (from != NULL)
135 free (from);
136 if (to != NULL)
137 free (to);
139 return;
144 ** the fl_board class should only handle one event on its own
145 ** when an FL_PUSH occurs, the widget must check in what state it is
146 ** and where a push can have effect in this state
148 int fl_board::handle (int event)
150 ::position * temppos;
152 switch (event)
154 case FL_PUSH:
155 /* check what was pushed */
156 if (theboard == NULL)
157 return (1);
159 if (state == BOARD_PLAY)
161 if (checkfrompush ())
163 return (1);
165 checktopush ();
168 else if (state == BOARD_EDIT)
170 checkeditpush ();
173 // state = BOARD_NONE
174 return (1);
176 case FL_ENTER:
177 case FL_MOVE:
178 if (positionhints == 0)
179 return (0);
181 temppos = getmousepos ();
183 // mouse was moved to an unrecognized position
184 if (temppos == NULL)
186 // stop timer, even if it is not running
187 Fl::remove_timeout (shmpos, (void *) this);
189 if (showpos != NULL)
191 del_position (showpos);
192 showpos = NULL;
193 if (showflag != 0)
195 showflag = 0;
196 redraw ();
199 return (1);
202 // mouse was moved to a known position
203 // previous position was NULL
204 if (showpos == NULL)
206 // start timer
207 Fl::add_timeout (.5, shmpos, (void *) this);
209 showpos = temppos;
210 return (1);
213 // check if mouse was moved to a different position
214 if ((showpos->row == temppos->row) &&
215 (showpos->col == temppos->col))
216 { // do nothing
217 del_position (temppos);
218 return (1);
221 // new known position
223 // stop timer, even if it is not running
224 Fl::remove_timeout (shmpos, (void *) this);
226 del_position (showpos);
227 showpos = NULL;
228 if (showflag != 0)
230 showflag = 0;
231 redraw ();
233 showpos = temppos;
235 // start timer
236 Fl::add_timeout (.5, shmpos, (void *) this);
238 return (1);
239 break;
241 case FL_LEAVE:
242 if (positionhints == 0)
243 return (0);
245 Fl::remove_timeout (shmpos, (void *) this);
247 if (showpos != NULL)
249 del_position (showpos);
250 showpos = NULL;
251 if (showflag != 0)
253 showflag = 0;
254 redraw ();
257 break;
259 default:
260 return (0);
263 return (0);
268 ** check if one of the from-points was pushed
270 int fl_board::checkfrompush ()
272 int pushx,
273 pushy,
275 x, y,
276 box;
278 pushx = Fl::event_x ();
279 pushy = Fl::event_y ();
280 box = base / 15;
282 for (i = 0; i < 24; i++)
284 pos2coor (&(fromtable[i]), x, y);
286 if ((pushx > (x - box)) &&
287 (pushy > (y - box)) &&
288 (pushx < (x + box)) &&
289 (pushy < (y + box)))
291 if ((from == NULL) ||
292 (from->col != fromtable[i].col) ||
293 (from->row != fromtable[i].row))
295 setfrom (& fromtable[i]);
296 redraw ();
298 else if (gipfpossible == 1)
300 fromtype = (fromtype == 1 ? 0 : 1);
301 redraw ();
303 return (1);
307 return (0);
312 ** check if one of the to-points was pushed
314 int fl_board::checktopush ()
316 int pushx,
317 pushy,
319 x, y,
320 box;
322 pushx = Fl::event_x ();
323 pushy = Fl::event_y ();
324 box = base / 15;
326 for (i = 0; i < 18; i++)
328 pos2coor (&(totable[i]), x, y);
330 if ((pushx > (x - box)) &&
331 (pushy > (y - box)) &&
332 (pushx < (x + box)) &&
333 (pushy < (y + box)))
335 setto (& totable[i]);
336 redraw ();
337 return (1);
341 return (0);
346 ** check if any point on the board was pushed
348 int fl_board::checkeditpush ()
350 int pushx,
351 pushy,
352 i, j,
353 x, y,
354 box;
355 ::position * temppos;
356 board * nboard;
358 pushx = Fl::event_x ();
359 pushy = Fl::event_y ();
360 box = base / 15;
362 temppos = new_position ();
363 /* check all board positions */
364 for (i = 1; i < 8; i++)
366 temppos->col = i;
367 for (j = 2; j <= b_colsize (i); j++)
369 temppos->row = j;
371 pos2coor (temppos, x, y);
372 if ((pushx > (x - box)) &&
373 (pushy > (y - box)) &&
374 (pushx < (x + box)) &&
375 (pushy < (y + box)))
377 if (b_ppiece (theboard, temppos) != '.')
379 if ((nboard = b_edit_piece (theboard, temppos, '.'))
380 != NULL)
382 b_del (theboard);
383 theboard = nboard;
386 else
388 if ((nboard = b_edit_piece (theboard, temppos, editpiece))
389 != NULL)
391 b_del (theboard);
392 theboard = nboard;
396 changecountervalues ();
397 redraw ();
398 return (1);
402 free (temppos);
404 return (0);
408 position * fl_board::getmousepos ()
410 int pushx,
411 pushy,
412 i, j,
413 x, y,
414 box;
415 ::position * temppos;
416 int colsize[] = {5, 6, 7, 8, 9, 8, 7, 6, 5};
418 pushx = Fl::event_x ();
419 pushy = Fl::event_y ();
420 box = base / 10;
422 temppos = new_position ();
423 /* draw pieces */
424 for (i = 0; i < 9; i++)
426 temppos->col = i;
427 for (j = 1; j <= colsize [i]; j++)
429 temppos->row = j;
431 pos2coor (temppos, x, y);
432 if ((pushx > (x - box)) &&
433 (pushy > (y - box)) &&
434 (pushx < (x + box)) &&
435 (pushy < (y + box)))
437 return (temppos);
441 free (temppos);
443 return (NULL);
447 void fl_board::draw ()
449 int i, j, nr,
450 x1, y1,
451 x2, y2,
452 width, height,
453 diam, straal;
454 char tempstr[10],
455 piece,
456 * posstr;
457 ::position * temppos;
458 uchar dam;
460 dam = damage();
461 if (!(dam & FL_DAMAGE_ALL) &&
462 (dam & FL_DAMAGE_ANIM))
463 { /* draw for move-animation */
464 /* maybe things can be speeded up by using clipping */
465 /* calculate clipping-region */
466 calc_clipping ();
468 else
470 clip_x = x();
471 clip_y = y();
472 clip_w = w();
473 clip_h = h();
475 fl_clip (clip_x, clip_y, clip_w, clip_h);
477 /* set everything to background color */
478 // fl_color (Fl_Widget::color());
479 fl_color (FL_GRAY);
480 fl_rectf (clip_x, clip_y, clip_w, clip_h);
482 draw_box ();
484 fl_color (FL_WHITE); // white
486 // hexagon
487 fl_begin_polygon ();
488 for (i = 0; i < 7; i++)
490 pos2coor (&(hexagon[i]), x1, y1);
491 #ifdef MSWIN
492 /* didn't look nice on mswin */
493 if ((i > 0) && (i < 4))
494 y1 += 1;
495 else
496 y1 -= 1;
497 #endif
498 fl_vertex (x1, y1);
500 fl_end_polygon ();
502 fl_color (FL_BLACK); // black
504 // lines
505 for (i = 0; i < 21; i++)
507 pos2coor (&(linetable[i][0]), x1, y1);
508 pos2coor (&(linetable[i][1]), x2, y2);
510 /* I have to add 1 to the third parameter, or
511 ** vertical lines don't get drawn on ms windows */
512 if (fl_not_clipped (min (x1, x2), min (y1, y2),
513 max (x1, x2) - min (x1, x2) + 1,
514 max (y1, y2) - min (y1, y2)))
515 fl_line (x1, y1, x2, y2);
518 // from-positions
519 straal = base / 24;
520 diam = straal * 2;
521 for (i = 0; i < 24; i++)
523 pos2coor (&(fromtable[i]), x1, y1);
524 if (fl_not_clipped (x1 - straal, y1 - straal,
525 x1 + straal, y1 + straal))
527 fl_begin_polygon ();
528 fl_circle (x1, y1, straal);
529 fl_end_polygon ();
531 #if 0
532 fl_pie (x1 - straal, y1 - straal, diam, diam, 0, 360);
533 #endif
536 /* position names */
537 fl_font (FL_HELVETICA, base/12);
539 height = fl_height () / 2 - fl_descent ();
540 for (i = 0; i < 9; i++)
542 sprintf (tempstr, "%c1", i+'a');
543 width = round (fl_width (tempstr) / 2);
544 x1 = xoffset + round (rowbase[i][0] * base);
545 y1 = yoffset + round ((rowbase[i][1] - .5 * .25) * base);
546 fl_draw (tempstr, x1 - width, y1 + height);
548 nr = (i < 5 ? i + 5 : 13 - i);
549 sprintf (tempstr, "%c%d", i+'a', nr);
550 width = round (fl_width (tempstr) / 2);
551 y1 = yoffset + round ((rowbase[i][1] - (nr + .5) * .25) * base);
552 fl_draw (tempstr, x1 - width, y1 + height);
555 /* draw pieces if there is a board */
556 if (theboard != NULL)
558 temppos = new_position ();
559 /* draw pieces */
560 for (i = 1; i < 8; i++)
562 temppos->col = i;
563 for (j = 2; j <= b_colsize (i); j++)
565 temppos->row = j;
566 if (b_ppiece (theboard, temppos) != '.')
568 drawpiece (temppos, b_ppiece (theboard, temppos));
572 free (temppos);
574 /* draw from and to (if necessary) */
575 if (state == BOARD_PLAY)
577 if (from != NULL)
579 piece = b_next_piece (theboard);
580 if (fromtype == 1)
582 piece = b_otherpiece (piece);
584 drawpiece (from, piece);
587 if (to != NULL)
589 drawcross (to->col, to->row);
593 /* draw crosses on row of pieces, if necessary */
594 if (row != NULL)
596 int counter = 1;
597 ::position * posp;
598 while ((posp = (::position *) llitembynr (row, counter)) != NULL)
600 drawcross (posp->col, posp->row);
601 counter++;
605 if (animlist != NULL)
607 drawanimpieces ();
611 // draw position-box
612 if ((positionhints != 0) && (showpos != NULL) && (showflag == 1))
614 posstr = postostr (showpos);
616 pos2coor (showpos, x1, y1);
617 width = 8 + (int) fl_width (posstr);
618 height = 4 + fl_height ();
619 y1 -= height + 2;
620 x1 -= 2;
622 if (fl_not_clipped (x1, y1, width + 2, height + 2))
624 fl_color (FL_DARK2); // 125,125,125
625 fl_rectf (x1 + 2, y1 + 2, width, height);
626 fl_color (lyellow); // 255,255,200
627 fl_rectf (x1, y1, width, height);
628 fl_color (FL_BLACK);
629 fl_rect (x1, y1, width, height);
630 fl_draw (posstr, x1 + 4, y1 + height - fl_descent () - 2);
633 free (posstr);
636 fl_pop_clip ();
638 return;
642 void fl_board::drawpiece (::position * pos, char piece)
644 int counter,
645 x, y;
646 struct movepiece {
647 char piece;
648 ::position * from;
649 ::position * to;
650 } * mpiece;
652 /* don't draw piece if in animation-list */
653 counter = 2;
654 while ((mpiece = (struct movepiece *) llitembynr (animlist, counter))
655 != NULL)
657 counter++;
658 if ((posp_col (pos) == posp_col (mpiece->from)) &&
659 (posp_row (pos) == posp_row (mpiece->from)))
660 return;
663 /* calculate position of center of the piece */
664 pos2coor (pos, x, y);
666 drawpiece (x, y, piece);
668 return;
671 void fl_board::drawpiece (int x, int y, char piece)
673 int straal, diam,
674 straal2, diam2,
675 straal3;
677 /* calculate size of piece */
678 straal = base / 12;
679 diam = straal * 2;
680 straal2 = base / 18;
681 diam2 = straal2 * 2;
682 straal3 = base / 22;
683 if (straal3 > (straal2 - 2))
684 straal3 = straal2 - 2;
686 if (!fl_not_clipped (x - straal, y - straal, diam, diam))
687 return;
689 if ((piece == 'o') ||
690 (piece == 'O'))
692 fl_color (lyellow);
694 else
696 fl_color (FL_BLACK);
699 fl_begin_polygon ();
700 fl_circle (x, y, straal);
701 fl_end_polygon ();
703 fl_color (FL_BLACK);
704 fl_begin_loop ();
705 fl_circle (x, y, straal);
706 fl_end_loop ();
708 if ((piece == 'O') ||
709 (piece == 'X'))
711 fl_color (FL_DARK1);
712 // fl_begin_complex_polygon ();
713 // fl_arc (x, y, straal2, 0, 360);
714 // fl_gap ();
715 // fl_arc (x, y, straal3, 0, 360);
716 // fl_end_complex_polygon ();
717 fl_begin_polygon ();
718 fl_circle (x, y, straal2);
719 fl_end_polygon ();
721 if (piece == 'O')
722 fl_color (lyellow);
723 else
724 fl_color (FL_BLACK);
725 fl_begin_polygon ();
726 fl_circle (x, y, straal3);
727 fl_end_polygon ();
730 #if 0
731 #ifdef MSWIN
732 fl_pie (x - straal + 1, y - straal + 1, diam - 2, diam - 2, 0, 360);
733 #else
734 fl_pie (x - straal, y - straal, diam - 1, diam - 1, 0, 360);
735 #endif
737 fl_color (FL_BLACK);
738 fl_arc (x - straal, y - straal, diam, diam, 0, 360);
740 if ((piece == 'O') ||
741 (piece == 'X'))
743 fl_color (FL_DARK1);
744 fl_arc (x - straal2, y - straal2, diam2, diam2, 0, 360);
745 fl_arc (x - straal2 + 1, y - straal2 + 1, diam2-2, diam2-2, 0, 360);
747 #endif
749 return;
753 void fl_board::drawanimpieces (void)
755 int counter;
756 struct movepiece {
757 char piece;
758 ::position * from;
759 ::position * to;
760 } * mpiece;
761 int x, y, x1, y1, x2, y2;
763 counter = 1;
764 while ((mpiece = (struct movepiece *) llitembynr (animlist, counter))
765 != NULL)
767 counter++;
769 /* calculate position of center of the piece */
770 pos2coor (mpiece->from, x1, y1);
771 pos2coor (mpiece->to, x2, y2);
772 x = x1 + (x2 - x1) * step / maxstep;
773 y = y1 + (y2 - y1) * step / maxstep;
775 drawpiece (x, y, mpiece->piece);
778 if (step == maxstep)
780 while ((mpiece = (struct movepiece *) llrembynr (animlist, 1)) != NULL)
782 free (mpiece->from);
783 free (mpiece->to);
784 free (mpiece);
786 free (animlist);
788 animlist = NULL;
790 return;
794 void fl_board::drawcross (int col, int row)
796 ::position temppos;
797 int x, y,
798 straal;
800 /* calculate position of center of the piece */
801 temppos.col = col;
802 temppos.row = row;
803 pos2coor (&temppos, x, y);
805 straal = base / 16;
807 if (!fl_not_clipped (x - straal, y - straal, straal * 2, straal * 2))
808 return;
810 fl_color (FL_RED);
813 ** I draw a lot of lines here to get the impression of a
814 ** thick cross
816 fl_line (x - straal, y - straal, x + straal, y + straal);
817 fl_line (x - straal + 1, y - straal, x + straal, y + straal - 1);
818 fl_line (x - straal, y - straal + 1, x + straal - 1, y + straal);
820 fl_line (x + straal, y - straal, x - straal, y + straal);
821 fl_line (x + straal - 1, y - straal, x - straal, y + straal - 1);
822 fl_line (x + straal, y - straal + 1, x - straal + 1, y + straal);
824 return;
828 void fl_board::resize (int x, int y, int w, int h)
830 Fl_Widget::resize (x, y, w, h);
832 calcsizes ();
834 if (showpos != NULL)
836 del_position (showpos);
837 showpos = NULL;
838 showflag = 0;
841 return;
846 ** calculate
847 ** xoffset
848 ** yoffset
849 ** base
851 ** to be used at every resize-event and at class-creation
853 void fl_board::calcsizes ()
855 int height,
856 width;
858 width = round (w() / 2.0);
859 height = round (h() / 2.5);
860 base = min (width, height);
862 xoffset = round((w() - base * 2.0) / 2) + x();
863 yoffset = round((h() - base * 2.5) / 2) + y();
865 return;
870 ** calculate screen-coordinates starting from a board-position
872 // solution: Fl_Input_ has a 'position' member function
873 inline void fl_board::pos2coor (const ::position *pos, int& x, int& y)
875 x = xoffset + round (rowbase[pos->col][0] * base);
876 y = yoffset + round ((rowbase[pos->col][1] - pos->row * .25) * base);
878 return;
882 void fl_board::setoutputwidgets (Fl_Output * wp, Fl_Output * wl,
883 fl_pile * wpi, Fl_Output * bp,
884 Fl_Output * bl, fl_pile * bpi,
885 Fl_Output * from_o, Fl_Output * to_o)
887 wpieces = wp;
888 wlost = wl;
889 wpile = wpi;
890 wpile->setcolor ('o');
892 bpieces = bp;
893 blost = bl;
894 bpile = bpi;
895 bpile->setcolor ('x');
897 t_from = from_o;
898 t_to = to_o;
900 changecountervalues ();
901 changefromtovalues ();
903 return;
906 void fl_board::changefromtovalues ()
908 char * tempstr;
910 if (from != NULL)
912 tempstr = postostr (from);
913 t_from->value (tempstr);
914 free (tempstr);
916 else
918 t_from->value (NULL);
921 if (to != NULL)
923 tempstr = postostr (to);
924 t_to->value (tempstr);
925 free (tempstr);
927 else
929 t_to->value (NULL);
932 redraw ();
934 return;
938 void fl_board::changecountervalues ()
940 char tempstr[20];
942 if (wpieces != NULL)
944 if (theboard != NULL)
946 sprintf (tempstr, "%d", b_white (theboard));
947 wpieces->value (tempstr);
948 sprintf (tempstr, "lost: %d", b_white_lost (theboard));
949 wlost->value (tempstr);
950 wpile->setvalue (b_white (theboard));
952 sprintf (tempstr, "%d", b_black (theboard));
953 bpieces->value (tempstr);
954 sprintf (tempstr, "lost: %d", b_black_lost (theboard));
955 blost->value (tempstr);
956 bpile->setvalue (b_black (theboard));
958 else
960 wpieces->value (NULL);
961 wlost->value (NULL);
962 wpile->setvalue (-1);
963 bpieces->value (NULL);
964 blost->value (NULL);
965 bpile->setvalue (-1);
969 return;
973 void fl_board::setboard (board * newboard)
975 if (b_compare (newboard, theboard) == 0)
976 { /* the new is the same as the old */
977 return;
980 if (theboard != NULL)
982 b_del (theboard);
984 theboard = b_copy (newboard);
986 changecountervalues ();
987 redraw ();
989 return;
993 void fl_board::setfrom (const ::position * newfrom)
995 if (from != NULL)
997 free (from);
999 from = (::position *) copy_position ((void *) newfrom);
1001 changefromtovalues ();
1003 return;
1007 void fl_board::setto (const ::position * newto)
1009 if ((newto != NULL) && (from != NULL) && (to != NULL) &&
1010 (execbutton != NULL) &&
1011 (posp_col (to) == posp_col (newto)) &&
1012 (posp_row (to) == posp_row (newto)))
1014 execbutton->do_callback ();
1015 return;
1017 if (to != NULL)
1019 free (to);
1021 to = (::position *) copy_position ((void *) newto);
1023 changefromtovalues ();
1025 return;
1029 void fl_board::seteditpiece (char newpiece)
1031 editpiece = newpiece;
1035 int fl_board::setlostwhite (int val)
1037 board * nboard;
1039 if (theboard == NULL)
1040 return (0);
1042 if ((nboard = b_edit_lostwhite (theboard, val)) != NULL)
1044 b_del (theboard);
1045 theboard = nboard;
1047 changecountervalues ();
1049 return (b_white_lost (theboard));
1053 int fl_board::setlostblack (int val)
1055 board * nboard;
1057 if (theboard == NULL)
1058 return (0);
1060 if ((nboard = b_edit_lostblack (theboard, val)) != NULL)
1062 b_del (theboard);
1063 theboard = nboard;
1065 changecountervalues ();
1067 return (b_black_lost (theboard));
1071 void fl_board::setstate (int newstate)
1073 state = newstate;
1075 if (state != BOARD_PLAY)
1077 setfrom (NULL);
1078 setto (NULL);
1083 void fl_board::showmousepos ()
1085 if (showpos != NULL)
1087 showflag = 1;
1088 redraw ();
1091 return;
1095 void shmpos (void * data)
1097 fl_board * boardobject = (fl_board *) data;
1099 boardobject->showmousepos ();
1101 return;
1105 void fl_board::setgipfpossible (int flag)
1107 if (flag == 1)
1109 gipfpossible = 1;
1110 fromtype = 1;
1112 else
1114 gipfpossible = 0;
1115 fromtype = 0;
1117 return;
1120 void fl_board::setrow (listheader * rowp)
1122 if (row != NULL)
1124 emptyll (row, del_position_f);
1125 free (row);
1127 if (rowp != NULL)
1128 row = copy_position_row (rowp);
1129 else
1130 row = NULL;
1132 redraw ();
1133 return;
1137 void fl_board::initanim (int st, listheader * al)
1139 int counter;
1140 struct movepiece {
1141 char piece;
1142 ::position * from;
1143 ::position * to;
1144 } * mpiece, * npiece;
1145 listheader * newl;
1147 maxstep = st;
1149 newl = (listheader *) malloc (sizeof (listheader));
1150 newlist (newl);
1152 counter = 1;
1153 while ((mpiece = (struct movepiece *) llitembynr (al, counter))
1154 != NULL)
1156 counter++;
1158 npiece = (struct movepiece *) malloc (sizeof (struct movepiece));
1159 npiece->piece = mpiece->piece;
1160 npiece->from = (::position *) copy_position ((void *) mpiece->from);
1161 npiece->to = (::position *) copy_position ((void *) mpiece->to);
1163 pushll (newl, npiece);
1166 if (animlist != NULL)
1168 while ((mpiece = (struct movepiece *) llrembynr (animlist, 1)) != NULL)
1170 free (mpiece->from);
1171 free (mpiece->to);
1172 free (mpiece);
1174 free (animlist);
1177 animlist = newl;
1179 return;
1183 void fl_board::calc_clipping ()
1185 int counter;
1186 struct movepiece {
1187 char piece;
1188 ::position * from;
1189 ::position * to;
1190 } * mpiece;
1191 int x1, y1,
1192 x2, y2,
1193 straal;
1195 mpiece = (struct movepiece *) llitembynr (animlist, 1);
1196 pos2coor (mpiece->from, x1, y1);
1197 counter = 1;
1198 while ((mpiece = (struct movepiece *) llitembynr (animlist, counter))
1199 != NULL)
1201 counter++;
1202 pos2coor (mpiece->to, x2, y2);
1204 straal = base / 12;
1206 /* the -2 and +2 are used for a little security */
1207 clip_x = min (x1, x2) - straal - 2;
1208 clip_y = min (y1, y2) - straal - 2;
1209 clip_w = max (x1, x2) - clip_x + straal + 2;
1210 clip_h = max (y1, y2) - clip_y + straal + 2;
1212 return;