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