Merge branch 'main/rendor-staging' into fixes
[ryzomcore.git] / nel / src / gui / dbview_digit.cpp
blob662764895f7389a8fa7b58b67bc3150b9a5facc2
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 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/gui/dbview_digit.h"
23 #include "nel/misc/xml_auto_ptr.h"
24 #include "nel/gui/view_renderer.h"
26 using namespace std;
27 using namespace NL3D;
28 using namespace NLMISC;
30 #ifdef DEBUG_NEW
31 #define new DEBUG_NEW
32 #endif
34 NLMISC_REGISTER_OBJECT(CViewBase, CDBViewDigit, std::string, "digit");
36 namespace NLGUI
39 // ***************************************************************************
40 CDBViewDigit::CDBViewDigit(const TCtorParam &param)
41 : CViewBase(param)
43 _NumDigit= 2;
44 _WSpace= -1;
45 _DivBase= 1;
49 std::string CDBViewDigit::getProperty( const std::string &name ) const
51 if( name == "value" )
53 if( _Number.getNodePtr() != NULL )
54 return _Number.getNodePtr()->getFullName();
55 else
56 return "";
58 else
59 if( name == "numdigit" )
61 return toString( _NumDigit );
63 else
64 if( name == "wspace" )
66 return toString( _WSpace );
68 else
69 if( name == "color" )
71 return toString( _Color );
73 else
74 return CViewBase::getProperty( name );
78 void CDBViewDigit::setProperty( const std::string &name, const std::string &value )
80 if( name == "value" )
82 _Number.link( value.c_str() );
83 return;
85 else
86 if( name == "numdigit" )
88 sint32 i;
89 if( fromString( value, i ) )
90 _NumDigit = i;
91 return;
93 else
94 if( name == "wspace" )
96 sint32 i;
97 if( fromString( value, i ) )
98 _WSpace = i;
99 return;
101 else
102 if( name == "color" )
104 CRGBA c;
105 if( fromString( value, c ) )
106 _Color = c;
107 return;
109 else
110 CViewBase::setProperty( name, value );
114 xmlNodePtr CDBViewDigit::serialize( xmlNodePtr parentNode, const char *type ) const
116 xmlNodePtr node = CViewBase::serialize( parentNode, type );
117 if( node == NULL )
118 return NULL;
120 xmlSetProp( node, BAD_CAST "type", BAD_CAST "digit" );
122 if( _Number.getNodePtr() != NULL )
123 xmlSetProp( node, BAD_CAST "value", BAD_CAST _Number.getNodePtr()->getFullName().c_str() );
124 else
125 xmlSetProp( node, BAD_CAST "value", BAD_CAST "" );
127 xmlSetProp( node, BAD_CAST "numdigit", BAD_CAST toString( _NumDigit ).c_str() );
128 xmlSetProp( node, BAD_CAST "wspace", BAD_CAST toString( _WSpace ).c_str() );
129 xmlSetProp( node, BAD_CAST "color", BAD_CAST toString( _Color ).c_str() );
131 return node;
135 // ***************************************************************************
136 bool CDBViewDigit::parse (xmlNodePtr cur, CInterfaceGroup * parentGroup)
138 if(!CViewBase::parse(cur, parentGroup))
139 return false;
141 CViewRenderer &rVR = *CViewRenderer::getInstance();
143 // link to the db
144 CXMLAutoPtr ptr;
145 ptr = xmlGetProp (cur, (xmlChar*)"value");
146 if ( ptr )
147 _Number.link ( ptr );
148 else
150 nlinfo ("no value in %s", _Id.c_str());
151 return false;
154 // read options
155 ptr = xmlGetProp (cur, (xmlChar*)"numdigit");
156 if(ptr) fromString((const char*)ptr, _NumDigit);
157 clamp(_NumDigit, 1, 10);
159 ptr = xmlGetProp (cur, (xmlChar*)"wspace");
160 if(ptr) fromString((const char*)ptr, _WSpace);
162 ptr= (char*) xmlGetProp( cur, (xmlChar*)"color" );
163 _Color = CRGBA(255,255,255,255);
164 if (ptr)
165 _Color = convertColor (ptr);
167 // compute window size. Remove one space.
168 sint32 wDigit= rVR.getFigurTextureW();
169 sint32 hDigit= rVR.getFigurTextureH();
170 setW((wDigit+_WSpace)*_NumDigit - _WSpace);
171 setH(hDigit);
173 // some init
174 // For _NumDigit=2; set the divBase to 100, etc...
175 _DivBase= 1;
176 for(uint i= 0;i<(uint)_NumDigit;i++)
178 _DivBase*= 10;
181 // init cache.
182 _Cache= -1;
184 return true;
188 // ***************************************************************************
189 void CDBViewDigit::updateCoords()
191 CViewBase::updateCoords();
195 // ***************************************************************************
196 void CDBViewDigit::draw ()
198 CViewRenderer &rVR = *CViewRenderer::getInstance();
199 sint32 wDigit= rVR.getFigurTextureW();
200 sint32 hDigit= rVR.getFigurTextureH();
202 // change bitmap ids
203 sint32 val= _Number.getSInt32();
204 val= max(val, sint32(0));
205 if(_Cache!=val)
207 _Cache= val;
208 // clamp the value to max possible (eg:99)
209 if(val>(sint32)_DivBase-1)
210 val=(sint32)_DivBase-1;
211 // compute each digit id
212 uint divisor= _DivBase/10;
213 for(sint i=0;i<_NumDigit;i++)
215 sint digitVal= (val/divisor)%10;
216 // set the digit text id
217 _DigitId[i]= rVR.getFigurTextureId(digitVal);
218 // next divisor
219 divisor/= 10;
223 // Display bitmaps
224 sint32 x= _XReal;
225 sint32 y= _YReal;
226 for(sint i=0;i<_NumDigit;i++)
228 rVR.drawRotFlipBitmap ( _RenderLayer, x, y, wDigit, hDigit, 0, false, _DigitId[i], _Color );
229 // next digit
230 x+= wDigit+_WSpace;