File: LabelGL.h

package info (click to toggle)
transcend 0.3.dfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,768 kB
  • sloc: cpp: 26,891; ansic: 693; sh: 210; makefile: 96; perl: 67
file content (141 lines) | stat: -rw-r--r-- 2,422 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Modification History
 *
 * 2001-October-13	Jason Rohrer
 * Created.
 *
 * 2001-October-29	Jason Rohrer
 * Added a missing destructor.
 */
 
 
#ifndef LABEL_GL_INCLUDED
#define LABEL_GL_INCLUDED 

#include "GUIComponentGL.h"
#include "TextGL.h"



/**
 * A text label for OpenGL-based GUIs.
 *
 * @author Jason Rohrer
 */
class LabelGL : public GUIComponentGL {


	public:



		/**
		 * Constructs a label.
		 *
		 * @param inAnchorX the x position of the upper left corner
		 *   of this component.
		 * @param inAnchorY the y position of the upper left corner
		 *   of this component.
		 * @param inWidth the width of this component.
		 * @param inHeight the height of this component.
		 * @param inString the text to display in this label.
		 *    Is copied internally, so must be destroyed
		 *    by caller if not const.
		 * @param inText the text object to use when drawing
		 *   this label.  Must be destroyed by caller after
		 *   this class is destroyed.
		 */
		LabelGL(
			double inAnchorX, double inAnchorY, double inWidth,
			double inHeight, char *inString, TextGL *inText );



		~LabelGL();

		
		
		/**
		 * Sets the text displayed by this label.
		 *
		 * @param inString the text to display in this label.
		 *    Is copied internally, so must be destroyed
		 *    by caller if not const.
		 */
		void setText( char *inString );


		
		/**
		 * Gets the text displayed by this label.
		 *
		 * @return the text to display in this label.
		 *    Must not be destroyed or modified by caller.
		 */
		char *getText();


		
		// override fireRedraw in GUIComponentGL
		virtual void fireRedraw();


		
	protected:
		TextGL *mText;

		char *mString;
	};



inline LabelGL::LabelGL(
	double inAnchorX, double inAnchorY, double inWidth,
	double inHeight, char *inString, TextGL *inText )
	: GUIComponentGL( inAnchorX, inAnchorY, inWidth, inHeight ),
	  mText( inText ), mString( NULL ) {

	setText( inString );
	}



inline LabelGL::~LabelGL() {
	if( mString != NULL ) {
		delete [] mString;
		}
	}



inline void LabelGL::setText( char *inString ) {
	if( mString != NULL ) {
		delete [] mString;
		}
	int length = strlen( inString ) + 1;
	
	mString = new char[ length ];

	memcpy( mString, inString, length );
	}



inline char *LabelGL::getText() {
	return mString;
	}


		
inline void LabelGL::fireRedraw() {
	
	mText->drawText( mString, mAnchorX, mAnchorY,
					 mWidth, mHeight );
	}



#endif