Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
text_area.h
Go to the documentation of this file.
1
/***************************************************************************
2
* text_area.h - description
3
* --------------------------
4
* begin : January 10, 2002
5
* copyright : (C) 2002 by David Ranger
6
* email : ussreliant@users.sourceforge.net
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* any later version. *
15
* *
16
***************************************************************************/
17
18
#ifndef TEXT_AREA_H
19
#define TEXT_AREA_H
20
21
//Version: 1.3 - February 27, 2002
22
//Changes:
23
//1.1 - Fixed misaligned down scroll button (FINALLY). Fixed text going past the text area (horizontal). Added multiline text areas.
24
//1.2 - Added sorting
25
//1.3 - Added DoMouse to classes. Also fixed bug where button class would always 1 for dragging
26
27
/* This class is designed to be self sufficient.
28
* The only external functions it requires that aren't provided by system libs are in glut_support.h
29
*/
30
31
//There are places where a float is converted to an int. This define takes extra steps to convert without a warning (float -> char -> int)
32
#define NO_WARNINGS
33
34
#if defined (__APPLE__) || defined (MACOSX)
35
#include <OpenGL/gl.h>
36
#include <GLUT/glut.h>
37
#else
38
#ifdef _WIN32
39
#ifndef NOMINMAX
40
#define NOMINMAX
41
#endif //tells VCC not to generate min/max macros
42
#include <windows.h>
43
#endif
44
#include <GL/gl.h>
45
#include <GL/glut.h>
46
#endif
47
48
#include "
glut_support.h
"
49
#include "
gfxlib_struct.h
"
50
51
#define DIR_TEXT "textures/gui/"
52
53
//These defines are used by the image loader
54
#define TEXT_AREA_00 "textures/gui/button_down.png"
55
#define TEXT_AREA_01 "textures/gui/button_up.png"
56
#define TEXT_AREA_02 "textures/gui/corner_top_left.png"
57
#define TEXT_AREA_03 "textures/gui/corner_top_right.png"
58
#define TEXT_AREA_04 "textures/gui/corner_bottom_left.png"
59
#define TEXT_AREA_05 "textures/gui/corner_bottom_right.png"
60
#define TEXT_AREA_06 "textures/gui/highlight_button_up.png"
61
#define TEXT_AREA_07 "textures/gui/highlight_button_down.png"
62
#define TEXT_AREA_08 "textures/gui/horizontal.png"
63
#define TEXT_AREA_09 "textures/gui/left_side.png"
64
#define TEXT_AREA_10 "textures/gui/right_side.png"
65
#define TEXT_AREA_11 "textures/gui/scrollbar.png"
66
#define TEXT_AREA_12 "textures/gui/highlight_scrollbar.png"
67
#define TEXT_AREA_13 "textures/gui/horizontal_end.png"
68
69
//These defines are used by the class functions to locate the texture in the array (above)
70
#define IMG_BUTTON_DOWN 0
71
#define IMG_BUTTON_UP 1
72
#define IMG_CORNER_TOP_LEFT 2
73
#define IMG_CORNER_TOP_RIGHT 3
74
#define IMG_CORNER_BOTTOM_LEFT 4
75
#define IMG_CORNER_BOTTOM_RIGHT 5
76
#define IMG_HIGHLIGHT_BUTTON_UP 6
77
#define IMG_HIGHLIGHT_BUTTON_DOWN 7
78
#define IMG_HIGHLIGHT_SCROLLBAR 12
79
#define IMG_TOP 8
80
#define IMG_BOTTOM 8
81
#define IMG_LEFT_SIDE 9
82
#define IMG_RIGHT_SIDE 10
83
#define IMG_SCROLLBAR 11
84
#define IMG_END 13
85
86
class
TextArea
87
{
88
public
:
TextArea
(
void
);
89
TextArea
(
float
x
,
float
y
,
float
wid,
float
hei,
int
scrollbar );
90
~TextArea
(
void
);
91
int
GetSelectedItem
()
92
{
93
return
cur_selected;
94
}
95
void
SetSelectedItem
(
int
newh )
96
{
97
cur_selected = newh;
98
}
99
void
DoHighlight
(
int
yes );
//DoHighlight(0) to disable mouse highlighting. Also disable clicking on entries
100
void
DoMultiline
(
int
yes )
101
{
102
do_multiline = yes;
103
}
//DoMultiline(1) to enable multi-line entries
104
void
Refresh
(
void
);
105
void
RenderText
(
void
);
106
void
AddTextItem
(
const
char
*name,
const
char
*description,
const
char
*parent_name = NULL,
const
GFXColor
col =
GFXColor
(
107
1,
108
1,
109
1,
110
1 ) );
111
void
ChangeTextItem
(
const
char
*name,
const
char
*description,
bool
wrap =
false
);
112
void
ChangeTextItemColor
(
const
char
*name,
const
GFXColor
&col );
113
void
SetText
(
const
char
*text );
//Sets the text. Enables Multiline and disables highlighting
114
void
ClearList
(
void
);
115
//Returns the char of the currently selected item. NULL if nothing is selected
116
char
*
GetSelectedItemName
(
void
);
117
char
*
GetSelectedItemDesc
(
void
);
118
void
SortList
(
void
);
119
120
//Returns 1 if the click is inside the text area. 0 if it's outside. Same thing for movement
121
//The class requires you convert the x,y co-ordinate to a -1 to 1 float. The class doesn't know the screen dimensions
122
int
MouseClick
(
int
button,
int
state,
float
x,
float
y );
123
int
MouseMove
(
float
x,
float
y );
124
//Mouse movement while the button is clicked
125
int
MouseMoveClick
(
float
x,
float
y );
126
127
//type: 1 is click
128
//2 is drag
129
//3 is movement
130
int
DoMouse
(
int
type,
float
x,
float
y,
int
button,
int
state );
131
132
private
:
133
//Flag that enables/disables the scrollbar (It is not shown if it is disabled). This includes the scroll buttons
134
char
has_scrollbar;
135
136
//Flags that enable/disable Highlighting and Mutli-line text
137
char
do_highlight;
138
char
do_multiline;
139
140
//Array is as follows:
141
//Entire box (the border), top scroll button, buttom scroll button, entire scrollbar, active scrollbar, text area
142
float
xcoord[6];
143
float
ycoord[6];
144
float
width[6];
145
float
height[6];
146
147
//Percentage of space to allocate for the border. [0] is the thin part, [1] is the scrollbar area (right side)
148
float
ratio[2];
149
150
//Ratios for the top and button buttons (proportional x,y, height, and width values)
151
float
button_ratio[4];
152
153
//Ratios for the scroll bar area (proportional x,y, height, and width values)
154
float
scrollbar_ratio[4];
155
156
//Amount of space to display between lines
157
float
text_spacing;
158
159
//Amout of space to allocate to the horizontal bar for each level of text (expanding trees)
160
float
horizontal_per_level;
161
162
//Amount of space between the text and the top/bottom border
163
float
horizontal_spacer;
164
165
//Amount of space to the left of text to have the vertical bar
166
float
vertical_left_of_text;
167
168
//Size of the font. The float version is to prevent rounding errors in calculations
169
int
font_size;
170
float
font_size_float;
171
172
//The number of lines of text we can display at once
173
float
max_lines;
174
175
//0 for no button clicked, 1 for top button, 2 for bottom button, 3 for scrollbar, 4 for above scrollbar, 5 for below scrollbar
176
char
button_pressed;
177
178
//The currently highlighted item
179
int
cur_highlighted;
180
181
//The number of items in our list
182
int
item_count;
183
184
//The currently selected number
185
int
cur_selected;
186
187
//The number of the first item in the visible area
188
int
top_item_number;
189
190
//The number of items to jump when clicking in the passive area of the scrollbar
191
int
page_size;
192
193
//This stores the y coord of where the mouse was when it started dragging the scrollbar
194
float
scroll_start;
195
196
//This stores the current y axes of the mouse while scrolling
197
float
scroll_cur;
198
199
//Linked list of items that will appear if the text area is a select box (doubles as an expanding tree)
200
class
TextAreaItem
*ItemList;
201
202
//Check if that x,y co-ordinate is inside us
203
int
Inside
(
float
x,
float
y,
int
group );
204
void
LoadTextures
(
void
);
205
void
RenderTextItem(
TextAreaItem
*current,
int
level
);
206
207
int
LocateCount(
float
y );
208
209
//Highlighted text (mouse over, selected item) will only occur at a Refresh()
210
void
HighlightCount(
int
count,
int
type );
211
212
void
DisplayScrollbar(
void
);
213
char
*
GetSelectedItem
(
int
type );
214
215
//Takes a line and puts them in as seperate items (line wrapping)
216
void
ChompIntoItems(
const
char
*text,
const
char
*
parent
);
217
};
218
219
//Keep everything public so the TextArea class can get faster access to the elements in this class
220
class
TextAreaItem
221
{
222
public
:
223
//TextAreaItem(void);
224
//parent_class is NULL for the master TextAreaItem
225
TextAreaItem
(
const
char
*new_name =
"blank"
,
const
char
*desc =
""
,
TextAreaItem
*parent_class = 0 );
226
~TextAreaItem
(
void
);
227
228
//A recursive function. This function will be called to all the children until one of them matches the search_name
229
//If no match is found, it will use the main tree.
230
TextAreaItem
*
FindChild
(
const
char
*search_name );
231
TextAreaItem
*
FindCount
(
int
count,
int
cur );
232
233
void
AddChild
(
const
char
*new_name,
const
char
*desc,
const
GFXColor
col
=
GFXColor
( 1, 1, 1, 1 ) );
234
void
ExpandTree
(
void
);
235
void
Sort
(
void
);
236
GFXColor
col
;
237
char
*
name
;
238
char
*
description
;
239
240
//The size of the array is 10 * child_count_multiplier. Allows for an expanding array
241
int
child_count_multiplier
;
242
int
child_count
;
243
TextAreaItem
**
child
;
244
245
TextAreaItem
*
parent
;
246
247
//seems to be unused, except for the constructor...
248
//int expanded;
249
};
250
251
void
LoadTextures
(
void
);
252
253
#endif //TEXT_AREA_H
254
src
gui
text_area.h
Generated on Fri May 29 2015 23:07:33 for Vegastrike 0.5.1 rc1 by
1.8.4