1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2020 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/view_bitmap.h"
23 #include "nel/misc/xml_auto_ptr.h"
24 #include "nel/gui/widget_manager.h"
25 #include "nel/gui/interface_group.h"
26 #include "nel/gui/group_container_base.h"
27 #include "nel/gui/group_html.h"
30 using namespace NLMISC
;
37 NLMISC_REGISTER_OBJECT(CViewBase
, CViewBitmap
, std::string
, "bitmap");
38 REGISTER_UI_CLASS(CViewBitmap
)
43 CViewBitmap::~CViewBitmap()
47 CGroupHTML
*groupHtml
= dynamic_cast<CGroupHTML
*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:webig:content:html"));
49 groupHtml
->removeImageDownload(_HtmlDownload
, dynamic_cast<CViewBase
*>(this));
55 std::string
CViewBitmap::getProperty( const std::string
&name
) const
59 return toString( _Color
);
62 if( name
== "txtoffsetx" )
64 return toString( _TxtOffsetX
);
67 if( name
== "txtoffsety" )
69 return toString( _TxtOffsetY
);
72 if( name
== "txtwidth" )
74 return toString( _TxtWidth
);
77 if( name
== "txtheight" )
79 return toString( _TxtHeight
);
82 if( name
== "texture" )
89 return toString( _Scale
);
94 return toString( _Rot
);
99 return toString( _Flip
);
104 return toString( _Tile
);
107 if( name
== "align" )
111 if( ( _Align
& 1 ) != 0 )
116 if( ( _Align
& 2 ) != 0 )
124 if( name
== "inherit_gc_alpha" )
126 return toString( _InheritGCAlpha
);
129 return CViewBase::getProperty( name
);
132 void CViewBitmap::setProperty( const std::string
&name
, const std::string
&value
)
134 if( name
== "color" )
137 if( fromString( value
, c
) )
142 if( name
== "txtoffsetx" )
145 if( fromString( value
, i
) )
150 if( name
== "txtoffsety" )
153 if( fromString( value
, i
) )
158 if( name
== "txtwidth" )
161 if( fromString( value
, i
) )
166 if( name
== "txtheight" )
169 if( fromString( value
, i
) )
174 if( name
== "texture" )
180 if( name
== "scale" )
183 if( fromString( value
, b
) )
191 if( fromString( value
, i
) )
199 if( fromString( value
, b
) )
207 if( fromString( value
, b
) )
212 if( name
== "align" )
214 std::string::size_type i
;
215 for( i
= 0; i
< value
.size(); i
++ )
217 const char c
= value
[ i
];
241 if( name
== "inherit_gc_alpha" )
244 if( fromString( value
, b
) )
249 CViewBase::setProperty( name
, value
);
253 xmlNodePtr
CViewBitmap::serialize( xmlNodePtr parentNode
, const char *type
) const
255 xmlNodePtr node
= CViewBase::serialize( parentNode
, type
);
259 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"bitmap" );
260 xmlSetProp( node
, BAD_CAST
"color", BAD_CAST
toString( _Color
).c_str() );
261 xmlSetProp( node
, BAD_CAST
"txtoffsetx", BAD_CAST
toString( _TxtOffsetX
).c_str() );
262 xmlSetProp( node
, BAD_CAST
"txtoffsety", BAD_CAST
toString( _TxtOffsetY
).c_str() );
263 xmlSetProp( node
, BAD_CAST
"txtwidth", BAD_CAST
toString( _TxtWidth
).c_str() );
264 xmlSetProp( node
, BAD_CAST
"txtheight", BAD_CAST
toString( _TxtHeight
).c_str() );
265 xmlSetProp( node
, BAD_CAST
"texture", BAD_CAST
getTexture().c_str() );
266 xmlSetProp( node
, BAD_CAST
"scale", BAD_CAST
toString( _Scale
).c_str() );
267 xmlSetProp( node
, BAD_CAST
"rot", BAD_CAST
toString( _Rot
).c_str() );
268 xmlSetProp( node
, BAD_CAST
"flip", BAD_CAST
toString( _Flip
).c_str() );
269 xmlSetProp( node
, BAD_CAST
"tile", BAD_CAST
toString( _Tile
).c_str() );
270 xmlSetProp( node
, BAD_CAST
"inherit_gc_alpha", BAD_CAST
toString( _InheritGCAlpha
).c_str() );
273 if( ( _Align
& 1 ) != 0 )
278 if( ( _Align
& 2 ) != 0 )
283 xmlSetProp( node
, BAD_CAST
"txtoffsetx", BAD_CAST align
.c_str() );
288 // ----------------------------------------------------------------------------
290 bool CViewBitmap::parse(xmlNodePtr cur
, CInterfaceGroup
* parentGroup
)
294 //try to get props that can be inherited from groups
295 //if a property is not defined, try to find it in the parent group.
296 //if it is undefined, set it to zero
297 if (! CViewBase::parse(cur
,parentGroup
) )
299 string tmp
= string("cannot parse view:")+getId()+", parent:"+parentGroup
->getId();
300 nlinfo (tmp
.c_str());
304 //try to get the NEEDED specific props
305 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"color" );
306 _Color
= CRGBA(255,255,255,255);
308 _Color
= convertColor (prop
);
310 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"txtoffsetx" );
312 if (prop
) fromString((const char*)prop
, _TxtOffsetX
);
314 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"txtoffsety" );
316 if (prop
) fromString((const char*)prop
, _TxtOffsetY
);
318 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"txtwidth" );
320 if (prop
) fromString((const char*)prop
, _TxtWidth
);
322 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"txtheight" );
324 if (prop
) fromString((const char*)prop
, _TxtHeight
);
326 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"texture" );
329 string TxName
= (const char *) prop
;
331 //CInterfaceManager *pIM = CInterfaceManager::getInstance();
332 //CViewRenderer &rVR = *CViewRenderer::getInstance();
333 //_TextureId = rVR.getTextureIdFromName (TxName);
336 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"scale" );
339 _Scale
= convertBool(prop
);
341 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"rot" );
344 fromString((const char*)prop
, _Rot
);
346 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"flip" );
349 _Flip
= convertBool(prop
);
351 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"tile" );
354 _Tile
= convertBool(prop
);
356 prop
= (char*) xmlGetProp (cur
, (xmlChar
*)"align");
360 const char *seekPtr
= prop
.getDatas();
361 while (*seekPtr
!= 0)
363 if ((*seekPtr
=='l')||(*seekPtr
=='L'))
367 if ((*seekPtr
=='r')||(*seekPtr
=='R'))
371 if ((*seekPtr
=='b')||(*seekPtr
=='B'))
375 if ((*seekPtr
=='t')||(*seekPtr
=='T'))
383 _InheritGCAlpha
= false;
384 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"inherit_gc_alpha" );
387 _InheritGCAlpha
= convertBool(prop
);
393 // ----------------------------------------------------------------------------
394 void CViewBitmap::draw ()
396 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
399 if(getModulateGlobalColor())
401 col
.modulateFromColor (_Color
, CWidgetManager::getInstance()->getGlobalColorForContent());
406 col
.A
= (uint8
)(((sint32
)col
.A
*((sint32
)CWidgetManager::getInstance()->getGlobalColorForContent().A
+1))>>8);
411 // search a parent container
412 CInterfaceGroup
*gr
= getParent();
415 if (gr
->isGroupContainer())
417 CGroupContainerBase
*gc
= static_cast<CGroupContainerBase
*>(gr
);
418 col
.A
= (uint8
)(((sint32
)col
.A
*((sint32
)gc
->getCurrentContainerAlpha()+1))>>8);
421 gr
= gr
->getParent();
425 if (_Scale
&& !_Tile
)
427 rVR
.drawRotFlipBitmap (_RenderLayer
, _XReal
, _YReal
,
437 rVR
.draw11RotFlipBitmap (_RenderLayer
, _XReal
, _YReal
,
444 rVR
.drawRotFlipBitmapTiled(_RenderLayer
, _XReal
, _YReal
,
454 // ----------------------------------------------------------------------------
455 void CViewBitmap::updateCoords()
459 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
461 rVR
.getTextureSizeFromId (_TextureId
, txw
, txh
);
465 CViewBase::updateCoords();
468 // ----------------------------------------------------------------------------
469 void CViewBitmap::setTexture(const std::string
& TxName
)
471 if (TxName
.find("://") != string::npos
|| TxName
.find("//") == 0)
473 CGroupHTML
*groupHtml
= dynamic_cast<CGroupHTML
*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:webig:content:html"));
475 string localname
= groupHtml
->localImageName(TxName
);
476 if (!CFile::fileExists(localname
))
477 localname
= "web_del.tga";
478 _TextureId
.setTexture (localname
.c_str(), _TxtOffsetX
, _TxtOffsetY
, _TxtWidth
, _TxtHeight
, false);
479 _HtmlDownload
= groupHtml
->addImageDownload(TxName
, dynamic_cast<CViewBase
*>(this));
486 CGroupHTML
*groupHtml
= dynamic_cast<CGroupHTML
*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:webig:content:html"));
488 groupHtml
->removeImageDownload(_HtmlDownload
, dynamic_cast<CViewBase
*>(this));
489 _HtmlDownload
= NULL
;
491 _TextureId
.setTexture (TxName
.c_str (), _TxtOffsetX
, _TxtOffsetY
, _TxtWidth
, _TxtHeight
, false);
495 // ----------------------------------------------------------------------------
496 std::string
CViewBitmap::getTexture () const
498 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
499 return rVR
.getTextureNameFromId (_TextureId
);
502 // ***************************************************************************
503 void CViewBitmap::fitTexture()
505 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
507 rVR
.getTextureSizeFromId(_TextureId
, w
, h
);
512 // ***************************************************************************
513 void CViewBitmap::setColorAsString(const std::string
& col
)
515 _Color
= convertColor (col
.c_str());
518 // ***************************************************************************
519 std::string
CViewBitmap::getColorAsString() const
521 return NLMISC::toString(_Color
.R
) + " " + NLMISC::toString(_Color
.G
) + " " + NLMISC::toString(_Color
.B
) + " " + NLMISC::toString(_Color
.A
);
524 // ***************************************************************************
525 void CViewBitmap::setColorAsInt(sint32 col
)
527 _Color
.setPacked(col
);
530 // ***************************************************************************
531 sint32
CViewBitmap::getColorAsInt() const
533 return _Color
.getPacked();
536 // ***************************************************************************
537 void CViewBitmap::setColorRGBA(NLMISC::CRGBA col
)
542 // ***************************************************************************
543 NLMISC::CRGBA
CViewBitmap::getColorRGBA() const
548 // ***************************************************************************
549 sint32
CViewBitmap::getMaxUsedW() const
555 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
556 rVR
.getTextureSizeFromId (_TextureId
, txw
, txh
);
560 // ***************************************************************************
561 sint32
CViewBitmap::getMinUsedW() const
563 return getMaxUsedW();
566 // ***************************************************************************
567 void CViewBitmap::serial(NLMISC::IStream
&f
)
569 CViewBase::serial(f
);
570 f
.serial(_TextureId
);
573 f
.serialEnum(_Align
);
575 nlSerialBitBool(f
, _Scale
);
576 nlSerialBitBool(f
, _Flip
);
577 nlSerialBitBool(f
, _Tile
);
578 nlSerialBitBool(f
, _InheritGCAlpha
);
579 f
.serial(_TxtOffsetX
);
580 f
.serial(_TxtOffsetY
);
582 f
.serial(_TxtHeight
);
587 // ***************************************************************************