Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interfaces_manager / osd.h
blob92a0206e6e1f74611e2ee9461f740455d6972090
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/>.
19 #ifndef CL_OSD_H
20 #define CL_OSD_H
23 /////////////
24 // Include //
25 /////////////
26 // Misc
27 #include "nel/misc/types_nl.h"
28 #include "nel/misc/ucstring.h"
29 #include "nel/misc/rgba.h"
30 // Client
31 #include "control.h"
32 #include "pen.h"
33 // Std
34 #include <map>
35 #include <fstream>
38 ///////////
39 // Using //
40 ///////////
41 using NLMISC::CRGBA;
42 using std::map;
43 using std::ifstream;
46 /**
47 * Class to manage an OSD (On Screen Display = Kind of window) for the interfaces.
48 * \author Guillaume PUZIN
49 * \author Nevrax France
50 * \date 2001
52 class COSD
54 public:
55 enum ECursor
57 Cur_None = 0,
58 Cur_Move, // Move
59 Cur_Resize, // Resize
60 Cur_Resize_TL, // Resize Top Left
61 Cur_Resize_T, // Resize Top
62 Cur_Resize_TR, // Resize Top Right
63 Cur_Resize_R, // Resize Right
64 Cur_Resize_BR, // Resize Bottom Right
65 Cur_Resize_B, // Resize Bottom
66 Cur_Resize_BL, // Resize Bottom Left
67 Cur_Resize_L, // Resize Left
70 enum TMode
72 none = 0,
73 selected,
74 resizable,
75 movable,
76 locked,
77 blocked
80 enum TResize
82 no_resize = 0,
84 resize_B,
85 resize_T,
86 resize_R,
87 resize_L,
89 resize_BL,
90 resize_TL,
91 resize_BR,
92 resize_TR,
94 resize_move
97 enum TBG // BG = Background.
99 BG_none = 0, // NO BG.
100 BG_plain, // BG is only made with 1 color (RGBA).
101 BG_stretch // BG is a Bitmap and 1 color (RGBA).
104 enum TTB // TB = Title Bar.
106 TB_none = 0, // NO TB.
107 TB_plain, // TB is only made with 1 color (RGBA).
108 TB_stretch // TB is a Bitmap and 1 color (RGBA).
111 private:
112 typedef std::map<uint, CControl *> TMapControls;
113 typedef std::list<CControl *> TListControl;
115 /// Map to find a control with the Id.
116 TMapControls _Controls;
117 /// The list of control in order to display.
118 TListControl _Children;
121 /// Initialize the button (1 function called for all constructors -> easier).
122 inline void init(uint id,float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel, float minWidth, float minHeight, bool popUp = false);
124 void getText(uint idCtrl);
125 void getCapture(uint idCtrl);
126 void getButton(uint idCtrl);
127 void getRadioButton(uint idCtrl);
128 void getRadioController(uint idCtrl);
130 void getBitmap(uint idCtrl);
131 void getList(uint idCtrl);
132 void getMultiList(uint idCtrl);
133 void getChatBox(uint idCtrl);
134 void getChatInput(uint idCtrl);
135 void getChoiceList(uint idCtrl);
136 void getCandidateList(uint idCtrl);
137 void getHorizontalList(uint idCtrl);
138 void getControlList(uint idCtrl);
139 void getSpellList(uint idCtrl);
140 void getProgressBar(uint idCtrl);
141 void getCastingBar(uint idCtrl);
142 void getBrickControl(uint idCtrl);
144 /// Resize the Left border of the OSD.
145 void resizeL(float x, float y);
146 /// Resize the Right border of the OSD.
147 void resizeR(float x, float y);
148 /// Resize the Bottom border of the OSD.
149 void resizeB(float x, float y);
150 /// Resize the Top border of the OSD.
151 void resizeT(float x, float y);
152 /// Move the OSD.
153 void move(float x, float y);
155 /// Function to test if a coordinate is in the rect.
156 bool testInRect(float x, float y, float rectX0, float rectY0, float rectX1, float rectY1);
158 /// Calculate a position according to the origin.
159 void calculatePos(float &x, float &y, CControl::THotSpot origin);
161 /// Calculate the Display X, Y, Width, Height.
162 void calculateDisplay();
164 /// Function to draw the background according to the mode.
165 void drawBG();
166 /// Function to draw the Title Bar according to the mode.
167 void drawTB();
168 /// Draw the resize borders.
169 void drawBorders(float bSizeW, float bSizeH, float x0, float y0, float x1, float y1, const CRGBA &color);
170 /// Draw a text with all information needed.
171 void drawText(float x, float y, const ucstring &text, const CPen &pen);
173 /// Test the mode of the OSD.
174 void testMode(float x, float y, float rectX0, float rectY0, float rectX1, float rectY1);
175 /// Determine the Resize Mode.
176 bool resizeMode(float x, float y);
178 protected:
179 /// the 'ID' fo the OSD (as defined for the interface manager)
180 uint _Id;
182 /// boolean indicating if the OSD is a 'pop-up' window, in this case, a click outside the window close that window
183 bool _PopUp;
185 /// Position of the OSD (between 0-1).
186 float _X;
187 float _Y;
188 /// Position of the OSD (in Pixel).
189 float _X_Pixel;
190 float _Y_Pixel;
192 /// Minimum values for window size
193 float _W_Min;
194 float _H_Min;
197 /// Display Position of the Control (between 0-1).
198 float _X_Display;
199 float _Y_Display;
201 /// Width and Height (between 0-1).
202 float _W;
203 float _H;
204 /// Width and Height (in pixel).
205 float _W_Pixel;
206 float _H_Pixel;
207 /// Display Width and Height of the Control (between 0-1).
208 float _W_Display;
209 float _H_Display;
211 /// Variables to know the offset between the click position and the OSD borders.
212 float _OffsetX;
213 float _OffsetY;
214 float _OffsetW;
215 float _OffsetH;
217 /// Is the OSD Visible.
218 bool _Show;
220 /** \name OSD
221 * Variables to manage the OSD.
223 //@{
224 /// How to display the OSD.
225 TMode _OSD_Mode;
226 /// Name of the OSD.
227 ucstring _OSD_Name;
228 /// Function called each update (every frame in most case).
229 uint _OSD_Update_Func;
230 //@}
232 /** \name Background
233 * Variables to manage the background of the OSD.
235 //@{
236 /// Display mode for the background.
237 TBG _BG_Mode;
238 /// Id of the texture for the background.
239 uint _BG;
240 /// Color of the Background.
241 CRGBA _BG_Color;
242 //@}
244 /** \name Title Bar
245 * Variables to manage the Title Bar of the OSD.
247 //@{
248 /// Display mode for the Title Bar.
249 TTB _TB_Mode;
250 /// Id of the texture for the Title BAr.
251 uint _TB;
252 /// Color of the Title Bar.
253 CRGBA _TB_Color;
254 /// Height of the Title Bar (in Pixel).
255 float _TB_H;
256 /// Display Height of the Title Bar.
257 float _TB_H_Display;
258 /// Pen of the Title Bar.
259 CPen _TB_Pen;
260 //@}
262 /** \name HighLight
263 * Variables to manage the HighLight of the OSD.
265 //@{
266 /// Color of the HighLight.
267 CRGBA _HL_Color;
268 /// HighLight Size (in Pixel).
269 float _HL_Size;
270 /// HighLight Size for the width (between 0-1).
271 float _HL_W;
272 /// HighLight Size for the height (between 0-1).
273 float _HL_H;
274 //@}
276 /** \name Resize
277 * Variables to manage the Resize of the OSD.
279 //@{
280 /// Resize Mode.
281 TResize _RS_Mode;
282 /// Resize borders Color
283 CRGBA _RS_Color;
284 /// Resize size (in pixel).
285 float _RS_Size;
286 /// Resize Size for the width (between 0-1).
287 float _RS_W;
288 /// Resize Size for the height (between 0-1).
289 float _RS_H;
290 //@}
292 ECursor _Cursor;
294 public:
295 /// Constructor
296 COSD(bool popUp = false);
297 COSD(uint Id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel, float minWidth, float minHeight, bool popUp = false);
298 /// Destructor
299 ~COSD();
301 /// The OSD size has changed -> resize controls.
302 void resize(uint32 width, uint32 height);
303 /// Update the OSD (for timers, etc.).
304 bool update(float x, float y, bool fullUse);
305 /// Display the OSD.
306 void display();
309 * Return the cursor used by the OSD at the moment.
310 * \return ECursor : 'Cur_None' if no cursor needed for the OSD.
311 * \warning This method should be called after the update one to be up to date.
313 ECursor cursor();
315 /// Manage the mouse click.
316 void click(float x, float y, bool &taken);
318 /// Manage the mouse right click.
319 void clickRight(float x, float y, bool &taken);
322 /// Add a control.
323 void addChild(uint idCtrl, CControl *ctrl);
324 /// Delete a control by the Id.
325 void delChild(uint idCtrl);
327 /// remove ctrl from children list (but not from control list)
328 void removeFromChildren(uint idCtrl);
330 /// Return the pointer of the control "id" or 0 if the control "id" doesn't exit.
331 CControl *getCtrl(uint id);
333 /// Load the OSD script.
334 void open(ifstream &file);
337 /** \name SHOW/HIDE
338 * Functions to show/hide the OSD.
340 //@{
342 * This function return if the OSD is visible or not .
343 * \return bool : true if the OSD is visible.
345 inline bool show() const {return _Show;}
347 * This function set if the OSD is visible or not .
348 * \param s : false to hide the OSD.
350 inline void show(bool s) {_Show = s;}
351 //@}
354 /** \name OSD
355 * Functions to manage the OSD.
357 //@{
358 /// Change the OSD Position (between O-1).
359 void osdSetPosition(float x, float y);
360 /// Return the OSD Position (between O-1).
361 void osdGetPosition(float &x, float &y) const ;
362 /// Change the OSD Size (in Pixel).
363 void osdSetSize(float w, float h);
364 /// Return the OSD Size (in Pixel).
365 void osdGetSize(float &w, float &h) const ;
366 /// Change the OSD Mode (locked, resize, selected, etc.)
367 void osdMode(TMode osdMode);
368 /// Return the current OSD Mode.
369 TMode osdMode() const ;
370 /// Change the OSD Name.
371 void osdName(const ucstring &osdName);
372 /// Return the OSD Name.
373 ucstring osdName() const;
374 /// Set the update Function.
375 void osdUpdateFunc(uint osdUpdateFunc);
376 /// Get the update Function.
377 uint osdUpdateFunc() const ;
378 uint getId() const { return _Id; }
379 //@}
381 /** \name Background
382 * Functions to manage the background.
384 //@{
385 /// Set the Background display mode.
386 void bgMode(TBG mode);
387 /// Get the Background display mode.
388 TBG bgMode() const ;
389 /// Set the texture Id for the Background.
390 void bg(uint b);
391 /// Get background Id.
392 uint bg() const ;
393 /// Set the Background RGBA.
394 void bgColor(const CRGBA &bRGBA);
395 /// Get the background RGBA.
396 CRGBA bgColor() const ;
397 //@}
399 /** \name Title Bar
400 * Functions to manage the Title Bar.
402 //@{
403 /// Set the Title Bar display mode.
404 void tbMode(TTB mode);
405 /// Get the Title Bar display mode.
406 TTB tbMode() const ;
407 /// Set the texture Id for the Title Bar.
408 void tb(uint t);
409 /// Get Title Bar Id.
410 uint tb() const ;
411 /// Set the Title Bar RGBA.
412 void tbColor(const CRGBA &tRGBA);
413 /// Get the Title Bar RGBA.
414 CRGBA tbColor() const ;
415 /// Set Title Bar Height (in Pixel)
416 void tbHeight(float height);
417 /// Get Title Bar Height (in Pixel)
418 float tbHeight() const;
419 /// Set the Pen for the Title Bar.
420 void tbPen(const CPen &pen);
421 /// Get the Pen of the Title Bar.
422 CPen tbPen() const ;
423 //@}
425 /** \name HighLight
426 * Functions to manage the HighLight.
428 //@{
429 /// Set the HighLight Color.
430 void hlColor(const CRGBA &hlColor);
431 /// Get the HighLight Color.
432 CRGBA hlColor() const ;
433 /// Set the HighLight Size (in Pixel).
434 void hlSize(float hlSize);
435 /// Get the HighLight Size (in Pixel).
436 float hlSize() const ;
437 //@}
439 /** \name Resize
440 * Functions to manage the Resize of the OSD.
442 //@{
443 /// Set the Resize Mode.
444 void rsMode(TResize rsMode);
445 /// Get the Resize Mode.
446 TResize rsMode() const ;
447 /// Set Resize borders Color
448 void rsColor(CRGBA rsColor);
449 /// Get Resize borders Color
450 CRGBA rsColor() const ;
451 /// Set Resize size (in pixel).
452 void rsSize(float rsSize);
453 /// Get Resize size (in pixel).
454 float rsSize() const ;
455 //@}
461 #endif // CL_OSD_H
463 /* End of osd.h */