MyGUI  3.0.1
MyGUI_StaticText.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_StaticText.h"
25 
26 namespace MyGUI
27 {
28 
30  {
31  }
32 
33  void StaticText::_initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name)
34  {
35  Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name);
36 
37  initialiseWidgetSkin(_info);
38  }
39 
41  {
42  shutdownWidgetSkin();
43  }
44 
46  {
47  shutdownWidgetSkin();
49  initialiseWidgetSkin(_info);
50  }
51 
52  void StaticText::initialiseWidgetSkin(ResourceSkin* _info)
53  {
54  // парсим свойства
55  const MapString& properties = _info->getProperties();
56  if (!properties.empty())
57  {
58  MapString::const_iterator iter = properties.end();
59  if ((iter = properties.find("FontName")) != properties.end()) setFontName(iter->second);
60  if ((iter = properties.find("FontHeight")) != properties.end()) setFontHeight(utility::parseInt(iter->second));
61  if ((iter = properties.find("TextAlign")) != properties.end()) setTextAlign(Align::parse(iter->second));
62  if ((iter = properties.find("TextColour")) != properties.end()) setTextColour(Colour::parse(iter->second));
63  }
64  }
65 
66  void StaticText::shutdownWidgetSkin()
67  {
68  }
69 
71  {
72  return (nullptr == mText) ? IntCoord() : mText->getCoord();
73  }
74 
76  {
77  return (nullptr == mText) ? IntSize() : mText->getTextSize();
78  }
79 
81  {
82  if (mText != nullptr) mText->setTextAlign(_align);
83  }
84 
86  {
87  if (mText != nullptr) return mText->getTextAlign();
88  return Align::Default;
89  }
90 
91  void StaticText::setTextColour(const Colour& _colour)
92  {
93  if (nullptr != mText) mText->setTextColour(_colour);
94  }
95 
97  {
98  return (nullptr == mText) ? Colour::Zero : mText->getTextColour();
99  }
100 
101  void StaticText::setFontName(const std::string& _font)
102  {
103  if (nullptr != mText) mText->setFontName(_font);
104  }
105 
106  const std::string& StaticText::getFontName()
107  {
108  if (nullptr == mText)
109  {
110  static std::string empty;
111  return empty;
112  }
113  return mText->getFontName();
114  }
115 
116  void StaticText::setFontHeight(int _height)
117  {
118  if (nullptr != mText) mText->setFontHeight(_height);
119  }
120 
122  {
123  return (nullptr == mText) ? 0 : mText->getFontHeight();
124  }
125 
126  void StaticText::setProperty(const std::string& _key, const std::string& _value)
127  {
128  if (_key == "Text_TextColour") setTextColour(utility::parseValue<Colour>(_value));
129  else if (_key == "Text_TextAlign") setTextAlign(utility::parseValue<Align>(_value));
130  else if (_key == "Text_FontName") setFontName(_value);
131  else if (_key == "Text_FontHeight") setFontHeight(utility::parseValue<int>(_value));
132  else
133  {
134  Base::setProperty(_key, _value);
135  return;
136  }
137  eventChangeProperty(this, _key, _value);
138  }
139 
140 } // namespace MyGUI