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