1 /***************************************************************************
2 						guimain.h    -  description
3 							-------------------
4 	begin                : march 22th, 2004
5 	copyright            : (C) 2004-2006 by Duong Khang NGUYEN
6 	email                : neoneurone @ gmail com
7 
8 	$Id: guimain.h 450 2010-11-21 19:11:43Z neoneurone $
9  ***************************************************************************/
10 
11 /***************************************************************************
12  *                                                                         *
13  *   This program is free software; you can redistribute it and/or modify  *
14  *   it under the terms of the GNU General Public License as published by  *
15  *   the Free Software Foundation; either version 2 of the License, or     *
16  *   any later version.                                                    *
17  *                                                                         *
18  ***************************************************************************/
19 
20 #ifndef _OPENCITY_GUIMAIN_H_
21 #define _OPENCITY_GUIMAIN_H_ 1
22 
23 #include "main.h"
24 #include "ui.h"
25 
26 #include "SDL_image.h"
27 
28 // Each GUIMain object has the following attributes
29 #define OC_GUIMAIN_VISIBLE    0x01		///< Is the object visible ?
30 #define OC_GUIMAIN_CLICKED    0x02		///< Has the object been clicked ?
31 #define OC_GUIMAIN_MOUSEOVER  0x04		///< Does the object have the mouse focus ?
32 
33 #define OC_GUIMAIN_BLENDING   0x40		///< Blending state for texture
34 
35 
36 //========================================================================
37 /** RGBA byte color structure.
38 	\sa OPENCITY_PALETTE
39 */
40 struct Color
41 {
42 	enum OPENCITY_COLOR {
43 		OC_BLACK,
44 		OC_RED,
45 		OC_GREEN,
46 		OC_BLUE,
47 		OC_YELLOW,
48 		OC_PINK,
49 		OC_WHITE,
50 		OC_COLOR_NUMBER
51 	};
52 
53 	GLubyte r, g, b, a;
54 };
55 
56 
57 //========================================================================
58 /** Few predefined colors
59 */
60 const Color OPENCITY_PALETTE [Color::OC_COLOR_NUMBER] =
61 {
62 	{0,     0,   0, 255},			// black
63 	{255,   0,   0, 255},			// red
64 	{0,   255,   0, 255},			// green
65 	{0,     0, 255, 255},			// blue
66 	{255, 255,   0, 255},			// yellow
67 	{255,   0, 255, 255},			// pink
68 	{255, 255, 255, 255}			// white
69 };
70 
71 
72 //========================================================================
73 /** The base interface class of all graphic user interface control.
74 	\Note Use "pctr" prefix for container pointers, "pbtn" prefix for
75 button pointers and "plbl" prefix for label pointers
76 */
77 class GUIMain : public UI {
78 public:
79 
80 //========================================================================
81 /** The default ctor. The new GUI control is not visible, the mouse over
82 state is false, and not clicked
83 */
84 	GUIMain();
85 
86 	virtual ~GUIMain();
87 
88 
89 //========================================================================
90 /** The derived classes must implement this method in order to receive
91 the "display" call from the GUIContainer
92 	\sa GUIContainer
93 */
94 	virtual void
95 	Display() const = 0;
96 
97 
98 //========================================================================
99 /** Get the GUIContainer of the control
100 	\return The constant pointer to the container of this control
101 	\sa GUIContainer
102 */
103 	GUIMain* const
GetContainer()104 	GetContainer() const {
105 		return _pctr;
106 	}
107 
108 
109 //========================================================================
110 /** Set the GUIContainer of the control to the specified one
111 	\param pguicontain The constant pointer of the new GUIContainer
112 	\sa GUIContainer
113 */
114 	void
SetContainer(GUIMain * const pguicontain)115 	SetContainer(
116 		GUIMain* const pguicontain ) {
117 		_pctr = pguicontain;
118 	}
119 
120 
121 //========================================================================
122 /** Get the 2D position of the control
123 	\param riX,riY The 2D XY coordinates of the control
124 */
125 	void
GetLocation(int & riX,int & riY)126 	GetLocation(
127 		int & riX,
128 		int & riY ) const {
129 		riX = _iX;
130 		riY = _iY;
131 	}
132 
133 
134 //========================================================================
135 /** Set the 2D position of the control
136 	\param rciX,rciY The 2D XY coordinates of the control
137 */
138 	void
SetLocation(const int & rciX,const int & rciY)139 	SetLocation(
140 		const int & rciX,
141 		const int & rciY ) {
142 		_iX = rciX;
143 		_iY = rciY;
144 	}
145 
146 
147 //========================================================================
148 /** Set the new size of the control
149 	\param rcuiW,rcuiH The width and height of the container
150 */
151 	void
SetSize(const uint & rcuiW,const uint & rcuiH)152 	SetSize(
153 		const uint& rcuiW,
154 		const uint& rcuiH ) {
155 		_uiWidth = rcuiW;
156 		_uiHeight = rcuiH;
157 	}
158 
159 
160 //========================================================================
161 /** Set the attirbute of the control
162 	\param rcubAttribute The new attribute value. You can use the bit
163 operations here.
164 */
165 	void
Set(const OC_BYTE & rcubAttribute)166 	Set(
167 		const OC_BYTE & rcubAttribute ) {
168 		_ubAttribute |= rcubAttribute;
169 	}
170 
171 
172 //========================================================================
173 /** Unset the attirbute of the control
174 	\param rcubAttribute The attributes to unset. You can use the bit
175 operations here.
176 */
177 	void
Unset(const OC_BYTE & rcubAttribute)178 	Unset(
179 		const OC_BYTE & rcubAttribute ) {
180 		_ubAttribute &= ~rcubAttribute;
181 	}
182 
183 
184 //========================================================================
185 /** Check if the specified attributes are set on the control
186 	\param rcubAttribute The attributes to test. You can use the bit
187 operations here.
188 	\return True if the specified attributes are set on the control, false
189 otherwise
190 */
191 	const bool
IsSet(const OC_BYTE & rcubAttribute)192 	IsSet(
193 		const OC_BYTE & rcubAttribute ) const {
194 		if ( (_ubAttribute & rcubAttribute) == rcubAttribute )
195 			return true;
196 		else
197 			return false;
198 	}
199 
200 
201    //========================================================================
202    //                         STATIC    METHODS
203    //========================================================================
204 
205 
206 protected:
207 	GUIMain*	_pctr;					///< points to the container of the control
208 	int 		_iX, _iY;				///< the upper left corner of the GUI control
209 	uint		_uiWidth, _uiHeight;	///< width, height
210 	OC_BYTE		_ubAttribute;			///< visible, clicked, mouseover
211 
212 };
213 
214 #endif
215 
216 
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228 
229 
230 
231 
232 
233 
234 
235 
236 
237 
238 
239 
240 
241 
242 
243 
244 
245 
246 
247