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_bar3.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
;
38 NLMISC_REGISTER_OBJECT(CViewBase
, CDBViewBar3
, std::string
, "bar3");
40 // ----------------------------------------------------------------------------
41 CDBViewBar3::CDBViewBar3(const TCtorParam
¶m
)
46 _ColorsNegative
[0] = _ColorsNegative
[1] = _ColorsNegative
[2] = NLMISC::CRGBA(0,0,0,0);
47 _ValueInt
[0] = _ValueInt
[1] = _ValueInt
[2] = 0;
48 _RangeInt
[0] = _RangeInt
[1] = _RangeInt
[2] = 255;
52 // ----------------------------------------------------------------------------
53 void CDBViewBar3::parseValProp(xmlNodePtr cur
, CInterfaceProperty
&dbProp
, sint32
&intProp
, const char *name
)
55 CXMLAutoPtr
prop((const char*) xmlGetProp( cur
, (xmlChar
*)name
));
58 if ( isdigit(*prop
.getDatas()) || *(prop
.getDatas())=='-')
59 fromString((const char*)prop
, intProp
);
66 void CDBViewBar3::setValProp( const std::string
&value
, CInterfaceProperty
&dbProp
, sint32
&intProp
)
69 if( fromString( value
, i
) )
72 dbProp
.link( value
.c_str() );
76 std::string
CDBViewBar3::getProperty( const std::string
&name
) const
78 if( name
== "value1" )
80 return getValProp( _Value
[ 0 ], _ValueInt
[ 0 ] );
83 if( name
== "value2" )
85 return getValProp( _Value
[ 1 ], _ValueInt
[ 1 ] );
88 if( name
== "value3" )
90 return getValProp( _Value
[ 2 ], _ValueInt
[ 2 ] );
93 if( name
== "range1" )
95 return getValProp( _Range
[ 0 ], _RangeInt
[ 0 ] );
98 if( name
== "range2" )
100 return getValProp( _Range
[ 1 ], _RangeInt
[ 1 ] );
103 if( name
== "range3" )
105 return getValProp( _Range
[ 2 ], _RangeInt
[ 2 ] );
108 if( name
== "color1" )
110 return toString( _Colors
[ 0 ] );
113 if( name
== "color2" )
115 return toString( _Colors
[ 1 ] );
118 if( name
== "color3" )
120 return toString( _Colors
[ 2 ] );
123 if( name
== "color1_negative" )
125 return toString( _ColorsNegative
[ 0 ] );
128 if( name
== "color2_negative" )
130 return toString( _ColorsNegative
[ 1 ] );
133 if( name
== "color3_negative" )
135 return toString( _ColorsNegative
[ 2 ] );
146 return CViewBitmap::getProperty( name
);
150 void CDBViewBar3::setProperty( const std::string
&name
, const std::string
&value
)
152 if( name
== "value1" )
154 setValProp( value
, _Value
[ 0 ], _ValueInt
[ 0 ] );
158 if( name
== "value2" )
160 setValProp( value
, _Value
[ 1 ], _ValueInt
[ 1 ] );
164 if( name
== "value3" )
166 setValProp( value
, _Value
[ 2 ], _ValueInt
[ 2 ] );
170 if( name
== "range1" )
172 setValProp( value
, _Range
[ 0 ], _RangeInt
[ 0 ] );
176 if( name
== "range2" )
178 setValProp( value
, _Range
[ 1 ], _RangeInt
[ 1 ] );
182 if( name
== "range3" )
184 setValProp( value
, _Range
[ 2 ], _RangeInt
[ 2 ] );
188 if( name
== "color1" )
191 if( fromString( value
, c
) )
196 if( name
== "color2" )
199 if( fromString( value
, c
) )
204 if( name
== "color3" )
207 if( fromString( value
, c
) )
212 if( name
== "color1_negative" )
215 if( fromString( value
, c
) )
216 _ColorsNegative
[ 0 ] = c
;
220 if( name
== "color2_negative" )
223 if( fromString( value
, c
) )
224 _ColorsNegative
[ 1 ] = c
;
228 if( name
== "color3_negative" )
231 if( fromString( value
, c
) )
232 _ColorsNegative
[ 2 ] = c
;
239 if( fromString( value
, b
) )
244 CViewBitmap::setProperty( name
, value
);
248 xmlNodePtr
CDBViewBar3::serialize( xmlNodePtr parentNode
, const char *type
) const
250 xmlNodePtr node
= CViewBitmap::serialize( parentNode
, type
);
254 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"bar3" );
255 xmlSetProp( node
, BAD_CAST
"value1", BAD_CAST
getValProp( _Value
[ 0 ], _ValueInt
[ 0 ] ).c_str() );
256 xmlSetProp( node
, BAD_CAST
"value2", BAD_CAST
getValProp( _Value
[ 1 ], _ValueInt
[ 1 ] ).c_str() );
257 xmlSetProp( node
, BAD_CAST
"value3", BAD_CAST
getValProp( _Value
[ 2 ], _ValueInt
[ 2 ] ).c_str() );
259 xmlSetProp( node
, BAD_CAST
"range1", BAD_CAST
getValProp( _Range
[ 0 ], _RangeInt
[ 0 ] ).c_str() );
260 xmlSetProp( node
, BAD_CAST
"range2", BAD_CAST
getValProp( _Range
[ 1 ], _RangeInt
[ 1 ] ).c_str() );
261 xmlSetProp( node
, BAD_CAST
"range3", BAD_CAST
getValProp( _Range
[ 2 ], _RangeInt
[ 2 ] ).c_str() );
263 xmlSetProp( node
, BAD_CAST
"color1", BAD_CAST
toString( _Colors
[ 0 ] ).c_str() );
264 xmlSetProp( node
, BAD_CAST
"color2", BAD_CAST
toString( _Colors
[ 1 ] ).c_str() );
265 xmlSetProp( node
, BAD_CAST
"color3", BAD_CAST
toString( _Colors
[ 2 ] ).c_str() );
267 xmlSetProp( node
, BAD_CAST
"color1_negative", BAD_CAST
toString( _ColorsNegative
[ 0 ] ).c_str() );
268 xmlSetProp( node
, BAD_CAST
"color2_negative", BAD_CAST
toString( _ColorsNegative
[ 1 ] ).c_str() );
269 xmlSetProp( node
, BAD_CAST
"color3_negative", BAD_CAST
toString( _ColorsNegative
[ 2 ] ).c_str() );
272 xmlSetProp( node
, BAD_CAST
"mini", BAD_CAST
"true" );
274 xmlSetProp( node
, BAD_CAST
"mini", BAD_CAST
"false" );
280 // ----------------------------------------------------------------------------
281 bool CDBViewBar3::parse (xmlNodePtr cur
, CInterfaceGroup
* parentGroup
)
283 if (!CViewBitmap::parse(cur
, parentGroup
))
285 string tmp
= "cannot parse view:"+getId()+", parent:"+parentGroup
->getId();
291 parseValProp(cur
, _Value
[0], _ValueInt
[0], "value1" );
292 parseValProp(cur
, _Value
[1], _ValueInt
[1], "value2" );
293 parseValProp(cur
, _Value
[2], _ValueInt
[2], "value3" );
296 parseValProp(cur
, _Range
[0], _RangeInt
[0], "range1" );
297 parseValProp(cur
, _Range
[1], _RangeInt
[1], "range2" );
298 parseValProp(cur
, _Range
[2], _RangeInt
[2], "range3" );
301 // Read colors etc....
304 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"color1" );
305 _Colors
[0] = convertColor(prop
);
306 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"color2" );
307 _Colors
[1] = convertColor(prop
);
308 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"color3" );
309 _Colors
[2] = convertColor(prop
);
311 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"color1_negative" );
312 _ColorsNegative
[0] = convertColor(prop
);
313 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"color2_negative" );
314 _ColorsNegative
[1] = convertColor(prop
);
315 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"color3_negative" );
316 _ColorsNegative
[2] = convertColor(prop
);
320 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"mini" );
322 if (convertBool(prop
))
331 // ----------------------------------------------------------------------------
332 void CDBViewBar3::setMini(bool b
)
336 _Slot
.setTexture ("w_slot_jauge_3_mini.tga");
338 _Slot
.setTexture ("w_slot_jauge_3.tga");
340 _Slot
.setPosRef (_PosRef
);
341 _Slot
.setParentPosRef (_ParentPosRef
);
347 setTexture ("w_jauge_fill_mini.tga");
349 setTexture ("w_jauge_fill.tga");
352 // ----------------------------------------------------------------------------
353 void CDBViewBar3::updateCoords ()
355 if (_ParentPos
== NULL
)
356 _Slot
.setParentPos (_Parent
);
358 _Slot
.setParentPos (_ParentPos
);
359 _Slot
.updateCoords();
363 // get the height of the texture
365 CViewRenderer::getInstance()->getTextureSizeFromId(_TextureId
, dummy
, _BarH
);
367 CViewBitmap::updateCoords();
370 // ----------------------------------------------------------------------------
371 sint32
CDBViewBar3::getCurrentValProp(const CInterfaceProperty
&dbProp
, sint32 intProp
)
373 if(dbProp
.getNodePtr())
374 return dbProp
.getSInt32();
379 std::string
CDBViewBar3::getValProp( const CInterfaceProperty
&prop
, sint32 intProp
) const
381 if( prop
.getNodePtr() != NULL
)
382 return prop
.getNodePtr()->getFullName();
384 return toString( intProp
);
388 // ----------------------------------------------------------------------------
389 void CDBViewBar3::draw ()
393 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
394 CRGBA gColor
= CWidgetManager::getInstance()->getGlobalColorForContent();
398 for (uint32 i
= 0; i
< 3; ++i
)
403 sint32 value
= getCurrentValProp(_Value
[i
], _ValueInt
[i
]);
404 sint32 range
= getCurrentValProp(_Range
[i
], _RangeInt
[i
]);
407 factor
= ( (float)value
/ (float)range
);
414 color
= _ColorsNegative
[i
];
421 // clamp the factor to 0/1
423 float wBar
= factor
* (float)(_Slot
.getWReal()-2);
425 color
.A
= (uint8
)(((sint32
)color
.A
*((sint32
)gColor
.A
+1))>>8);
426 _WReal
= (sint32
)wBar
;
428 rVR
.drawRotFlipBitmap (_RenderLayer
, _XReal
+1, _YReal
+i
*3+2, _WReal
, _BarH
, 0, false, _TextureId
, color
);
433 for (uint32 i
= 0; i
< 3; ++i
)
438 sint32 value
= getCurrentValProp(_Value
[i
], _ValueInt
[i
]);
439 sint32 range
= getCurrentValProp(_Range
[i
], _RangeInt
[i
]);
442 factor
= ( (float)value
/ (float)range
);
449 color
= _ColorsNegative
[i
];
456 // clamp the factor to 0/1
458 float wBar
= factor
* (float)(_Slot
.getWReal()-4);
460 color
.A
= (uint8
)(((sint32
)color
.A
*((sint32
)gColor
.A
+1))>>8);
461 _WReal
= (sint32
)wBar
;
463 rVR
.drawRotFlipBitmap (_RenderLayer
, _XReal
+2, _YReal
+i
*7+4, _WReal
, _BarH
, 0, false, _TextureId
, color
);
468 void CDBViewBar3::forceLink()