get rid of compiler warnings
[btb/d2x.git] / ui / radio.c
1 /* $Id: radio.c,v 1.5 2005-02-26 10:00:40 chris Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 #ifdef RCS
16 static char rcsid[] = "$Id: radio.c,v 1.5 2005-02-26 10:00:40 chris Exp $";
17 #endif
18
19 #ifdef HAVE_CONFIG_H
20 #include "conf.h"
21 #endif
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "fix.h"
27 #include "pstypes.h"
28 #include "gr.h"
29 #include "ui.h"
30 #include "key.h"
31 #include "u_mem.h"
32
33 #include "mono.h"
34
35 #define Middle(x) ((2*(x)+1)/4)
36
37 void ui_draw_radio( UI_GADGET_RADIO * radio )
38 {
39
40         if ((radio->status==1) || (radio->position != radio->oldposition))
41         {
42                 radio->status = 0;
43
44                 ui_mouse_hide();
45                 gr_set_current_canvas( radio->canvas );
46
47                 if (radio->flag)
48                         gr_set_fontcolor( CRED, -1 );
49                 else
50                         gr_set_fontcolor( CBLACK, -1 );
51
52                 if (radio->position == 0 )
53                 {
54                         ui_draw_box_out( 0, 0, radio->width-1, radio->height-1 );
55                         ui_string_centered(  Middle(radio->width), Middle(radio->height), "þ" );
56                 } else {
57                         ui_draw_box_in( 0, 0, radio->width-1, radio->height-1 );
58                         ui_string_centered(  Middle(radio->width)+1, Middle(radio->height)+1, "þ" );
59                 }
60
61                 if (CurWindow->keyboard_focus_gadget == (UI_GADGET *)radio)
62                         gr_set_fontcolor( CRED, CWHITE );
63                 else
64                         gr_set_fontcolor( CBLACK, CWHITE );
65
66                 gr_ustring( radio->width+4, 2, radio->text );
67
68                 ui_mouse_show();
69         }
70 }
71
72
73 UI_GADGET_RADIO * ui_add_gadget_radio( UI_WINDOW * wnd, short x, short y, short w, short h, short group, char * text )
74 {
75         UI_GADGET_RADIO * radio;
76
77         radio = (UI_GADGET_RADIO *)ui_gadget_add( wnd, 4, x, y, x+w-1, y+h-1 );
78
79         radio->text = d_strdup(text);
80         radio->width = w;
81         radio->height = h;
82         radio->position = 0;
83         radio->oldposition = 0;
84         radio->pressed = 0;
85         radio->flag = 0;
86         radio->group = group;
87
88         return radio;
89
90 }
91
92
93 void ui_radio_do( UI_GADGET_RADIO * radio, int keypress )
94 {
95         UI_GADGET * tmp;
96         UI_GADGET_RADIO * tmpr;
97         int OnMe, ButtonLastSelected;
98         keypress  = keypress;
99
100         OnMe = ui_mouse_on_gadget( (UI_GADGET *)radio );
101
102         radio->oldposition = radio->position;
103
104         if (selected_gadget != NULL)
105         {
106                 if (selected_gadget->kind==4)
107                         ButtonLastSelected = 1;
108                 else
109                         ButtonLastSelected = 0;
110         } else
111                 ButtonLastSelected = 1;
112
113
114         if ( B1_PRESSED && OnMe && ButtonLastSelected )
115         {
116
117                 radio->position = 1;
118         } else  {
119                 radio->position = 0;
120         }
121
122
123         if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)radio) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) )
124                 radio->position = 2;
125
126         if ((radio->position==0) && (radio->oldposition==1) && OnMe )
127                 radio->pressed = 1;
128         else if ((radio->position==0) && (radio->oldposition==2) && (CurWindow->keyboard_focus_gadget==(UI_GADGET *)radio) )
129                 radio->pressed = 1;
130         else
131                 radio->pressed = 0;
132
133         if ((radio->pressed == 1) && (radio->flag==0))
134         {
135                 tmp = (UI_GADGET *)radio->next;
136
137                 while (tmp != (UI_GADGET *)radio )
138                 {
139                         if (tmp->kind==4)
140                         {
141                                 tmpr = (UI_GADGET_RADIO *)tmp;
142                                 if ((tmpr->group == radio->group ) && (tmpr->flag) )
143                                 {
144                                         tmpr->flag = 0;
145                                         tmpr->status = 1;
146                                         tmpr->pressed = 0;
147                                 }
148                         }
149                         tmp = tmp->next;
150                 }
151                 radio->flag = 1;
152         }
153
154         ui_draw_radio( radio );
155
156 }
157
158