]> icculus.org git repositories - taylor/freespace2.git/blob - include/ui.h
rendering functions mostly done; more complete shader setup
[taylor/freespace2.git] / include / ui.h
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Ui/UI.H $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Include file for our user interface.
16  *
17  * $Log$
18  * Revision 1.3  2002/06/09 04:41:15  relnev
19  * added copyright header
20  *
21  * Revision 1.2  2002/05/27 00:38:47  relnev
22  * virtual
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:12  root
25  * Initial import.
26  *
27  * 
28  * 20    8/16/99 9:45a Jefff
29  * changes to cursor management to allow a 2nd temporary cursor
30  * 
31  * 19    8/11/99 3:21p Jefff
32  * set_bmaps clarification by daveb
33  * 
34  * 18    8/11/99 12:18p Jefff
35  * added option to slider2 class to not force slider reset on
36  * set_numberItems
37  * 
38  * 17    8/10/99 6:54p Dave
39  * Mad optimizations. Added paging to the nebula effect.
40  * 
41  * 16    8/05/99 2:44p Jefff
42  * added disabled callback to UI_BUTTON
43  * 
44  * 15    6/25/99 11:59a Dave
45  * Multi options screen.
46  * 
47  * 14    6/22/99 7:03p Dave
48  * New detail options screen.
49  * 
50  * 13    5/21/99 6:45p Dave
51  * Sped up ui loading a bit. Sped up localization disk access stuff. Multi
52  * start game screen, multi password, and multi pxo-help screen.
53  * 
54  * 12    5/04/99 5:20p Dave
55  * Fixed up multiplayer join screen and host options screen. Should both
56  * be at 100% now.
57  * 
58  * 11    5/03/99 8:33p Dave
59  * New version of multi host options screen.
60  * 
61  * 10    4/29/99 2:15p Neilk
62  * fixed slider so there is an extra callback for mouse locks
63  * 
64  * 9     4/16/99 5:22p Neilk
65  * Added UI_SLIDER2 class
66  * 
67  * 8     2/21/99 6:02p Dave
68  * Fixed standalone WSS packets. 
69  * 
70  * 7     2/11/99 3:08p Dave
71  * PXO refresh button. Very preliminary squad war support.
72  * 
73  * 6     2/01/99 5:55p Dave
74  * Removed the idea of explicit bitmaps for buttons. Fixed text
75  * highlighting for disabled gadgets.
76  * 
77  * 5     12/18/98 1:13a Dave
78  * Rough 1024x768 support for Direct3D. Proper detection and usage through
79  * the launcher.
80  * 
81  * 4     12/02/98 5:47p Dave
82  * Put in interface xstr code. Converted barracks screen to new format.
83  * 
84  * 3     11/30/98 1:07p Dave
85  * 16 bit conversion, first run.
86  * 
87  * 2     10/07/98 10:54a Dave
88  * Initial checkin.
89  * 
90  * 1     10/07/98 10:51a Dave
91  * 
92  * 71    5/12/98 11:59p Dave
93  * Put in some more functionality for Parallax Online.
94  * 
95  * 70    5/11/98 5:29p Hoffoss
96  * Added mouse button mapped to joystick button support.
97  * 
98  * 69    5/05/98 1:49a Lawrance
99  * Add member function to disable processing for all gadgets in a window
100  * 
101  * 68    5/03/98 1:55a Lawrance
102  * Add function call that forces button code to skip first callback for
103  * highlighing
104  * 
105  * 67    4/17/98 12:22a Dave
106  * Bumped up MAX_TOOLTIPS from 350 to 500 so Freespace will start.
107  * 
108  * 66    4/14/98 5:07p Dave
109  * Don't load or send invalid pilot pics. Fixed chatbox graphic errors.
110  * Made chatbox display team icons in a team vs. team game. Fixed up pause
111  * and endgame sequencing issues.
112  * 
113  * 65    4/14/98 4:27p Hoffoss
114  * Changed the way tooltips render as requested.
115  * 
116  * 64    4/13/98 4:30p Hoffoss
117  * Fixed a bunch of stupid little bugs in options screen.  Also changed
118  * forced_draw() to work like it used to.
119  * 
120  * 63    4/12/98 2:09p Dave
121  * Make main hall door text less stupid. Make sure inputbox focus in the
122  * multi host options screen is managed more intelligently.
123  * 
124  * 62    4/10/98 5:36p Dave
125  * Put in user notification of illegal values in multi host options
126  * screen. Fixed server respawn ship class problem.
127  * 
128  * 61    4/10/98 4:51p Hoffoss
129  * Made several changes related to tooltips.
130  * 
131  * 60    4/09/98 7:14p Hoffoss
132  * Did some cool changes for tooltips.
133  * 
134  * 59    4/09/98 5:57p Hoffoss
135  * Added custom tooltip handler functionality for callback.
136  * 
137  * 58    4/09/98 12:12p Mike
138  * Separate versioning for demo and full versions.
139  * Fix inputbox bugs.
140  * 
141  * 57    3/30/98 6:24p Hoffoss
142  * Added the tooltip (foreign language translation of text) system.
143  * 
144  * 56    3/23/98 5:48p Hoffoss
145  * Improved listbox handling.  Most notibly the scrollbar arrows work now.
146  * 
147  * 55    3/22/98 10:50p Lawrance
148  * Allow sliders to not have end-buttons.
149  * 
150  * 54    3/10/98 4:06p Hoffoss
151  * Removed unused variables.
152  * 
153  * 53    3/09/98 5:55p Dave
154  * Fixed stats to take asteroid hits into account. Polished up UI stuff in
155  * team select. Finished up pilot info popup. Tracked down and fixed
156  * double click bug.
157  * 
158  * 52    3/02/98 3:54p Lawrance
159  * make button draw function public
160  * 
161  * 51    2/26/98 4:21p Dave
162  * More robust multiplayer voice.
163  * 
164  * 50    2/11/98 6:24p Hoffoss
165  * Fixed bug where disabled and hidden buttons give failed sound when
166  * pressed.  Shouldn't happen when they are hidden.
167  * 
168  * 49    2/09/98 10:03a Hoffoss
169  * Made first_time variable public so I can clear the stupid thing in code
170  * that I want it to be cleared in.
171  * 
172  * 48    1/26/98 6:28p Lawrance
173  * Add ability to for a button press event externally.
174  * 
175  * 47    1/23/98 5:43p Dave
176  * Finished bringing standalone up to speed. Coded in new host options
177  * screen.
178  * 
179  * 46    1/16/98 7:57p Lawrance
180  * support animating input box cursor
181  * 
182  * 45    1/15/98 5:10p Allender
183  * ton of interface changes.  chatbox in multiplayer now behaves
184  * differently than before.  It's always active in any screen that uses
185  * it.  Only non-printatble characters will get passed back out from
186  * chatbox
187  * 
188  * 44    1/14/98 6:44p Hoffoss
189  * Massive changes to UI code.  A lot cleaner and better now.  Did all
190  * this to get the new UI_DOT_SLIDER to work properly, which the old code
191  * wasn't flexible enough to handle.
192  * 
193  * 43    1/02/98 9:11p Lawrance
194  * Add button_hot() function
195  * 
196  * 42    12/22/97 5:08p Hoffoss
197  * Changed inputbox class to be able to accept only certain keys, changed
198  * pilot screens to utilize this feature.  Added to assert with pilot file
199  * saving.
200  * 
201  * 41    12/11/97 8:15p Dave
202  * Put in network options screen. Xed out olf protocol selection screen.
203  * 
204  * 40    12/10/97 3:14p Dave
205  * Added an overloaded set_mask_bmap(int) function for the UI_WINDOW
206  * 
207  * 39    12/08/97 6:22p Lawrance
208  * blink cursor on inputbox
209  * 
210  * 38    12/06/97 4:27p Dave
211  * Another load of interface and multiplayer bug fixes.
212  * 
213  * 37    11/25/97 3:51p Hoffoss
214  * Changed edit background rect position slightly.
215  * 
216  * 36    11/19/97 8:32p Hoffoss
217  * Changed UI buttons so they go back to unpressed when they are disabled.
218  * 
219  * 35    10/29/97 7:25p Hoffoss
220  * Added crude support for UI button double click checking.
221  * 
222  * 34    10/24/97 10:58p Hoffoss
223  * Made some changes to the UI code to do some things I need it to do.
224  * 
225  * 33    10/01/97 4:40p Lawrance
226  * allow process() to have key input
227  * 
228  * 32    9/18/97 10:31p Lawrance
229  * allow listbox to change text
230  * 
231  * 31    9/09/97 4:32p Dave
232  * Added sel_changed() function to UI_LISTBOX to check is the selection
233  * has changed.
234  * 
235  * 30    9/07/97 10:05p Lawrance
236  * add icon class
237  * 
238  * 29    8/30/97 12:23p Lawrance
239  * add button function to reset the status of a button
240  * 
241  * 28    8/29/97 7:33p Lawrance
242  * move cleanup code from destructor to destroy() method
243  * 
244  * 27    8/24/97 5:25p Lawrance
245  * improve drawing of buttons 
246  * 
247  * 26    8/21/97 12:13p Dave
248  * Made it possible for input box to ignore esc to lose focus.
249  * 
250  * 25    8/19/97 1:27p Dave
251  * Modified input box to allow character limitation by pixel width.
252  * Changed list box so that you can create an empty box and add items as
253  * you need to.
254  * 
255  * 24    8/18/97 5:28p Lawrance
256  * integrating sounds for when mouse goes over an active control
257  * 
258  * 23    8/17/97 2:42p Lawrance
259  * add code to have selected bitmap for buttons linger for a certain time
260  * 
261  * 22    8/15/97 8:21p Dave
262  * Modified UI_INPUTBOX so that it is possible to draw it invisibly. That
263  * is, only the text is displayed.
264  * 
265  * 21    8/14/97 5:23p Dave
266  * Added clear_all_items() to the UI_LISTBOX
267  * 
268  * 20    6/13/97 5:51p Lawrance
269  * add in support for repeating buttons
270  * 
271  * 19    6/11/97 1:32p Allender
272  * externed sort_filelist
273  * 
274  * 18    5/26/97 10:26a Lawrance
275  * get slider control working 100%
276  * 
277  * 17    5/22/97 5:36p Lawrance
278  * allowing custom art for scrollbars
279  * 
280  * 16    5/21/97 11:07a Lawrance
281  * integrate masks and custom bitmaps
282  * 
283  * 15    4/28/97 2:19p Lawrance
284  * added clear_focus() function
285  * 
286  * 14    4/22/97 10:11a John
287  * Added checkbox lists to listboxes
288  * 
289  * 13    4/15/97 3:47p Allender
290  * moved type selection of list box items into actual UI code.  Made it
291  * behave more like windows listboxes do
292  * 
293  * 12    1/28/97 4:58p Lawrance
294  * allowing hidden UI components
295  * 
296  * 11    12/23/96 2:42p Lawrance
297  * allowing keys to select list box items in the mission load screen
298  * 
299  * 10    12/04/96 3:00p John
300  * Added code to allow adjusting of HUD colors and saved it to the player
301  * config file.
302  * 
303  * 9     12/03/96 3:46p Lawrance
304  * added ability to set contents of input box
305  * 
306  * 8     12/03/96 11:29a John
307  * Made scroll buttons on listbox scroll once, then delay, then repeat
308  * when the buttons are held down.
309  * 
310  * 7     12/02/96 2:17p John
311  * Made right button drag UI gadgets around and
312  * Ctrl+Shift+Alt+F12 dumps out where they are.
313  * 
314  * 6     12/01/96 3:48a Lawrance
315  * added function set_current to UI_LISTBOX
316  * 
317  * 5     11/29/96 6:08p Lawrance
318  * enabled check-boxes to be set to a specific value outside of the
319  * create() function
320  * 
321  * 4     11/21/96 10:58a John
322  * Started adding code to drag buttons.
323  * 
324  * 3     11/18/96 4:28p Jasen
325  * making class member process return an int
326  * 
327  * 2     11/15/96 11:42a John
328  * 
329  * 1     11/14/96 6:55p John
330  *
331  * $NoKeywords: $
332  */
333
334 #ifndef _UI_H
335 #define _UI_H
336
337 #include "2d.h"
338
339 #define UI_KIND_BUTTON                          1
340 #define UI_KIND_KEYTRAP                         2
341 #define UI_KIND_CHECKBOX                        3
342 #define UI_KIND_RADIO                           4
343 #define UI_KIND_SCROLLBAR                       5
344 #define UI_KIND_LISTBOX                         6
345 #define UI_KIND_INPUTBOX                        7
346 #define UI_KIND_SLIDER                          8
347 #define UI_KIND_ICON                                    9
348 #define UI_KIND_DOT_SLIDER                      10
349 #define UI_KIND_SLIDER2                         11
350 #define UI_KIND_DOT_SLIDER_NEW  12
351
352 #define MAX_KEY_BUFFER                          32              // for listboxes
353
354 #define MAX_BMAPS_PER_GADGET            15
355
356 #define UI_INPUTBOX_FLAG_INVIS                  (1 << 0)                // don't draw the input box boarders
357 #define UI_INPUTBOX_FLAG_KEYTHRU                        (1 << 1)                // pass all keypresses through to parent
358 #define UI_INPUTBOX_FLAG_ESC_CLR                        (1 << 2)                // allow escape key to clear input box
359 #define UI_INPUTBOX_FLAG_ESC_FOC                        (1 << 3)                // escape loses focus for the input box
360 #define UI_INPUTBOX_FLAG_PASSWD                 (1 << 4)                // display all characters as special "password" characters
361 #define UI_INPUTBOX_FLAG_EAT_USED               (1 << 5)                // don't return any characters actually used by inputbox
362 #define UI_INPUTBOX_FLAG_LETTER_FIRST   (1 << 6)                // require input string to begin with a letter.
363 #define UI_INPUTBOX_FLAG_NO_LETTERS             (1 << 7)                // don't allow [a-z,A-Z] at all, no matter what
364 #define UI_INPUTBOX_FLAG_NO_NUMERALS    (1 << 8)                // don't allow [0-9] at all, no matter what
365 #define UI_INPUTBOX_FLAG_TEXT_CEN               (1 << 9)                // always draw text centered in the inputbox
366 #define UI_INPUTBOX_FLAG_NO_BACK                        (1 << 10)       // don't draw a black background rectangle
367
368 #define UI_GF_MOUSE_CAPTURED                            (1 << 31)  // gadget has all rights to the mouse
369
370 class UI_WINDOW;
371 class UI_BUTTON;
372 class UI_KEYTRAP;
373 class UI_CHECKBOX;
374 class UI_RADIO;
375 class UI_SCROLLBAR;
376 class UI_LISTBOX;
377 class UI_INPUTBOX;
378 // class UI_SLIDER;
379 class UI_DOT_SLIDER;
380 class UI_DOT_SLIDER_NEW;
381
382 class UI_GADGET
383 {
384         friend class UI_WINDOW;
385         friend class UI_BUTTON;
386         friend class UI_KEYTRAP;
387         friend class UI_CHECKBOX;
388         friend class UI_RADIO;
389         friend class UI_SCROLLBAR;
390         friend class UI_LISTBOX;
391         friend class UI_INPUTBOX;
392         // friend UI_SLIDER;
393         friend class UI_DOT_SLIDER;     
394         friend class UI_DOT_SLIDER_NEW;
395
396         protected:
397                 int kind;
398                 int hotkey;
399                 int x, y, w, h;
400                 int m_flags;
401                 void (*user_function)(void);
402                 int disabled_flag;
403                 int base_dragging;
404                 int base_drag_x, base_drag_y;
405                 int base_start_x, base_start_y;
406                 int hidden;
407
408                 // Data for supporting linking controls to hotspots
409                 int linked_to_hotspot;
410                 int hotspot_num;
411
412                 // Data for supporting bitmaps associated with different states of the control
413                 int uses_bmaps;
414                 int m_num_frames;
415 //              ubyte           *bmap_storage[MAX_BMAPS_PER_GADGET];
416
417                 void drag_with_children( int dx, int dy );
418                 void start_drag_with_children();
419                 void stop_drag_with_children();
420
421                 UI_GADGET *parent;
422                 UI_GADGET *children;
423                 UI_GADGET *prev;
424                 UI_GADGET *next;
425
426                 int is_mouse_on_children();
427                 void remove_from_family();
428                 void set_parent(UI_GADGET *_parent);
429
430                 UI_GADGET *get_next();
431                 UI_GADGET *get_prev();
432                 UI_WINDOW *my_wnd;
433                 
434                 virtual void process(int focus = 0);
435                 virtual void destroy();
436                 int check_move();
437
438         public:
439                 int bmap_ids[MAX_BMAPS_PER_GADGET];
440
441                 UI_GADGET();    // constructor
442                 virtual ~UI_GADGET();   // destructor
443
444                 void base_create( UI_WINDOW *wnd, int kind, int x, int y, int w, int h );
445                 virtual void draw();
446                 void set_focus();
447                 void clear_focus();
448                 int has_focus();
449                 void set_hotkey(int keycode);
450                 void set_callback(void (*user_function)(void));
451                 void disable();
452                 void enable(int n = 1);
453                 void capture_mouse();
454                 int mouse_captured(UI_GADGET *gadget = NULL);
455                 int disabled();
456                 int enabled();
457                 virtual void hide(int n = 1);
458                 virtual void unhide();
459                 void update_dimensions(int x, int y, int w, int h);
460                 void get_dimensions(int *x, int *y, int *w, int *h);
461                 int is_mouse_on();
462                 void get_mouse_pos(int *x, int *y);
463
464                 void link_hotspot(int num);
465                 int get_hotspot();
466                 int bmaps_used() { return uses_bmaps; }
467
468                 // loads nframes bitmaps, starting at index start_frame.
469                 // anything < start_frame will not be loaded.
470                 // this keeps the loading code from trying to load bitmaps which don't exist
471                 // and taking an unnecessary disk hit.          
472                 int set_bmaps(const char *ani_filename, int nframes = 3, int start_frame = 1);          // extracts MAX_BMAPS_PER_GADGET from .ani file         
473
474                 void reset();  // zero out m_flags
475                 int is_hidden() { return hidden; }
476 };
477
478 // xstrings for a window
479 #define UI_NUM_XSTR_COLORS                      2
480 #define UI_XSTR_COLOR_GREEN             0                       // shades of green/gray
481 #define UI_XSTR_COLOR_PINK                      1                       // pinkish hue
482 typedef struct UI_XSTR {
483         const char *xstr;                                                                               // base string
484         int xstr_id;                                                                    // xstring id   
485         int x, y;                                                                               // coords of the string
486         int clr;                                                                                        // color to use
487         int font_id;                                                                    // font id              
488         UI_GADGET *assoc;                                                               // the associated gadget
489 } UI_XSTR;
490
491 #define MAX_UI_XSTRS                                    100
492
493 // Button terminology:
494 //   Up = button is in up state (also called pressed)
495 //   Down = button is in down state (also called released)
496 //   Just pressed = button has just gone from up to down state
497 //   Just released = button has just gone from down to up state
498 //   Clicked = a trigger type effect caused by 'just pressed' event or repeat while 'down'
499 //   Double clicked = 2 'just pressed' events occuring within a short amount of time
500
501 // Button flags
502 #define BF_UP                                                   (1<<0)
503 #define BF_DOWN                                         (1<<1)
504 #define BF_JUST_PRESSED                         (1<<2)
505 #define BF_JUST_RELEASED                        (1<<3)
506 #define BF_CLICKED                                      (1<<4)
507 #define BF_DOUBLE_CLICKED                       (1<<5)
508 #define BF_HIGHLIGHTED                          (1<<6)  // button is not highlighted (ie mouse is not over)
509 #define BF_JUST_HIGHLIGHTED             (1<<7)  // button has just been highlighted, true for 1 frame
510 #define BF_IGNORE_FOCUS                         (1<<8)  // button should not use focus to accept space/enter keypresses
511 #define BF_HOTKEY_JUST_PRESSED  (1<<9)  // button hotkey was just pressed
512 #define BF_REPEATS                                      (1<<10) // if held down, generates repeating presses
513 #define BF_SKIP_FIRST_HIGHLIGHT_CALLBACK (1<<11)        // skip first callback for mouse over event
514
515 class UI_BUTTON : public UI_GADGET
516 {
517         friend class UI_SCROLLBAR;
518         // friend UI_SLIDER;
519         friend class UI_DOT_SLIDER;
520         friend class UI_DOT_SLIDER_NEW;
521
522                 char *text;
523                 int position;                   // indicates position of button (0 - up, 1 - down by mouse click 2 - down by keypress
524                 int next_repeat;                // timestamp for next repeat if held down
525                 int m_press_linger;     // timestamp for hold a pressed state animation
526                 int hotkey_if_focus;    // hotkey for button that only works if it has focus
527                 int force_draw_frame;   // frame number to draw next time (override default)
528                 int first_callback;             // true until first time callback function is called for button highlight
529
530                 // Used to index into bmap_ids[] array to locate right bitmap for button
531                 enum { B_NORMAL = 0 };
532                 enum { B_HIGHLIGHT = 1 };
533                 enum { B_PRESSED = 2 };
534                 enum { B_DISABLED = 3 };
535                 enum { B_REPEAT_TIME = 100 };  // ms
536                         
537                 void (*m_just_highlighted_function)(void);      // call-back that gets called when button gets highlighted
538                 void (*m_disabled_function)(void);                              // callback that gets called when disabled button gets pressed (sound, popup, etc)
539
540                 void frame_reset();
541                 virtual void process(int focus = 0);
542                 virtual void destroy();
543
544                 int custom_cursor_bmap;                                 // bmap handle of special cursor used on mouseovers
545                 int previous_cursor_bmap;                               // store old cursor
546                 void maybe_show_custom_cursor();                // call this in process() 
547                 void restore_previous_cursor();         // called in frame_reset()
548
549         public:
550                 virtual void draw();
551                 void set_hotkey_if_focus(int key);
552                 int pressed();                          // has it been selected (ie clicked on)
553                 int double_clicked();   // button was double clicked on
554                 int just_pressed();             // button has just been selected
555                 int just_highlighted(); // button has just had mouse go over it
556                 int button_down();              // is the button depressed?
557                 int button_hilighted(); // is the mouse over this button?
558                 void set_button_hilighted();    // force button to be highlighted
559                 void press_button();            // force button to get pressed
560                 void create(UI_WINDOW *wnd, const char *_text, int _x, int _y, int _w, int _h, int do_repeat=0, int ignore_focus = 0);
561                 void set_highlight_action( void (*user_function)(void) );
562                 void set_disabled_action( void (*user_function)(void) );
563                 void draw_forced(int frame_num);
564                 void reset_status();
565                 void reset_timestamps();
566                 void skip_first_highlight_callback();
567                 void repeatable(int yes);
568                 void set_custom_cursor_bmap(int bmap_id) { custom_cursor_bmap = bmap_id; }
569 };
570
571 class UI_KEYTRAP : public UI_GADGET
572 {
573                 int pressed_down;
574                 virtual void draw();
575                 virtual void process(int focus = 0);
576
577         public:
578                 int pressed();
579                 void create(UI_WINDOW *wnd, int hotkey, void (*user_function)(void) );
580 };
581
582 class UI_INPUTBOX : public UI_GADGET
583 {
584                 char *text;
585                 char *passwd_text;
586                 int length;
587                 int position;
588                 int oldposition;
589                 int pressed_down;
590                 int changed_flag;
591                 int flags;
592                 int pixel_limit;    // base max characters on how wide the string is (-1 to ignore) in pixels
593                 int locked;
594 //              int should_reset;
595 //              int ignore_escape;
596                 color *text_color;
597                 char *valid_chars;
598                 char *invalid_chars;
599
600                 // cursor drawing
601                 int cursor_first_frame;
602                 int cursor_nframes;
603                 int cursor_fps;
604                 int cursor_current_frame;
605                 int cursor_elapsed_time;
606
607                 int     validate_input(int chr);
608                 void    init_cursor();
609
610                 virtual void draw();
611                 virtual void process(int focus = 0);
612                 virtual void destroy();
613
614         public:
615 //              int first_time;
616
617                 void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _textlen, const char *text, int _flags = 0, int pixel_lim = -1, color *clr = NULL);
618                 void set_valid_chars(const char *vchars);
619                 void set_invalid_chars(const char *ichars);
620                 int changed();
621                 int pressed();
622                 void get_text(char *out);
623                 void set_text(const char *in);
624 };
625
626 // Icon flags
627 #define ICON_NOT_HIGHLIGHTED            (1<<0)  // icon is not highlighted (ie mouse is not over)
628 #define ICON_JUST_HIGHLIGHTED   (1<<1)  // icon has just been highlighted, true for 1 frame
629
630 class UI_ICON : public UI_GADGET
631 {
632                 char *text;
633
634                 // Used to index into bmap_ids[] array to locate right bitmap for button
635                 enum { ICON_NORMAL = 0 };
636                 enum { ICON_HIGHLIGHT = 1 };
637                 enum { ICON_SELECTED = 2 };
638                 enum { ICON_DISABLED = 3 };
639                         
640                 virtual void draw();
641                 virtual void process(int focus = 0);
642                 virtual void destroy();
643
644         public:
645                 void create(UI_WINDOW *wnd, const char *_text, int _x, int _y, int _w, int _h);
646 };
647
648 class UI_CHECKBOX : public UI_GADGET
649 {
650                 char *text;
651                 int position;
652                 int pressed_down;
653                 int flag;
654                 virtual void draw();
655                 virtual void process(int focus = 0);
656                 virtual void destroy();
657
658                 // Used to index into bmap_ids[] array to locate right bitmap for checkbox
659                 enum { CBOX_UP_CLEAR = 0 };
660                 enum { CBOX_DOWN_CLEAR = 1 };
661                 enum { CBOX_UP_MARKED = 2 };
662                 enum { CBOX_DOWN_MARKED = 3 };
663                 enum { CBOX_DISABLED_CLEAR = 4 };
664                 enum { CBOX_DISABLED_MARKED = 5 };
665
666         public:
667                 int changed();
668                 int checked();
669                 void create(UI_WINDOW *wnd, const char *_text, int _x, int _y, int _state );
670                 void set_state(int _state);
671 };
672
673 class UI_RADIO : public UI_GADGET
674 {
675                 char *text;
676                 int position;
677                 int pressed_down;
678                 int flag;
679                 int group;
680                 virtual void draw();
681                 virtual void process(int focus = 0);
682                 virtual void destroy();
683
684                 // Used to index into bmap_ids[] array to locate right bitmap for radio button
685                 enum { RADIO_UP_CLEAR = 0 };
686                 enum { RADIO_DOWN_CLEAR = 1 };
687                 enum { RADIO_UP_MARKED = 2 };
688                 enum { RADIO_DOWN_MARKED = 3 };
689                 enum { RADIO_DISABLED_CLEAR = 4 };
690                 enum { RADIO_DISABLED_MARKED = 5 };
691
692         public:
693                 int changed();
694                 int checked();
695                 void create(UI_WINDOW *wnd, const char *_text, int _x, int _y, int _state, int _group );
696 };
697
698 class UI_SCROLLBAR : public UI_GADGET
699 {
700         friend class UI_LISTBOX;
701         friend class UI_BUTTON;
702                 int horz;
703                 int start;
704                 int stop;
705                 int position;
706                 int window_size;
707                 int bar_length;
708                 int bar_position;
709                 int bar_size;
710                 UI_BUTTON up_button;
711                 UI_BUTTON down_button;
712                 int last_scrolled;
713                 int drag_x, drag_y;
714                 int drag_starting;
715                 int dragging;
716                 int moved;
717
718                 virtual void draw();
719                 virtual void process(int focus = 0);
720
721                 // Used to index into bmap_ids[] array to locate right bitmap for scrollbar
722                 enum { SB_NORMAL = 0 };
723                 enum { SB_DISABLED = 1 };
724
725         public:
726                 void create(UI_WINDOW *wnd, int _x, int _y, int _h,int _start, int _stop, int _position, int _window_size  );
727                 int getpos();
728                 int changed();
729                 void hide(int n = 1);
730                 void unhide();
731                 int get_hidden();
732                 void link_hotspot(int up_button_num, int down_button_num);
733                 int set_bmaps(const char *up_button_fname, const char *down_button_fname, const char *line_fname);
734 };
735
736 class UI_SLIDER2 : public UI_GADGET
737 {
738         friend class UI_BUTTON;
739         private:
740                 int numberItems;                                // total range
741                 int numberPositions;                    // total positions (height - bitmapbuttonheight)
742                 int currentItem;                                // current item we are on
743                 int currentPosition;                    // current position
744                 int last_scrolled;
745                 int mouse_locked;
746                 int slider_mode;                                //              
747                 UI_BUTTON sliderBackground;// invisible button to detect clicks
748                 int bitmapSliderControl;        // this is the bitmap of the slider button itself
749                 void (*upCallback)();
750                 void (*downCallback)();
751                 void (*captureCallback)();      // this is called when the mouse is released
752                 UI_BUTTON *upButton, *downButton;
753                 int slider_w, slider_h, slider_half_h;          // this is the width and height and half height of the bitmap used for the slider
754                 virtual void draw();
755                 virtual void process(int focus = 0);
756
757                 // Used to index into bmap_ids[] array to locate right bitmap for slider
758                 enum { S2_NORMAL = 0 };
759                 enum { S2_HIGHLIGHT = 1 };
760                 enum { S2_PRESSED = 2 };
761                 enum { S2_DISABLED = 3 };
762
763                 // Used for slider mode
764                 enum { S2M_ON_ME = 0 };
765                 enum { S2M_MOVING = 1 };
766                 enum { S2M_DEFAULT = 2 };
767
768         public:
769                 // create the slider
770                 void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, int _numberItems, const char *_bitmapSliderControl,
771                                                 void (*_upCallback)(), void (*_downCallback)(), void (*_captureCallback)());
772                 
773                 // range management
774                 int get_numberItems();          // return number of itmes
775                 int get_currentPosition();      // return current position
776                 int get_currentItem();          // return current item
777                 void set_numberItems(int _numberItems, int reset = 1);          // change range. maybe reset back to position 0
778                 void set_currentItem(int _currentItem);         // force slider to new position manually
779                 void force_currentItem(int _currentItem);               // force slider to new position manually, _not_ calling any callbacks
780
781                 // force down
782                 void forceDown();
783
784                 // force up
785                 void forceUp();
786
787                 // general ui commands
788                 void hide(int n = 1);
789                 void unhide();
790                 int get_hidden();
791 };
792
793 // to be phased out eventually in FS2
794 class UI_DOT_SLIDER : public UI_GADGET
795 {
796         friend class UI_BUTTON;
797
798                 UI_BUTTON button;
799                 UI_BUTTON up_button;
800                 UI_BUTTON down_button;
801                 int first_frame, total_frames;
802                 int has_end_buttons;
803                 int num_pos;
804
805         public:
806                 int pos;  // 0 thru 10
807
808                 void create(UI_WINDOW *wnd, int _x, int _y, const char *bm, int id, int end_buttons = 1, int num_pos = 10);             
809                 virtual void draw();
810                 virtual void process(int focus = 0);
811                 virtual void destroy();
812 };
813
814 class UI_DOT_SLIDER_NEW : public UI_GADGET
815 {
816         friend class UI_BUTTON;
817                 UI_BUTTON button;
818                 UI_BUTTON up_button;
819                 UI_BUTTON down_button;          
820                 int has_end_buttons;
821                 int num_pos;
822                 int dot_width;
823
824         public:
825                 int pos;  // 0 thru 10
826
827                 void create(UI_WINDOW *wnd, int _x, int _y, int num_pos, const char *bm_slider, int slider_mask,
828                                                                                                                                                                         const char *bm_left = NULL, int left_mask = -1, int left_x = -1, int left_y = -1,
829                                                                                                                                                                         const char *bm_right = NULL, int right_mask = -1, int right_x = -1, int right_y = -1,
830                                                                                                                                                                         int dot_width = 19);
831                 virtual void draw();
832                 virtual void process(int focus = 0);            
833 };
834
835 class UI_LISTBOX : public UI_GADGET
836 {
837         private:
838                 char **list;
839                 char *check_list;
840                 int max_items;
841                 int num_items;
842                 int num_items_displayed;
843                 int first_item;
844                 int old_first_item;
845                 int current_item;
846                 int selected_item;
847                 int toggled_item;
848                 int old_current_item;
849                 int last_scrolled;
850                 int dragging;
851                 int textheight;
852                 int has_scrollbar;
853                 char key_buffer[MAX_KEY_BUFFER];
854                 int key_buffer_count;
855                 int last_typed;
856                 UI_SCROLLBAR scrollbar;
857
858                 virtual void draw();
859                 virtual void process(int focus = 0);
860
861                 // Used to index into bmap_ids[] array to locate right bitmap for listbox
862                 enum { LBOX_NORMAL = 0 };
863                 enum { LBOX_DISABLED = 1 };
864
865         public:
866                 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);
867                 int selected(); // selected: Returns >= 0 if an item was selected
868                 int current();  // current:  Returns which item listbox bar is currently on. This could be -1, if none selected!                
869                 int toggled();  // toggled:  Returns which item was toggled with spacebr or mouse click of check_list is not NULL               
870                 void set_current(int _index);   // sets the current item in the list box
871                 void set_first_item(int _index);
872                 char *get_string(int _index);
873                 void clear_all_items();       // deletes all the items in the list (makes them empty strings)
874                 int add_string(char *str);
875                 int sel_changed();           // returns > 0 if the selected item has changed
876                 void set_new_list(int _numitems, char **_list);
877
878                 int set_bmaps(const char *lbox_fname, const char *b_up_fname, const char *b_down_fname, const char *sb_fname);
879                 void link_hotspot(int up_button_num, int down_button_num);
880 };
881
882 #define WIN_BORDER 1
883 #define WIN_FILLED 2
884 #define WIN_SAVE_BG 4
885 #define WIN_DIALOG (4+2+1)
886
887 class UI_WINDOW
888 {
889         friend class UI_GADGET;
890         friend class UI_BUTTON;
891         friend class UI_KEYTRAP;
892         friend class UI_CHECKBOX;
893         friend class UI_RADIO;
894         friend class UI_SCROLLBAR;
895         friend class UI_LISTBOX;
896         friend class UI_INPUTBOX;
897         // friend UI_SLIDER;
898         friend class UI_SLIDER2;
899         friend class UI_DOT_SLIDER;
900         friend class UI_DOT_SLIDER_NEW;
901         friend class UI_ICON;
902
903 protected:
904         int flags;
905         int x, y;
906         int w, h;
907         int f_id;                                                               // font id
908         int last_tooltip_hotspot;
909         uint last_tooltip_time;
910         int tt_group;  // which tooltip group this window uses, or -1 if none
911         int ignore_gadgets;
912
913         UI_GADGET *first_gadget;
914         UI_GADGET *selected_gadget;
915         UI_GADGET *mouse_captured_gadget;
916
917         int mask_bmap_id;                                               // bitmap id of the mask bitmap to define hotspots
918         int foreground_bmap_id;                         // bitmap id of the foreground bitmap to display
919         bitmap *mask_bmap_ptr;                          // pointer to bitmap of the mask
920         ushort *mask_data;                                      // points to raw mask bitmap data
921         int mask_w, mask_h;                                     // width and height of the mask
922
923         UI_XSTR *xstrs[MAX_UI_XSTRS];   // strings for drawing in code instead of in artwork
924
925
926         int keypress;           // filled in each frame
927         int keypress_text;      // filled in each frame
928         void capture_mouse(UI_GADGET *gadget = NULL);
929         void release_bitmaps();         // called internally when window destroys gadgets
930         void check_focus_switch_keys();
931         void do_dump_check();
932         void draw_xstrs();                      // draw xstrs
933         void draw_one_xstr(UI_XSTR *xstr, int frame);
934
935 public:
936         UI_WINDOW();    // constructor
937         ~UI_WINDOW();   // destructor
938         void set_mask_bmap(const char *fname);
939         void set_mask_bmap(int bmap, const char *name);
940         void set_foreground_bmap(const char *fname);
941         void create( int x, int y, int w, int h, int flags );
942         int process( int key_in = -1,int process_mouse = 1);
943         void draw();
944         void draw_tooltip();
945         void draw_XSTR_forced(UI_GADGET *owner, int frame);
946         int get_current_hotspot();
947         void destroy();
948         ushort *get_mask_data(int *w, int *h) { *w = mask_w; *h = mask_h; return mask_data; }
949         void render_tooltip(const char *str);
950         void set_ignore_gadgets(int state);
951         void add_XSTR(const char *string, int xstr_id, int x, int y, UI_GADGET *assoc, int color_type, int font_id = -1);
952         void add_XSTR(UI_XSTR *xstr);
953
954         const char *(*tooltip_handler)(const char *text);
955         int last_keypress;              // filled in each frame
956         int ttx, tty;
957         int use_hack_to_get_around_stupid_problem_flag;
958 };
959
960 // 2 extremely useful structs
961 typedef struct ui_button_info {
962         const char *filename;
963         int x, y, xt, yt;
964         int hotspot;
965         UI_BUTTON button;  // because we have a class inside this struct, we need the constructor below..
966
967         ui_button_info(const char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
968 } ui_button_info;
969
970
971 /*
972 typedef struct {
973         char *mask;
974         int start;
975         int end;
976 } tooltip_group;
977
978 typedef struct {
979         int hotspot;
980         char *text;
981 } tooltip;
982
983 #define MAX_TOOLTIP_GROUPS      50
984 #define MAX_TOOLTIPS                    500
985
986 extern int Num_tooltip_groups;
987 extern tooltip_group Tooltip_groups[MAX_TOOLTIP_GROUPS];
988 extern tooltip Tooltips[MAX_TOOLTIPS];
989 */
990
991 int ui_getfilelist( int MaxNum, char **list, char *filespec );
992 void ui_sort_filenames( int n, char **list );
993
994 /*
995 class UI_SLIDER : public UI_GADGET
996 {
997         friend UI_BUTTON;
998                 int horz;
999                 int position;
1000                 int window_size;
1001                 int fake_length;
1002                 int fake_position;
1003                 int fake_size;
1004                 UI_BUTTON left_button;
1005                 UI_BUTTON right_button;
1006                 int last_scrolled;
1007                 int drag_x, drag_y;
1008                 int drag_starting;
1009                 int dragging;
1010                 int moved;
1011
1012                 int marker_x, marker_y, marker_w, marker_h;
1013                 int n_positions, pixel_range, increment;
1014                 float start, stop, current;
1015                 int mouse_locked;
1016
1017                 virtual void draw();
1018                 virtual void process(int focus = 0);
1019
1020                 // Used to index into bmap_ids[] array to locate right bitmap for slider
1021                 enum { SLIDER_BAR_NORMAL = 0 };
1022                 enum { SLIDER_BAR_DISABLED = 1 };
1023                 enum { SLIDER_MARKER_NORMAL = 2 };
1024                 enum { SLIDER_MARKER_DISABLED = 3 };
1025
1026         public:
1027                 void create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, float _start, float _stop, float _pos, int n_positions);
1028                 int getpos();
1029                 float getcurrent();
1030                 int changed();
1031                 void hide();
1032                 void unhide();
1033                 int get_hidden();
1034                 void link_hotspot(int up_button_num, int down_button_num);
1035                 int set_bmaps(char *left_button_fname, char *right_button_fname, char *bar_fname, char *marker_fname);
1036 };
1037 */
1038
1039 #endif
1040