FS2_Open
Open source remastering of the Freespace 2 engine
radio.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
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 the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "globalincs/alphacolors.h"
13 #include "ui/ui.h"
14 #include "ui/uidefs.h"
15 
16 
17 
18 void UI_RADIO::create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state, int _group )
19 {
20  int _w, _h;
21 
22  _w = 18;
23  _h = 18;
24 
25  if (_text)
26  text = vm_strdup(_text);
27  else
28  text = NULL;
29 
30  base_create( wnd, UI_KIND_RADIO, _x, _y, _w, _h );
31 
32  position = 0;
33  pressed_down = 0;
34  flag = _state;
35  group = _group;
36 }
37 
38 void UI_RADIO::destroy()
39 {
40  if (text)
41  vm_free(text);
42 
44 }
45 
46 void UI_RADIO::draw()
47 {
48  int offset;
49 
50 
51  if ( uses_bmaps ) {
52 
53  if ( disabled_flag ) {
54  if ( flag ) {
55  if ( bmap_ids[RADIO_DISABLED_MARKED] != -1 ) {
56  gr_set_bitmap(bmap_ids[RADIO_DISABLED_MARKED]);
58  }
59  }
60  else {
61  if ( bmap_ids[RADIO_DISABLED_CLEAR] != -1 ) {
62  gr_set_bitmap(bmap_ids[RADIO_DISABLED_CLEAR]);
64  }
65  }
66  }
67  else { // not disabled
68  if ( position == 0 ) { // up
69  if ( flag ) { // marked
70  if ( bmap_ids[RADIO_UP_MARKED] != -1 ) {
71  gr_set_bitmap(bmap_ids[RADIO_UP_MARKED]);
73  }
74  }
75  else { // not marked
76  if ( bmap_ids[RADIO_UP_CLEAR] != -1 ) {
77  gr_set_bitmap(bmap_ids[RADIO_UP_CLEAR]);
79  }
80  }
81  }
82  else { // down
83  if ( flag ) { // marked
84  if ( bmap_ids[RADIO_DOWN_MARKED] != -1 ) {
85  gr_set_bitmap(bmap_ids[RADIO_DOWN_MARKED]);
87  }
88  }
89  else { // not marked
90  if ( bmap_ids[RADIO_DOWN_CLEAR] != -1 ) {
91  gr_set_bitmap(bmap_ids[RADIO_DOWN_CLEAR]);
93  }
94  }
95  }
96  }
97  }
98  else {
100  gr_set_clip( x, y, w, h, GR_RESIZE_MENU );
101 
102  if (position == 0 ) {
103  ui_draw_box_out( 0, 0, w-1, h-1 );
104  offset = 0;
105  } else {
106  ui_draw_box_in( 0, 0, w-1, h-1 );
107  offset = 1;
108  }
109 
110  if (disabled_flag)
112  else if (my_wnd->selected_gadget == this)
114  else
116 
117  if (flag) {
118  gr_circle( Middle(w)+offset, Middle(h)+offset, 8, GR_RESIZE_MENU );
119  } else {
120  gr_circle( Middle(w)+offset, Middle(h)+offset, 8, GR_RESIZE_MENU );
122  gr_circle( Middle(w)+offset, Middle(h)+offset, 4, GR_RESIZE_MENU );
123  }
124 
125  if (disabled_flag)
127  else if (my_wnd->selected_gadget == this)
129  else
131 
132  if ( text ) {
133  gr_reset_clip();
134  gr_string( x+w+4, y+2, text, GR_RESIZE_MENU );
135  }
136  }
137 }
138 
139 void UI_RADIO::process(int focus)
140 {
141  int OnMe, oldposition;
142 
143  if (disabled_flag) {
144  position = 0;
145  return;
146  }
147 
148  if (my_wnd->selected_gadget == this)
149  focus = 1;
150 
151  OnMe = is_mouse_on();
152 
153  oldposition = position;
154 
155  if (B1_PRESSED && OnMe) {
156  position = 1;
157  } else {
158  position = 0;
159  }
160 
161  if (my_wnd->keypress == hotkey) {
162  position = 2;
163  my_wnd->last_keypress = 0;
164  }
165 
166  if ( focus && ((my_wnd->keypress == KEY_SPACEBAR) || (my_wnd->keypress == KEY_ENTER)) )
167  position = 2;
168 
169  if (focus)
170  if ( (oldposition == 2) && (keyd_pressed[KEY_SPACEBAR] || keyd_pressed[KEY_ENTER]) )
171  position = 2;
172 
173  pressed_down = 0;
174 
175  if (position) {
176  if ( (oldposition == 1) && OnMe )
177  pressed_down = 1;
178  if ( (oldposition == 2) && focus )
179  pressed_down = 1;
180  }
181 
182  if (pressed_down && user_function) {
183  user_function();
184  }
185 
186  if (pressed_down && (flag == 0)) {
187  UI_GADGET *tmp = (UI_GADGET *) next;
188  UI_RADIO *tmpr;
189 
190  while (tmp != this) {
191  if (tmp->kind == UI_KIND_RADIO) {
192  tmpr = (UI_RADIO *) tmp;
193  if ((tmpr->group == group) && tmpr->flag) {
194  tmpr->flag = 0;
195  tmpr->pressed_down = 0;
196  }
197  }
198 
199  tmp = tmp->next;
200  }
201 
202  flag = 1;
203  }
204 }
205 
207 {
208  return pressed_down;
209 }
210 
212 {
213  return flag;
214 }
#define vm_free(ptr)
Definition: pstypes.h:548
int hotkey
Definition: ui.h:78
GLfloat GLfloat GLfloat GLfloat h
Definition: Glext.h:7280
int is_mouse_on()
Definition: gadget.cpp:371
#define GR_RESIZE_MENU
Definition: 2d.h:684
__inline void gr_circle(int xc, int yc, int d, int resize_mode=GR_RESIZE_FULL)
Definition: 2d.h:774
UI_WINDOW * my_wnd
Definition: ui.h:111
int bmap_ids[MAX_BMAPS_PER_GADGET]
Definition: ui.h:118
__inline void gr_string(int x, int y, const char *string, int resize_mode=GR_RESIZE_FULL)
Definition: 2d.h:769
Definition: ui.h:61
#define UI_KIND_RADIO
Definition: ui.h:21
GLboolean GLuint group
Definition: Glext.h:10591
void base_create(UI_WINDOW *wnd, int _kind, int _x, int _y, int _w, int _h)
Definition: gadget.cpp:244
int changed()
Definition: radio.cpp:206
Definition: ui.h:366
void gr_set_color_fast(color *dst)
Definition: 2d.cpp:1197
void ui_draw_box_in(int x1, int y1, int x2, int y2)
Definition: uidraw.cpp:80
void gr_set_bitmap(int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha)
Definition: 2d.cpp:2105
void ui_draw_box_out(int x1, int y1, int x2, int y2)
Definition: uidraw.cpp:69
__inline void gr_set_clip(int x, int y, int w, int h, int resize_mode=GR_RESIZE_FULL)
Definition: 2d.h:741
#define gr_reset_clip
Definition: 2d.h:745
virtual void destroy()
Definition: gadget.cpp:160
GLintptr offset
Definition: Glext.h:5497
#define CWHITE
Definition: uidefs.h:25
void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state, int _group)
Definition: radio.cpp:18
UI_GADGET * next
Definition: ui.h:103
#define KEY_ENTER
Definition: key.h:125
#define CDARK_GRAY
Definition: uidefs.h:24
#define vm_strdup(ptr)
Definition: pstypes.h:549
GLint GLint GLint GLint GLint x
Definition: Glext.h:5182
int uses_bmaps
Definition: ui.h:93
#define CBRIGHT_GREEN
Definition: uidefs.h:22
#define B1_PRESSED
Definition: uidefs.h:47
int disabled_flag
Definition: ui.h:82
GLubyte GLubyte GLubyte GLubyte w
Definition: Glext.h:5679
int last_keypress
Definition: ui.h:650
int kind
Definition: ui.h:77
Definition: ui.h:584
ubyte keyd_pressed[NUM_KEYS]
Definition: key.cpp:42
#define KEY_SPACEBAR
Definition: key.h:128
void gr_bitmap(int _x, int _y, int resize_mode)
Definition: 2d.cpp:1303
#define CGREEN
Definition: uidefs.h:21
void(* user_function)(void)
Definition: ui.h:81
int checked()
Definition: radio.cpp:211
void gr_set_font(int fontnum)
Definition: font.cpp:566
int keypress
Definition: ui.h:622
int f_id
Definition: ui.h:603
GLint y
Definition: Gl.h:1505
#define Middle(x)
Definition: uidefs.h:74
UI_GADGET * selected_gadget
Definition: ui.h:610