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) 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/gui/dbview_digit.h"
23 #include "nel/misc/xml_auto_ptr.h"
24 #include "nel/gui/view_renderer.h"
28 using namespace NLMISC
;
34 NLMISC_REGISTER_OBJECT(CViewBase
, CDBViewDigit
, std::string
, "digit");
39 // ***************************************************************************
40 CDBViewDigit::CDBViewDigit(const TCtorParam
¶m
)
49 std::string
CDBViewDigit::getProperty( const std::string
&name
) const
53 if( _Number
.getNodePtr() != NULL
)
54 return _Number
.getNodePtr()->getFullName();
59 if( name
== "numdigit" )
61 return toString( _NumDigit
);
64 if( name
== "wspace" )
66 return toString( _WSpace
);
71 return toString( _Color
);
74 return CViewBase::getProperty( name
);
78 void CDBViewDigit::setProperty( const std::string
&name
, const std::string
&value
)
82 _Number
.link( value
.c_str() );
86 if( name
== "numdigit" )
89 if( fromString( value
, i
) )
94 if( name
== "wspace" )
97 if( fromString( value
, i
) )
102 if( name
== "color" )
105 if( fromString( value
, c
) )
110 CViewBase::setProperty( name
, value
);
114 xmlNodePtr
CDBViewDigit::serialize( xmlNodePtr parentNode
, const char *type
) const
116 xmlNodePtr node
= CViewBase::serialize( parentNode
, type
);
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() );
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() );
135 // ***************************************************************************
136 bool CDBViewDigit::parse (xmlNodePtr cur
, CInterfaceGroup
* parentGroup
)
138 if(!CViewBase::parse(cur
, parentGroup
))
141 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
145 ptr
= xmlGetProp (cur
, (xmlChar
*)"value");
147 _Number
.link ( ptr
);
150 nlinfo ("no value in %s", _Id
.c_str());
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);
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
);
174 // For _NumDigit=2; set the divBase to 100, etc...
176 for(uint i
= 0;i
<(uint
)_NumDigit
;i
++)
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();
203 sint32 val
= _Number
.getSInt32();
204 val
= max(val
, sint32(0));
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
);
226 for(sint i
=0;i
<_NumDigit
;i
++)
228 rVR
.drawRotFlipBitmap ( _RenderLayer
, x
, y
, wDigit
, hDigit
, 0, false, _DigitId
[i
], _Color
);