FS2_Open
Open source remastering of the Freespace 2 engine
slider.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 
13 #include "bmpman/bmpman.h"
14 #include "gamesnd/gamesnd.h"
15 #include "globalincs/alphacolors.h"
16 #include "io/timer.h"
18 #include "ui/ui.h"
19 #include "ui/uidefs.h"
20 
21 
22 
24 void UI_DOT_SLIDER_NEW::create(UI_WINDOW *wnd, int _x, int _y, int _num_pos, char *bm_slider, int slider_mask,
25  char *bm_left, int left_mask, int left_x, int left_y,
26  char *bm_right, int right_mask, int right_x, int right_y,
27  int _dot_width)
28 {
29  // no end buttons yet
30  has_end_buttons = 0;
31 
32  // if any of the left/right arrow information is specified, make sure its _all_ specified
33  if((bm_left != NULL) || (left_mask != -1) || (bm_right != NULL) || (right_mask != -1)){
34  Assert((bm_left != NULL) && (left_mask >= 0) && (bm_right != NULL) && (right_mask >= 0));
35  if((bm_left == NULL) || (left_mask < 0) || (bm_right == NULL) || (right_mask < 0)){
36  return;
37  }
38 
39  // now we know we have end buttons
40  has_end_buttons = 1;
41  }
42 
43  // internal stuff
44  num_pos = _num_pos;
45  base_create(wnd, UI_KIND_DOT_SLIDER_NEW, _x, _y, 0, 20);
46  pos = 0;
47  dot_width = _dot_width;
48 
49  // set bitmaps for the slider itself
50  button.create( wnd, "", _x, _y, 0, 0, 0, 1 );
51  button.set_parent(this);
52  button.link_hotspot(slider_mask);
53  button.set_bmaps(bm_slider, num_pos, 0);
54  button.hide();
55 
56  // maybe setup buttons for the arrows
57  if ( has_end_buttons ) {
58  // Second button is the up (increase) button
59  up_button.create( wnd, "", right_x, right_y, 0, 0, 1, 1 );
60  up_button.set_parent(this);
62  up_button.link_hotspot(right_mask);
63  up_button.set_bmaps(bm_right);
64 
65  // Third button is the down (decrease) button
66  down_button.create( wnd, "", left_x, left_y, 0, 0, 1, 1 );
67  down_button.set_parent(this);
69  down_button.link_hotspot(left_mask);
70  down_button.set_bmaps(bm_left);
71  }
72 }
73 
75 {
76  // draw end buttons
77  if ( has_end_buttons ) {
78  up_button.draw();
79  down_button.draw();
80  }
81 
82  // draw the proper dot
83  Assert((pos >= 0) && (pos <= num_pos));
84 
85  // for position -1, we don't draw (no dots)
86  if(pos >= 0){
87  button.unhide();
88  button.draw_forced(pos);
89  button.hide();
90  }
91 }
92 
94 {
95  if (disabled_flag) {
97  if (button.is_mouse_on() && B1_JUST_PRESSED) {
99  } else if (has_end_buttons && (up_button.is_mouse_on() || down_button.is_mouse_on())) {
101  }
102 
103 
104  if ( (hotkey >= 0) && (my_wnd->keypress == hotkey) ){
106  }
107  }
108 
109  return;
110  }
111 
112  // check focus and derived focus with one variable
113  if (my_wnd->selected_gadget == this){
114  focus = 1;
115  }
116 
117  // first check the dot area
118  button.process(focus);
119  if (button.button_down() || button.pressed() || mouse_captured()) {
120  capture_mouse(); // while we are changing level, ignore all other buttons
121 
122  pos = (ui_mouse.x - x) / dot_width;
123 
124  if (pos < 0){
125  pos = 0;
126  }
127 
128  // if we have 10 positions, 0 - 9 are valid
129  if ( pos >= num_pos ) {
130  pos = num_pos - 1;
131  }
132 
133  return;
134  }
135 
136  if ( has_end_buttons ) {
137  up_button.process(focus);
138  if (up_button.pressed()) {
139  if (pos < num_pos-1){
140  pos++;
141  } else {
143  }
144  }
145 
146  down_button.process(focus);
147  if (down_button.pressed()) {
148  if(pos){
149  pos--;
150  } else {
152  }
153  }
154  }
155 }
156 
157 //
158 // OLD DOT SLIDER - TO BE PHASED OUT. IF YOU NEED TO USE A UI_DOT_SLIDER, use a UI_DOT_SLIDER_NEW -------------------
159 //
160 
162 void UI_DOT_SLIDER::create(UI_WINDOW *wnd, int _x, int _y, char *bm, int id, int end_buttons, int _num_pos)
163 {
164  char filename[MAX_PATH_LEN];
165  int bx, by, bw, hotspot;
166 
167  has_end_buttons = end_buttons;
168 
169  if ( has_end_buttons ) {
170  bx = _x + 24;
171  by = _y + 1;
172  bw = 190;
173  hotspot = id + 1;
174  } else {
175  bx = _x;
176  by = _y;
177  bw = 80;
178  hotspot = id;
179  }
180 
181  num_pos = _num_pos;
182 
183  sprintf(filename, "%s%.2d", bm, hotspot);
184  first_frame = bm_load_animation(filename, &total_frames);
185  if (first_frame < 0) {
186  Error(LOCATION, "Could not load %s.ani\n", filename);
187  disable();
188  hide();
189  return;
190  }
191 
192  base_create(wnd, UI_KIND_DOT_SLIDER, bx, by, bw, 20);
193  pos = 0;
194 
195  // A DOT_SLIDER has up to 3 child buttons..
196 
197  by = _y;
198 
199  // First button is the region with the dots
200  button.create( wnd, "", bx, by, bw, 20, 0, 1 );
201  button.set_parent(this);
202  button.link_hotspot(hotspot);
203  button.hide();
204 
205  if ( has_end_buttons ) {
206  // Second button is the up (increase) button
207  sprintf(filename, "%s%.2d", bm, id + 2);
208  up_button.create( wnd, "", _x + 216, _y, 22, 24, 1, 1 );
209  up_button.set_parent(this);
211  up_button.set_bmaps(filename);
212  up_button.link_hotspot(id + 2);
213 
214  // Third button is the down (decrease) button
215  sprintf(filename, "%s%.2d", bm, id);
216  down_button.create( wnd, "", _x, _y, 22, 24, 1, 1 );
217  down_button.set_parent(this);
219  down_button.set_bmaps(filename);
220  down_button.link_hotspot(id);
221  }
222 }
223 
225 {
226  // release ani frames for the dots.
227  bm_release(first_frame);
228 
230 }
231 
233 {
234  if ( has_end_buttons ) {
235  up_button.draw();
236  down_button.draw();
237  }
238  Assert((pos >= 0) && (pos <= num_pos));
239  gr_set_bitmap(first_frame + pos); // draw the dot level
241 }
242 
243 void UI_DOT_SLIDER::process(int focus)
244 {
245  if (disabled_flag)
246  return;
247 
248  // check focus and derived focus with one variable
249  if (my_wnd->selected_gadget == this)
250  focus = 1;
251 
252  // first check the dot area
253  button.process(focus);
254  if (button.button_down() || button.pressed() || mouse_captured()) {
255  capture_mouse(); // while we are changing level, ignore all other buttons
256 
257  if ( has_end_buttons ) {
258  pos = (ui_mouse.x - x + 17) / 19;
259  } else {
260  pos = (ui_mouse.x - x) / 19;
261  }
262 
263  if (pos < 0){
264  pos = 0;
265  }
266 
267  if ( pos > num_pos ){
268  pos = num_pos;
269  }
270 
271  return;
272  }
273 
274  if ( has_end_buttons ) {
275  up_button.process(focus);
276  if (up_button.pressed()) {
277  if (pos < num_pos){
278  pos++;
279  } else {
281  }
282  }
283 
284  down_button.process(focus);
285  if (down_button.pressed()) {
286  if (pos){
287  pos--;
288  } else {
290  }
291  }
292  }
293 }
294 
void create(UI_WINDOW *wnd, int _x, int _y, int _num_pos, char *bm_slider, int slider_mask, char *bm_left=NULL, int left_mask=-1, int left_x=-1, int left_y=-1, char *bm_right=NULL, int right_mask=-1, int right_x=-1, int right_y=-1, int _dot_width=19)
DOT_SLIDER class down here.
Definition: slider.cpp:24
void set_highlight_action(void(*_user_function)(void))
Definition: button.cpp:375
virtual void draw()
Definition: slider.cpp:232
int pos
Definition: ui.h:493
int hotkey
Definition: ui.h:78
int is_mouse_on()
Definition: gadget.cpp:371
#define GR_RESIZE_MENU
Definition: 2d.h:684
int mouse_captured(UI_GADGET *gadget=NULL)
Definition: gadget.cpp:234
UI_WINDOW * my_wnd
Definition: ui.h:111
virtual void unhide()
Definition: gadget.cpp:217
Assert(pm!=NULL)
virtual void draw()
Definition: button.cpp:120
general failure sound for any event
Definition: gamesnd.h:297
void base_create(UI_WINDOW *wnd, int _kind, int _x, int _y, int _w, int _h)
Definition: gadget.cpp:244
#define UI_KIND_DOT_SLIDER_NEW
Definition: ui.h:29
virtual void hide(int n)
Definition: gadget.cpp:207
void gr_set_bitmap(int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha)
Definition: 2d.cpp:2105
virtual void process(int focus=0)
Definition: slider.cpp:243
int bm_release(int handle, int clear_render_targets)
Frees both a bitmap's data and it's associated slot.
Definition: bmpman.cpp:2603
int bm_load_animation(const char *real_filename, int *nframes, int *fps, int *keyframe, int can_drop_frames, int dir_type)
Loads a bitmap sequance so we can draw with it.
Definition: bmpman.cpp:1420
UI_MOUSE ui_mouse
Definition: uimouse.cpp:17
#define B1_JUST_PRESSED
Definition: uidefs.h:49
void draw_forced(int frame_num)
Definition: button.cpp:104
int set_bmaps(char *ani_filename, int nframes=3, int start_frame=1)
Definition: gadget.cpp:71
virtual void destroy()
Definition: gadget.cpp:160
int x
Definition: ui.h:79
char * filename
int pressed()
Definition: button.cpp:325
void create(UI_WINDOW *wnd, int _x, int _y, char *bm, int id, int end_buttons=1, int _num_pos=10)
DOT_SLIDER class down here.
Definition: slider.cpp:162
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
GLenum GLuint id
Definition: Glext.h:5156
int use_hack_to_get_around_stupid_problem_flag
Definition: ui.h:652
GLint GLint GLint GLint GLint x
Definition: Glext.h:5182
int x
Definition: uidefs.h:59
void _cdecl void void _cdecl Error(const char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
void capture_mouse()
Definition: gadget.cpp:225
int hidden
Definition: ui.h:86
#define MAX_PATH_LEN
Definition: pstypes.h:325
GLbyte by
Definition: Glext.h:8237
int disabled_flag
Definition: ui.h:82
void set_parent(UI_GADGET *_parent)
Definition: gadget.cpp:580
void link_hotspot(int num)
Definition: gadget.cpp:50
void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h, int do_repeat=0, int ignore_focus=0)
Definition: button.cpp:26
int button_down()
Definition: button.cpp:363
Definition: ui.h:584
#define LOCATION
Definition: pstypes.h:245
void common_play_highlight_sound()
Definition: gamesnd.cpp:1151
virtual void hide()
Definition: gadget.cpp:212
#define UI_KIND_DOT_SLIDER
Definition: ui.h:27
virtual void destroy()
Definition: slider.cpp:224
void gr_bitmap(int _x, int _y, int resize_mode)
Definition: 2d.cpp:1303
virtual void process(int focus=0)
Definition: slider.cpp:93
void gamesnd_play_iface(int n)
Definition: gamesnd.cpp:260
void disable()
Definition: gadget.cpp:432
int keypress
Definition: ui.h:622
virtual void draw()
Definition: slider.cpp:74
GLint y
Definition: Gl.h:1505
UI_GADGET * selected_gadget
Definition: ui.h:610