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/>.
22 #include "interfaces_manager.h"
25 //-----------------------------------------------
28 //-----------------------------------------------
29 CControl::CControl(uint id
)
31 init(id
, 0.f
, 0.f
, 0.f
, 0.f
, 0.f
, 0.f
, 0.f
, 0.f
);
35 //-----------------------------------------------
38 //-----------------------------------------------
39 CControl::CControl(uint id
, float x
, float y
, float x_pixel
, float y_pixel
, float w
, float h
, float w_pixel
, float h_pixel
)
41 init(id
, x
, y
, x_pixel
, y_pixel
, w
, h
, w_pixel
, h_pixel
);
45 //-----------------------------------------------
48 //-----------------------------------------------
49 void CControl::init(uint id
, float x
, float y
, float x_pixel
, float y_pixel
, float w
, float h
, float w_pixel
, float h_pixel
)
57 _X
= x
; // Position X of the Control (between 0-1).
58 _Y
= y
; // Position Y of the Control (between 0-1).
59 _X_Pixel
= x_pixel
; // Position X of the Control (in Pixel).
60 _Y_Pixel
= y_pixel
; // Position Y of the Control (in Pixel).
62 _W
= w
; // Width of the control (between 0-1).
63 _H
= h
; // Height of the control (between 0-1).
64 _W_Pixel
= w_pixel
; // Width of the control (in Pixel).
65 _H_Pixel
= h_pixel
; // Height of the control (in Pixel).
67 // The control position is relative to this Reference.
70 // Size of the Parent.
74 // Delta to add to the position because of the Hot Spot.
80 // Do the control have to be displayed. true -> yes.
86 // Calculate others variables.
91 //-----------------------------------------------
93 // The window size has changed -> resize the control.
94 //-----------------------------------------------
95 void CControl::resize(uint32
, uint32
)
100 for(TListControl::iterator it
= _Children
.begin(); it
!= _Children
.end(); ++it
)
102 if((*it
)->parent() == this)
105 calculateOrigin(x
, y
, (*it
)->origin());
106 (*it
)->ref(x
, y
, _W_Ref
, _H_Ref
);
111 //-----------------------------------------------
113 // Set some references for the display.
114 //-----------------------------------------------
115 void CControl::ref(float x
, float y
, float w
, float h
)
125 for(TListControl::iterator it
= _Children
.begin(); it
!= _Children
.end(); ++it
)
127 if((*it
)->parent() == this)
130 calculateOrigin(x
, y
, (*it
)->origin());
131 (*it
)->ref(x
, y
, _W_Ref
, _H_Ref
);
136 //-----------------------------------------------
138 // Add a child to the control.
139 //-----------------------------------------------
140 void CControl::addChild(CControl
*ctrl
)
142 _Children
.push_back(ctrl
);
146 //-----------------------------------------------
148 // Change the Hot Spot.
149 //-----------------------------------------------
150 void CControl::hotSpot(THotSpot hs
)
156 for(TListControl::iterator it
= _Children
.begin(); it
!= _Children
.end(); ++it
)
158 if((*it
)->parent() == this)
161 calculateOrigin(x
, y
, (*it
)->origin());
162 (*it
)->ref(x
, y
, _W_Ref
, _H_Ref
);
167 //-----------------------------------------------
169 // Return the Hot Spot.
170 //-----------------------------------------------
171 CControl::THotSpot
CControl::hotSpot()
177 //-----------------------------------------------
179 // Hide or show the control. false -> hide, true -> show.
180 //-----------------------------------------------
181 void CControl::show(bool show
)
186 //-----------------------------------------------
188 // Return the show of the control.
189 //-----------------------------------------------
190 bool CControl::show()
195 //-----------------------------------------------
196 // calculateDisplay :
197 // Calculate the Display X, Y, Width, Height.
198 //-----------------------------------------------
199 void CControl::calculateDisplay()
202 CInterfMngr::getWindowSize(w
, h
);
204 // Calculate the display Width and Height.
206 _W_Display
= _W
*_W_Ref
+ _W_Pixel
/w
;
208 _W_Display
= _W
*_W_Ref
;
211 _H_Display
= _H
*_H_Ref
+ _H_Pixel
/h
;
213 _H_Display
= _H
*_H_Ref
;
215 // Calculate the HotSpot.
218 _X_Display
= _X_Ref
+ _X
*_W_Ref
+ _X_Pixel
/w
+ _X_HotSpot
;
219 _Y_Display
= _Y_Ref
+ _Y
*_H_Ref
+ _Y_Pixel
/h
+ _Y_HotSpot
;
220 }// calculateDisplay //
222 //-----------------------------------------------
224 // Calculate the display position of the control in relation to the position of the control (Hot Spot).
225 //-----------------------------------------------
226 void CControl::calculateHS()
231 _X_HotSpot
= -_W_Display
;
235 _X_HotSpot
= -_W_Display
/2.f
;
244 _X_HotSpot
= -_W_Display
;
245 _Y_HotSpot
= -_H_Display
/2.f
;
248 _X_HotSpot
= -_W_Display
/2.f
;
249 _Y_HotSpot
= -_H_Display
/2.f
;
253 _Y_HotSpot
= -_H_Display
/2.f
;
257 _X_HotSpot
= -_W_Display
;
258 _Y_HotSpot
= -_H_Display
;
261 _X_HotSpot
= -_W_Display
/2.f
;
262 _Y_HotSpot
= -_H_Display
;
266 _Y_HotSpot
= -_H_Display
;
271 //-----------------------------------------------
273 // Function to calculate where to position a child.
274 //-----------------------------------------------
275 void CControl::calculateOrigin(float &x
, float &y
, THotSpot origin
)
279 case CControl::HS_TL
:
281 y
= _Y_Display
+_H_Display
;
283 case CControl::HS_TM
:
284 x
= _X_Display
+_W_Display
/2.f
;
285 y
= _Y_Display
+_H_Display
;
287 case CControl::HS_TR
:
288 x
= _X_Display
+_W_Display
;
289 y
= _Y_Display
+_H_Display
;
292 case CControl::HS_ML
:
294 y
= _Y_Display
+_H_Display
/2.f
;
296 case CControl::HS_MM
:
297 x
= _X_Display
+_W_Display
/2.f
;
298 y
= _Y_Display
+_H_Display
/2.f
;
300 case CControl::HS_MR
:
301 x
= _X_Display
+_W_Display
;
302 y
= _Y_Display
+_H_Display
/2.f
;
305 case CControl::HS_BL
:
309 case CControl::HS_BM
:
310 x
= _X_Display
+_W_Display
/2.f
;
313 case CControl::HS_BR
:
314 x
= _X_Display
+_W_Display
;
318 }// calculateOrigin //
322 //-----------------------------------------------
324 // called when the mouse has moved, give the new coordinates
325 //-----------------------------------------------
326 void CControl::mouseMove( float x
, float y
)
328 // send the message to all it's children
330 TListControl::iterator itChild
;
331 const TListControl::iterator itChildEnd
= _Children
.end();
333 for (itChild
= _Children
.begin() ; itChild
!= itChildEnd
; ++itChild
)
335 (*itChild
)->mouseMove( x
, y
);
340 //-----------------------------------------------
342 // manage left mouse button click
343 //-----------------------------------------------
344 void CControl::click(float x
, float y
, bool &taken
)
349 //-----------------------------------------------
351 // manage right mouse button click
352 //-----------------------------------------------
353 void CControl::clickRight(float x
, float y
, bool &taken
)
358 //-----------------------------------------------
359 // getDisplayValues :
360 // get display values of this control
361 //-----------------------------------------------
362 void CControl::getDisplayValues(float &x
, float &y
, float &h
, float &w
) const
368 }// getDisplayValues //
372 //-----------------------------------------------
374 // get the size of the control
375 //-----------------------------------------------
376 void CControl::getSize( float &w
, float &h
, float &wPixel
, float &hPixel
) const
385 //-----------------------------------------------
387 // get the position of the control
388 //-----------------------------------------------
389 void CControl::getPosition( float &x
, float &y
, float &xPixel
, float &yPixel
) const
398 //-----------------------------------------------
400 // set the size of the control
401 //-----------------------------------------------
402 void CControl::setSize( float w
, float h
, float wPixel
, float hPixel
)
412 for(TListControl::iterator it
= _Children
.begin(); it
!= _Children
.end(); ++it
)
414 if((*it
)->parent() == this)
417 calculateOrigin(nx
, ny
, (*it
)->origin());
418 (*it
)->ref(nx
, ny
, _W_Ref
, _H_Ref
);
424 //-----------------------------------------------
426 // set the position of the control
427 //-----------------------------------------------
428 void CControl::setPosition( float x
, float y
, float xPixel
, float yPixel
)
438 for(TListControl::iterator it
= _Children
.begin(); it
!= _Children
.end(); ++it
)
440 if((*it
)->parent() == this)
443 calculateOrigin(nx
, ny
, (*it
)->origin());
444 (*it
)->ref(nx
, ny
, _W_Ref
, _H_Ref
);