]> icculus.org git repositories - btb/d2x.git/blob - ui/radio.c
use the orientation parameter of g3_draw_bitmap
[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
95         OnMe = ui_mouse_on_gadget( (UI_GADGET *)radio );
96
97         radio->oldposition = radio->position;
98
99         if (selected_gadget != NULL)
100         {
101                 if (selected_gadget->kind==4)
102                         ButtonLastSelected = 1;
103                 else
104                         ButtonLastSelected = 0;
105         } else
106                 ButtonLastSelected = 1;
107
108
109         if ( B1_PRESSED && OnMe && ButtonLastSelected )
110         {
111
112                 radio->position = 1;
113         } else  {
114                 radio->position = 0;
115         }
116
117
118         if ((CurWindow->keyboard_focus_gadget==(UI_GADGET *)radio) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER] ) )
119                 radio->position = 2;
120
121         if ((radio->position==0) && (radio->oldposition==1) && OnMe )
122                 radio->pressed = 1;
123         else if ((radio->position==0) && (radio->oldposition==2) && (CurWindow->keyboard_focus_gadget==(UI_GADGET *)radio) )
124                 radio->pressed = 1;
125         else
126                 radio->pressed = 0;
127
128         if ((radio->pressed == 1) && (radio->flag==0))
129         {
130                 tmp = (UI_GADGET *)radio->next;
131
132                 while (tmp != (UI_GADGET *)radio )
133                 {
134                         if (tmp->kind==4)
135                         {
136                                 tmpr = (UI_GADGET_RADIO *)tmp;
137                                 if ((tmpr->group == radio->group ) && (tmpr->flag) )
138                                 {
139                                         tmpr->flag = 0;
140                                         tmpr->status = 1;
141                                         tmpr->pressed = 0;
142                                 }
143                         }
144                         tmp = tmp->next;
145                 }
146                 radio->flag = 1;
147         }
148
149         ui_draw_radio( radio );
150
151 }
152
153 void ui_radio_set_value(UI_GADGET_RADIO *radio, sbyte value)
154 {
155         UI_GADGET_RADIO *tmp;
156
157         if (radio->flag == value)
158                 return;
159
160         radio->flag = value;
161         radio->status = 1;      // redraw
162
163         tmp = (UI_GADGET_RADIO *) radio->next;
164
165         while (tmp != radio)
166         {
167                 if ((tmp->kind == 4) && (tmp->group == radio->group) && tmp->flag)
168                 {
169                         tmp->flag = 0;
170                         tmp->status = 1;
171                 }
172                 tmp = (UI_GADGET_RADIO *) tmp->next;
173         }
174 }