Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / rosace.h
blobedcf4c0a235d9b13d48ea80c215417bab4985438
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef CL_ROSACE_H
21 #define CL_ROSACE_H
24 //////////////
25 // INCLUDES //
26 //////////////
27 // Misc.
28 #include "nel/misc/types_nl.h"
29 #include "nel/misc/debug.h"
30 // Inerface 3D.
31 #include "nel/3d/u_texture.h"
32 // Std.
33 #include <string>
34 #include <vector>
35 #include <map>
38 ///////////
39 // USING //
40 ///////////
41 using NL3D::UTextureFile;
42 using std::string;
43 using std::vector;
44 using std::map;
47 ///////////
48 // CLASS //
49 ///////////
50 /**
51 * Class to manage the rosace component.
52 * \author Guillaume PUZIN
53 * \author Nevrax France
54 * \date 2001
56 class CRosaceComponent
58 public:
59 /// Callback function for the interface controls.
60 typedef void (*TFunc) (void);
62 protected:
63 /// Position X of the component (between 0-1).
64 float _X;
65 /// Position Y of the component (between 0-1).
66 float _Y;
67 /// Width of the component (between 0-1).
68 float _W;
69 /// Height of the component (between 0-1).
70 float _H;
71 /// Callback function associated.
72 TFunc _Callback;
73 /// Texture used to display the component.
74 UTextureFile *_Texture;
76 public:
77 /// Constructor
78 CRosaceComponent();
79 /// Display the component.
80 void display(bool selected);
81 /// Execute the callback associated to the component.
82 void execute();
83 /// Set the texture for the component.
84 void texture(const string &filename);
85 /// Return true if the position (x,y) is inside the rosace.
86 bool inside(float x, float y);
87 /// Set the callback function.
88 inline void callback(TFunc func) {_Callback = func;}
89 /// Set the component position.
90 inline void setPos(float x, float y) {_X = x; _Y = y;}
91 /// Get the component position.
92 inline void getPos(float &x, float &y) { x = _X; y = _Y;}
96 /**
97 * Class to manage the rosace page.
98 * \author Guillaume PUZIN
99 * \author Nevrax France
100 * \date 2001
102 class CRosacePage
104 public:
105 enum TMode
107 CursorMode,
108 CursorAngleMode,
109 RelativeMode,
110 DirectMode,
112 NbRosaceMode // Not really a mode.
115 protected:
116 typedef vector<CRosaceComponent> TComponents;
117 vector<CRosaceComponent> _Components;
119 /// Page selected.
120 sint _Selected;
121 /// Old postion X.
122 float _OldX;
123 /// Old postion Y.
124 float _OldY;
126 /// Component Width (between 0-1)
127 float _W;
128 /// Component Height (between 0-1)
129 float _H;
130 /// Component Width (in Pixel)
131 float _W_Pixel;
132 /// Component Height (in Pixel)
133 float _H_Pixel;
136 private:
137 /// Select the component under the position (x,y) or unselect all if nothing at this position.
138 void cursorMode(float x, float y);
139 /// Select a component according to the angle generated by position (x,y) and screen center.
140 void cursorAngleMode(float x, float y);
142 void relativeMode(float x, float y);
144 void directMode(float x, float y);
146 public:
147 /// Constructor
148 CRosacePage();
149 CRosacePage(sint nb);
150 /// Return the number of components in the page.
151 inline uint size() const {return (uint)_Components.size();}
152 /// Display all the components in the page.
153 void display();
154 /// Execute the callback associated to the selected component.
155 void execute();
156 /// Select the next valide component.
157 void next();
158 /// Select the previous valide component.
159 void previous();
160 /// Generate the rosace (all components).
161 void generate();
162 /// Update the page.
163 void update(float x, float y, TMode mode);
164 /// Return if the current selected component is valide.
165 inline bool valide() {return (_Selected>=0 && _Selected<(sint)size());}
167 void select(double ang);
169 /** \name Operators
170 * Operator to access to the selected component.
171 * \param comp Number of the component to access.
172 * \warning Those functions do not test if the parameter is out of range !
174 //@{
175 CRosaceComponent &operator [] (const uint &comp)
177 nlassert(comp<size());
178 return _Components[comp];
181 const CRosaceComponent &operator [] (const uint &comp) const
183 nlassert(comp<size());
184 return _Components[comp];
186 //@}
191 * Class to manage the rosace context.
192 * \author Guillaume PUZIN
193 * \author Nevrax France
194 * \date 2001
196 class CRosaceContext
198 protected:
199 typedef vector<CRosacePage> TPages;
200 vector<CRosacePage> _Pages;
202 /// Page selected.
203 sint _Selected;
205 public:
206 /// Constructor
207 CRosaceContext();
208 CRosaceContext(sint nb);
209 /// Return the number of pages in the context.
210 inline uint size() const {return (uint)_Pages.size();}
211 /// Display all the pages in the context.
212 void display();
213 /// Execute the callback associated to the selected component in the selected page.
214 void execute();
215 /// Add a page.
216 void add(const CRosacePage &page);
217 /// Update the context.
218 void update(float x, float y, CRosacePage::TMode mode);
219 /// Return if the current selected page is valide.
220 inline bool valide() {return (_Selected>=0 && _Selected<(sint)size());}
221 /// Select the next valide page.
222 void next();
223 /// Select the previous valide page.
224 void previous();
226 /** \name Operators
227 * Operator to access to the selected page.
228 * \param page Number of the page to access.
229 * \warning Those functions do not test if the parameter is out of range !
231 //@{
232 CRosacePage &operator [] (const uint &page)
234 nlassert(page<size());
235 return _Pages[page];
238 const CRosacePage &operator [] (const uint &page) const
240 nlassert(page<size());
241 return _Pages[page];
243 //@}
248 * Class to manage the rosace.
249 * \author Guillaume PUZIN
250 * \author Nevrax France
251 * \date 2001
253 class CRosace
255 protected:
256 /// Contexts in the rosace.
257 typedef map<string, CRosaceContext> TContexts;
258 TContexts _Contexts;
259 /// Mode to manage the rosace.
260 CRosacePage::TMode _Mode;
261 /// Current context.
262 string _Selected;
264 private:
265 /// Initialize the rosace.
266 void init();
268 public:
269 /// Constructor
270 CRosace();
271 /// Destructor.
272 ~CRosace();
274 /// Add a page. ("" is not valide name).
275 void add(const string &name, const CRosaceContext &context);
276 /// Is the current context valide.
277 bool valide();
278 /// Select a context.
279 void select(const string &name) {_Selected = name;}
280 /// Change the mode.
281 void mode(CRosacePage::TMode mode) {_Mode = mode;}
283 /// Display the rosace.
284 void display();
285 /// Update the rosace.
286 void update(float x, float y);
287 /// Execute the callback function corresponding to the selected component.
288 void execute();
289 /// Swap to next rosace page.
290 void swap();
294 #endif // CL_ROSACE_H
296 /* End of rosace.h */