1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
27 #include "nel/misc/types_nl.h"
28 #include "nel/misc/ucstring.h"
29 #include "nel/misc/rgba.h"
47 * Class to manage an OSD (On Screen Display = Kind of window) for the interfaces.
48 * \author Guillaume PUZIN
49 * \author Nevrax France
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
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).
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
);
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.
166 /// Function to draw the Title Bar according to the mode.
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
);
179 /// the 'ID' fo the OSD (as defined for the interface manager)
182 /// boolean indicating if the OSD is a 'pop-up' window, in this case, a click outside the window close that window
185 /// Position of the OSD (between 0-1).
188 /// Position of the OSD (in Pixel).
192 /// Minimum values for window size
197 /// Display Position of the Control (between 0-1).
201 /// Width and Height (between 0-1).
204 /// Width and Height (in pixel).
207 /// Display Width and Height of the Control (between 0-1).
211 /// Variables to know the offset between the click position and the OSD borders.
217 /// Is the OSD Visible.
221 * Variables to manage the OSD.
224 /// How to display the OSD.
228 /// Function called each update (every frame in most case).
229 uint _OSD_Update_Func
;
233 * Variables to manage the background of the OSD.
236 /// Display mode for the background.
238 /// Id of the texture for the background.
240 /// Color of the Background.
245 * Variables to manage the Title Bar of the OSD.
248 /// Display mode for the Title Bar.
250 /// Id of the texture for the Title BAr.
252 /// Color of the Title Bar.
254 /// Height of the Title Bar (in Pixel).
256 /// Display Height of the Title Bar.
258 /// Pen of the Title Bar.
263 * Variables to manage the HighLight of the OSD.
266 /// Color of the HighLight.
268 /// HighLight Size (in Pixel).
270 /// HighLight Size for the width (between 0-1).
272 /// HighLight Size for the height (between 0-1).
277 * Variables to manage the Resize of the OSD.
282 /// Resize borders Color
284 /// Resize size (in pixel).
286 /// Resize Size for the width (between 0-1).
288 /// Resize Size for the height (between 0-1).
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);
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
);
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.
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
);
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
);
338 * Functions to show/hide the OSD.
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
;}
355 * Functions to manage the OSD.
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
; }
382 * Functions to manage the background.
385 /// Set the Background display mode.
386 void bgMode(TBG mode
);
387 /// Get the Background display mode.
389 /// Set the texture Id for the Background.
391 /// Get background Id.
393 /// Set the Background RGBA.
394 void bgColor(const CRGBA
&bRGBA
);
395 /// Get the background RGBA.
396 CRGBA
bgColor() const ;
400 * Functions to manage the Title Bar.
403 /// Set the Title Bar display mode.
404 void tbMode(TTB mode
);
405 /// Get the Title Bar display mode.
407 /// Set the texture Id for the Title Bar.
409 /// Get Title Bar Id.
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.
426 * Functions to manage the HighLight.
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 ;
440 * Functions to manage the Resize of the OSD.
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 ;