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 #ifndef _UI_H
13 #define _UI_H
14 
15 #include "graphics/2d.h"
16 #include "graphics/font.h"
17 
18 #define UI_KIND_BUTTON				1
19 #define UI_KIND_KEYTRAP				2
20 #define UI_KIND_CHECKBOX			3
21 #define UI_KIND_RADIO				4
22 #define UI_KIND_SCROLLBAR			5
23 #define UI_KIND_LISTBOX				6
24 #define UI_KIND_INPUTBOX			7
25 #define UI_KIND_SLIDER				8
26 #define UI_KIND_ICON					9
27 #define UI_KIND_DOT_SLIDER			10
28 #define UI_KIND_SLIDER2				11
29 #define UI_KIND_DOT_SLIDER_NEW	12
30 
31 #define MAX_KEY_BUFFER				32		// for listboxes
32 
33 #define MAX_BMAPS_PER_GADGET		15
34 
35 #define UI_INPUTBOX_FLAG_INVIS			(1 << 0)		// don't draw the input box boarders
36 #define UI_INPUTBOX_FLAG_KEYTHRU			(1 << 1)		// pass all keypresses through to parent
37 #define UI_INPUTBOX_FLAG_ESC_CLR			(1 << 2)		// allow escape key to clear input box
38 #define UI_INPUTBOX_FLAG_ESC_FOC			(1 << 3)		// escape loses focus for the input box
39 #define UI_INPUTBOX_FLAG_PASSWD			(1 << 4)		// display all characters as special "password" characters
40 #define UI_INPUTBOX_FLAG_EAT_USED		(1 << 5)		// don't return any characters actually used by inputbox
41 #define UI_INPUTBOX_FLAG_LETTER_FIRST	(1 << 6)		// require input string to begin with a letter.
42 #define UI_INPUTBOX_FLAG_NO_LETTERS		(1 << 7)		// don't allow [a-z,A-Z] at all, no matter what
43 #define UI_INPUTBOX_FLAG_NO_NUMERALS	(1 << 8)		// don't allow [0-9] at all, no matter what
44 #define UI_INPUTBOX_FLAG_TEXT_CEN		(1 << 9)		// always draw text centered in the inputbox
45 #define UI_INPUTBOX_FLAG_NO_BACK			(1 << 10)	// don't draw a black background rectangle
46 
47 #define UI_GF_MOUSE_CAPTURED				(1 << 31)  // gadget has all rights to the mouse
48 
49 class UI_WINDOW;
50 class UI_BUTTON;
51 class UI_KEYTRAP;
52 class UI_CHECKBOX;
53 class UI_RADIO;
54 class UI_SCROLLBAR;
55 class UI_LISTBOX;
56 class UI_INPUTBOX;
57 // class UI_SLIDER;
58 class UI_DOT_SLIDER;
59 class UI_DOT_SLIDER_NEW;
60 
61 class UI_GADGET
62 {
63 	friend class UI_WINDOW;
64 	friend class UI_BUTTON;
65 	friend class UI_KEYTRAP;
66 	friend class UI_CHECKBOX;
67 	friend class UI_RADIO;
68 	friend class UI_SCROLLBAR;
69 	friend class UI_LISTBOX;
70 	friend class UI_INPUTBOX;
71 	// friend class UI_SLIDER;
72 	friend class UI_DOT_SLIDER;
73 	friend class UI_DOT_SLIDER_NEW;
74 
75 	protected:
76 		char *bm_filename;
77 		int kind;
78 		int hotkey;
79 		int x, y, w, h;
80 		int m_flags;
81 		void (*user_function)(void);
82 		int disabled_flag;
83 		int base_dragging;
84 		int base_drag_x, base_drag_y;
85 		int base_start_x, base_start_y;
86 		int hidden;
87 
88 		// Data for supporting linking controls to hotspots
89 		int linked_to_hotspot;
90 		int hotspot_num;
91 
92 		// Data for supporting bitmaps associated with different states of the control
93 		int uses_bmaps;
94 		int m_num_frames;
95 //		ubyte		*bmap_storage[MAX_BMAPS_PER_GADGET];
96 
97 		void drag_with_children( int dx, int dy );
98 		void start_drag_with_children();
99 		void stop_drag_with_children();
100 
101 		UI_GADGET *parent;
102 		UI_GADGET *children;
103 		UI_GADGET *prev;
104 		UI_GADGET *next;
105 
106 		int is_mouse_on_children();
107 		void remove_from_family();
108 		void set_parent(UI_GADGET *_parent);
109 
110 		UI_GADGET *get_next();
111 		UI_GADGET *get_prev();
112 		UI_WINDOW *my_wnd;
113 
114 		virtual void process(int focus = 0);
115 		virtual void destroy();
116 		int check_move();
117 
118 	public:
119 		int bmap_ids[MAX_BMAPS_PER_GADGET];
120 
121 		UI_GADGET();	// constructor
122 		virtual ~UI_GADGET();	// destructor
123 
124 		void base_create( UI_WINDOW *wnd, int kind, int x, int y, int w, int h );
125 		virtual void draw();
126 		void set_focus();
127 		void clear_focus();
128 		int has_focus();
129 		void set_hotkey(int keycode);
130 		void set_callback(void (*_user_function)(void));
131 		void disable();
132 		void enable(int n = 1);
133 		void capture_mouse();
134 		int mouse_captured(UI_GADGET *gadget = NULL);
135 		int disabled();
136 		int enabled();
137 		virtual void hide(int n = 1);
138 		virtual void unhide();
139 		void update_dimensions(int x, int y, int w, int h);
140 		void get_dimensions(int *x, int *y, int *w, int *h);
141 		int is_mouse_on();
142 		void get_mouse_pos(int *x, int *y);
143 
144 		void link_hotspot(int num);
145 		int get_hotspot();
bmaps_used()146 		int bmaps_used() { return uses_bmaps; }
147 
148 		// loads nframes bitmaps, starting at index start_frame.
149 		// anything < start_frame will not be loaded.
150 		// this keeps the loading code from trying to load bitmaps which don't exist
151 		// and taking an unnecessary disk hit.
152 		int set_bmaps(char *ani_filename, int nframes = 3, int start_frame = 1);		// extracts MAX_BMAPS_PER_GADGET from .ani file
153 
154 		void reset();  // zero out m_flags
is_hidden()155 		int is_hidden() { return hidden; }
156 };
157 
158 // xstrings for a window
159 #define UI_NUM_XSTR_COLORS			2
160 #define UI_XSTR_COLOR_GREEN		0			// shades of green/gray
161 #define UI_XSTR_COLOR_PINK			1			// pinkish hue
162 typedef struct UI_XSTR {
163 	char *xstr;										// base string
164 	int xstr_id;									// xstring id
165 	int x, y;										// coords of the string
166 	int clr;											// color to use
167 	int font_id;									// font id
168 	UI_GADGET *assoc;								// the associated gadget
169 } UI_XSTR;
170 
171 #define MAX_UI_XSTRS					100
172 
173 // Button terminology:
174 //   Up = button is in up state (also called pressed)
175 //   Down = button is in down state (also called released)
176 //   Just pressed = button has just gone from up to down state
177 //   Just released = button has just gone from down to up state
178 //   Clicked = a trigger type effect caused by 'just pressed' event or repeat while 'down'
179 //   Double clicked = 2 'just pressed' events occuring within a short amount of time
180 
181 // Button flags
182 #define BF_UP							(1<<0)
183 #define BF_DOWN						(1<<1)
184 #define BF_JUST_PRESSED				(1<<2)
185 #define BF_JUST_RELEASED			(1<<3)
186 #define BF_CLICKED					(1<<4)
187 #define BF_DOUBLE_CLICKED			(1<<5)
188 #define BF_HIGHLIGHTED				(1<<6)  // button is not highlighted (ie mouse is not over)
189 #define BF_JUST_HIGHLIGHTED		(1<<7)  // button has just been highlighted, true for 1 frame
190 #define BF_IGNORE_FOCUS				(1<<8)  // button should not use focus to accept space/enter keypresses
191 #define BF_HOTKEY_JUST_PRESSED	(1<<9)  // button hotkey was just pressed
192 #define BF_REPEATS					(1<<10) // if held down, generates repeating presses
193 #define BF_SKIP_FIRST_HIGHLIGHT_CALLBACK (1<<11)	// skip first callback for mouse over event
194 
195 class UI_BUTTON : public UI_GADGET
196 {
197 	friend class UI_SCROLLBAR;
198 	// friend class UI_SLIDER;
199 	friend class UI_DOT_SLIDER;
200 	friend class UI_DOT_SLIDER_NEW;
201 
202 		char *text;
203 		int position;			// indicates position of button (0 - up, 1 - down by mouse click 2 - down by keypress
204 		int next_repeat;		// timestamp for next repeat if held down
205 		int m_press_linger;	// timestamp for hold a pressed state animation
206 		int hotkey_if_focus;	// hotkey for button that only works if it has focus
207 		int force_draw_frame;	// frame number to draw next time (override default)
208 		int first_callback;		// true until first time callback function is called for button highlight
209 
210 		// Used to index into bmap_ids[] array to locate right bitmap for button
211 		enum { B_NORMAL = 0 };
212 		enum { B_HIGHLIGHT = 1 };
213 		enum { B_PRESSED = 2 };
214 		enum { B_DISABLED = 3 };
215 		enum { B_REPEAT_TIME = 100 };  // ms
216 
217 		void (*m_just_highlighted_function)(void);	// call-back that gets called when button gets highlighted
218 		void (*m_disabled_function)(void);				// callback that gets called when disabled button gets pressed (sound, popup, etc)
219 
220 		void frame_reset();
221 		virtual void process(int focus = 0);
222 		virtual void destroy();
223 
224 		int custom_cursor_bmap;					// bmap handle of special cursor used on mouseovers
225 		int previous_cursor_bmap;				// store old cursor
226 		void maybe_show_custom_cursor();		// call this in process()
227 		void restore_previous_cursor();		// called in frame_reset()
228 
229 	public:
230 		virtual void draw();
231 		void set_hotkey_if_focus(int key);
232 		int pressed();				// has it been selected (ie clicked on)
233 		int double_clicked();	// button was double clicked on
234 		int just_pressed();		// button has just been selected
235 		int just_highlighted();	// button has just had mouse go over it
236 		int button_down();		// is the button depressed?
237 		int button_hilighted();	// is the mouse over this button?
238 		void set_button_hilighted();	// force button to be highlighted
239 		void press_button();		// force button to get pressed
240 		void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h, int do_repeat=0, int ignore_focus = 0);
241 		void set_highlight_action( void (*_user_function)(void) );
242 		void set_disabled_action( void (*_user_function)(void) );
243 		void draw_forced(int frame_num);
244 		void reset_status();
245 		void reset_timestamps();
246 		void skip_first_highlight_callback();
247 		void repeatable(int yes);
set_custom_cursor_bmap(int bmap_id)248 		void set_custom_cursor_bmap(int bmap_id) { custom_cursor_bmap = bmap_id; };
249 };
250 
251 class UI_KEYTRAP : public UI_GADGET
252 {
253 		int pressed_down;
254 		virtual void draw();
255 		virtual void process(int focus = 0);
256 
257 	public:
258 		int pressed();
259 		void create(UI_WINDOW *wnd, int hotkey, void (*_user_function)(void) );
260 };
261 
262 class UI_USERBOX : public UI_GADGET
263 {
264 		int b1_held_down;
265 		int b1_clicked;
266 		int b1_double_clicked;
267 		int b1_dragging;
268 		int b1_drag_x1, b1_drag_y1;
269 		int b1_drag_x2, b1_drag_y2;
270 		int b1_done_dragging;
271 		int keypress;
272 		int mouse_onme;
273 		int mouse_x, mouse_y;
274 		int bitmap_number;
275 };
276 
277 class UI_INPUTBOX : public UI_GADGET
278 {
279 		char *text;
280 		char *passwd_text;
281 		int length;
282 		int position;
283 		int oldposition;
284 		int pressed_down;
285 		int changed_flag;
286 		int flags;
287 		int pixel_limit;    // base max characters on how wide the string is (-1 to ignore) in pixels
288 		int locked;
289 //		int should_reset;
290 		int ignore_escape;
291 		color *text_color;
292 		char *valid_chars;
293 		char *invalid_chars;
294 
295 		// cursor drawing
296 		int cursor_first_frame;
297 		int cursor_nframes;
298 		int cursor_fps;
299 		int cursor_current_frame;
300 		int cursor_elapsed_time;
301 
302 		int	validate_input(int chr);
303 		void	init_cursor();
304 
305 		virtual void draw();
306 		virtual void process(int focus = 0);
307 		virtual void destroy();
308 
309 	public:
310 //		int first_time;
311 
312 		void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _textlen, char *text, int _flags = 0, int pixel_lim = -1, color *clr = NULL);
313 		void set_valid_chars(char *vchars);
314 		void set_invalid_chars(char *ichars);
315 		int changed();
316 		int pressed();
317 		void get_text(char *out);
318 		void set_text(const char *in);
319 };
320 
321 // Icon flags
322 #define	ICON_NOT_HIGHLIGHTED		(1<<0)	// icon is not highlighted (ie mouse is not over)
323 #define	ICON_JUST_HIGHLIGHTED	(1<<1)	// icon has just been highlighted, true for 1 frame
324 
325 class UI_ICON : public UI_GADGET
326 {
327 		char *text;
328 
329 		// Used to index into bmap_ids[] array to locate right bitmap for button
330 		enum { ICON_NORMAL = 0 };
331 		enum { ICON_HIGHLIGHT = 1 };
332 		enum { ICON_SELECTED = 2 };
333 		enum { ICON_DISABLED = 3 };
334 
335 		virtual void draw();
336 		virtual void process(int focus = 0);
337 		virtual void destroy();
338 
339 	public:
340 		void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h);
341 };
342 
343 class UI_CHECKBOX : public UI_GADGET
344 {
345 		char *text;
346 		int position;
347 		int pressed_down;
348 		int flag;
349 		virtual void draw();
350 		virtual void process(int focus = 0);
351 		virtual void destroy();
352 
353 		// Used to index into bmap_ids[] array to locate right bitmap for checkbox
354 		enum { CBOX_UP_CLEAR = 0 };
355 		enum { CBOX_DOWN_CLEAR = 1 };
356 		enum { CBOX_UP_MARKED = 2 };
357 		enum { CBOX_DOWN_MARKED = 3 };
358 		enum { CBOX_DISABLED_CLEAR = 4 };
359 		enum { CBOX_DISABLED_MARKED = 5 };
360 
361 	public:
362 		int changed();
363 		int checked();
364 		void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state );
365 		void set_state(int _state);
366 };
367 
368 class UI_RADIO : public UI_GADGET
369 {
370 		char *text;
371 		int position;
372 		int pressed_down;
373 		int flag;
374 		int group;
375 		virtual void draw();
376 		virtual void process(int focus = 0);
377 		virtual void destroy();
378 
379 		// Used to index into bmap_ids[] array to locate right bitmap for radio button
380 		enum { RADIO_UP_CLEAR = 0 };
381 		enum { RADIO_DOWN_CLEAR = 1 };
382 		enum { RADIO_UP_MARKED = 2 };
383 		enum { RADIO_DOWN_MARKED = 3 };
384 		enum { RADIO_DISABLED_CLEAR = 4 };
385 		enum { RADIO_DISABLED_MARKED = 5 };
386 
387 	public:
388 		int changed();
389 		int checked();
390 		void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _state, int _group );
391 };
392 
393 class UI_SCROLLBAR : public UI_GADGET
394 {
395 	friend class UI_LISTBOX;
396 	friend class UI_BUTTON;
397 		int horz;
398 		int start;
399 		int stop;
400 		int position;
401 		int window_size;
402 		int bar_length;
403 		int bar_position;
404 		int bar_size;
405 		UI_BUTTON up_button;
406 		UI_BUTTON down_button;
407 		int last_scrolled;
408 		int drag_x, drag_y;
409 		int drag_starting;
410 		int dragging;
411 		int moved;
412 
413 		virtual void draw();
414 		virtual void process(int focus = 0);
415 
416 		// Used to index into bmap_ids[] array to locate right bitmap for scrollbar
417 		enum { SB_NORMAL = 0 };
418 		enum { SB_DISABLED = 1 };
419 
420 	public:
421 		void create(UI_WINDOW *wnd, int _x, int _y, int _h,int _start, int _stop, int _position, int _window_size  );
422 		int getpos();
423 		int changed();
424 		void hide();
425 		void unhide();
426 		int get_hidden();
427 		void link_hotspot(int up_button_num, int down_button_num);
428 		int set_bmaps(char *up_button_fname, char *down_button_fname, char *line_fname);
429 };
430 
431 class UI_SLIDER2 : public UI_GADGET
432 {
433 	friend class UI_BUTTON;
434 	private:
435 		int numberItems;				// total range
436 		int numberPositions;			// total positions (height - bitmapbuttonheight)
437 		int currentItem;				// current item we are on
438 		int currentPosition;			// current position
439 		int last_scrolled;
440 		int mouse_locked;
441 		int slider_mode;				//
442 		UI_BUTTON sliderBackground;// invisible button to detect clicks
443 		int bitmapSliderControl;	// this is the bitmap of the slider button itself
444 		void (*upCallback)();
445 		void (*downCallback)();
446 		void (*captureCallback)();	// this is called when the mouse is released
447 		UI_BUTTON *upButton, *downButton;
448 		int slider_w, slider_h, slider_half_h;		// this is the width and height and half height of the bitmap used for the slider
449 		virtual void draw();
450 		virtual void process(int focus = 0);
451 
452 		// Used to index into bmap_ids[] array to locate right bitmap for slider
453 		enum { S2_NORMAL = 0 };
454 		enum { S2_HIGHLIGHT = 1 };
455 		enum { S2_PRESSED = 2 };
456 		enum { S2_DISABLED = 3 };
457 
458 		// Used for slider mode
459 		enum { S2M_ON_ME = 0 };
460 		enum { S2M_MOVING = 1 };
461 		enum { S2M_DEFAULT = 2 };
462 
463 	public:
464 		// create the slider
465 		void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, int _numberItems, char *_bitmapSliderControl,
466 						void (*_upCallback)(), void (*_downCallback)(), void (*_captureCallback)());
467 
468 		// range management
469 		int get_numberItems();		// return number of itmes
470 		int get_currentPosition();	// return current position
471 		int get_currentItem();		// return current item
472 		void set_numberItems(int _numberItems, int _reset = 1);		// change range. maybe reset back to position 0
473 		void set_currentItem(int _currentItem);		// force slider to new position manually
474 		void force_currentItem(int _currentItem);		// force slider to new position manually, _not_ calling any callbacks
475 
476 		// force down
477 		void forceDown();
478 
479 		// force up
480 		void forceUp();
481 
482 		// general ui commands
483 		void hide();
484 		void unhide();
485 		int get_hidden();
486 };
487 
488 // to be phased out eventually in FS2
489 class UI_DOT_SLIDER : public UI_GADGET
490 {
491 	friend class UI_BUTTON;
492 
493 		UI_BUTTON button;
494 		UI_BUTTON up_button;
495 		UI_BUTTON down_button;
496 		int first_frame, total_frames;
497 		int has_end_buttons;
498 		int num_pos;
499 
500 	public:
501 		int pos;  // 0 thru 10
502 
503 		void create(UI_WINDOW *wnd, int _x, int _y, char *bm, int id, int end_buttons = 1, int num_pos = 10);
504 		virtual void draw();
505 		virtual void process(int focus = 0);
506 		virtual void destroy();
507 };
508 
509 class UI_DOT_SLIDER_NEW : public UI_GADGET
510 {
511 	friend class UI_BUTTON;
512 		UI_BUTTON button;
513 		UI_BUTTON up_button;
514 		UI_BUTTON down_button;
515 		int has_end_buttons;
516 		int num_pos;
517 		int dot_width;
518 
519 	public:
520 		int pos;  // 0 thru 10
521 
522 		void create(UI_WINDOW *wnd, int _x, int _y, int num_pos, char *bm_slider, int slider_mask,
523 																					char *bm_left = NULL, int left_mask = -1, int left_x = -1, int left_y = -1,
524 																					char *bm_right = NULL, int right_mask = -1, int right_x = -1, int right_y = -1,
525 																					int dot_width = 19);
526 		virtual void draw();
527 		virtual void process(int focus = 0);
528 };
529 
530 class UI_LISTBOX : public UI_GADGET
531 {
532 	private:
533 		char **list;
534 		char *check_list;
535 		int max_items;
536 		int num_items;
537 		int num_items_displayed;
538 		int first_item;
539 		int old_first_item;
540 		int current_item;
541 		int selected_item;
542 		int toggled_item;
543 		int old_current_item;
544 		int last_scrolled;
545 		int dragging;
546 		int textheight;
547 		int has_scrollbar;
548 		char key_buffer[MAX_KEY_BUFFER];
549 		int key_buffer_count;
550 		int last_typed;
551 		UI_SCROLLBAR scrollbar;
552 
553 		// kazan
554 		int draw_frame;
555 
556 		virtual void draw();
557 		virtual void process(int focus = 0);
558 
559 		// Used to index into bmap_ids[] array to locate right bitmap for listbox
560 		enum { LBOX_NORMAL = 0 };
561 		enum { LBOX_DISABLED = 1 };
562 
563 	public:
564 		void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, int _numitem, char **_list, char *_check_list = NULL, int _max_items = -1);
565 		int selected();	// selected: Returns >= 0 if an item was selected
566 		int current();	// current:  Returns which item listbox bar is currently on. This could be -1, if none selected!
567 		int toggled();	// toggled:  Returns which item was toggled with spacebr or mouse click of check_list is not NULL
568 		void set_current(int _index);	// sets the current item in the list box
569 		void set_first_item(int _index);
570 		char *get_string(int _index);
571 		void clear_all_items();       // deletes all the items in the list (makes them empty strings)
572 		int add_string(char *str);
573 		int sel_changed();           // returns > 0 if the selected item has changed
574 		void set_new_list(int _numitems, char **_list);
575 
576 		// kazan
577 		void set_drawframe(int mode);
578 		int CurSize();
579 		int MaxSize();
580 		void RemoveFirstItem();
581 		void ScrollEnd();
582 
583 		int set_bmaps(char *lbox_fname, char *b_up_fname, char *b_down_fname, char *sb_fname);
584 		void link_hotspot(int up_button_num, int down_button_num);
585 };
586 
587 #define WIN_BORDER 1
588 #define WIN_FILLED 2
589 #define WIN_SAVE_BG 4
590 #define WIN_DIALOG (4+2+1)
591 
592 class UI_WINDOW
593 {
594 	friend class UI_GADGET;
595 	friend class UI_BUTTON;
596 	friend class UI_KEYTRAP;
597 	friend class UI_CHECKBOX;
598 	friend class UI_RADIO;
599 	friend class UI_SCROLLBAR;
600 	friend class UI_LISTBOX;
601 	friend class UI_INPUTBOX;
602 	// friend class UI_SLIDER;
603 	friend class UI_SLIDER2;
604 	friend class UI_DOT_SLIDER;
605 	friend class UI_DOT_SLIDER_NEW;
606 	friend class UI_ICON;
607 
608 protected:
609 	int flags;
610 	int x, y;
611 	int w, h;
612 	int f_id;								// font id
613 	int last_tooltip_hotspot;
614 	uint last_tooltip_time;
615 	int tt_group;  // which tooltip group this window uses, or -1 if none
616 	int ignore_gadgets;
617 
618 	UI_GADGET *first_gadget;
619 	UI_GADGET *selected_gadget;
620 	UI_GADGET *mouse_captured_gadget;
621 
622 	int mask_bmap_id;						// bitmap id of the mask bitmap to define hotspots
623 	int foreground_bmap_id;				// bitmap id of the foreground bitmap to display
624 	bitmap *mask_bmap_ptr;				// pointer to bitmap of the mask
625 	ubyte *mask_data;					// points to raw mask bitmap data
626 	int mask_w, mask_h;					// width and height of the mask
627 
628 	UI_XSTR	*xstrs[MAX_UI_XSTRS];	// strings for drawing in code instead of in artwork
629 
630 
631 	int keypress;		// filled in each frame
632 	void capture_mouse(UI_GADGET *gadget = NULL);
633 	void release_bitmaps();		// called internally when window destroys gadgets
634 	void check_focus_switch_keys();
635 	void do_dump_check();
636 	void draw_xstrs();			// draw xstrs
637 	void draw_one_xstr(UI_XSTR *xstr, int frame);
638 
639 public:
640 	UI_WINDOW();	// constructor
641 	~UI_WINDOW();	// destructor
642 	void set_mask_bmap(char *fname);
643 	void set_mask_bmap(int bmap, char *name);
644 	void set_foreground_bmap(char *fname);
645 	void create( int x, int y, int w, int h, int flags, int f_id = -1 );
646 	int process( int key_in = -1,int process_mouse = 1);
647 	void draw();
648 	void draw_tooltip();
649 	void draw_XSTR_forced(UI_GADGET *owner, int frame);
650 	int get_current_hotspot();
651 	void destroy();
get_mask_data(int * w_md,int * h_md)652 	ubyte *get_mask_data(int *w_md, int *h_md) { *w_md = mask_w; *h_md = mask_h; return mask_data; }
653 	void render_tooltip(char *str);
654 	void set_ignore_gadgets(int state);
655 	void add_XSTR(char *string, int xstr_id, int x, int y, UI_GADGET *assoc, int color_type, int font_id = -1);
656 	void add_XSTR(UI_XSTR *xstr);
657 
658 	const char *(*tooltip_handler)(const char *text);
659 	int last_keypress;		// filled in each frame
660 	int ttx, tty;
661 	int use_hack_to_get_around_stupid_problem_flag;
662 };
663 
664 // 2 extremely useful structs
665 typedef struct ui_button_info {
666 	char *filename;
667 	int x, y, xt, yt;
668 	int hotspot;
669 	UI_BUTTON button;  // because we have a class inside this struct, we need the constructor below..
670 
ui_button_infoui_button_info671 	ui_button_info(char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
672 } ui_button_info;
673 
674 
675 /*
676 typedef struct {
677 	char *mask;
678 	int start;
679 	int end;
680 } tooltip_group;
681 
682 typedef struct {
683 	int hotspot;
684 	char *text;
685 } tooltip;
686 
687 #define MAX_TOOLTIP_GROUPS	50
688 #define MAX_TOOLTIPS			500
689 
690 extern int Num_tooltip_groups;
691 extern tooltip_group Tooltip_groups[MAX_TOOLTIP_GROUPS];
692 extern tooltip Tooltips[MAX_TOOLTIPS];
693 */
694 
695 int ui_getfilelist( int MaxNum, char **list, char *filespec );
696 void ui_sort_filenames( int n, char **list );
697 
698 /*
699 class UI_SLIDER : public UI_GADGET
700 {
701 	friend class UI_BUTTON;
702 		int horz;
703 		int position;
704 		int window_size;
705 		int fake_length;
706 		int fake_position;
707 		int fake_size;
708 		UI_BUTTON left_button;
709 		UI_BUTTON right_button;
710 		int last_scrolled;
711 		int drag_x, drag_y;
712 		int drag_starting;
713 		int dragging;
714 		int moved;
715 
716 		int marker_x, marker_y, marker_w, marker_h;
717 		int n_positions, pixel_range, increment;
718 		float start, stop, current;
719 		int mouse_locked;
720 
721 		virtual void draw();
722 		virtual void process(int focus = 0);
723 
724 		// Used to index into bmap_ids[] array to locate right bitmap for slider
725 		enum { SLIDER_BAR_NORMAL = 0 };
726 		enum { SLIDER_BAR_DISABLED = 1 };
727 		enum { SLIDER_MARKER_NORMAL = 2 };
728 		enum { SLIDER_MARKER_DISABLED = 3 };
729 
730 	public:
731 		void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, float _start, float _stop, float _pos, int n_positions);
732 		int getpos();
733 		float getcurrent();
734 		int changed();
735 		void hide();
736 		void unhide();
737 		int get_hidden();
738 		void link_hotspot(int up_button_num, int down_button_num);
739 		int set_bmaps(char *left_button_fname, char *right_button_fname, char *bar_fname, char *marker_fname);
740 };
741 */
742 
743 #endif
744