2 Copyright © 2004 Parallel Realities
3 Copyright © 2007-2008 Kővágó Zoltán <DirtY.iCE.hu@gmail.com>
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.
22 #include "CGraphics.h"
24 #include "console/console.hpp"
25 #include "gettext.hpp"
28 * Draws the options for a radio button widget with the currently selected
30 * @param widget The radio button widget
31 * @param maxWidth The width of the largest widget (used for spacing)
33 void drawOptions(Widget
*widget
, int maxWidth
)
35 int x
= widget
->x
+ maxWidth
+ 55;
39 std::string options
= _(widget
->options
);
40 std::string::iterator it
= options
.begin();
51 graphics
.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
52 if (count
== *widget
->value
)
53 graphics
.setFontColor(0x00, 0x00, 0x00, 0x00, 0xff, 0x00);
57 graphics
.setFontColor(0x77, 0x77, 0x77, 0x00, 0x00, 0x00);
60 text
= graphics
.getString(item
, false);
62 if ((widget
->enabled
) && (count
== *widget
->value
))
63 graphics
.drawWidgetRect(bx
+ x
, by
+ widget
->y
, text
->w
, text
->h
);
65 graphics
.blit(text
, bx
+ x
, by
+ widget
->y
, graphics
.screen
, false);
81 graphics
.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
82 if (count
== *widget
->value
)
83 graphics
.setFontColor(0x00, 0x00, 0x00, 0x00, 0xff, 0x00);
87 graphics
.setFontColor(0x77, 0x77, 0x77, 0x00, 0x00, 0x00);
90 text
= graphics
.getString(item
, false);
92 if ((widget
->enabled
) && (count
== *widget
->value
))
94 graphics
.drawWidgetRect(bx
+ x
, by
+ widget
->y
, text
->w
, text
->h
);
97 graphics
.blit(text
, bx
+ x
, by
+ widget
->y
, graphics
.screen
, false);
101 * Draws a horizontal slider widget with its current value
102 * used to fill the bar
103 * @param widget The slider widget
104 * @param maxWidth The width of the largest widget (used for spacing)
106 void drawSlider(Widget
*widget
, int maxWidth
)
108 int x
= widget
->x
+ maxWidth
+ 50;
112 graphics
.drawRect(bx
+ x
, by
+ widget
->y
, 300, 18, graphics
.white
, graphics
.screen
);
116 graphics
.drawRect(bx
+ x
, by
+ widget
->y
, 300, 18, graphics
.grey
, graphics
.screen
);
119 graphics
.drawRect(bx
+ x
+ 1, by
+ widget
->y
+ 1, 298, 16, graphics
.black
, graphics
.screen
);
121 float width
= 296.00 / widget
->max
;
123 width
*= *widget
->value
;
127 graphics
.drawRect(bx
+ x
+ 2, by
+ widget
->y
+ 2, (int)width
, 14, graphics
.green
, graphics
.screen
);
131 graphics
.drawRect(bx
+ x
+ 2, by
+ widget
->y
+ 2, (int)width
, 14, graphics
.darkGreen
, graphics
.screen
);
137 * Draws a widget used to represent joypad buttons. A widget with a value of
138 * -1000 or less appears as ...
139 * @param widget The Joypad Button widget
141 void drawJoypadButtonOption(Widget
*widget
)
143 graphics
.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
150 // joysticks have a button 0 so we can't
151 // do the same thing as the keyboard(!)
152 if (*widget
->value
<= -1000)
154 sprintf(text
, "...");
158 sprintf(text
, _("Button #%d").c_str(), *widget
->value
);
161 graphics
.drawString(text
, bx
+ x
, by
+ widget
->y
, TXT_LEFT
, graphics
.screen
);
165 * Draws a widget used to represent a key based on the widget's current value
166 * @param widget The Widget
168 void drawKeyOption(Widget
*widget
)
170 graphics
.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
177 sprintf(text
, "%s", Keyboard::translateKey(*widget
->value
));
179 graphics
.drawString(text
, bx
+ x
, by
+ widget
->y
, TXT_LEFT
, graphics
.screen
);
183 * Creates an image for the specified image. The text colour and background
184 * colour as set depending on the status of the widget
185 * @param widget The Widget to create the image for
187 void generateWidgetImage(Widget
*widget
)
189 if (widget
== engine
.highlightedWidget
)
191 graphics
.setFontColor(0x00, 0x00, 0x00, 0x00, 0xff, 0x00);
197 graphics
.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
201 graphics
.setFontColor(0x77, 0x77, 0x77, 0x00, 0x00, 0x00);
205 widget
->image
= graphics
.getString(_(widget
->label
), false);
209 * Draws all the widgets in their specified positions. Widgets that
210 * have no image have an image created for them. Invisible widgets
215 graphics
.setFontSize(0);
217 Widget
*widget
= (Widget
*)engine
.widgetList
.getHead();
221 while (widget
->next
!= NULL
)
223 widget
= (Widget
*)widget
->next
;
225 if (widget
->image
== NULL
)
227 generateWidgetImage(widget
);
230 maxWidth
= std::max(maxWidth
, widget
->image
->w
);
233 widget
= (Widget
*)engine
.widgetList
.getHead();
235 while (widget
->next
!= NULL
)
237 widget
= (Widget
*)widget
->next
;
239 if (!widget
->visible
)
244 if ((!widget
->value
) && (widget
->type
!= WG_LABEL
))
246 warning
<< "Widget variable for '" << widget
->name
<< "' not set!" << std::endl
;
252 widget
->x
= (640 - widget
->image
->w
) / 2;
255 if (widget
== engine
.highlightedWidget
)
257 graphics
.drawWidgetRect(bx
+ widget
->x
, by
+ widget
->y
, widget
->image
->w
, widget
->image
->h
);
261 graphics
.drawRect(bx
+ widget
->x
- 3, by
+ widget
->y
- 2, widget
->image
->w
+ 6, widget
->image
->h
+ 4, graphics
.black
, graphics
.screen
);
264 graphics
.blit(widget
->image
, bx
+ widget
->x
, by
+ widget
->y
, graphics
.screen
, false);
266 switch (widget
->type
)
269 drawOptions(widget
, maxWidth
);
272 case WG_SMOOTH_SLIDER
:
273 drawSlider(widget
, maxWidth
);
276 drawKeyOption(widget
);
279 drawJoypadButtonOption(widget
);
283 widget
->changed
= false;