2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/UI/RADIO.cpp $
15 * Code to handle radio buttons.
18 * Revision 1.3 2004/09/20 01:31:45 theoddone33
21 * Revision 1.2 2002/06/09 04:41:29 relnev
22 * added copyright header
24 * Revision 1.1.1.1 2002/05/03 03:28:11 root
28 * 4 12/02/98 5:47p Dave
29 * Put in interface xstr code. Converted barracks screen to new format.
31 * 3 10/13/98 9:29a Dave
32 * Started neatening up freespace.h. Many variables renamed and
33 * reorganized. Added AlphaColors.[h,cpp]
35 * 2 10/07/98 10:54a Dave
38 * 1 10/07/98 10:51a Dave
40 * 9 3/10/98 4:19p John
41 * Cleaned up graphics lib. Took out most unused gr functions. Made D3D
42 * & Glide have popups and print screen. Took out all >8bpp software
43 * support. Made Fred zbuffer. Made zbuffer allocate dynamically to
44 * support Fred. Made zbuffering key off of functions rather than one
47 * 8 2/03/98 4:21p Hoffoss
48 * Made UI controls draw white text when disabled.
50 * 7 1/14/98 6:44p Hoffoss
51 * Massive changes to UI code. A lot cleaner and better now. Did all
52 * this to get the new UI_DOT_SLIDER to work properly, which the old code
53 * wasn't flexible enough to handle.
55 * 6 6/12/97 12:39p John
56 * made ui use freespace colors
58 * 5 6/11/97 1:13p John
59 * Started fixing all the text colors in the game.
61 * 4 5/26/97 10:26a Lawrance
62 * get slider control working 100%
64 * 3 1/01/97 6:46p Lawrance
65 * changed text color of radio button to green from black
67 * 2 11/15/96 11:43a John
69 * 1 11/14/96 6:55p John
76 #include "alphacolors.h"
78 void UI_RADIO::create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state, int _group )
82 // gr_get_string_size( &_w, &_h, "X" );
91 base_create( wnd, UI_KIND_RADIO, _x, _y, _w, _h );
99 void UI_RADIO::destroy()
104 UI_GADGET::destroy();
107 void UI_RADIO::draw()
114 if ( disabled_flag ) {
116 if ( bmap_ids[RADIO_DISABLED_MARKED] != -1 ) {
117 gr_set_bitmap(bmap_ids[RADIO_DISABLED_MARKED], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
122 if ( bmap_ids[RADIO_DISABLED_CLEAR] != -1 ) {
123 gr_set_bitmap(bmap_ids[RADIO_DISABLED_CLEAR], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
128 else { // not disabled
129 if ( position == 0 ) { // up
130 if ( flag ) { // marked
131 if ( bmap_ids[RADIO_UP_MARKED] != -1 ) {
132 gr_set_bitmap(bmap_ids[RADIO_UP_MARKED], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
137 if ( bmap_ids[RADIO_UP_CLEAR] != -1 ) {
138 gr_set_bitmap(bmap_ids[RADIO_UP_CLEAR], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
144 if ( flag ) { // marked
145 if ( bmap_ids[RADIO_DOWN_MARKED] != -1 ) {
146 gr_set_bitmap(bmap_ids[RADIO_DOWN_MARKED], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
151 if ( bmap_ids[RADIO_DOWN_CLEAR] != -1 ) {
152 gr_set_bitmap(bmap_ids[RADIO_DOWN_CLEAR], GR_ALPHABLEND_NONE, GR_BITBLT_MODE_NORMAL, 1.0f, -1, -1);
160 gr_set_font(my_wnd->f_id);
161 gr_set_clip( x, y, w, h );
163 if (position == 0 ) {
164 ui_draw_box_out( 0, 0, w-1, h-1 );
167 ui_draw_box_in( 0, 0, w-1, h-1 );
172 gr_set_color_fast(&CDARK_GRAY);
173 else if (my_wnd->selected_gadget == this)
174 gr_set_color_fast(&CBRIGHT_GREEN);
176 gr_set_color_fast(&CGREEN);
179 // ui_string_centered( Middle(w)+offset, Middle(h)+offset, "*" );
181 // ui_string_centered( Middle(w)+offset, Middle(h)+offset, "o" );
183 gr_circle( Middle(w)+offset, Middle(h)+offset, 8 );
185 gr_circle( Middle(w)+offset, Middle(h)+offset, 8 );
186 gr_set_color_fast( &CWHITE );
187 gr_circle( Middle(w)+offset, Middle(h)+offset, 4 );
191 gr_set_color_fast(&CDARK_GRAY);
192 else if (my_wnd->selected_gadget == this)
193 gr_set_color_fast(&CBRIGHT_GREEN);
195 gr_set_color_fast(&CGREEN);
199 gr_string( x+w+4, y+2, text );
204 void UI_RADIO::process(int focus)
206 int OnMe, oldposition;
213 if (my_wnd->selected_gadget == this)
216 OnMe = is_mouse_on();
218 oldposition = position;
220 if (B1_PRESSED && OnMe) {
226 if (my_wnd->keypress == hotkey) {
228 my_wnd->last_keypress = 0;
231 if ( focus && ((my_wnd->keypress == KEY_SPACEBAR) || (my_wnd->keypress == KEY_ENTER)) )
235 if ( (oldposition == 2) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER]) )
241 if ( (oldposition == 1) && OnMe )
243 if ( (oldposition == 2) && focus )
247 if (pressed_down && user_function) {
251 if (pressed_down && (flag == 0)) {
252 UI_GADGET *tmp = (UI_GADGET *) next;
255 while (tmp != this) {
256 if (tmp->kind == UI_KIND_RADIO) {
257 tmpr = (UI_RADIO *) tmp;
258 if ((tmpr->group == group) && tmpr->flag) {
260 tmpr->pressed_down = 0;
271 int UI_RADIO::changed()
276 int UI_RADIO::checked()