1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013-2014 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "nel/gui/ctrl_text_button.h"
24 #include "nel/misc/xml_auto_ptr.h"
25 #include "nel/gui/view_text.h"
26 #include "nel/gui/view_text_id.h"
27 #include "nel/gui/group_container_base.h"
28 #include "nel/gui/lua_ihm.h"
29 #include "nel/gui/widget_manager.h"
30 #include "nel/gui/interface_factory.h"
31 #include "nel/misc/i18n.h"
34 using namespace NLMISC
;
41 NLMISC_REGISTER_OBJECT(CViewBase
, CCtrlTextButton
, std::string
, "text_button");
46 // ***************************************************************************
47 CCtrlTextButton::CCtrlTextButton(const TCtorParam
¶m
)
48 : CCtrlBaseButton(param
)
50 _BmpLeftW
= _BmpMiddleW
= _BmpRightW
= _BmpH
= 0;
59 _TextColorNormal
= CRGBA(255, 255, 255, 255);
60 _TextColorPushed
= CRGBA(255, 255, 255, 255);
61 _TextColorOver
= CRGBA(255, 255, 255, 255);
62 _TextShadowColorNormal
= CRGBA(0, 0, 0, 255);
63 _TextShadowColorPushed
= CRGBA(0, 0, 0, 255);
64 _TextShadowColorOver
= CRGBA(0, 0, 0, 255);
65 _TextModulateGlobalColorNormal
= true;
66 _TextModulateGlobalColorPushed
= true;
67 _TextModulateGlobalColorOver
= true;
68 _TextHeaderColor
= false;
69 _TextPosRef
= Hotspot_MM
;
70 _TextParentPosRef
= Hotspot_MM
;
71 _ForceTextOver
= false;
74 CCtrlTextButton::~CCtrlTextButton()
76 if( _ViewText
!= NULL
)
83 std::string
CCtrlTextButton::getProperty( const std::string
&name
) const
86 if( _ViewText
!= NULL
)
87 prop
= _ViewText
->getTextProperty( name
);
92 if( name
== "tx_normal" )
95 tex
= CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdNormal
[ 0 ] );
96 std::string::size_type i
= tex
.rfind( "_l.tga" );
97 if( i
!= std::string::npos
)
98 tex
= tex
.substr( 0, i
);
102 if( name
== "tx_pushed" )
105 tex
= CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdPushed
[ 0 ] );
106 std::string::size_type i
= tex
.rfind( "_l.tga" );
107 if( i
!= std::string::npos
)
108 tex
= tex
.substr( 0, i
);
112 if( name
== "tx_over" )
115 tex
= CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdOver
[ 0 ] );
116 std::string::size_type i
= tex
.rfind( "_l.tga" );
117 if( i
!= std::string::npos
)
118 tex
= tex
.substr( 0, i
);
122 if( name
== "wmargin" )
124 return toString( _WMargin
);
129 return toString( _WMin
);
134 return toString( _HMin
);
137 if( name
== "hardtext" )
139 if( _ViewText
!= NULL
)
140 return _ViewText
->getText();
142 return std::string( "" );
145 if( name
== "text_y" )
147 return toString( _TextY
);
150 if( name
== "text_x" )
152 return toString( _TextX
);
155 if( name
== "text_underlined" )
157 if( _ViewText
!= NULL
)
158 return toString( _ViewText
->getUnderlined() );
160 return std::string( "" );
163 if( name
== "text_posref" )
166 pr
= CInterfaceElement::HotSpotToString( _TextPosRef
);
170 if( name
== "text_parent_posref" )
173 pr
= CInterfaceElement::HotSpotToString( _TextParentPosRef
);
177 if( name
== "text_color_normal" )
179 return toString( _TextColorNormal
);
182 if( name
== "text_color_pushed" )
184 return toString( _TextColorPushed
);
187 if( name
== "text_color_over" )
189 return toString( _TextColorOver
);
192 if( name
== "text_shadow_color_normal" )
194 return toString( _TextShadowColorNormal
);
197 if( name
== "text_shadow_color_pushed" )
199 return toString( _TextShadowColorPushed
);
202 if( name
== "text_shadow_color_over" )
204 return toString( _TextShadowColorOver
);
207 if( name
== "text_global_color_normal" )
209 return toString( _TextModulateGlobalColorNormal
);
212 if( name
== "text_global_color_pushed" )
214 return toString( _TextModulateGlobalColorPushed
);
217 if( name
== "text_global_color_over" )
219 return toString( _TextModulateGlobalColorOver
);
222 if( name
== "force_text_over" )
224 return toString( _ForceTextOver
);
227 if( name
== "text_header_color" )
229 return toString( _TextHeaderColor
);
232 return CCtrlBaseButton::getProperty( name
);
235 void CCtrlTextButton::setProperty( const std::string
&name
, const std::string
&value
)
237 if( _ViewText
!= NULL
)
239 if( _ViewText
->setTextProperty( name
, value
) )
241 _ViewText
->invalidateContent();
246 if( name
== "tx_normal" )
249 tex
= CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdNormal
[ 0 ] );
250 std::string::size_type i
= tex
.rfind( "_l.tga" );
251 if( i
!= std::string::npos
)
252 tex
= tex
.substr( 0, i
);
254 _TextureIdNormal
[ 0 ].setTexture( std::string( value
+ "_l.tga" ).c_str() );
255 _TextureIdNormal
[ 1 ].setTexture( std::string( value
+ "_m.tga" ).c_str() );
256 _TextureIdNormal
[ 2 ].setTexture( std::string( value
+ "_r.tga" ).c_str() );
258 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
259 rVR
.getTextureSizeFromId(_TextureIdNormal
[0], _BmpLeftW
, _BmpH
);
260 rVR
.getTextureSizeFromId(_TextureIdNormal
[1], _BmpMiddleW
, _BmpH
);
261 rVR
.getTextureSizeFromId(_TextureIdNormal
[2], _BmpRightW
, _BmpH
);
265 if( name
== "tx_pushed" )
268 tex
= CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdPushed
[ 0 ] );
269 std::string::size_type i
= tex
.rfind( "_l.tga" );
270 if( i
!= std::string::npos
)
271 tex
= tex
.substr( 0, i
);
273 _TextureIdPushed
[ 0 ].setTexture( std::string( value
+ "_l.tga" ).c_str() );
274 _TextureIdPushed
[ 1 ].setTexture( std::string( value
+ "_m.tga" ).c_str() );
275 _TextureIdPushed
[ 2 ].setTexture( std::string( value
+ "_r.tga" ).c_str() );
279 if( name
== "tx_over" )
282 tex
= CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdOver
[ 0 ] );
283 std::string::size_type i
= tex
.rfind( "_l.tga" );
284 if( i
!= std::string::npos
)
285 tex
= tex
.substr( 0, i
);
287 _TextureIdOver
[ 0 ].setTexture( std::string( value
+ "_l.tga" ).c_str() );
288 _TextureIdOver
[ 1 ].setTexture( std::string( value
+ "_m.tga" ).c_str() );
289 _TextureIdOver
[ 2 ].setTexture( std::string( value
+ "_r.tga" ).c_str() );
293 if( name
== "wmargin" )
296 if( fromString( value
, i
) )
304 if( fromString( value
, i
) )
312 if( fromString( value
, i
) )
317 if( name
== "hardtext" )
319 if( _ViewText
!= NULL
)
320 _ViewText
->setHardText( value
);
324 if( name
== "text_y" )
327 if( fromString( value
, i
) )
332 if( name
== "text_x" )
335 if( fromString( value
, i
) )
340 if( name
== "text_underlined" )
343 if( _ViewText
!= NULL
)
344 if( fromString( value
, b
) )
345 _ViewText
->setUnderlined( b
);
350 if( name
== "text_posref" )
352 _TextPosRef
= convertHotSpot( value
.c_str() );
356 if( name
== "text_parent_posref" )
358 _TextParentPosRef
= convertHotSpot( value
.c_str() );
362 if( name
== "text_color_normal" )
365 if( fromString( value
, c
) )
366 _TextColorNormal
= c
;
370 if( name
== "text_color_pushed" )
373 if( fromString( value
, c
) )
374 _TextColorPushed
= c
;
378 if( name
== "text_color_over" )
381 if( fromString( value
, c
) )
386 if( name
== "text_shadow_color_normal" )
389 if( fromString( value
, c
) )
390 _TextShadowColorNormal
= c
;
394 if( name
== "text_shadow_color_pushed" )
397 if( fromString( value
, c
) )
398 _TextShadowColorPushed
= c
;
402 if( name
== "text_shadow_color_over" )
405 if( fromString( value
, c
) )
406 _TextShadowColorOver
= c
;
410 if( name
== "text_global_color_normal" )
413 if( fromString( value
, b
) )
414 _TextModulateGlobalColorNormal
= b
;
418 if( name
== "text_global_color_pushed" )
421 if( fromString( value
, b
) )
422 _TextModulateGlobalColorPushed
= b
;
426 if( name
== "text_global_color_over" )
429 if( fromString( value
, b
) )
430 _TextModulateGlobalColorOver
= b
;
434 if( name
== "force_text_over" )
437 if( fromString( value
, b
) )
442 if( name
== "text_header_color" )
445 if( fromString( value
, b
) )
446 _TextHeaderColor
= b
;
450 CCtrlBaseButton::setProperty( name
, value
);
454 xmlNodePtr
CCtrlTextButton::serialize( xmlNodePtr parentNode
, const char *type
) const
456 xmlNodePtr node
= CCtrlBaseButton::serialize( parentNode
, type
);
460 xmlSetProp( node
, BAD_CAST
"type", BAD_CAST
"text_button" );
463 tex
= CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdNormal
[ 0 ] );
464 std::string::size_type i
= tex
.rfind( "_l.tga" );
465 if( i
!= std::string::npos
)
466 tex
= tex
.substr( 0, i
);
468 xmlNewProp( node
, BAD_CAST
"tx_normal", BAD_CAST tex
.c_str() );
471 tex
= CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdPushed
[ 0 ] );
472 i
= tex
.rfind( "_l.tga" );
473 if( i
!= std::string::npos
)
474 tex
= tex
.substr( 0, i
);
476 xmlNewProp( node
, BAD_CAST
"tx_pushed", BAD_CAST tex
.c_str() );
480 tex
= CViewRenderer::getInstance()->getTextureNameFromId( _TextureIdOver
[ 0 ] );
481 i
= tex
.rfind( "_l.tga" );
482 if( i
!= std::string::npos
)
483 tex
= tex
.substr( 0, i
);
485 xmlNewProp( node
, BAD_CAST
"tx_over", BAD_CAST tex
.c_str() );
488 xmlNewProp( node
, BAD_CAST
"wmargin", BAD_CAST
toString( _WMargin
).c_str() );
489 xmlNewProp( node
, BAD_CAST
"wmin", BAD_CAST
toString( _WMin
).c_str() );
490 xmlNewProp( node
, BAD_CAST
"hmin", BAD_CAST
toString( _HMin
).c_str() );
491 xmlNewProp( node
, BAD_CAST
"hardtext", BAD_CAST _ViewText
->getText().c_str() );
492 xmlNewProp( node
, BAD_CAST
"text_y", BAD_CAST
toString( _TextY
).c_str() );
493 xmlNewProp( node
, BAD_CAST
"text_x", BAD_CAST
toString( _TextX
).c_str() );
494 xmlNewProp( node
, BAD_CAST
"text_underlined", BAD_CAST
toString( _ViewText
->getUnderlined() ).c_str() );
496 tex
= CInterfaceElement::HotSpotCoupleToString( _TextParentPosRef
, _TextPosRef
);
497 xmlNewProp( node
, BAD_CAST
"text_posref", BAD_CAST tex
.c_str() );
499 xmlNewProp( node
, BAD_CAST
"text_color_normal", BAD_CAST
toString( _TextColorNormal
).c_str() );
500 xmlNewProp( node
, BAD_CAST
"text_color_pushed", BAD_CAST
toString( _TextColorPushed
).c_str() );
501 xmlNewProp( node
, BAD_CAST
"text_color_over", BAD_CAST
toString( _TextColorOver
).c_str() );
503 xmlNewProp( node
, BAD_CAST
"text_shadow_color_normal", BAD_CAST
toString( _TextShadowColorNormal
).c_str() );
504 xmlNewProp( node
, BAD_CAST
"text_shadow_color_pushed", BAD_CAST
toString( _TextShadowColorPushed
).c_str() );
505 xmlNewProp( node
, BAD_CAST
"text_shadow_color_over", BAD_CAST
toString( _TextShadowColorOver
).c_str() );
507 xmlNewProp( node
, BAD_CAST
"text_global_color_normal",
508 BAD_CAST
toString( _TextModulateGlobalColorNormal
).c_str() );
510 xmlNewProp( node
, BAD_CAST
"text_global_color_pushed",
511 BAD_CAST
toString( _TextModulateGlobalColorPushed
).c_str() );
513 xmlNewProp( node
, BAD_CAST
"text_global_color_over",
514 BAD_CAST
toString( _TextModulateGlobalColorOver
).c_str() );
516 xmlNewProp( node
, BAD_CAST
"force_text_over", BAD_CAST
toString( _ForceTextOver
).c_str() );
517 xmlNewProp( node
, BAD_CAST
"text_header_color", BAD_CAST
toString( _TextHeaderColor
).c_str() );
519 if( _ViewText
!= NULL
)
520 _ViewText
->serializeTextOptions( node
);
525 // ***************************************************************************
526 bool CCtrlTextButton::parse(xmlNodePtr cur
, CInterfaceGroup
* parentGroup
)
529 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
531 //try to get props that can be inherited from groups
532 //if a property is not defined, try to find it in the parent group.
533 //if it is undefined, set it to zero
534 if (! CCtrlBaseButton::parse(cur
,parentGroup
) )
536 string tmp
= "cannot parse view:"+getId()+", parent:"+parentGroup
->getId();
541 // *** Read Textures.
542 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"tx_normal" );
545 string TxName
= toLowerAscii(std::string((const char *) prop
));
546 _TextureIdNormal
[0].setTexture((TxName
+"_l.tga").c_str());
547 _TextureIdNormal
[1].setTexture((TxName
+"_m.tga").c_str());
548 _TextureIdNormal
[2].setTexture((TxName
+"_r.tga").c_str());
551 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"tx_pushed" );
554 string TxName
= toLowerAscii(std::string((const char *) prop
));
555 _TextureIdPushed
[0].setTexture((TxName
+"_l.tga").c_str());
556 _TextureIdPushed
[1].setTexture((TxName
+"_m.tga").c_str());
557 _TextureIdPushed
[2].setTexture((TxName
+"_r.tga").c_str());
560 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"tx_over" );
563 string TxName
= toLowerAscii(std::string((const char *) prop
));
564 _TextureIdOver
[0].setTexture((TxName
+"_l.tga").c_str());
565 _TextureIdOver
[1].setTexture((TxName
+"_m.tga").c_str());
566 _TextureIdOver
[2].setTexture((TxName
+"_r.tga").c_str());
570 nlctassert(NumTexture
==3);
571 rVR
.getTextureSizeFromId(_TextureIdNormal
[0], _BmpLeftW
, _BmpH
);
572 rVR
.getTextureSizeFromId(_TextureIdNormal
[1], _BmpMiddleW
, _BmpH
);
573 rVR
.getTextureSizeFromId(_TextureIdNormal
[2], _BmpRightW
, _BmpH
);
576 // *** Create the ViewText for draw, and set text
577 // ViewTextId or standard view?
578 CXMLAutoPtr
ptr((const char*)xmlGetProp(cur
,(xmlChar
*)"textid"));
579 _IsViewTextId
= (bool)ptr
;
581 _ViewText
= new CViewTextID(CViewBase::TCtorParam());
583 _ViewText
= new CViewText(CViewBase::TCtorParam());
584 _ViewText
->setId(_Id
+"_text");
585 _ViewText
->setSerializable( false );
586 _ViewText
->parseTextOptions(cur
);
587 _ViewText
->setAvoidResizeParent(avoidResizeParent());
589 ((CViewTextID
*)_ViewText
)->parseTextIdOptions(cur
);
590 // Same RenderLayer as us.
591 _ViewText
->setRenderLayer(getRenderLayer());
592 _ViewText
->setParentElm(this);
593 // Parse the hardText (if not text id)
596 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"hardtext" );
599 const char *propPtr
= prop
;
600 _ViewText
->setTextLocalized(propPtr
, true);
606 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"wmargin" );
609 fromString((const char *) prop
, _WMargin
);
614 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"wmin" );
617 fromString((const char *) prop
, _WMin
);
619 // _WMin is at least the size of All W Bitmaps
620 _WMin
= max(_WMin
, _BmpLeftW
+ _BmpMiddleW
+ _BmpRightW
);
624 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"hmin" );
627 fromString((const char *) prop
, _HMin
);
629 _HMin
= max(_HMin
, _BmpH
);
633 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_y" );
636 fromString((const char *) prop
, _TextY
);
639 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_x" );
642 fromString((const char *) prop
, _TextX
);
645 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_underlined" );
648 _ViewText
->setUnderlined(convertBool(prop
));
651 prop
= (char*) xmlGetProp( cur
, (xmlChar
*) "text_posref" );
652 _TextParentPosRef
= Hotspot_MM
;
653 _TextPosRef
= Hotspot_MM
;
656 char *seekPtr
= prop
.getDatas();
657 seekPtr
= strtok(seekPtr
," \t");
660 // mean that there s a bad formated posref (missing space or tab)
661 nlwarning("bad 'text_pos_ref' formatting");
665 _TextParentPosRef
= convertHotSpot (seekPtr
);
666 seekPtr
= strtok (seekPtr
+1+strlen(seekPtr
)," \t");
667 _TextPosRef
= convertHotSpot (seekPtr
);
672 // *** Read Text Colors
674 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_color_normal" );
675 _TextColorNormal
= CRGBA(255,255,255,255);
677 _TextColorNormal
= convertColor (prop
);
680 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_color_pushed" );
681 _TextColorPushed
= CRGBA(255,255,255,255);
683 _TextColorPushed
= convertColor(prop
);
686 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_color_over" );
687 _TextColorOver
= CRGBA(255,255,255,255);
689 _TextColorOver
= convertColor(prop
);
692 // *** Read Text Shadow Colors
694 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_shadow_color_normal" );
695 _TextShadowColorNormal
= CRGBA(0,0,0,255);
697 _TextShadowColorNormal
= convertColor (prop
);
700 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_shadow_color_pushed" );
701 _TextShadowColorPushed
= CRGBA(0,0,0,255);
703 _TextShadowColorPushed
= convertColor(prop
);
706 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_shadow_color_over" );
707 _TextShadowColorOver
= CRGBA(0,0,0,255);
709 _TextShadowColorOver
= convertColor(prop
);
711 // *** Read Text Global Color
712 // Default: take "global_color" param interface_element option.
713 _TextModulateGlobalColorNormal
= _TextModulateGlobalColorPushed
= _TextModulateGlobalColorOver
= getModulateGlobalColor();
715 // Read special text global_color for each state
716 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_global_color_normal" );
717 if (prop
) _TextModulateGlobalColorNormal
= convertBool(prop
);
718 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_global_color_pushed" );
719 if (prop
) _TextModulateGlobalColorPushed
= convertBool(prop
);
720 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_global_color_over" );
721 if (prop
) _TextModulateGlobalColorOver
= convertBool(prop
);
722 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"force_text_over" );
723 if (prop
) _ForceTextOver
= convertBool(prop
);
725 // read Text header color
726 prop
= (char*) xmlGetProp( cur
, (xmlChar
*)"text_header_color" );
727 if (prop
) _TextHeaderColor
= convertBool(prop
);
732 // ***************************************************************************
733 void CCtrlTextButton::setTexture(const std::string
&l
, const std::string
&m
, const std::string
&r
, bool updateHeight
)
735 nlctassert(NumTexture
==3);
736 _TextureIdNormal
[0].setTexture(l
.c_str());
737 _TextureIdNormal
[1].setTexture(m
.c_str());
738 _TextureIdNormal
[2].setTexture(r
.c_str());
743 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
744 rVR
.getTextureSizeFromId(_TextureIdNormal
[0], _BmpLeftW
, newH
);
745 rVR
.getTextureSizeFromId(_TextureIdNormal
[1], _BmpMiddleW
, newH
);
746 rVR
.getTextureSizeFromId(_TextureIdNormal
[2], _BmpRightW
, newH
);
748 if (updateHeight
) _BmpH
= newH
;
751 // ***************************************************************************
752 void CCtrlTextButton::setTexturePushed(const std::string
&l
, const std::string
&m
, const std::string
&r
)
754 nlctassert(NumTexture
==3);
755 _TextureIdPushed
[0].setTexture(l
.c_str());
756 _TextureIdPushed
[1].setTexture(m
.c_str());
757 _TextureIdPushed
[2].setTexture(r
.c_str());
760 // ***************************************************************************
761 void CCtrlTextButton::setTextureOver(const std::string
&l
, const std::string
&m
, const std::string
&r
)
763 nlctassert(NumTexture
==3);
764 _TextureIdOver
[0].setTexture(l
.c_str());
765 _TextureIdOver
[1].setTexture(m
.c_str());
766 _TextureIdOver
[2].setTexture(r
.c_str());
769 // ***************************************************************************
770 void CCtrlTextButton::draw ()
772 CViewRenderer::CTextureId
*pTxId
= NULL
;
775 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
776 CRGBA globalColor
= CWidgetManager::getInstance()->getGlobalColorForContent();
779 bool lastOver
= false;
780 updateOver(lastOver
);
782 // *** Choose Button State
787 if (_Pushed
&& !editorMode
)
789 pTxId
= _TextureIdPushed
;
790 color
= getCurrentColorPushed(globalColor
);
794 pTxId
= _TextureIdNormal
;
795 color
= getCurrentColorNormal(globalColor
);
801 // CViewPointer &rIP = *CInterfaceManager::getInstance()->getPointer();
802 // Init the radio button
807 // if it is equal to the ref value, then the button must appear pushed
808 pTxId
= _TextureIdPushed
;
809 color
= getCurrentColorPushed(globalColor
);
813 if ((_Over
) && (CWidgetManager::getInstance()->getCapturePointerLeft() == this) && !editorMode
)
815 pTxId
= _TextureIdPushed
;
816 color
= getCurrentColorPushed(globalColor
);
820 pTxId
= _TextureIdNormal
;
821 color
= getCurrentColorNormal(globalColor
);
829 if (_Over
&& (CWidgetManager::getInstance()->getCapturePointerLeft() == this) && !editorMode
)
831 pTxId
= _TextureIdPushed
;
832 color
= getCurrentColorPushed(globalColor
);
836 pTxId
= _TextureIdNormal
;
837 color
= getCurrentColorNormal(globalColor
);
847 color
.A
= (uint8
)(((sint32
)color
.A
*((sint32
)globalColor
.A
+1))>>8);
850 if (getFrozen() && getFrozenHalfTone())
856 txw
= _WReal
- _BmpLeftW
- _BmpRightW
;
858 nlctassert(NumTexture
==3);
859 rVR
.drawRotFlipBitmap ( _RenderLayer
, x
, y
, _BmpLeftW
, txh
, 0, false, pTxId
[0], color
);
860 rVR
.drawRotFlipBitmap ( _RenderLayer
, x
+_BmpLeftW
, y
, txw
, txh
, 0, false, pTxId
[1], color
);
861 rVR
.drawRotFlipBitmap ( _RenderLayer
, x
+_BmpLeftW
+txw
, y
, _BmpRightW
, txh
, 0, false, pTxId
[2], color
);
863 CCtrlBase
*capturePointerLeft
= CWidgetManager::getInstance()->getCapturePointerLeft();
866 if( ( !editorMode
&& _Over
&& (_OverWhenPushed
|| !(_Pushed
|| capturePointerLeft
== this ) ) )
869 if( !editorMode
&& (lastOver
== false) && (_AHOnOver
!= NULL
) )
870 CAHManager::getInstance()->runActionHandler (_AHOnOver
, this, _AHOverParams
);
872 // the pointer is over the button.
873 color
= getCurrentColorOver(globalColor
);
874 color
.A
= (uint8
)(((sint32
)color
.A
*((sint32
)globalColor
.A
+1))>>8);
877 if (getFrozen() && getFrozenHalfTone())
880 nlctassert(NumTexture
==3);
881 pTxId
= _TextureIdOver
;
882 uint layerOffset
= _ForceTextOver
? 0 : 1; // Must write Over On Top of the text ?
884 rVR
.drawRotFlipBitmap ( _RenderLayer
+layerOffset
, x
, y
, _BmpLeftW
, txh
, 0, false, pTxId
[0], color
);
885 rVR
.drawRotFlipBitmap ( _RenderLayer
+layerOffset
, x
+_BmpLeftW
, y
, txw
, txh
, 0, false, pTxId
[1], color
);
886 rVR
.drawRotFlipBitmap ( _RenderLayer
+layerOffset
, x
+_BmpLeftW
+txw
, y
, _BmpRightW
, txh
, 0, false, pTxId
[2], color
);
889 // *** Setup ViewText Color according to selected one (should be drawn after because of eltorder)
890 // update header color?
894 CInterfaceGroup
*pIG
= getRootWindow();
895 if(pIG
->isGroupContainer())
897 CGroupContainerBase
*pGC
= static_cast<CGroupContainerBase
*>(pIG
);
898 viewTextColor
= pGC
->getDrawnHeaderColor();
901 // Setup ViewText color
902 if( _ViewText
!= NULL
)
904 if ( pTxId
==_TextureIdNormal
|| editorMode
)
906 if(_TextHeaderColor
) viewTextColor
.A
= _TextColorNormal
.A
;
907 else viewTextColor
= _TextColorNormal
;
908 _ViewText
->setColor(viewTextColor
);
909 _ViewText
->setShadowColor(_TextShadowColorNormal
);
910 _ViewText
->setModulateGlobalColor(_TextModulateGlobalColorNormal
);
912 else if ( pTxId
==_TextureIdPushed
)
914 if(_TextHeaderColor
) viewTextColor
.A
= _TextColorPushed
.A
;
915 else viewTextColor
= _TextColorPushed
;
916 _ViewText
->setColor(viewTextColor
);
917 _ViewText
->setShadowColor(_TextShadowColorPushed
);
918 _ViewText
->setModulateGlobalColor(_TextModulateGlobalColorPushed
);
920 else if ( pTxId
==_TextureIdOver
)
922 if(_TextHeaderColor
) viewTextColor
.A
= _TextColorOver
.A
;
923 else viewTextColor
= _TextColorOver
;
924 _ViewText
->setColor(viewTextColor
);
925 _ViewText
->setShadowColor(_TextShadowColorOver
);
926 _ViewText
->setModulateGlobalColor(_TextModulateGlobalColorOver
);
928 if(getFrozen() && getFrozenHalfTone())
929 _ViewText
->setAlpha(_ViewText
->getAlpha()>>2);
935 // ***************************************************************************
936 void CCtrlTextButton::checkCoords()
938 if( _ViewText
!= NULL
)
939 _ViewText
->checkCoords();
941 CCtrlBaseButton::checkCoords();
945 // ***************************************************************************
946 void CCtrlTextButton::updateCoords()
948 // Should have been setuped with addCtrl
951 if( _Name
== "==MARKED==" )
954 // Compute Size according to bitmap and Text.
957 _W
= _ViewText
->getW() + _WMargin
+ _TextX
;
958 // Ensure as big as possible button
963 _H
= max(_BmpH
, _ViewText
->getH());
967 CViewBase::updateCoords();
969 _ViewText
->updateCoords();
972 // ***************************************************************************
973 sint32
CCtrlTextButton::getWMax() const
975 return max(_ViewText
->getW(false) + _WMargin
+ _TextX
, _WMin
);
978 // ***************************************************************************
979 void CCtrlTextButton::setup()
983 if( _ViewText
== NULL
)
985 CViewBase
*v
= CInterfaceFactory::createClass( "text" );
986 nlassert( v
!= NULL
);
987 _ViewText
= dynamic_cast< CViewText
* >( v
);
988 _ViewText
->setId( _Id
+ "_text" );
989 _ViewText
->setText( "text" );
990 _ViewText
->setSerializable( false );
993 // setup the viewText and add to parent
994 _ViewText
->setParentElm (this);
995 _ViewText
->setParentPos (this);
996 _ViewText
->setParentPosRef (_TextParentPosRef
);
997 _ViewText
->setPosRef (_TextPosRef
);
998 _ViewText
->setActive(_Active
);
999 _ViewText
->setX(_TextX
);
1000 _ViewText
->setY(_TextY
);
1003 // ***************************************************************************
1004 void CCtrlTextButton::setTextX(sint32 x
)
1007 if (_ViewText
) _ViewText
->setX(_TextX
);
1010 // ***************************************************************************
1011 sint32
CCtrlTextButton::getMaxUsedW() const
1016 // ***************************************************************************
1017 sint32
CCtrlTextButton::getMinUsedW() const
1022 // ***************************************************************************
1023 void CCtrlTextButton::setActive(bool state
)
1025 _ViewText
->setActive(state
);
1026 CCtrlBaseButton::setActive(state
);
1030 // ***************************************************************************
1031 void CCtrlTextButton::onAddToGroup()
1033 // Add the view if not done
1039 // ***************************************************************************
1040 void CCtrlTextButton::setText (const std::string
&text
)
1042 if (_ViewText
&& !_IsViewTextId
)
1043 _ViewText
->setText(text
);
1046 // ***************************************************************************
1047 std::string
CCtrlTextButton::getText () const
1049 if (_ViewText
&& !_IsViewTextId
)
1050 return _ViewText
->getText();
1051 return std::string();
1054 void CCtrlTextButton::setLocalize(bool localize
)
1056 if (_ViewText
&& !_IsViewTextId
)
1057 _ViewText
->setLocalized(localize
);
1060 bool CCtrlTextButton::isLocalized() const
1062 if (_ViewText
&& !_IsViewTextId
)
1063 return _ViewText
->isLocalized();
1067 #ifdef RYZOM_LUA_UCSTRING
1068 // ***************************************************************************
1069 void CCtrlTextButton::setTextAsUtf16 (const ucstring
&text
)
1071 if (_ViewText
&& !_IsViewTextId
)
1072 _ViewText
->setText(text
.toUtf8());
1075 // ***************************************************************************
1076 ucstring
CCtrlTextButton::getTextAsUtf16 () const
1078 if (_ViewText
&& !_IsViewTextId
)
1079 return CUtfStringView(_ViewText
->getText()).toUtf16();
1080 return ucstring("");
1084 // ***************************************************************************
1085 void CCtrlTextButton::setHardText (const std::string
&text
)
1087 if (_ViewText
&& !_IsViewTextId
)
1088 _ViewText
->setHardText(text
);
1091 // ***************************************************************************
1092 string
CCtrlTextButton::getHardText () const
1094 if (_ViewText
&& !_IsViewTextId
)
1095 return _ViewText
->getHardText();
1099 // ***************************************************************************
1101 CViewText
* CCtrlTextButton::getViewText()
1106 // ***************************************************************************
1108 void CCtrlTextButton::setTextureLua(const std::string
&name
)
1110 _TextureIdNormal
[0].setTexture(std::string(name
+ "_l.tga").c_str());
1111 _TextureIdNormal
[1].setTexture(std::string(name
+ "_m.tga").c_str());
1112 _TextureIdNormal
[2].setTexture(std::string(name
+ "_r.tga").c_str());
1115 // ***************************************************************************
1117 void CCtrlTextButton::setTexturePushedLua(const std::string
&name
)
1119 _TextureIdPushed
[0].setTexture(std::string(name
+ "_l.tga").c_str());
1120 _TextureIdPushed
[1].setTexture(std::string(name
+ "_m.tga").c_str());
1121 _TextureIdPushed
[2].setTexture(std::string(name
+ "_r.tga").c_str());
1124 // ***************************************************************************
1126 void CCtrlTextButton::setTextureOverLua(const std::string
&name
)
1128 _TextureIdOver
[0].setTexture(std::string(name
+ "_l.tga").c_str());
1129 _TextureIdOver
[1].setTexture(std::string(name
+ "_m.tga").c_str());
1130 _TextureIdOver
[2].setTexture(std::string(name
+ "_r.tga").c_str());
1133 // ***************************************************************************
1135 std::string
CCtrlTextButton::getTexture() const
1137 std::string tx
= CViewRenderer::getInstance()->getTextureNameFromId(_TextureIdNormal
[0]);
1138 std::string::size_type i
= tx
.rfind("_l.tga");
1139 if (i
!= std::string::npos
)
1140 tx
= tx
.substr(0, i
);
1145 // ***************************************************************************
1147 std::string
CCtrlTextButton::getTexturePushed() const
1149 std::string tx
= CViewRenderer::getInstance()->getTextureNameFromId(_TextureIdOver
[0]);
1150 std::string::size_type i
= tx
.rfind("_l.tga");
1151 if (i
!= std::string::npos
)
1152 tx
= tx
.substr(0, i
);
1157 // ***************************************************************************
1159 std::string
CCtrlTextButton::getTextureOver() const
1161 std::string tx
= CViewRenderer::getInstance()->getTextureNameFromId(_TextureIdPushed
[0]);
1162 std::string::size_type i
= tx
.rfind("_l.tga");
1163 if (i
!= std::string::npos
)
1164 tx
= tx
.substr(0, i
);
1169 // ***************************************************************************
1171 int CCtrlTextButton::luaGetViewText(CLuaState
&ls
)
1173 const char *funcName
= "getViewText";
1174 CLuaIHM::checkArgCount(ls
, funcName
, 0);
1175 CLuaIHM::pushUIOnStack(ls
, getViewText());
1179 // ***************************************************************************
1180 void CCtrlTextButton::onRemoved()
1184 void CCtrlTextButton::onWidgetDeleted( CInterfaceElement
*e
)
1188 void CCtrlTextButton::moveBy( sint32 x
, sint32 y
)
1190 CInterfaceElement::moveBy( x
, y
);
1192 if( _ViewText
!= NULL
)
1193 _ViewText
->updateCoords();