Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interfaces_manager / capture.cpp
blob5e6c31eeac79f6b364e98fc53eff3ca4786c81e8
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 // 3D Interface.
26 #include "nel/3d/u_driver.h"
27 #include "nel/3d/u_text_context.h"
28 // Client
29 #include "capture.h"
30 #include "interfaces_manager.h"
33 ////////////////
34 // Namespaces //
35 ////////////////
36 using namespace NLMISC;
37 using namespace NL3D;
38 using namespace std;
41 /////////////
42 // Externs //
43 /////////////
44 extern UDriver *Driver;
45 extern UTextContext *TextContext;
48 //-----------------------------------------------
49 // CCapture :
50 // Constructor.
51 //-----------------------------------------------
52 CCapture::CCapture(uint id)
53 : CControl(id)
55 init(0);
56 }// CCapture //
58 //-----------------------------------------------
59 // CCapture :
60 // Constructor.
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)
65 init(numFunc);
66 }// CCapture //
68 //-----------------------------------------------
69 // CCapture :
70 // Constructor.
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)
75 init(numFunc);
76 }// CCapture //
78 //-----------------------------------------------
79 // ~CCapture :
80 // Destructor.
81 //-----------------------------------------------
82 CCapture::~CCapture()
84 // Remove the listener.
85 Driver->EventServer.removeListener(EventCharId, this);
86 }// ~CCapture //
88 //-----------------------------------------------
89 // init :
90 // Initialize the button (1 function called for all constructors -> easier).
91 //-----------------------------------------------
92 void CCapture::init(uint numFunc)
95 _NumFunc = numFunc;
96 _MaxChar = 256;
97 _Insert = false;
98 _Prompt = "";
100 // Add an event Listener for the char event.
101 Driver->EventServer.addListener(EventCharId, this);
102 }// init //
105 //---------------------------------------------------
106 // operator() :
107 // Function that receives events.
108 //---------------------------------------------------
109 void CCapture::operator()(const CEvent& event)
111 // Not in insert mode -> return (or disconnect listener).
112 if(!_Insert)
113 return;
115 // What is the char pushed ?
116 CEventChar ec = (CEventChar &) event;
117 switch(ec.Char)
119 // SPACE
120 // case KeySPACE:
121 // return;
122 // break;
124 // RETURN
125 case KeyRETURN:
126 _Insert = false;
127 CInterfMngr::runFuncCtrl(_NumFunc, id());
128 break;
130 // TAB
131 case KeyTAB:
132 break;
134 // ESCAPE
135 case KeyESCAPE:
136 break;
138 // BACKSPACE
139 case KeyBACK:
140 // delete last character
141 if(_Str.size () > 0)
143 ucstring::iterator it = _Str.end();
144 _Str.erase(--it);
146 break;
148 // OTHER
149 default:
150 // If the char is not alphanumeric -> return.
151 // if(!isalnum(ec.Char))
152 // return;
154 if(_Str.size() < _MaxChar)
155 _Str += ec.Char;
156 break;
158 }// operator() //
162 //-----------------------------------------------
163 // display :
164 // Display the text.
165 //-----------------------------------------------
166 void CCapture::display()
168 // If the control is hide -> return
169 if(!_Show)
170 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();
175 CScissor scissor;
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;
187 if(_X_Display>scisX)
188 scisX = _X_Display;
189 if(_Y_Display>scisY)
190 scisY = _Y_Display;
191 if(xtmp<xscistmp)
192 scisWidth = xtmp-scisX;
193 else
194 scisWidth = xscistmp-scisX;
195 if(ytmp<yscistmp)
196 scisHeight = ytmp-scisY;
197 else
198 scisHeight = yscistmp-scisY;
199 scissor.init(scisX, scisY, scisWidth, scisHeight);
200 Driver->setScissor(scissor);
203 // write text
204 ucstring str(_Prompt);
205 str += _Str;
207 if(_Insert)
209 str += "_";
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;
224 if (_Insert)
226 if (strWidth > _W_Display)
227 xDisplay -= (strWidth - _W_Display);
230 TextContext->printAt( xDisplay , _Y_Display+_H_Display/2, index);
231 TextContext->erase(index);
233 // Restore Scissor.
234 Driver->setScissor(oldScissor);
235 }// display //
237 //-----------------------------------------------
238 // click :
239 // Manage the click for the control.
240 //-----------------------------------------------
241 void CCapture::click(float x, float y, bool &taken)
243 _Insert = false;
245 if (!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))
250 _Insert = true;
251 taken = true;
254 }// click //