(Temporarily) set "animate" to "none" by default (broken feature).
[gf1.git] / fl_pile.cxx
blob64801e5901a496cbf4fd7fd816bfce26d07e36ef
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 #include <algorithm>
29 #define round(x) (int)(x + 0.5)
33 ** constructor
35 fl_pile::fl_pile(int X,int Y,int W,int H,const char *l)
36 : Fl_Widget (X, Y, W, H, l)
38 nrpieces = 0;
39 color = 'o';
41 calcsizes ();
43 // I don't know if this is a good solution
44 // lyellow = FL_COLOR_CUBE +
45 // FL_RED_MULTIPLY * 4 +
46 // FL_GREEN_MULTIPLY * 7 +
47 // FL_BLUE_MULTIPLY * 3;
48 lyellow = fl_color_cube(255 * FL_NUM_RED/256,
49 255 * FL_NUM_GREEN/256,
50 200 * FL_NUM_BLUE/256);
52 return;
57 ** destructor
59 fl_pile::~fl_pile ()
61 return;
66 ** I don't think I have to handle anything here
68 int fl_pile::handle (int event)
70 switch (event)
72 default:
73 return (0);
78 void fl_pile::draw ()
80 int i,
81 x1, y1;
83 /* set everything to background color */
84 fl_color (Fl_Widget::color());
85 fl_rectf (x()+1, y()+1, w()-2, h()-2);
87 draw_box ();
89 if (color == 'o')
90 fl_color (lyellow); // yellow
91 else
92 fl_color (FL_BLACK); // black
94 for (i = 1; i <= nrpieces; i++)
96 x1 = xoffset;
97 y1 = yoffset - round (i * pieceh * 1.5);
99 fl_rectf (x1, y1, piecew, pieceh);
102 fl_color (FL_BLACK);
103 for (i = 1; i <= nrpieces; i++)
105 x1 = xoffset;
106 y1 = yoffset - round (i * pieceh * 1.5);
108 fl_rect (x1, y1, piecew, pieceh);
111 return;
115 void fl_pile::resize (int x, int y, int w, int h)
117 Fl_Widget::resize (x, y, w, h);
119 calcsizes ();
121 return;
126 ** calculate
127 ** xoffset
128 ** yoffset
129 ** piecew
130 ** pieceh
132 ** to be used at every resize-event and at class-creation
134 void fl_pile::calcsizes ()
136 int height,
137 width;
139 width = round (w() / 1.5);
140 height = round (h() / 5.5);
141 piecew = std::min (width, height);
142 pieceh = (int) (piecew / 5.0);
144 xoffset = round((w() - piecew) / 2) + x();
145 yoffset = h() + y();
147 return;
151 void fl_pile::setvalue (int val)
153 nrpieces = val;
154 redraw ();
156 return;
160 void fl_pile::setcolor (char col)
162 color = col;
163 redraw ();
165 return;