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/>.
26 #include "nel/3d/u_driver.h"
27 #include "nel/3d/u_text_context.h"
30 #include "interfaces_manager.h"
36 using namespace NLMISC
;
44 extern UDriver
*Driver
;
45 extern UTextContext
*TextContext
;
48 //-----------------------------------------------
51 //-----------------------------------------------
52 CCapture::CCapture(uint id
)
58 //-----------------------------------------------
61 //-----------------------------------------------
62 CCapture::CCapture(uint id
, float x
, float y
, float x_pixel
, float y_pixel
, float w
, float h
, float w_pixel
, float h_pixel
, uint numFunc
, const CPen
&pen
)
63 : CControl(id
, x
, y
, x_pixel
, y_pixel
, w
, h
, w_pixel
, h_pixel
), CPen(pen
)
68 //-----------------------------------------------
71 //-----------------------------------------------
72 CCapture::CCapture(uint id
, float x
, float y
, float x_pixel
, float y_pixel
, float w
, float h
, float w_pixel
, float h_pixel
, uint numFunc
, uint32 fontSize
, CRGBA color
, bool shadow
)
73 : CControl(id
, x
, y
, x_pixel
, y_pixel
, w
, h
, w_pixel
, h_pixel
), CPen(fontSize
, color
, shadow
)
78 //-----------------------------------------------
81 //-----------------------------------------------
84 // Remove the listener.
85 Driver
->EventServer
.removeListener(EventCharId
, this);
88 //-----------------------------------------------
90 // Initialize the button (1 function called for all constructors -> easier).
91 //-----------------------------------------------
92 void CCapture::init(uint numFunc
)
100 // Add an event Listener for the char event.
101 Driver
->EventServer
.addListener(EventCharId
, this);
105 //---------------------------------------------------
107 // Function that receives events.
108 //---------------------------------------------------
109 void CCapture::operator()(const CEvent
& event
)
111 // Not in insert mode -> return (or disconnect listener).
115 // What is the char pushed ?
116 CEventChar ec
= (CEventChar
&) event
;
127 CInterfMngr::runFuncCtrl(_NumFunc
, id());
140 // delete last character
143 ucstring::iterator it
= _Str
.end();
150 // If the char is not alphanumeric -> return.
151 // if(!isalnum(ec.Char))
154 if(_Str
.size() < _MaxChar
)
162 //-----------------------------------------------
165 //-----------------------------------------------
166 void CCapture::display()
168 // If the control is hide -> return
172 /// \todo GUIGUI : initialize the scissor with oldScissor and remove tmp variables.
173 // Backup scissor and create the new scissor to clip the list correctly.
174 CScissor oldScissor
= Driver
->getScissor();
177 float scisX
, scisY
, scisWidth
, scisHeight
;
178 scisX
= oldScissor
.X
;
179 scisY
= oldScissor
.Y
;
180 scisWidth
= oldScissor
.Width
;
181 scisHeight
= oldScissor
.Height
;
183 float xtmp
= _X_Display
+_W_Display
;
184 float ytmp
= _Y_Display
+_H_Display
;
185 float xscistmp
= scisX
+scisWidth
;
186 float yscistmp
= scisY
+scisHeight
;
192 scisWidth
= xtmp
-scisX
;
194 scisWidth
= xscistmp
-scisX
;
196 scisHeight
= ytmp
-scisY
;
198 scisHeight
= yscistmp
-scisY
;
199 scissor
.init(scisX
, scisY
, scisWidth
, scisHeight
);
200 Driver
->setScissor(scissor
);
204 ucstring
str(_Prompt
);
212 TextContext
->setShaded(_Shadow
);
213 TextContext
->setHotSpot(UTextContext::MiddleLeft
);
214 TextContext
->setColor(_Color
);
215 TextContext
->setFontSize(_FontSize
);
217 const uint32 index
= TextContext
->textPush( str
);
218 const float strWidth
= TextContext
->getStringInfo(index
).StringWidth
/ Driver
->getWindowWidth();
221 // display string starting by the first character if !insert or display to ensure the input prompt is visible in insert mode
222 // calculate the x coordinate where to start displaying
223 float xDisplay
= _X_Display
;
226 if (strWidth
> _W_Display
)
227 xDisplay
-= (strWidth
- _W_Display
);
230 TextContext
->printAt( xDisplay
, _Y_Display
+_H_Display
/2, index
);
231 TextContext
->erase(index
);
234 Driver
->setScissor(oldScissor
);
237 //-----------------------------------------------
239 // Manage the click for the control.
240 //-----------------------------------------------
241 void CCapture::click(float x
, float y
, bool &taken
)
247 // If the click is in the capture Rect.
248 if(x
>=_X_Display
&& x
<=(_X_Display
+_W_Display
) && y
>=_Y_Display
&& y
<=(_Y_Display
+_H_Display
))