@@ -42,7 +42,9 @@ namespace Skylicht
42
42
m_updateTextRender (true ),
43
43
m_font (NULL ),
44
44
m_customfont (font),
45
- m_fontData (NULL )
45
+ m_fontData (NULL ),
46
+ m_lastWidth (0 .0f ),
47
+ m_lastHeight (0 .0f )
46
48
{
47
49
48
50
}
@@ -59,7 +61,9 @@ namespace Skylicht
59
61
m_updateTextRender (true ),
60
62
m_font (NULL ),
61
63
m_customfont (font),
62
- m_fontData (NULL )
64
+ m_fontData (NULL ),
65
+ m_lastWidth (0 .0f ),
66
+ m_lastHeight (0 .0f )
63
67
{
64
68
init ();
65
69
}
@@ -402,6 +406,15 @@ namespace Skylicht
402
406
m_font = font;
403
407
}
404
408
409
+ const core::rectf& rect = getRect ();
410
+
411
+ if (m_lastWidth != rect.getWidth () || m_lastHeight != rect.getHeight ())
412
+ {
413
+ m_lastWidth = rect.getWidth ();
414
+ m_lastHeight = rect.getHeight ();
415
+ m_updateTextRender = true ;
416
+ }
417
+
405
418
if (m_updateTextRender == true )
406
419
{
407
420
// encode string to list modules & format
@@ -411,7 +424,7 @@ namespace Skylicht
411
424
if (m_multiLine == true )
412
425
{
413
426
// split to multi line
414
- splitText (m_arrayCharRender, m_arrayCharFormat, (int )getRect (). getWidth () );
427
+ splitText (m_arrayCharRender, m_arrayCharFormat, (int )m_lastWidth );
415
428
}
416
429
else
417
430
{
@@ -451,9 +464,9 @@ namespace Skylicht
451
464
452
465
// calc text algin vertial
453
466
if (TextVertical == EGUIVerticalAlign::Middle)
454
- y = ((int )getRect (). getHeight () - textHeight - m_textOffsetY) / 2 ;
467
+ y = ((int )m_lastHeight - textHeight - m_textOffsetY) / 2 ;
455
468
else if (TextVertical == EGUIVerticalAlign::Bottom)
456
- y = (int )getRect (). getHeight () - textHeight;
469
+ y = (int )m_lastHeight - textHeight;
457
470
458
471
if (m_centerRotate == true )
459
472
y = -textHeight / 2 ;
@@ -684,29 +697,33 @@ namespace Skylicht
684
697
CObjectSerializable* CGUIText::createSerializable ()
685
698
{
686
699
CObjectSerializable* object = CGUIElement::createSerializable ();
687
- object->autoRelease (new CBoolProperty (object, " Multiline " , m_multiLine));
688
- object->autoRelease (new CIntProperty (object, " Char padding " , m_charPadding));
689
- object->autoRelease (new CIntProperty (object, " Char space padding " , m_charSpacePadding));
690
- object->autoRelease (new CIntProperty (object, " Line padding " , m_linePadding));
700
+ object->autoRelease (new CBoolProperty (object, " multiline " , m_multiLine));
701
+ object->autoRelease (new CIntProperty (object, " charPadding " , m_charPadding));
702
+ object->autoRelease (new CIntProperty (object, " charSpacePadding " , m_charSpacePadding));
703
+ object->autoRelease (new CIntProperty (object, " linePadding " , m_linePadding));
691
704
692
- CEnumProperty<EGUIVerticalAlign>* verticalAlign = new CEnumProperty<EGUIVerticalAlign>(object, " Text Verticle " , TextVertical);
705
+ CEnumProperty<EGUIVerticalAlign>* verticalAlign = new CEnumProperty<EGUIVerticalAlign>(object, " textVerticle " , TextVertical);
693
706
verticalAlign->addEnumString (" Top" , EGUIVerticalAlign::Top);
694
707
verticalAlign->addEnumString (" Middle" , EGUIVerticalAlign::Middle);
695
708
verticalAlign->addEnumString (" Bottom" , EGUIVerticalAlign::Bottom);
696
709
object->autoRelease (verticalAlign);
697
710
698
- CEnumProperty<EGUIHorizontalAlign>* horizontalAlign = new CEnumProperty<EGUIHorizontalAlign>(object, " Text Horizontal " , TextHorizontal);
711
+ CEnumProperty<EGUIHorizontalAlign>* horizontalAlign = new CEnumProperty<EGUIHorizontalAlign>(object, " textHorizontal " , TextHorizontal);
699
712
horizontalAlign->addEnumString (" Left" , EGUIHorizontalAlign::Left);
700
713
horizontalAlign->addEnumString (" Center" , EGUIHorizontalAlign::Center);
701
714
horizontalAlign->addEnumString (" Right" , EGUIHorizontalAlign::Right);
702
715
object->autoRelease (horizontalAlign);
703
716
704
- object->autoRelease (new CFilePathProperty (object, " Font" , m_fontSource.c_str (), " font" ));
705
- CStringProperty* fontGUID = new CStringProperty (object, " FontGUID" , m_fontGUID.c_str ());
717
+ object->autoRelease (new CFilePathProperty (object, " font" , m_fontSource.c_str (), " font" ));
718
+
719
+ if (m_fontData)
720
+ m_fontGUID = m_fontData->getGUID ();
721
+
722
+ CStringProperty* fontGUID = new CStringProperty (object, " font.guid" , m_fontGUID.c_str ());
706
723
fontGUID->setHidden (true );
707
724
object->autoRelease (fontGUID);
708
725
709
- object->autoRelease (new CStringProperty (object, " Text " , m_text.c_str ()));
726
+ object->autoRelease (new CStringProperty (object, " text " , m_text.c_str ()));
710
727
711
728
return object;
712
729
}
@@ -715,22 +732,32 @@ namespace Skylicht
715
732
{
716
733
CGUIElement::loadSerializable (object);
717
734
718
- m_multiLine = object->get <bool >(" Multiline" , true );
719
- m_charPadding = object->get <int >(" Char padding" , 0 );
720
- m_charSpacePadding = object->get <int >(" Char space padding" , 0 );
721
- m_linePadding = object->get <int >(" Line padding" , 0 );
735
+ m_multiLine = object->get <bool >(" multiline" , true );
736
+ m_charPadding = object->get <int >(" charPadding" , 0 );
737
+ m_charSpacePadding = object->get <int >(" charSpacePadding" , 0 );
738
+ m_linePadding = object->get <int >(" linePadding" , 0 );
739
+
740
+ TextVertical = object->get <EGUIVerticalAlign>(" textVerticle" , EGUIVerticalAlign::Top);
741
+ TextHorizontal = object->get <EGUIHorizontalAlign>(" textHorizontal" , EGUIHorizontalAlign::Left);
722
742
723
- TextVertical = object->get <EGUIVerticalAlign >(" Text Verticle " , EGUIVerticalAlign::Top );
724
- TextHorizontal = object->get <EGUIHorizontalAlign >(" Text Horizontal " , EGUIHorizontalAlign::Left );
743
+ m_fontSource = object->get <std::string >(" font " , std::string ( " " ) );
744
+ m_fontGUID = object->get <std::string >(" font.guid " , std::string ( " " ) );
725
745
726
- m_fontSource = object->get <std::string>(" Font" , std::string (" " ));
727
- m_fontGUID = object->get <std::string>(" Font" , std::string (" " ));
746
+ // read font by id first
747
+ m_fontData = CFontManager::getInstance ()->getFontById (m_fontGUID.c_str ());
748
+ if (!m_fontData)
749
+ {
750
+ m_fontData = CFontManager::getInstance ()->loadFontSource (m_fontSource.c_str ());
751
+ }
728
752
729
- m_fontData = CFontManager::getInstance ()-> loadFontSource (m_fontSource. c_str ());
753
+ // init font
730
754
if (m_fontData)
755
+ {
731
756
m_fontData->initFont ();
757
+ m_fontGUID = m_fontData->getGUID ();
758
+ }
732
759
733
- std::string value = object->get <std::string>(" Text " , std::string (" " ));
760
+ std::string value = object->get <std::string>(" text " , std::string (" " ));
734
761
setText (value.c_str ());
735
762
736
763
m_updateTextRender = true ;
0 commit comments