2 Copyright (C) 2004 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * Draws the options for a radio button widget with the currently selected
26 * @param widget The radio button widget
27 * @param maxWidth The width of the largest widget (used for spacing)
29 void drawOptions(Widget *widget, int maxWidth)
31 int x = widget->x + maxWidth + 55;
35 char *c = widget->options;
42 unsigned int token_len;
44 char *eow = strchr (c, '|');
49 if (token_len > sizeof (token) - 1)
50 token_len = sizeof (token) - 1;
51 memcpy (token, c, token_len);
52 token [token_len] = 0;
60 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
61 if (count == *widget->value)
62 graphics.setFontColor(0x00, 0x00, 0x00, 0x00, 0xff, 0x00);
66 graphics.setFontColor(0x77, 0x77, 0x77, 0x00, 0x00, 0x00);
69 text = graphics.getString(token, false);
71 if ((widget->enabled) && (count == *widget->value))
72 graphics.drawWidgetRect(x, widget->y, text->w, text->h);
74 graphics.blit(text, x, widget->y, graphics.screen, false);
82 * Draws a horizontal slider widget with its current value
83 * used to fill the bar
84 * @param widget The slider widget
85 * @param maxWidth The width of the largest widget (used for spacing)
87 void drawSlider(Widget *widget, int maxWidth)
89 int x = widget->x + maxWidth + 50;
93 graphics.drawRect(x, widget->y, 300, 18, graphics.white, graphics.screen);
97 graphics.drawRect(x, widget->y, 300, 18, graphics.grey, graphics.screen);
100 graphics.drawRect(x + 1, widget->y + 1, 298, 16, graphics.black, graphics.screen);
102 float width = 296.00 / widget->max;
104 width *= *widget->value;
108 graphics.drawRect(x + 2, widget->y + 2, (int)width, 14, graphics.green, graphics.screen);
112 graphics.drawRect(x + 2, widget->y + 2, (int)width, 14, graphics.darkGreen, graphics.screen);
118 * Draws a widget used to represent joypad buttons. A widget with a value of
119 * -1000 or less appears as ...
120 * @param widget The Joypad Button widget
122 void drawJoypadButtonOption(Widget *widget)
124 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
131 // joysticks have a button 0 so we can't
132 // do the same thing as the keyboard(!)
133 if (*widget->value <= -1000)
135 snprintf(text, sizeof text, "...");
137 else if (*widget->value == -2)
139 snprintf(text, sizeof text, "N/A");
143 snprintf(text, sizeof text, "Button #%d", *widget->value);
146 graphics.drawString(text, x, widget->y, TXT_LEFT, graphics.screen);
150 * Draws a widget used to represent a key based on the widget's current value
151 * @param widget The Widget
153 void drawKeyOption(Widget *widget)
155 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
159 graphics.drawString(Keyboard::translateKey(*widget->value),
160 x, widget->y, TXT_LEFT, graphics.screen);
164 * Creates an image for the specified image. The text colour and background
165 * colour as set depending on the status of the widget
166 * @param widget The Widget to create the image for
168 void generateWidgetImage(Widget *widget)
170 if (widget == engine.highlightedWidget)
172 graphics.setFontColor(0x00, 0x00, 0x00, 0x00, 0xff, 0x00);
178 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
182 graphics.setFontColor(0x77, 0x77, 0x77, 0x00, 0x00, 0x00);
186 widget->image = graphics.getString(widget->label, false);
190 * Draws all the widgets in their specified positions. Widgets that
191 * have no image have an image created for them. Invisible widgets
196 graphics.setFontSize(0);
198 Widget *widget = (Widget*)engine.widgetList.getHead();
202 while (widget->next != NULL)
204 widget = (Widget*)widget->next;
206 if (widget->image == NULL)
208 generateWidgetImage(widget);
211 maxWidth = max(maxWidth, widget->image->w);
214 widget = (Widget*)engine.widgetList.getHead();
216 while (widget->next != NULL)
218 widget = (Widget*)widget->next;
220 if (!widget->visible)
225 if ((!widget->value) && (widget->type != WG_LABEL))
227 debug(("WARNING: Widget variable for '%s' not set!\n", widget->name));
233 widget->x = (640 - widget->image->w) / 2;
236 if (widget == engine.highlightedWidget)
238 graphics.drawWidgetRect(widget->x, widget->y, widget->image->w, widget->image->h);
242 graphics.drawRect(widget->x - 3, widget->y - 2, widget->image->w + 6, widget->image->h + 4, graphics.black, graphics.screen);
245 graphics.blit(widget->image, widget->x, widget->y, graphics.screen, false);
247 switch (widget->type)
250 drawOptions(widget, maxWidth);
253 case WG_SMOOTH_SLIDER:
254 drawSlider(widget, maxWidth);
257 drawKeyOption(widget);
260 drawJoypadButtonOption(widget);
264 widget->changed = false;