Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interfaces_manager / button.cpp
blob43ef37a8eba98ad83fc620a394761b8d40955b40
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"
22 //////////////
23 // Includes //
24 //////////////
25 // Misc.
27 // Net.
29 // 3D Interface.
30 #include "nel/3d/u_driver.h"
31 #include "nel/3d/u_text_context.h"
33 // Client.
34 #include "button.h"
35 #include "interfaces_manager.h"
38 ///////////
39 // Using //
40 ///////////
41 using namespace std;
42 using namespace NL3D;
45 /////////////
46 // Externs //
47 /////////////
48 extern UDriver *Driver;
49 extern UTextContext *TextContext;
52 /////////////
53 // Globals //
54 /////////////
57 ///////////////
58 // Functions //
59 ///////////////
60 //-----------------------------------------------
61 // CButton :
62 // Constructor.
63 //-----------------------------------------------
64 CButton::CButton(uint id)
65 : CControl(id)
67 init(0, 0, 0);
68 }// CButton //
70 //-----------------------------------------------
71 // CButton :
72 // Constructor.
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);
78 }// CButton //
80 //-----------------------------------------------
81 // CButton :
82 // Constructor.
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);
88 }// CButton //
91 //-----------------------------------------------
92 // init :
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;
100 _State = released;
101 _Text.clear();
102 }// init //
104 //-----------------------------------------------
105 // pen :
106 // Set the Pen to use for the Text of the button.
107 //-----------------------------------------------
108 void CButton::pen(const CPen &pen)
110 _Pen = pen;
111 }// pen //
113 //-----------------------------------------------
114 // unSelect :
115 // unselect the button.
116 //-----------------------------------------------
117 void CButton::unSelect()
119 CButtonBase::unSelect();
120 _State = released;
121 }// push //
124 //-----------------------------------------------
125 // display :
126 // Display the Button.
127 //-----------------------------------------------
128 void CButton::display()
130 // If the control is hide -> return
131 if(!_Show)
132 return;
134 TBG mode;
135 uint texture;
136 CRGBA color;
138 if(_Enable)
140 if(_On)
142 mode = _BGModeOn;
143 texture = _TextureOn;
144 color = _ColorOn;
146 else
148 mode = _BGModeOff;
149 texture = _TextureOff;
150 color = _ColorOff;
153 else
155 mode = _BGModeDisable;
156 texture = _TextureDisable;
157 color = _ColorDisable;
160 switch(mode)
162 case BG_plain:
163 Driver->drawQuad(_X_Display, _Y_Display, _X_Display+_W_Display, _Y_Display+_H_Display, color);
164 break;
166 case BG_stretch:
168 UTextureFile *utexture = CInterfMngr::getTexture(texture);
169 if(utexture)
171 Driver->drawBitmap(_X_Display, _Y_Display, _W_Display, _H_Display, *utexture, true, color);
173 else
175 // Draw a quad
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);
185 break;
188 // Display the Text of the Button.
189 if(!_Text.empty())
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);
197 }// display //
199 //-----------------------------------------------
200 // click :
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());
217 taken = true;
219 else if (_NumFuncOn != 0)
221 CButtonBase::select();
222 _State = left_clicked;
223 CInterfMngr::runFuncCtrl(_NumFuncOn, id());
224 taken = true;
228 }// click //
231 //-----------------------------------------------
232 // click :
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());
246 taken = true;
249 }// click //