2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Draws the options for a radio button widget with the currently selected
27 * @param widget The radio button widget
28 * @param maxWidth The width of the largest widget (used for spacing)
30 void drawOptions(Widget *widget, int maxWidth)
32 int x = widget->x + maxWidth + 55;
36 char *c = widget->options;
43 unsigned int token_len;
45 char *eow = strchr (c, '|');
50 if (token_len > sizeof (token) - 1)
51 token_len = sizeof (token) - 1;
52 memcpy (token, c, token_len);
53 token [token_len] = 0;
61 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
62 if (count == *widget->value)
63 graphics.setFontColor(0x00, 0x00, 0x00, 0x00, 0xff, 0x00);
67 graphics.setFontColor(0x77, 0x77, 0x77, 0x00, 0x00, 0x00);
70 text = graphics.getString(token, false);
72 if ((widget->enabled) && (count == *widget->value))
73 graphics.drawWidgetRect(x, widget->y, text->w, text->h);
75 graphics.blit(text, x, widget->y, graphics.screen, false);
83 * Draws a horizontal slider widget with its current value
84 * used to fill the bar
85 * @param widget The slider widget
86 * @param maxWidth The width of the largest widget (used for spacing)
88 void drawSlider(Widget *widget, int maxWidth)
90 int x = widget->x + maxWidth + 50;
94 graphics.drawRect(x, widget->y, 300, 18, graphics.white, graphics.screen);
98 graphics.drawRect(x, widget->y, 300, 18, graphics.grey, graphics.screen);
101 graphics.drawRect(x + 1, widget->y + 1, 298, 16, graphics.black, graphics.screen);
103 float width = 296.00 / widget->max;
105 width *= *widget->value;
109 graphics.drawRect(x + 2, widget->y + 2, (int)width, 14, graphics.green, graphics.screen);
113 graphics.drawRect(x + 2, widget->y + 2, (int)width, 14, graphics.darkGreen, graphics.screen);
119 * Draws a widget used to represent joypad buttons. A widget with a value of
120 * -1000 or less appears as ...
121 * @param widget The Joypad Button widget
123 void drawJoypadButtonOption(Widget *widget)
125 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
132 // joysticks have a button 0 so we can't
133 // do the same thing as the keyboard(!)
134 if (*widget->value < -2)
136 snprintf(text, sizeof text, "...");
138 else if (*widget->value == -2)
140 snprintf(text, sizeof text, "N/A");
144 snprintf(text, sizeof text, "Button #%d", *widget->value);
147 graphics.drawString(text, x, widget->y, TXT_LEFT, graphics.screen);
151 * Draws a widget used to represent a key based on the widget's current value
152 * @param widget The Widget
154 void drawKeyOption(Widget *widget)
156 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
160 graphics.drawString(Keyboard::translateKey(*widget->value),
161 x, widget->y, TXT_LEFT, graphics.screen);
165 * Creates an image for the specified image. The text colour and background
166 * colour as set depending on the status of the widget
167 * @param widget The Widget to create the image for
169 void generateWidgetImage(Widget *widget)
171 if (widget == engine.highlightedWidget)
173 graphics.setFontColor(0x00, 0x00, 0x00, 0x00, 0xff, 0x00);
179 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
183 graphics.setFontColor(0x77, 0x77, 0x77, 0x00, 0x00, 0x00);
187 widget->image = graphics.getString(widget->label, false);
191 * Draws all the widgets in their specified positions. Widgets that
192 * have no image have an image created for them. Invisible widgets
197 graphics.setFontSize(0);
199 Widget *widget = (Widget*)engine.widgetList.getHead();
203 while (widget->next != NULL)
205 widget = (Widget*)widget->next;
207 if (widget->image == NULL)
209 generateWidgetImage(widget);
212 maxWidth = max(maxWidth, widget->image->w);
215 widget = (Widget*)engine.widgetList.getHead();
217 while (widget->next != NULL)
219 widget = (Widget*)widget->next;
221 if (!widget->visible)
226 if ((!widget->value) && (widget->type != WG_LABEL))
228 debug(("WARNING: Widget variable for '%s' not set!\n", widget->name));
234 widget->x = (640 - widget->image->w) / 2;
237 if (widget == engine.highlightedWidget)
239 graphics.drawWidgetRect(widget->x, widget->y, widget->image->w, widget->image->h);
243 graphics.drawRect(widget->x - 3, widget->y - 2, widget->image->w + 6, widget->image->h + 4, graphics.black, graphics.screen);
246 graphics.blit(widget->image, widget->x, widget->y, graphics.screen, false);
248 switch (widget->type)
251 drawOptions(widget, maxWidth);
254 case WG_SMOOTH_SLIDER:
255 drawSlider(widget, maxWidth);
258 drawKeyOption(widget);
261 drawJoypadButtonOption(widget);
265 widget->changed = false;