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