1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2012-2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
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/>.
22 #include "nel/misc/rgba.h"
23 #include "nel/gui/interface_property.h"
24 #include "nel/gui/interface_common.h"
25 #include "nel/gui/db_manager.h"
26 #include "nel/misc/common.h"
28 using namespace NLMISC
;
37 bool CInterfaceProperty::link( CCDBNodeLeaf
*dbNode
)
39 _VolatileValue
= dbNode
;
40 return (dbNode
!= NULL
);
43 bool CInterfaceProperty::link( CCDBNodeBranch
*dbNode
, const string
&leafId
, CCDBNodeLeaf
*defaultLeaf
)
45 // no branch => default leaf
48 _VolatileValue
= defaultLeaf
;
53 _VolatileValue
= dbNode
->getLeaf( leafId
.c_str(), false );
58 _VolatileValue
= defaultLeaf
;
62 bool CInterfaceProperty::link (const char *DBProp
)
64 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(DBProp
, false);
65 if (_VolatileValue
== NULL
)
68 nlinfo("prop not created : %s", DBProp
);
69 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(DBProp
);
76 void CInterfaceProperty::setDouble(double value
)
80 setSInt64(parts
.i64
[0]);
83 double CInterfaceProperty::getDouble() const
86 parts
.i64
[0] = getSInt64();
95 void CInterfaceProperty::readSInt64(const char * ptr
,const string
& id
)
98 //the value is volatile, and a database entry is created
99 if ( isdigit(*ptr
) || *ptr
=='-')
101 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
104 _VolatileValue
->setValue64( i
);
106 //the value is volatile and points to a db entry created elsewhere
109 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(str
);
121 // ----------------------------------------------------------------------------
122 void CInterfaceProperty::readDouble(const char * ptr
,const string
& id
)
125 if ( isdigit(*ptr
) || *ptr
=='-')
127 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
129 fromString(ptr
, buf
.d
[0]);
130 _VolatileValue
->setValue64(buf
.i64
[0]);
134 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(str
);
143 // ----------------------------------------------------------------------------
144 void CInterfaceProperty::readSInt32 (const char *ptr
, const string
& id
)
147 //the value is volatile, and a database entry is created
148 if ( isdigit(*ptr
) || *ptr
=='-')
150 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
153 _VolatileValue
->setValue32( i
);
155 //the value is volatile and points to a db entry created elsewhere
158 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(str
);
167 CRGBA
CInterfaceProperty::getRGBA() const
170 sint64 buf
= getSInt64();
171 rgba
.R
= (sint8
) (buf
&255);
172 rgba
.G
= (sint8
) ((buf
>>8)&255 );
173 rgba
.B
= (sint8
) ((buf
>>16)&255);
174 rgba
.A
= (sint8
) ((buf
>>24)&255);
179 void CInterfaceProperty::setRGBA (const CRGBA
& value
)
181 setSInt64( (value
.R
)+ (((sint32
)value
.G
)<<8) + (((sint32
)value
.B
)<<16) + (((sint32
)value
.A
)<<24));
185 void CInterfaceProperty::readRGBA (const char *value
,const string
& id
)
190 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
191 int r
=0, g
=0, b
=0, a
=255;
192 sscanf (value
, "%d %d %d %d", &r
, &g
, &b
, &a
);
197 sint64 val
= r
+(g
<<8)+(b
<<16)+(a
<<24);
199 CRGBA rgba
= getRGBA();
203 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(str
);
208 void CInterfaceProperty::readHotSpot (const char *ptr
,const string
& id
)
211 if ( !strcmp(ptr
,"TL") )
213 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
214 _VolatileValue
->setValue64((sint64
)Hotspot_TL
);
216 else if ( !strcmp(ptr
,"TM") )
218 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
219 _VolatileValue
->setValue64( (sint64
)Hotspot_TM
);
221 else if ( !strcmp(ptr
,"TR") )
223 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
224 _VolatileValue
->setValue64( (sint64
)Hotspot_TR
);
226 else if ( !strcmp(ptr
,"ML") )
228 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
229 _VolatileValue
->setValue64( (sint64
)Hotspot_ML
);
231 else if ( !strcmp(ptr
,"MM") )
233 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
234 _VolatileValue
->setValue64( (sint64
)Hotspot_MM
);
236 else if ( !strcmp(ptr
,"MR") )
238 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
239 _VolatileValue
->setValue64( (sint64
)Hotspot_MR
);
241 else if ( !strcmp(ptr
,"BL") )
243 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
244 _VolatileValue
->setValue64( (sint64
)Hotspot_BL
);
246 else if ( !strcmp(ptr
,"BM") )
248 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
249 _VolatileValue
->setValue64( (sint64
)Hotspot_BM
);
251 else if ( !strcmp(ptr
,"BR") )
253 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
254 _VolatileValue
->setValue64( (sint64
)Hotspot_BR
);
258 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(str
);
262 void CInterfaceProperty::setBool(bool value
)
264 _VolatileValue
->setValue8 (value
);
267 bool CInterfaceProperty::getBool() const
269 return _VolatileValue
->getValue8() != 0 ? true : false;
272 void CInterfaceProperty::readBool (const char* value
,const string
& id
)
275 if ( !strcmp(value
,"true") )
277 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
278 _VolatileValue
->setValue8( (sint8
)true );
280 else if ( !strcmp(value
,"false") )
282 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
283 _VolatileValue
->setValue8( (sint8
)false );
285 else if ( isdigit(*value
) || *value
=='-')
287 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(id
);
289 fromString(value
, value8
);
290 _VolatileValue
->setValue8( value8
);
293 _VolatileValue
= NLGUI::CDBManager::getInstance()->getDbProp(str
);
297 // ***************************************************************************
298 void CInterfaceProperty::swap32(CInterfaceProperty
&o
)
300 CCDBNodeLeaf
*a
= getNodePtr();
301 CCDBNodeLeaf
*b
= o
.getNodePtr();
304 sint32 val
= a
->getValue32();
305 a
->setValue32(b
->getValue32());