Browse Source

TextField get/set font and serialize

dmuratshin 10 years ago
parent
commit
aa743bd5bf
2 changed files with 12 additions and 0 deletions
  1. 11 0
      oxygine/src/TextField.cpp
  2. 1 0
      oxygine/src/TextField.h

+ 11 - 0
oxygine/src/TextField.cpp

@@ -91,6 +91,11 @@ namespace oxygine
         needRebuild();
     }
 
+    const Font* TextField::getFont() const
+    {
+        return _style.font;
+    }
+
     void TextField::setFont(const Font* font)
     {
         _style.font = font;
@@ -346,6 +351,8 @@ namespace oxygine
         setAttr(node, "halign", _style.hAlign, def.hAlign);
         setAttr(node, "multiline", _style.multiline, def.multiline);
         setAttr(node, "breakLongWords", _style.breakLongWords, def.breakLongWords);
+        if (_style.font)
+            node.append_attribute("font").set_value(_style.font->getName().c_str());
         node.set_name("TextField");
     }
 
@@ -362,6 +369,10 @@ namespace oxygine
         _style.breakLongWords = node.attribute("breakLongWords").as_bool(def.breakLongWords);
         _style.fontSize2Scale = node.attribute("fontsize2scale").as_int(def.fontSize2Scale);
         _style.linesOffset = node.attribute("linesOffset").as_int(def.linesOffset);
+        const char* fnt = node.attribute("font").as_string(0);
+        if (fnt)
+            _style.font = data->factory->getResFont(fnt)->getFont();
+
         needRebuild();
         setText(node.attribute("text").as_string());
     }

+ 1 - 0
oxygine/src/TextField.h

@@ -30,6 +30,7 @@ namespace oxygine
         const Rect&                 getTextRect();
         /**Returns current text*/
         const std::string&          getText() const { return _text; }
+        const Font*                 getFont() const;
         int                         getFontSize2Scale() const;
         int                         getLinesOffset() const;
         TextStyle::VerticalAlign    getVAlign() const;