Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / interfaces_manager / spell_control.cpp
blobe3dcca2741f2746c49d851ce203ee6ee8c51c657
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 #include "stdpch.h"
21 //////////////
22 // Includes //
23 //////////////
24 // Client
25 #include "spell_control.h"
26 #include "interfaces_manager.h"
28 // 3D
29 #include "nel/3d/u_driver.h"
30 #include "nel/3d/u_text_context.h"
34 ///////////
35 // Using //
36 ///////////
37 using namespace NL3D;
40 ////////////
41 // Extern //
42 ////////////
43 extern UDriver *Driver;
44 extern UTextContext *TextContext;
47 //-----------------------------------------------
48 // Constructor :
49 //-----------------------------------------------
50 CSpellControl::CSpellControl(uint id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel,
51 uint16 spacing, const CPen &spellPen, const CPen &commentPen )
52 :CControl (id, x, y, x_pixel, y_pixel, w, h, w_pixel, h_pixel)
54 init(spacing, spellPen, commentPen);
55 } // constructor //
57 //-----------------------------------------------
58 // Constructor :
59 //-----------------------------------------------
60 CSpellControl::CSpellControl(uint id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel,
61 uint16 spacing, uint32 fontSize1, const CRGBA &color1, bool shadow1, uint32 fontSize2, const CRGBA &color2, bool shadow2 )
62 :CControl (id, x, y, x_pixel, y_pixel, w, h, w_pixel, h_pixel)
64 init(spacing, CPen(fontSize1, color1, shadow1), CPen(fontSize2, color2, shadow2));
65 } // constructor //
69 //-----------------------------------------------
70 // Destructor :
71 //-----------------------------------------------
72 CSpellControl::~CSpellControl()
74 } // destructor //
76 //-----------------------------------------------
77 // init :
78 //-----------------------------------------------
79 void CSpellControl::init( uint16 spacing, const CPen &spellPen, const CPen &commentPen)
81 _Spacing = spacing;
83 _SpellText.fontSize( spellPen.fontSize() );
84 _SpellText.color( spellPen.color() );
85 _SpellText.shadow( spellPen.shadow() );
87 _Comment.fontSize( commentPen.fontSize() );
88 _Comment.color( commentPen.color() );
89 _Comment.shadow( commentPen.shadow() );
91 _Button.ref( _X_Ref, _Y_Ref, _W_Ref, _H_Ref );
92 _Button.hotSpot( THotSpot::HS_TR );
93 _Button.origin( THotSpot::HS_BL );
95 _RootIcon.ref( _X_Ref, _Y_Ref, _W_Ref, _H_Ref );
96 _RootIcon.hotSpot( THotSpot::HS_TR );
97 _RootIcon.origin( THotSpot::HS_BL );
99 _SpellText.ref( _X_Ref, _Y_Ref, _W_Ref, _H_Ref );
100 _SpellText.hotSpot( THotSpot::HS_TR );
101 _SpellText.origin( THotSpot::HS_BL );
103 _Comment.ref( _X_Ref, _Y_Ref, _W_Ref, _H_Ref );
104 _Comment.hotSpot( THotSpot::HS_TR );
105 _Comment.origin( THotSpot::HS_BL );
106 }// init //
108 //-----------------------------------------------
109 // initRootBitmap :
110 //-----------------------------------------------
111 /*void CSpellControl::initRootBitmap( CSpellClient *spell)
113 nlassert(spell);
115 } // initRootBitmap //
118 //-----------------------------------------------
119 // display :
120 //-----------------------------------------------
121 void CSpellControl::display()
123 // If the control is hide -> return
124 if(!_Show)
125 return;
127 /// \todo Malkav : found a way to refresh the comment line when it's edited somwhere else...
128 if (_Spell)
129 _Comment.text( _Spell->getComment() );
131 /// \todo GUIGUI : initialize the scissor with oldScissor and remove tmp variables.
132 // Backup scissor and create the new scissor to clip the list correctly.
133 CScissor oldScissor = Driver->getScissor();
134 CScissor scissor;
136 float scisX, scisY, scisWidth, scisHeight;
137 scisX = oldScissor.X;
138 scisY = oldScissor.Y;
139 scisWidth = oldScissor.Width;
140 scisHeight = oldScissor.Height;
142 float xtmp = _X_Display + _W_Display;
143 float ytmp = _Y_Display + _H_Display;
144 float xscistmp = scisX + scisWidth;
145 float yscistmp = scisY + scisHeight;
147 if( _X_Display > scisX )
148 scisX = _X_Display;
149 if( _Y_Display > scisY)
150 scisY = _Y_Display;
151 if( xtmp < xscistmp)
152 scisWidth = xtmp-scisX;
153 else
154 scisWidth = xscistmp-scisX;
155 if( ytmp < yscistmp)
156 scisHeight = ytmp-scisY;
157 else
158 scisHeight = yscistmp-scisY;
160 scissor.init(scisX, scisY, scisWidth, scisHeight);
161 // Driver->setScissor(scissor);
163 // draw background
164 // ONLY FOR DEBUG
165 /* UTextureFile *utexture = CInterfMngr::getTexture(2);
166 if(utexture)
168 Driver->drawBitmap(_X_Display, _Y_Display, _W_Display, _H_Display, *utexture, true);
171 // draw the visible controls
172 float x = _X;
173 float xPixel = _X_Pixel;
175 float w = 0, h = 0, wPixel = 0, hPixel = 0;
177 // display button
178 _Button.setPosition( x, _Y, xPixel , _Y_Pixel);
179 _Button.display();
181 _Button.getSize(w, h, wPixel, hPixel);
183 x += w;
184 xPixel += wPixel;
186 // display root brick icon
188 //------------------------------------------------------
189 xPixel += _Spacing;
190 _RootIcon.setPosition( x, _Y, xPixel , _Y_Pixel);
191 //--- if the spell is 'latent', grey the icon
192 if (_Spell->isLatent())
194 CRGBA old = _RootIcon.rgba();
195 _RootIcon.rgba( CRGBA(128,128,128,255) );
196 _RootIcon.display();
197 _RootIcon.rgba( old);
199 else
201 _RootIcon.display();
204 _RootIcon.getSize(w, h, wPixel, hPixel);
205 x += w;
206 xPixel += wPixel;
208 //------------------------------------------------------
210 // display spell text
211 if ( _Comment.text().length() == 0)
213 xPixel += _Spacing;
215 _SpellText.setPosition( x, _Y, xPixel , _Y_Pixel);
216 _SpellText.display();
218 _SpellText.getSize(w, h, wPixel, hPixel);
219 x += w;
220 xPixel += wPixel;
222 else
224 // display comment
225 xPixel += _Spacing;
227 _Comment.setPosition( x, _Y, xPixel , _Y_Pixel);
228 _Comment.display();
230 _Comment.getSize(w, h, wPixel, hPixel);
231 x += w;
232 xPixel += wPixel;
235 // restore scissor
236 Driver->setScissor(oldScissor);
238 } // display //
241 //-----------------------------------------------
242 // click :
243 //-----------------------------------------------
244 void CSpellControl::click(float x, float y, bool &taken)
246 if (taken)
248 _Button.unSelect();
250 return;
252 // test click coordinates
253 if(x>=_X_Display && x<=(_X_Display+_W_Display) && y>=_Y_Display && y<=(_Y_Display+_H_Display))
255 _Button.select();
257 if (_NumFuncOn != 0)
258 CInterfMngr::runFuncCtrl(_NumFuncOn, id(), _Spell);
260 taken = true;
262 else
264 _Button.unSelect();
266 } // click //
269 //-----------------------------------------------
270 // clickRight :
271 //-----------------------------------------------
272 void CSpellControl::clickRight(float x, float y, bool &taken)
274 if (taken)
275 return;
277 // test click coordinates
278 if(x>=_X_Display && x<=(_X_Display+_W_Display) && y>=_Y_Display && y<=(_Y_Display+_H_Display))
280 if (_NumFuncRightClick != 0)
281 CInterfMngr::runFuncCtrl(_NumFuncRightClick, id(), this);
283 taken = true;
286 } // clickRight //
289 //-----------------------------------------------
290 // ref :
291 // Set some references for the display.
292 //-----------------------------------------------
293 void CSpellControl::ref(float x, float y, float w, float h)
295 _X_Ref = x;
296 _Y_Ref = y;
297 _W_Ref = w;
298 _H_Ref = h;
300 calculateDisplay();
302 // Update chidren.
303 for(TListControl::iterator it = _Children.begin(); it != _Children.end(); ++it)
305 if((*it)->parent() == this)
307 float x, y;
308 calculateOrigin(x, y, (*it)->origin());
309 (*it)->ref(x, y, _W_Ref, _H_Ref);
313 // update internal controls
314 _Button.ref(x, y, w, h);
315 _SpellText.ref(x, y, w, h);
316 _Comment.ref(x, y, w, h);
317 _RootIcon.ref(x,y,w,h);
318 }// ref //