FS2_Open
Open source remastering of the Freespace 2 engine
icon.cpp
Go to the documentation of this file.
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 #include "globalincs/alphacolors.h"
13 #include "ui/ui.h"
14 #include "ui/uidefs.h"
15 
16 
17 
18 // ---------------------------------------------------------------------------------------
19 // UI_ICON::create()
20 //
21 //
22 void UI_ICON::create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h)
23 {
24  if (_text)
25  text = vm_strdup(_text);
26  else
27  text = NULL;
28 
29  base_create(wnd, UI_KIND_ICON, _x, _y, _w, _h);
30  m_flags = 0;
31 }
32 
33 void UI_ICON::destroy()
34 {
35  if (text) {
36  vm_free(text);
37  text = NULL;
38  }
39 
41 }
42 
43 void UI_ICON::draw()
44 {
45  if (uses_bmaps) {
46  gr_reset_clip();
47  if (disabled_flag) {
48  if (bmap_ids[ICON_DISABLED] != -1) {
49  gr_set_bitmap(bmap_ids[ICON_DISABLED]);
51  }
52 
53  } else if (this->is_mouse_on()) {
54  if (B1_PRESSED) {
55  if (bmap_ids[ICON_SELECTED] != -1) {
56  gr_set_bitmap(bmap_ids[ICON_SELECTED]);
58  }
59 
60  } else {
61  if (bmap_ids[ICON_HIGHLIGHT] != -1) {
62  gr_set_bitmap(bmap_ids[ICON_HIGHLIGHT]);
64  }
65  }
66 
67  } else {
68  if (bmap_ids[ICON_NORMAL] != -1) {
69  gr_set_bitmap(bmap_ids[ICON_NORMAL]);
71  }
72  }
73 
74  } else {
77 
78  ui_draw_box_out(0, 0, w-1, h-1);
79  if (disabled_flag)
81  else
83 
84  if (text)
86 
87  gr_reset_clip();
88  }
89 }
90 
91 // -----------------------------------------------------------------------
92 // process()
93 //
94 void UI_ICON::process(int focus)
95 {
96  int OnMe;
97 
98  if (disabled_flag) {
99  return;
100  }
101 
102  OnMe = is_mouse_on();
103 
104  if (!OnMe) {
106 
107  } else {
108  if ( m_flags & ICON_NOT_HIGHLIGHTED ) {
110  // if a callback exists, call it
111  m_flags &= ~ICON_NOT_HIGHLIGHTED;
112  }
113  }
114 }
#define vm_free(ptr)
Definition: pstypes.h:548
GLfloat GLfloat GLfloat GLfloat h
Definition: Glext.h:7280
int is_mouse_on()
Definition: gadget.cpp:371
#define GR_RESIZE_MENU
Definition: 2d.h:684
UI_WINDOW * my_wnd
Definition: ui.h:111
int bmap_ids[MAX_BMAPS_PER_GADGET]
Definition: ui.h:118
void base_create(UI_WINDOW *wnd, int _kind, int _x, int _y, int _w, int _h)
Definition: gadget.cpp:244
void gr_set_color_fast(color *dst)
Definition: 2d.cpp:1197
void gr_set_bitmap(int bitmap_num, int alphablend_mode, int bitblt_mode, float alpha)
Definition: 2d.cpp:2105
void ui_draw_box_out(int x1, int y1, int x2, int y2)
Definition: uidraw.cpp:69
__inline void gr_set_clip(int x, int y, int w, int h, int resize_mode=GR_RESIZE_FULL)
Definition: 2d.h:741
#define gr_reset_clip
Definition: 2d.h:745
virtual void destroy()
Definition: gadget.cpp:160
#define ICON_NOT_HIGHLIGHTED
Definition: ui.h:320
#define CDARK_GRAY
Definition: uidefs.h:24
#define vm_strdup(ptr)
Definition: pstypes.h:549
#define ICON_JUST_HIGHLIGHTED
Definition: ui.h:321
#define UI_KIND_ICON
Definition: ui.h:26
#define CBLACK
Definition: uidefs.h:20
GLint GLint GLint GLint GLint x
Definition: Glext.h:5182
int uses_bmaps
Definition: ui.h:93
#define B1_PRESSED
Definition: uidefs.h:47
int disabled_flag
Definition: ui.h:82
GLubyte GLubyte GLubyte GLubyte w
Definition: Glext.h:5679
int m_flags
Definition: ui.h:80
Definition: ui.h:584
void create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h)
Definition: icon.cpp:22
void gr_bitmap(int _x, int _y, int resize_mode)
Definition: 2d.cpp:1303
void ui_string_centered(int x, int y, char *s)
Definition: uidraw.cpp:28
void gr_set_font(int fontnum)
Definition: font.cpp:566
int f_id
Definition: ui.h:603
GLint y
Definition: Gl.h:1505
#define Middle(x)
Definition: uidefs.h:74