Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / gui / interface_property.cpp
blobc3208c9d036c6dc32382f4e2e791ec66de5bb46d
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2012-2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
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/>.
21 #include "stdpch.h"
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;
29 using namespace std;
31 #ifdef DEBUG_NEW
32 #define new DEBUG_NEW
33 #endif
35 namespace NLGUI
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
46 if( !dbNode )
48 _VolatileValue = defaultLeaf;
49 return false;
52 // get the leaf
53 _VolatileValue = dbNode->getLeaf( leafId.c_str(), false );
54 if( _VolatileValue )
55 return true;
57 // default
58 _VolatileValue = defaultLeaf;
59 return false;
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);
70 return false;
72 return true;
76 void CInterfaceProperty::setDouble(double value)
78 C64BitsParts parts;
79 parts.d[0] = value;
80 setSInt64(parts.i64[0]);
83 double CInterfaceProperty::getDouble() const
85 C64BitsParts parts;
86 parts.i64[0] = getSInt64();
87 return parts.d[0];
90 // *****************
91 // sint64 operations
92 // *****************
95 void CInterfaceProperty::readSInt64(const char * ptr,const string& id)
97 string str (ptr);
98 //the value is volatile, and a database entry is created
99 if ( isdigit(*ptr) || *ptr=='-')
101 _VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(id);
102 sint64 i;
103 fromString(ptr, i);
104 _VolatileValue->setValue64( i );
106 //the value is volatile and points to a db entry created elsewhere
107 else
109 _VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(str);
116 // ****************
117 // float operations
118 // ****************
121 // ----------------------------------------------------------------------------
122 void CInterfaceProperty::readDouble(const char * ptr,const string& id)
124 string str (ptr);
125 if ( isdigit(*ptr) || *ptr=='-')
127 _VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(id);
128 C64BitsParts buf;
129 fromString(ptr, buf.d[0]);
130 _VolatileValue->setValue64(buf.i64[0]);
132 else
134 _VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(str);
138 // *****************
139 // sint32 operations
140 // *****************
143 // ----------------------------------------------------------------------------
144 void CInterfaceProperty::readSInt32 (const char *ptr, const string& id)
146 string str (ptr);
147 //the value is volatile, and a database entry is created
148 if ( isdigit(*ptr) || *ptr=='-')
150 _VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(id);
151 sint32 i;
152 fromString(ptr, i);
153 _VolatileValue->setValue32( i );
155 //the value is volatile and points to a db entry created elsewhere
156 else
158 _VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(str);
164 // *****************
165 // rgba operations
166 // *****************
167 CRGBA CInterfaceProperty::getRGBA() const
169 CRGBA rgba;
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);
175 return rgba;
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)
187 string str (value);
188 if (isdigit(*value))
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);
193 clamp (r, 0, 255);
194 clamp (g, 0, 255);
195 clamp (b, 0, 255);
196 clamp (a, 0, 255);
197 sint64 val = r+(g<<8)+(b<<16)+(a<<24);
198 setSInt64(val);
199 CRGBA rgba = getRGBA();
201 else
203 _VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(str);
208 void CInterfaceProperty::readHotSpot (const char *ptr,const string& id)
210 string str(ptr);
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 );
257 else
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)
274 string str (value);
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);
288 sint8 value8;
289 fromString(value, value8);
290 _VolatileValue->setValue8( value8 );
292 else
293 _VolatileValue = NLGUI::CDBManager::getInstance()->getDbProp(str);
297 // ***************************************************************************
298 void CInterfaceProperty::swap32(CInterfaceProperty &o)
300 CCDBNodeLeaf *a= getNodePtr();
301 CCDBNodeLeaf *b= o.getNodePtr();
302 if(!a || !b)
303 return;
304 sint32 val= a->getValue32();
305 a->setValue32(b->getValue32());
306 b->setValue32(val);