Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / gui / group_editbox_decor.cpp
bloba44007af1b858066662ce8efe1ce30fe05d38941
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Winch Gate Property Limited
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdpch.h"
21 #include "nel/gui/group_editbox_decor.h"
22 #include "nel/gui/view_bitmap.h"
23 #include "nel/gui/view_text.h"
25 #ifdef DEBUG_NEW
26 #define new DEBUG_NEW
27 #endif
29 namespace NLGUI
31 class EBDPrivate
33 public:
34 enum Textures
36 BG,
39 TM,
40 BM,
41 TL,
42 TR,
43 BL,
44 BR,
45 TCOUNT
48 EBDPrivate()
50 for(sint i = 0; i < TCOUNT; ++i)
52 _Textures.push_back(new CViewBitmap( CViewBase::TCtorParam()));
56 ~EBDPrivate()
58 for(uint i = 0; i < _Textures.size(); ++i)
59 delete _Textures[i];
60 _Textures.clear();
63 void draw()
65 for(uint i = 0; i < _Textures.size(); ++i)
67 CViewBitmap *bm = _Textures[i];
68 bm->draw();
72 void updateCoords()
74 for(uint i = 0; i < _Textures.size(); ++i)
76 CViewBitmap *bm = _Textures[i];
77 bm->fitTexture();
80 // W and H parameters depend on the sizes of the other textures
81 // Negative sizes mean that the sizes are that much smaller than the parent
82 sint32 w, h;
83 h = _Textures[ TL ]->getHReal() + _Textures[ BL ]->getHReal();
84 h *= -1;
85 _Textures[ L ]->setH( h );
87 h = _Textures[ TR ]->getHReal() + _Textures[ BR ]->getHReal();
88 h *= -1;
89 _Textures[ R ]->setH( h );
91 w = _Textures[ TL ]->getWReal() + _Textures[ TR ]->getWReal();
92 w *= -1;
93 _Textures[ TM ]->setW( w );
95 w = _Textures[ BL ]->getWReal() + _Textures[ BR ]->getWReal();
96 w *= -1;
97 _Textures[ BM ]->setW( w );
99 h = _Textures[ TM ]->getHReal() + _Textures[ BM ]->getHReal();
100 h *= -1;
101 w = _Textures[ L ]->getWReal() + _Textures[ R ]->getWReal();
102 w *= -1;
103 _Textures[ BG ]->setW( w );
104 _Textures[ BG ]->setH( h );
106 for(uint i = 0; i < _Textures.size(); ++i)
108 CViewBitmap *bm = _Textures[i];
109 bm->updateCoords();
113 void setup( CInterfaceGroup *parent )
115 for(uint i = 0; i < _Textures.size(); ++i)
117 CViewBitmap *bm = _Textures[i];
118 bm->setParent(parent);
119 bm->setParentPos(parent);
120 bm->setParentSize(parent);
121 bm->setEditorSelectable(false);
124 _Textures[ TL ]->setPosRef( Hotspot_TL );
125 _Textures[ TL ]->setParentPosRef( Hotspot_TL );
127 _Textures[ TM ]->setPosRef( Hotspot_TM );
128 _Textures[ TM ]->setParentPosRef( Hotspot_TM );
129 _Textures[ TM ]->setScale( true );
130 _Textures[ TM ]->setSizeRef( "w" );
132 _Textures[ TR ]->setPosRef( Hotspot_TR );
133 _Textures[ TR ]->setParentPosRef( Hotspot_TR );
135 _Textures[ BL ]->setPosRef( Hotspot_BL );
136 _Textures[ BL ]->setParentPosRef( Hotspot_BL );
138 _Textures[ BM ]->setPosRef( Hotspot_BM );
139 _Textures[ BM ]->setParentPosRef( Hotspot_BM );
140 _Textures[ BM ]->setScale( true );
141 _Textures[ BM ]->setSizeRef( "w" );
143 _Textures[ BR ]->setPosRef( Hotspot_BR );
144 _Textures[ BR ]->setParentPosRef( Hotspot_BR );
146 _Textures[ L ]->setPosRef( Hotspot_ML );
147 _Textures[ L ]->setParentPosRef( Hotspot_ML );
148 _Textures[ L ]->setScale( true );
149 _Textures[ L ]->setSizeRef( "h" );
151 _Textures[ R ]->setPosRef( Hotspot_MR );
152 _Textures[ R ]->setParentPosRef( Hotspot_MR );
153 _Textures[ R ]->setScale( true );
154 _Textures[ R ]->setSizeRef( "h" );
156 _Textures[ BG ]->setPosRef( Hotspot_MM );
157 _Textures[ BG ]->setParentPosRef( Hotspot_MM );
158 _Textures[ BG ]->setScale( true );
159 _Textures[ BG ]->setSizeRef( "wh" );
162 std::vector< CViewBitmap* > _Textures;
165 NLMISC_REGISTER_OBJECT( CViewBase, CGroupEditBoxDecor, std::string, "edit_box_decor" );
167 CGroupEditBoxDecor::CGroupEditBoxDecor( const TCtorParam &param ) :
168 CGroupEditBox( param )
170 _Pvt = new EBDPrivate();
171 _Pvt->setup( this );
173 createViewText();
174 getVT()->setSerializable( false );
175 getVT()->setEditorSelectable( false );
178 CGroupEditBoxDecor::~CGroupEditBoxDecor()
180 delete _Pvt;
181 _Pvt = NULL;
184 void CGroupEditBoxDecor::moveBy( sint32 x, sint32 y )
186 CInterfaceElement::moveBy( x, y );
188 _Pvt->updateCoords();
191 void CGroupEditBoxDecor::setIdRecurse( const std::string &newID )
193 CInterfaceElement::setIdRecurse( newID );
194 _ViewText->setIdRecurse( _ViewText->getShortId() );
197 std::string CGroupEditBoxDecor::getProperty( const std::string &name ) const
199 if( name == "tx_tl" )
201 return _Pvt->_Textures[ EBDPrivate::TL ]->getTexture();
203 else
204 if( name == "tx_tm" )
206 return _Pvt->_Textures[ EBDPrivate::TM ]->getTexture();
208 else
209 if( name == "tx_tr" )
211 return _Pvt->_Textures[ EBDPrivate::TR ]->getTexture();
213 else
214 if( name == "tx_bl" )
216 return _Pvt->_Textures[ EBDPrivate::BL ]->getTexture();
218 else
219 if( name == "tx_bm" )
221 return _Pvt->_Textures[ EBDPrivate::BM ]->getTexture();
223 else
224 if( name == "tx_br" )
226 return _Pvt->_Textures[ EBDPrivate::BR ]->getTexture();
228 else
229 if( name == "tx_l" )
231 return _Pvt->_Textures[ EBDPrivate::L ]->getTexture();
233 else
234 if( name == "tx_r" )
236 return _Pvt->_Textures[ EBDPrivate::R ]->getTexture();
238 else
239 if( name == "tx_bg" )
241 return _Pvt->_Textures[ EBDPrivate::BG ]->getTexture();
243 else
244 return CGroupEditBox::getProperty( name );
247 void CGroupEditBoxDecor::setProperty( const std::string &name, const std::string &value )
249 if( name == "tx_tl" )
251 _Pvt->_Textures[ EBDPrivate::TL ]->setTexture( value );
253 else
254 if( name == "tx_tm" )
256 _Pvt->_Textures[ EBDPrivate::TM ]->setTexture( value );
258 else
259 if( name == "tx_tr" )
261 _Pvt->_Textures[ EBDPrivate::TR ]->setTexture( value );
263 else
264 if( name == "tx_bl" )
266 _Pvt->_Textures[ EBDPrivate::BL ]->setTexture( value );
268 else
269 if( name == "tx_bm" )
271 _Pvt->_Textures[ EBDPrivate::BM ]->setTexture( value );
273 else
274 if( name == "tx_br" )
276 _Pvt->_Textures[ EBDPrivate::BR ]->setTexture( value );
278 else
279 if( name == "tx_l" )
281 _Pvt->_Textures[ EBDPrivate::L ]->setTexture( value );
283 else
284 if( name == "tx_r" )
286 _Pvt->_Textures[ EBDPrivate::R ]->setTexture( value );
288 else
289 if( name == "tx_bg" )
291 _Pvt->_Textures[ EBDPrivate::BG ]->setTexture( value );
293 else
294 CGroupEditBox::setProperty( name, value );
297 xmlNodePtr CGroupEditBoxDecor::serialize( xmlNodePtr parentNode, const char *type ) const
299 xmlNodePtr node = CGroupEditBox::serialize( parentNode, type );
300 if( node == NULL )
301 return NULL;
303 xmlSetProp( node, BAD_CAST "type", BAD_CAST "edit_box_decor" );
304 xmlSetProp( node, BAD_CAST "tx_tl", BAD_CAST _Pvt->_Textures[ EBDPrivate::TL ]->getTexture().c_str() );
305 xmlSetProp( node, BAD_CAST "tx_tr", BAD_CAST _Pvt->_Textures[ EBDPrivate::TR ]->getTexture().c_str() );
306 xmlSetProp( node, BAD_CAST "tx_tm", BAD_CAST _Pvt->_Textures[ EBDPrivate::TM ]->getTexture().c_str() );
307 xmlSetProp( node, BAD_CAST "tx_bl", BAD_CAST _Pvt->_Textures[ EBDPrivate::BL ]->getTexture().c_str() );
308 xmlSetProp( node, BAD_CAST "tx_bm", BAD_CAST _Pvt->_Textures[ EBDPrivate::BM ]->getTexture().c_str() );
309 xmlSetProp( node, BAD_CAST "tx_br", BAD_CAST _Pvt->_Textures[ EBDPrivate::BR ]->getTexture().c_str() );
310 xmlSetProp( node, BAD_CAST "tx_l", BAD_CAST _Pvt->_Textures[ EBDPrivate::L ]->getTexture().c_str() );
311 xmlSetProp( node, BAD_CAST "tx_r", BAD_CAST _Pvt->_Textures[ EBDPrivate::R ]->getTexture().c_str() );
312 xmlSetProp( node, BAD_CAST "tx_bg", BAD_CAST _Pvt->_Textures[ EBDPrivate::BG ]->getTexture().c_str() );
314 return node;
317 bool CGroupEditBoxDecor::parse( xmlNodePtr cur, CInterfaceGroup *parent )
319 if( !CGroupEditBox::parse( cur, parent ) )
320 return false;
322 CXMLAutoPtr prop;
324 prop = ( char* ) xmlGetProp( cur, BAD_CAST "tx_tl" );
325 if( prop )
326 _Pvt->_Textures[ EBDPrivate::TL ]->setTexture( ( const char* )prop );
328 prop = ( char* ) xmlGetProp( cur, BAD_CAST "tx_tm" );
329 if( prop )
330 _Pvt->_Textures[ EBDPrivate::TM ]->setTexture( ( const char* )prop );
332 prop = ( char* ) xmlGetProp( cur, BAD_CAST "tx_tr" );
333 if( prop )
334 _Pvt->_Textures[ EBDPrivate::TR ]->setTexture( ( const char* )prop );
336 prop = ( char* ) xmlGetProp( cur, BAD_CAST "tx_bl" );
337 if( prop )
338 _Pvt->_Textures[ EBDPrivate::BL ]->setTexture( ( const char* )prop );
340 prop = ( char* ) xmlGetProp( cur, BAD_CAST "tx_bm" );
341 if( prop )
342 _Pvt->_Textures[ EBDPrivate::BM ]->setTexture( ( const char* )prop );
344 prop = ( char* ) xmlGetProp( cur, BAD_CAST "tx_br" );
345 if( prop )
346 _Pvt->_Textures[ EBDPrivate::BR ]->setTexture( ( const char* )prop );
348 prop = ( char* ) xmlGetProp( cur, BAD_CAST "tx_l" );
349 if( prop )
350 _Pvt->_Textures[ EBDPrivate::L ]->setTexture( ( const char* )prop );
352 prop = ( char* ) xmlGetProp( cur, BAD_CAST "tx_r" );
353 if( prop )
354 _Pvt->_Textures[ EBDPrivate::R ]->setTexture( ( const char* )prop );
356 prop = ( char* ) xmlGetProp( cur, BAD_CAST "tx_bg" );
357 if( prop )
358 _Pvt->_Textures[ EBDPrivate::BG ]->setTexture( ( const char* )prop );
360 getVT()->setIdRecurse( "edit_text" );
362 return true;
365 void CGroupEditBoxDecor::draw()
367 CGroupEditBox::draw();
369 _Pvt->draw();
372 void CGroupEditBoxDecor::updateCoords()
374 sint32 tw = _Pvt->_Textures[ EBDPrivate::L ]->getWReal();
375 getVT()->setX( tw + 1 );
377 CGroupEditBox::updateCoords();
378 _Pvt->updateCoords();
381 void CGroupEditBoxDecor::forceLink()