Support for g++-4.1.
[gf1.git] / fl_pile.cxx
blobc44d5ee640abafb6b17720ab42b7b91321fd4326
1 /*
2 ** $Id$
3 **
4 ** all that is necessary for drawing a pile of pieces
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 <FL/fl_draw.H>
25 #include "fl_pile.h"
27 #ifndef min
28 #define min(x,y) (x < y ? x : y)
29 #endif
31 #ifndef max
32 #define max(x,y) (x > y ? x : y)
33 #endif
35 #define round(x) (int)(x + 0.5)
39 ** constructor
41 fl_pile::fl_pile(int X,int Y,int W,int H,const char *l)
42 : Fl_Widget (X, Y, W, H, l)
44 nrpieces = 0;
45 color = 'o';
47 calcsizes ();
49 // I don't know if this is a good solution
50 // lyellow = FL_COLOR_CUBE +
51 // FL_RED_MULTIPLY * 4 +
52 // FL_GREEN_MULTIPLY * 7 +
53 // FL_BLUE_MULTIPLY * 3;
54 lyellow = fl_color_cube(255 * FL_NUM_RED/256,
55 255 * FL_NUM_GREEN/256,
56 200 * FL_NUM_BLUE/256);
58 return;
63 ** destructor
65 fl_pile::~fl_pile ()
67 return;
72 ** I don't think I have to handle anything here
74 int fl_pile::handle (int event)
76 switch (event)
78 default:
79 return (0);
84 void fl_pile::draw ()
86 int i,
87 x1, y1;
89 /* set everything to background color */
90 fl_color (Fl_Widget::color());
91 fl_rectf (x()+1, y()+1, w()-2, h()-2);
93 draw_box ();
95 if (color == 'o')
96 fl_color (lyellow); // yellow
97 else
98 fl_color (FL_BLACK); // black
100 for (i = 1; i <= nrpieces; i++)
102 x1 = xoffset;
103 y1 = yoffset - round (i * pieceh * 1.5);
105 fl_rectf (x1, y1, piecew, pieceh);
108 fl_color (FL_BLACK);
109 for (i = 1; i <= nrpieces; i++)
111 x1 = xoffset;
112 y1 = yoffset - round (i * pieceh * 1.5);
114 fl_rect (x1, y1, piecew, pieceh);
117 return;
121 void fl_pile::resize (int x, int y, int w, int h)
123 Fl_Widget::resize (x, y, w, h);
125 calcsizes ();
127 return;
132 ** calculate
133 ** xoffset
134 ** yoffset
135 ** piecew
136 ** pieceh
138 ** to be used at every resize-event and at class-creation
140 void fl_pile::calcsizes ()
142 int height,
143 width;
145 width = round (w() / 1.5);
146 height = round (h() / 5.5);
147 piecew = min (width, height);
148 pieceh = (int) (piecew / 5.0);
150 xoffset = round((w() - piecew) / 2) + x();
151 yoffset = h() + y();
153 return;
157 void fl_pile::setvalue (int val)
159 nrpieces = val;
160 redraw ();
162 return;
166 void fl_pile::setcolor (char col)
168 color = col;
169 redraw ();
171 return;