Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / src / gui / dbview_quantity.cpp
blob84c21419198742a2ebcf6199501fc2a5d6bb16f1
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) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "stdpch.h"
23 #include "nel/gui/dbview_quantity.h"
24 #include "nel/misc/xml_auto_ptr.h"
25 #include "nel/misc/i18n.h"
27 using namespace std;
28 using namespace NL3D;
29 using namespace NLMISC;
31 #ifdef DEBUG_NEW
32 #define new DEBUG_NEW
33 #endif
35 NLMISC_REGISTER_OBJECT(CViewBase, CDBViewQuantity, std::string, "text_quantity");
37 namespace NLGUI
40 // ***************************************************************************
41 CDBViewQuantity::CDBViewQuantity(const TCtorParam &param)
42 : CViewText(param)
47 std::string CDBViewQuantity::getProperty( const std::string &name ) const
49 if( name == "value" )
51 if( _Number.getNodePtr() != NULL )
52 return _Number.getNodePtr()->getFullName();
53 else
54 return "";
56 else
57 if( name == "valuemax" )
59 if( _NumberMax.getNodePtr() != NULL )
60 return _NumberMax.getNodePtr()->getFullName();
61 else
62 return "";
64 else
65 if( name == "emptytext" )
67 return _EmptyText;
69 else
70 return CViewText::getProperty( name );
74 void CDBViewQuantity::setProperty( const std::string &name, const std::string &value )
76 if( name == "value" )
78 _Number.link( value.c_str() );
79 return;
81 else
82 if( name == "valuemax" )
84 _NumberMax.link( value.c_str() );
85 return;
87 else
88 if( name == "emptytext" )
90 _EmptyText = value;
91 return;
93 else
94 CViewText::setProperty( name, value );
98 xmlNodePtr CDBViewQuantity::serialize( xmlNodePtr parentNode, const char *type ) const
100 xmlNodePtr node = CViewText::serialize( parentNode, type );
101 if( node == NULL )
102 return NULL;
104 xmlSetProp( node, BAD_CAST "type", BAD_CAST "text_quantity" );
106 if( _Number.getNodePtr() != NULL )
107 xmlSetProp( node, BAD_CAST "value", BAD_CAST _Number.getNodePtr()->getFullName().c_str() );
108 else
109 xmlSetProp( node, BAD_CAST "value", BAD_CAST "" );
111 if( _NumberMax.getNodePtr() != NULL )
112 xmlSetProp( node, BAD_CAST "valuemax", BAD_CAST _NumberMax.getNodePtr()->getFullName().c_str() );
113 else
114 xmlSetProp( node, BAD_CAST "valuemax", BAD_CAST "" );
116 xmlSetProp( node, BAD_CAST "emptytext", BAD_CAST _EmptyText.c_str() );
118 return node;
121 // ***************************************************************************
122 bool CDBViewQuantity::parse (xmlNodePtr cur, CInterfaceGroup * parentGroup)
124 if(!CViewText::parse(cur, parentGroup))
125 return false;
127 // link to the db
128 CXMLAutoPtr ptr;
129 ptr = xmlGetProp (cur, (xmlChar*)"value");
130 if ( ptr )
131 _Number.link ( ptr );
132 else
134 nlinfo ("no value in %s", _Id.c_str());
135 return false;
137 ptr = xmlGetProp (cur, (xmlChar*)"valuemax");
138 if ( ptr )
139 _NumberMax.link ( ptr );
140 else
142 nlinfo ("no max value in %s", _Id.c_str());
143 return false;
146 // empty opt
147 ptr = xmlGetProp (cur, (xmlChar*)"emptytext");
148 if(ptr)
150 const char *propPtr = ptr;
151 if (NLMISC::startsWith(propPtr, "ui"))
152 _EmptyText = CI18N::get(propPtr);
153 else
154 _EmptyText = propPtr;
157 // init cache.
158 _Cache= 0;
159 _CacheMax= 0;
160 buildTextFromCache();
162 return true;
165 // ***************************************************************************
166 void CDBViewQuantity::draw ()
168 if( _Number.hasValue() && _NumberMax.hasValue() )
170 // change text
171 sint32 val= _Number.getSInt32();
172 sint32 valMax= _NumberMax.getSInt32();
173 if(_Cache!=val || _CacheMax!=valMax)
175 _Cache= val;
176 _CacheMax=valMax;
177 buildTextFromCache();
181 // parent call
182 CViewText::draw();
185 // ***************************************************************************
186 void CDBViewQuantity::buildTextFromCache()
188 if(_Cache==0 && !_EmptyText.empty())
190 setText(_EmptyText);
192 else
194 char buf[256];
195 smprintf(buf, 256, "%d/%d", _Cache, _CacheMax);
196 setText(toString((const char*)buf));
200 void CDBViewQuantity::forceLink()