]> icculus.org git repositories - taylor/freespace2.git/blob - src/ui/icon.cpp
Initial revision
[taylor/freespace2.git] / src / ui / icon.cpp
1 /*
2  * $Logfile: /Freespace2/code/UI/icon.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * C++ class implementation for icon UI element
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:11  root
11  * Initial revision
12  *
13  * 
14  * 4     12/02/98 5:47p Dave
15  * Put in interface xstr code. Converted barracks screen to new format.
16  * 
17  * 3     10/13/98 9:29a Dave
18  * Started neatening up freespace.h. Many variables renamed and
19  * reorganized. Added AlphaColors.[h,cpp]
20  * 
21  * 2     10/07/98 10:54a Dave
22  * Initial checkin.
23  * 
24  * 1     10/07/98 10:51a Dave
25  * 
26  * 5     2/03/98 4:21p Hoffoss
27  * Made UI controls draw white text when disabled.
28  * 
29  * 4     1/20/98 10:36a Hoffoss
30  * Fixed optimized warnings.
31  * 
32  * 3     1/14/98 6:43p Hoffoss
33  * Massive changes to UI code.  A lot cleaner and better now.  Did all
34  * this to get the new UI_DOT_SLIDER to work properly, which the old code
35  * wasn't flexible enough to handle.
36  * 
37  * 2     9/07/97 10:05p Lawrance
38  * add icon class
39  * 
40  * 1     9/06/97 11:22p Lawrance
41  *
42  * $NoKeywords: $
43  */
44
45 #include "uidefs.h"
46 #include "ui.h"
47 #include "alphacolors.h"
48
49 // ---------------------------------------------------------------------------------------
50 // UI_ICON::create()
51 //
52 //
53 void UI_ICON::create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h)
54 {
55         if (_text)      
56                 text = strdup(_text);
57         else
58                 text = NULL;
59
60         base_create(wnd, UI_KIND_ICON, _x, _y, _w, _h);
61         m_flags = 0;
62 }
63
64 void UI_ICON::destroy()
65 {
66         if (text) {
67                 free(text);
68                 text = NULL;
69         }
70
71         UI_GADGET::destroy();
72 }
73
74 void UI_ICON::draw()
75 {
76         if (uses_bmaps) {
77                 gr_reset_clip();
78                 if (disabled_flag) {
79                         if (bmap_ids[ICON_DISABLED] != -1) {
80                                 gr_set_bitmap(bmap_ids[ICON_DISABLED]);
81                                 gr_bitmap(x,y);
82                         }
83
84                 } else if (this->is_mouse_on()) {
85                         if (B1_PRESSED) {
86                                 if (bmap_ids[ICON_SELECTED] != -1) {
87                                         gr_set_bitmap(bmap_ids[ICON_SELECTED]);
88                                         gr_bitmap(x, y);
89                                 }
90
91                         } else {
92                                 if (bmap_ids[ICON_HIGHLIGHT] != -1) {
93                                         gr_set_bitmap(bmap_ids[ICON_HIGHLIGHT]);
94                                         gr_bitmap(x, y);
95                                 }
96                         }
97
98                 } else {
99                         if (bmap_ids[ICON_NORMAL] != -1) {
100                                 gr_set_bitmap(bmap_ids[ICON_NORMAL]);
101                                 gr_bitmap(x, y);
102                         }
103                 }
104
105         } else {
106                 gr_set_font(my_wnd->f_id);
107                 gr_set_clip(x, y, w, h);
108
109                 ui_draw_box_out(0, 0, w-1, h-1);
110                 if (disabled_flag)
111                         gr_set_color_fast(&CDARK_GRAY);
112                 else 
113                         gr_set_color_fast(&CBLACK);
114
115                 if (text)
116                         ui_string_centered(Middle(w), Middle(h), text);
117
118                 gr_reset_clip();
119         }
120 }
121
122 // -----------------------------------------------------------------------
123 // process()
124 //
125 void UI_ICON::process(int focus)
126 {
127         int OnMe;
128
129         if (disabled_flag) {
130                 return;
131         }
132
133         OnMe = is_mouse_on();
134
135         if (!OnMe) {
136                 m_flags |= ICON_NOT_HIGHLIGHTED;
137
138         } else {
139                 if ( m_flags & ICON_NOT_HIGHLIGHTED ) {
140                         m_flags |= ICON_JUST_HIGHLIGHTED;
141                         // if a callback exists, call it
142                         m_flags &= ~ICON_NOT_HIGHLIGHTED;
143                 }
144         }
145 }