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/>.
25 #include "spell_control.h"
26 #include "interfaces_manager.h"
29 #include "nel/3d/u_driver.h"
30 #include "nel/3d/u_text_context.h"
43 extern UDriver
*Driver
;
44 extern UTextContext
*TextContext
;
47 //-----------------------------------------------
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
);
57 //-----------------------------------------------
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
));
69 //-----------------------------------------------
71 //-----------------------------------------------
72 CSpellControl::~CSpellControl()
76 //-----------------------------------------------
78 //-----------------------------------------------
79 void CSpellControl::init( uint16 spacing
, const CPen
&spellPen
, const CPen
&commentPen
)
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
);
108 //-----------------------------------------------
110 //-----------------------------------------------
111 /*void CSpellControl::initRootBitmap( CSpellClient *spell)
115 } // initRootBitmap //
118 //-----------------------------------------------
120 //-----------------------------------------------
121 void CSpellControl::display()
123 // If the control is hide -> return
127 /// \todo Malkav : found a way to refresh the comment line when it's edited somwhere else...
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();
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
)
149 if( _Y_Display
> scisY
)
152 scisWidth
= xtmp
-scisX
;
154 scisWidth
= xscistmp
-scisX
;
156 scisHeight
= ytmp
-scisY
;
158 scisHeight
= yscistmp
-scisY
;
160 scissor
.init(scisX
, scisY
, scisWidth
, scisHeight
);
161 // Driver->setScissor(scissor);
165 /* UTextureFile *utexture = CInterfMngr::getTexture(2);
168 Driver->drawBitmap(_X_Display, _Y_Display, _W_Display, _H_Display, *utexture, true);
171 // draw the visible controls
173 float xPixel
= _X_Pixel
;
175 float w
= 0, h
= 0, wPixel
= 0, hPixel
= 0;
178 _Button
.setPosition( x
, _Y
, xPixel
, _Y_Pixel
);
181 _Button
.getSize(w
, h
, wPixel
, hPixel
);
186 // display root brick icon
188 //------------------------------------------------------
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) );
197 _RootIcon
.rgba( old
);
204 _RootIcon
.getSize(w
, h
, wPixel
, hPixel
);
208 //------------------------------------------------------
210 // display spell text
211 if ( _Comment
.text().length() == 0)
215 _SpellText
.setPosition( x
, _Y
, xPixel
, _Y_Pixel
);
216 _SpellText
.display();
218 _SpellText
.getSize(w
, h
, wPixel
, hPixel
);
227 _Comment
.setPosition( x
, _Y
, xPixel
, _Y_Pixel
);
230 _Comment
.getSize(w
, h
, wPixel
, hPixel
);
236 Driver
->setScissor(oldScissor
);
241 //-----------------------------------------------
243 //-----------------------------------------------
244 void CSpellControl::click(float x
, float y
, bool &taken
)
252 // test click coordinates
253 if(x
>=_X_Display
&& x
<=(_X_Display
+_W_Display
) && y
>=_Y_Display
&& y
<=(_Y_Display
+_H_Display
))
258 CInterfMngr::runFuncCtrl(_NumFuncOn
, id(), _Spell
);
269 //-----------------------------------------------
271 //-----------------------------------------------
272 void CSpellControl::clickRight(float x
, float y
, bool &taken
)
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);
289 //-----------------------------------------------
291 // Set some references for the display.
292 //-----------------------------------------------
293 void CSpellControl::ref(float x
, float y
, float w
, float h
)
303 for(TListControl::iterator it
= _Children
.begin(); it
!= _Children
.end(); ++it
)
305 if((*it
)->parent() == this)
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
);