2 * $Logfile: /Freespace2/code/UI/RADIO.cpp $
7 * Code to handle radio buttons.
10 * Revision 1.1 2002/05/03 03:28:11 root
14 * 4 12/02/98 5:47p Dave
15 * Put in interface xstr code. Converted barracks screen to new format.
17 * 3 10/13/98 9:29a Dave
18 * Started neatening up freespace.h. Many variables renamed and
19 * reorganized. Added AlphaColors.[h,cpp]
21 * 2 10/07/98 10:54a Dave
24 * 1 10/07/98 10:51a Dave
26 * 9 3/10/98 4:19p John
27 * Cleaned up graphics lib. Took out most unused gr functions. Made D3D
28 * & Glide have popups and print screen. Took out all >8bpp software
29 * support. Made Fred zbuffer. Made zbuffer allocate dynamically to
30 * support Fred. Made zbuffering key off of functions rather than one
33 * 8 2/03/98 4:21p Hoffoss
34 * Made UI controls draw white text when disabled.
36 * 7 1/14/98 6:44p Hoffoss
37 * Massive changes to UI code. A lot cleaner and better now. Did all
38 * this to get the new UI_DOT_SLIDER to work properly, which the old code
39 * wasn't flexible enough to handle.
41 * 6 6/12/97 12:39p John
42 * made ui use freespace colors
44 * 5 6/11/97 1:13p John
45 * Started fixing all the text colors in the game.
47 * 4 5/26/97 10:26a Lawrance
48 * get slider control working 100%
50 * 3 1/01/97 6:46p Lawrance
51 * changed text color of radio button to green from black
53 * 2 11/15/96 11:43a John
55 * 1 11/14/96 6:55p John
62 #include "alphacolors.h"
64 void UI_RADIO::create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state, int _group )
68 // gr_get_string_size( &_w, &_h, "X" );
77 base_create( wnd, UI_KIND_RADIO, _x, _y, _w, _h );
85 void UI_RADIO::destroy()
100 if ( disabled_flag ) {
102 if ( bmap_ids[RADIO_DISABLED_MARKED] != -1 ) {
103 gr_set_bitmap(bmap_ids[RADIO_DISABLED_MARKED]);
108 if ( bmap_ids[RADIO_DISABLED_CLEAR] != -1 ) {
109 gr_set_bitmap(bmap_ids[RADIO_DISABLED_CLEAR]);
114 else { // not disabled
115 if ( position == 0 ) { // up
116 if ( flag ) { // marked
117 if ( bmap_ids[RADIO_UP_MARKED] != -1 ) {
118 gr_set_bitmap(bmap_ids[RADIO_UP_MARKED]);
123 if ( bmap_ids[RADIO_UP_CLEAR] != -1 ) {
124 gr_set_bitmap(bmap_ids[RADIO_UP_CLEAR]);
130 if ( flag ) { // marked
131 if ( bmap_ids[RADIO_DOWN_MARKED] != -1 ) {
132 gr_set_bitmap(bmap_ids[RADIO_DOWN_MARKED]);
137 if ( bmap_ids[RADIO_DOWN_CLEAR] != -1 ) {
138 gr_set_bitmap(bmap_ids[RADIO_DOWN_CLEAR]);
146 gr_set_font(my_wnd->f_id);
147 gr_set_clip( x, y, w, h );
149 if (position == 0 ) {
150 ui_draw_box_out( 0, 0, w-1, h-1 );
153 ui_draw_box_in( 0, 0, w-1, h-1 );
158 gr_set_color_fast(&CDARK_GRAY);
159 else if (my_wnd->selected_gadget == this)
160 gr_set_color_fast(&CBRIGHT_GREEN);
162 gr_set_color_fast(&CGREEN);
165 // ui_string_centered( Middle(w)+offset, Middle(h)+offset, "*" );
167 // ui_string_centered( Middle(w)+offset, Middle(h)+offset, "o" );
169 gr_circle( Middle(w)+offset, Middle(h)+offset, 8 );
171 gr_circle( Middle(w)+offset, Middle(h)+offset, 8 );
172 gr_set_color_fast( &CWHITE );
173 gr_circle( Middle(w)+offset, Middle(h)+offset, 4 );
177 gr_set_color_fast(&CDARK_GRAY);
178 else if (my_wnd->selected_gadget == this)
179 gr_set_color_fast(&CBRIGHT_GREEN);
181 gr_set_color_fast(&CGREEN);
185 gr_string( x+w+4, y+2, text );
190 void UI_RADIO::process(int focus)
192 int OnMe, oldposition;
199 if (my_wnd->selected_gadget == this)
202 OnMe = is_mouse_on();
204 oldposition = position;
206 if (B1_PRESSED && OnMe) {
212 if (my_wnd->keypress == hotkey) {
214 my_wnd->last_keypress = 0;
217 if ( focus && ((my_wnd->keypress == KEY_SPACEBAR) || (my_wnd->keypress == KEY_ENTER)) )
221 if ( (oldposition == 2) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER]) )
227 if ( (oldposition == 1) && OnMe )
229 if ( (oldposition == 2) && focus )
233 if (pressed_down && user_function) {
237 if (pressed_down && (flag == 0)) {
238 UI_GADGET *tmp = (UI_GADGET *) next;
241 while (tmp != this) {
242 if (tmp->kind == UI_KIND_RADIO) {
243 tmpr = (UI_RADIO *) tmp;
244 if ((tmpr->group == group) && tmpr->flag) {
246 tmpr->pressed_down = 0;
257 int UI_RADIO::changed()
262 int UI_RADIO::checked()