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_bar.h"
23 #include "nel/misc/xml_auto_ptr.h"
24 #include "nel/gui/interface_group.h"
25 #include "nel/gui/widget_manager.h"
26 #include "nel/gui/db_manager.h"
30 using namespace NLMISC
;
36 NLMISC_REGISTER_OBJECT(CViewBase
, CDBViewBar
, std::string
, "bar");
41 // ----------------------------------------------------------------------------
42 void CDBViewBar::parseValProp(xmlNodePtr cur
, CInterfaceProperty
&dbProp
, sint32
&intProp
, const char *name
)
44 CXMLAutoPtr
prop((const char*) xmlGetProp( cur
, (xmlChar
*)name
));
47 if ( isdigit(*prop
.getDatas()) || *(prop
.getDatas())=='-')
48 fromString((const char*)prop
, intProp
);
54 std::string
CDBViewBar::getProperty( const std::string
&name
) const
58 if( _Value
.getNodePtr() != NULL
)
59 return _Value
.getNodePtr()->getFullName();
61 return toString( _ValueInt
);
66 if( _Range
.getNodePtr() != NULL
)
67 return _Range
.getNodePtr()->getFullName();
69 return toString( _RangeInt
);
72 if( name
== "reference" )
74 if( _Reference
.getNodePtr() != NULL
)
75 return _Reference
.getNodePtr()->getFullName();
77 return toString( _ReferenceInt
);
80 if( name
== "color_negative" )
82 return toString( _ColorNegative
);
87 if( _Type
== ViewBar_Mini
)
93 if( name
== "ultra_mini" )
95 if( _Type
== ViewBar_UltraMini
)
101 if( name
== "mini_thick" )
103 if( _Type
== ViewBar_MiniThick
)
109 return CViewBitmap::getProperty( name
);
112 void CDBViewBar::setProperty( const std::string
&name
, const std::string
&value
)
114 if( name
== "value" )
117 if( fromString( value
, i
) )
120 _Value
.link( value
.c_str() );
124 if( name
== "range" )
127 if( fromString( value
, i
) )
130 _Range
.link( value
.c_str() );
134 if( name
== "reference" )
137 if( fromString( value
, i
) )
140 _Reference
.link( value
.c_str() );
144 if( name
== "color_negative" )
147 if( fromString( value
, c
) )
155 if( fromString( value
, b
) )
157 _Type
= ViewBar_Mini
;
161 if( name
== "ultra_mini" )
164 if( fromString( value
, b
) )
166 _Type
= ViewBar_UltraMini
;
170 if( name
== "mini_thick" )
173 if( fromString( value
, b
) )
175 _Type
= ViewBar_MiniThick
;
179 CViewBitmap::setProperty( name
, value
);
183 xmlNodePtr
CDBViewBar::serialize( xmlNodePtr parentNode
, const char *type
) const
185 xmlNodePtr node
= CViewBitmap::serialize( parentNode
, type
);
189 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"bar" );
191 if( _Value
.getNodePtr() != NULL
)
192 xmlSetProp( node
, BAD_CAST
"value", BAD_CAST _Value
.getNodePtr()->getFullName().c_str() );
194 xmlSetProp( node
, BAD_CAST
"value", BAD_CAST
toString( _RangeInt
).c_str() );
196 if( _Range
.getNodePtr() != NULL
)
197 xmlSetProp( node
, BAD_CAST
"range", BAD_CAST _Range
.getNodePtr()->getFullName().c_str() );
199 xmlSetProp( node
, BAD_CAST
"range", BAD_CAST
toString( _RangeInt
).c_str() );
201 if( _Reference
.getNodePtr() != NULL
)
202 xmlSetProp( node
, BAD_CAST
"reference", BAD_CAST _Reference
.getNodePtr()->getFullName().c_str() );
204 xmlSetProp( node
, BAD_CAST
"reference", BAD_CAST
toString( _ReferenceInt
).c_str() );
206 xmlSetProp( node
, BAD_CAST
"color_negative", BAD_CAST
toString( _ColorNegative
).c_str() );
208 if( _Type
== ViewBar_Mini
)
209 xmlSetProp( node
, BAD_CAST
"mini", BAD_CAST
"true" );
211 xmlSetProp( node
, BAD_CAST
"mini", BAD_CAST
"false" );
213 if( _Type
== ViewBar_UltraMini
)
214 xmlSetProp( node
, BAD_CAST
"ultra_mini", BAD_CAST
"true" );
216 xmlSetProp( node
, BAD_CAST
"ultra_mini", BAD_CAST
"false" );
218 if( _Type
== ViewBar_MiniThick
)
219 xmlSetProp( node
, BAD_CAST
"mini_thick", BAD_CAST
"true" );
221 xmlSetProp( node
, BAD_CAST
"mini_thick", BAD_CAST
"false" );
226 // ----------------------------------------------------------------------------
227 bool CDBViewBar::parse (xmlNodePtr cur
, CInterfaceGroup
* parentGroup
)
229 if (!CViewBitmap::parse(cur
, parentGroup
))
231 string tmp
= "cannot parse view:"+getId()+", parent:"+parentGroup
->getId();
238 // read value, range and reference
239 parseValProp(cur
, _Value
, _ValueInt
, "value");
240 parseValProp(cur
, _Range
, _RangeInt
, "range");
241 parseValProp(cur
, _Reference
, _ReferenceInt
, "reference");
244 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"color_negative" );
245 _ColorNegative
= CRGBA(0,0,0,0);
247 _ColorNegative
= convertColor (prop
);
250 _Type
= ViewBar_Normal
;
252 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"mini" );
254 if (convertBool(prop
))
255 setType(ViewBar_Mini
);
257 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"ultra_mini" );
259 if (convertBool(prop
))
260 setType(ViewBar_UltraMini
);
262 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"mini_thick" );
264 if (convertBool(prop
))
265 setType(ViewBar_MiniThick
);
267 if (_Type
== ViewBar_Normal
)
268 setType(ViewBar_Normal
);
273 // ----------------------------------------------------------------------------
274 void CDBViewBar::setType (TViewBar vb
)
279 case ViewBar_Normal
: _Slot
.setTexture ("w_slot_jauge_1.tga"); break;
280 case ViewBar_Mini
: _Slot
.setTexture ("w_slot_jauge_1_mini.tga"); break;
281 case ViewBar_UltraMini
: _Slot
.setTexture ("w_slot_jauge_1_umin.tga"); break;
282 case ViewBar_MiniThick
: _Slot
.setTexture ("w_slot_jauge_1_tmin.tga"); break;
285 _Slot
.setPosRef (_PosRef
);
286 _Slot
.setParentPosRef (_ParentPosRef
);
293 case ViewBar_Normal
: setTexture ("w_jauge_fill.tga"); break;
294 case ViewBar_Mini
: setTexture ("w_jauge_fill_mini.tga"); break;
295 case ViewBar_UltraMini
: setTexture ("w_jauge_fill_umin.tga"); break;
296 case ViewBar_MiniThick
: setTexture ("w_jauge_fill_tmin.tga"); break;
299 // Get the Height Size.
301 CViewRenderer::getInstance()->getTextureSizeFromId(_TextureId
, wBar
, _HBar
);
304 // ----------------------------------------------------------------------------
305 void CDBViewBar::updateCoords ()
307 if (_ParentPos
== NULL
)
308 _Slot
.setParentPos (_Parent
);
310 _Slot
.setParentPos (_ParentPos
);
311 _Slot
.updateCoords();
314 CViewBitmap::updateCoords();
317 // ----------------------------------------------------------------------------
318 sint64
CDBViewBar::getCurrentValProp(const CInterfaceProperty
&dbProp
, sint32 intProp
)
320 if(dbProp
.getNodePtr())
321 return dbProp
.getSInt64();
326 // ----------------------------------------------------------------------------
327 void CDBViewBar::draw ()
329 float wBar
= (float)(_Slot
.getWReal()-4);
331 sint64 value
= getCurrentValProp(_Value
, _ValueInt
);
332 sint64 range
= getCurrentValProp(_Range
, _RangeInt
);
333 sint64 reference
= getCurrentValProp(_Reference
, _ReferenceInt
);
335 // remove the reference
340 CRGBA color
= _Color
;
344 float ratio
= (float)value
/ range
;
345 if (_ColorNegative
.A
!= 0 && ratio
< 0.0f
)
348 color
= _ColorNegative
;
350 NLMISC::clamp(ratio
, 0.f
, 1.f
);
356 _WReal
= (sint32
)wBar
;
360 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
362 color
.A
= (uint8
)(((sint32
)color
.A
*((sint32
)CWidgetManager::getInstance()->getGlobalColorForContent().A
+1))>>8);
364 // compute the DeltaY: mean of dif.
365 sint32 deltaY
= (_H
-_HBar
)/2;
366 rVR
.drawRotFlipBitmap (_RenderLayer
, _XReal
+2, _YReal
+deltaY
, _WReal
, _HBar
, 0, false, _TextureId
, color
);
369 // ----------------------------------------------------------------------------
370 void CDBViewBar::setValueDbLink (const std::string
&r
)
372 CCDBNodeLeaf
*pNL
= NLGUI::CDBManager::getInstance()->getDbProp(r
,false);
373 if (pNL
!= NULL
) _Value
.setNodePtr(pNL
);
376 // ----------------------------------------------------------------------------
377 void CDBViewBar::setRangeDbLink (const std::string
&r
)
379 CCDBNodeLeaf
*pNL
= NLGUI::CDBManager::getInstance()->getDbProp(r
,false);
380 if (pNL
!= NULL
) _Range
.setNodePtr(pNL
);
383 // ----------------------------------------------------------------------------
384 void CDBViewBar::setReferenceDbLink (const std::string
&r
)
386 CCDBNodeLeaf
*pNL
= NLGUI::CDBManager::getInstance()->getDbProp(r
,false);
387 if (pNL
!= NULL
) _Reference
.setNodePtr(pNL
);
390 // ----------------------------------------------------------------------------
391 string
CDBViewBar::getValueDbLink () const
393 if (_Value
.getNodePtr() == NULL
) return "";
394 return _Value
.getNodePtr()->getFullName();
397 // ----------------------------------------------------------------------------
398 string
CDBViewBar::getRangeDbLink () const
400 if (_Range
.getNodePtr() == NULL
) return "";
401 return _Range
.getNodePtr()->getFullName();
404 // ----------------------------------------------------------------------------
405 string
CDBViewBar::getReferenceDbLink () const
407 if (_Reference
.getNodePtr() == NULL
) return "";
408 return _Reference
.getNodePtr()->getFullName();