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/>.
30 #include "nel/3d/u_driver.h"
31 #include "nel/3d/u_text_context.h"
35 #include "interfaces_manager.h"
48 extern UDriver
*Driver
;
49 extern UTextContext
*TextContext
;
60 //-----------------------------------------------
63 //-----------------------------------------------
64 CButton::CButton(uint id
)
70 //-----------------------------------------------
73 //-----------------------------------------------
74 CButton::CButton(uint id
, float x
, float y
, float x_pixel
, float y_pixel
, float w
, float h
, float w_pixel
, float h_pixel
, uint numFuncOn
, uint numFuncR
, uint numFuncD
, const CButtonBase
&buttonBase
)
75 : CControl(id
, x
, y
, x_pixel
, y_pixel
, w
, h
, w_pixel
, h_pixel
), CButtonBase(buttonBase
)
77 init(numFuncOn
, numFuncR
, numFuncD
);
80 //-----------------------------------------------
83 //-----------------------------------------------
84 CButton::CButton(uint id
, float x
, float y
, float x_pixel
, float y_pixel
, float w
, float h
, float w_pixel
, float h_pixel
, uint numFuncOn
, uint numFuncR
, uint numFuncD
, CRGBA on
, CRGBA off
, CRGBA disable
)
85 : CControl(id
, x
, y
, x_pixel
, y_pixel
, w
, h
, w_pixel
, h_pixel
), CButtonBase(on
, off
, disable
)
87 init(numFuncOn
, numFuncR
, numFuncD
);
91 //-----------------------------------------------
93 // Initialize the button (1 function called for all constructors -> easier).
94 //-----------------------------------------------
95 void CButton::init(uint numFuncOn
, uint numFuncR
, uint numFuncD
)
97 _NumFuncOn
= numFuncOn
;
98 _NumFuncRightClick
= numFuncR
;
99 _NumFuncDbleClick
= numFuncD
;
104 //-----------------------------------------------
106 // Set the Pen to use for the Text of the button.
107 //-----------------------------------------------
108 void CButton::pen(const CPen
&pen
)
113 //-----------------------------------------------
115 // unselect the button.
116 //-----------------------------------------------
117 void CButton::unSelect()
119 CButtonBase::unSelect();
124 //-----------------------------------------------
126 // Display the Button.
127 //-----------------------------------------------
128 void CButton::display()
130 // If the control is hide -> return
143 texture
= _TextureOn
;
149 texture
= _TextureOff
;
155 mode
= _BGModeDisable
;
156 texture
= _TextureDisable
;
157 color
= _ColorDisable
;
163 Driver
->drawQuad(_X_Display
, _Y_Display
, _X_Display
+_W_Display
, _Y_Display
+_H_Display
, color
);
168 UTextureFile
*utexture
= CInterfMngr::getTexture(texture
);
171 Driver
->drawBitmap(_X_Display
, _Y_Display
, _W_Display
, _H_Display
, *utexture
, true, color
);
176 Driver
->drawQuad(_X_Display
, _Y_Display
, _X_Display
+_W_Display
, _Y_Display
+_H_Display
, CRGBA(255,0,255));
177 // Draw the debug msg.
178 TextContext
->setShaded(true);
179 TextContext
->setFontSize(10);
180 TextContext
->setColor(CRGBA(255,255,255));
181 TextContext
->setHotSpot(UTextContext::BottomLeft
);
182 TextContext
->printfAt(_X_Display
, _Y_Display
, "%d Miss", texture
);
188 // Display the Text of the Button.
191 TextContext
->setShaded(_Pen
.shadow());
192 TextContext
->setFontSize(_Pen
.fontSize());
193 TextContext
->setColor(_Pen
.color());
194 TextContext
->setHotSpot(UTextContext::MiddleMiddle
);
195 TextContext
->printAt(_X_Display
+_W_Display
/2, _Y_Display
+_H_Display
/2, _Text
);
199 //-----------------------------------------------
201 // Manage the click of the mouse for the Button.
202 //-----------------------------------------------
203 void CButton::click(float x
, float y
, bool &taken
)
205 // If the button is enabled and taken is false
206 if(_Enable
&& (!taken
) )
208 // test click ccordinates
209 if(x
>=_X_Display
&& x
<=(_X_Display
+_W_Display
) && y
>=_Y_Display
&& y
<=(_Y_Display
+_H_Display
))
211 /// \todo Malkav: TO DO : SIMULATE DOUBLE CLICK !!!!!!! SHOULD MAKE A REAL DOUBLE CLICK EVENT
212 if ( (_State
== left_clicked
) && (_NumFuncDbleClick
!= 0) )
214 CButtonBase::select();
215 _State
= double_clicked
;
216 CInterfMngr::runFuncCtrl(_NumFuncDbleClick
, id());
219 else if (_NumFuncOn
!= 0)
221 CButtonBase::select();
222 _State
= left_clicked
;
223 CInterfMngr::runFuncCtrl(_NumFuncOn
, id());
231 //-----------------------------------------------
233 // Manage the click of the mouse for the Button.
234 //-----------------------------------------------
235 void CButton::clickRight(float x
, float y
, bool &taken
)
237 // If the button is enabled and taken is false
238 if(_Enable
&& (!taken
) && (_NumFuncRightClick
!= 0) )
240 // test click ccordinates
241 if(x
>=_X_Display
&& x
<=(_X_Display
+_W_Display
) && y
>=_Y_Display
&& y
<=(_Y_Display
+_H_Display
))
243 CButtonBase::select();
244 _State
= right_clicked
;
245 CInterfMngr::runFuncCtrl(_NumFuncRightClick
, id());