Ignition Rendering

API Reference

5.1.0
BaseText.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef IGNITION_RENDERING_BASE_BASETEXT_HH_
18 #define IGNITION_RENDERING_BASE_BASETEXT_HH_
19 
20 #include <string>
23 
24 namespace ignition
25 {
26  namespace rendering
27  {
28  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
29  //
31  template <class T>
32  class BaseText :
33  public virtual Text,
34  public virtual T
35  {
37  protected: BaseText();
38 
40  public: virtual ~BaseText();
41 
42  // Documentation inherited.
43  public: virtual void PreRender() override;
44 
45  // Documentation inherited.
46  public: virtual void Destroy() override;
47 
48  // Documentation inherited.
49  public: void SetFontName(const std::string &_font) override;
50 
51  // Documentation inherited.
52  public: std::string FontName() const override;
53 
54  // Documentation inherited.
55  public: virtual void SetTextString(const std::string &_text) override;
56 
57  // Documentation inherited.
58  public: virtual std::string TextString() const override;
59 
60  // Documentation inherited.
61  public: virtual void SetColor(const ignition::math::Color &_color)
62  override;
63 
64  // Documentation inherited.
65  public: virtual ignition::math::Color Color() const override;
66 
67  // Documentation inherited.
68  public: virtual void SetCharHeight(const float _height) override;
69 
70  // Documentation inherited.
71  public: virtual float CharHeight() const override;
72 
73  // Documentation inherited.
74  public: virtual void SetSpaceWidth(const float _width) override;
75 
76  // Documentation inherited.
77  public: virtual float SpaceWidth() const override;
78 
79  // Documentation inherited.
80  public: virtual void SetTextAlignment(const TextHorizontalAlign &_hAlign,
81  const TextVerticalAlign &_vAlign) override;
82  // Documentation inherited.
83  public: virtual TextHorizontalAlign HorizontalAlignment() const override;
84 
85  // Documentation inherited.
86  public: virtual TextVerticalAlign VerticalAlignment() const override;
87 
88  // Documentation inherited.
89  public: virtual void SetBaseline(const float _baseline) override;
90 
91  // Documentation inherited.
92  public: virtual float Baseline() const override;
93 
94  // Documentation inherited.
95  public: void SetShowOnTop(const bool _onTop) override;
96 
97  // Documentation inherited.
98  public: virtual bool ShowOnTop() const override;
99 
100  // Documentation inherited.
101  public: virtual ignition::math::AxisAlignedBox AABB() const override;
102 
104  protected: std::string fontName = "Liberation Sans";
105 
107  protected: std::string text;
108 
111 
113  protected: float charHeight = 1.0;
114 
116  protected: float spaceWidth = 0;
117 
119  protected: TextHorizontalAlign horizontalAlign =
121 
123  protected: TextVerticalAlign verticalAlign = TextVerticalAlign::BOTTOM;
124 
126  protected: float baseline = 0;
127 
130  protected: bool onTop = false;
131 
133  protected: bool textDirty = false;
134  };
135 
137  // BaseText
139  template <class T>
141  {
142  }
143 
145  template <class T>
147  {
148  }
149 
151  template <class T>
153  {
154  return this->fontName;
155  }
156 
158  template <class T>
160  {
161  this->fontName = _font;
162  this->textDirty = true;
163  }
164 
166  template <class T>
168  {
169  return this->text;
170  }
171 
173  template <class T>
175  {
176  this->text = _text;
177  this->textDirty = true;
178  }
179 
181  template <class T>
183  {
184  return this->color;
185  }
186 
188  template <class T>
190  {
191  this->color = _color;
192  this->textDirty = true;
193  }
194 
196  template <class T>
198  {
199  return this->charHeight;
200  }
201 
203  template <class T>
204  void BaseText<T>::SetCharHeight(const float _height)
205  {
206  this->charHeight = _height;
207  this->textDirty = true;
208  }
209 
211  template <class T>
213  {
214  return this->spaceWidth;
215  }
216 
218  template <class T>
219  void BaseText<T>::SetSpaceWidth(const float _width)
220  {
221  this->spaceWidth = _width;
222  this->textDirty = true;
223  }
224 
226  template <class T>
228  {
229  return this->horizontalAlign;
230  }
231 
233  template <class T>
235  {
236  return this->verticalAlign;
237  }
238 
240  template <class T>
242  const TextVerticalAlign &_vertAlign)
243  {
244  this->horizontalAlign = _horzAlign;
245  this->verticalAlign = _vertAlign;
246  this->textDirty = true;
247  }
248 
250  template <class T>
251  float BaseText<T>::Baseline() const
252  {
253  return this->baseline;
254  }
255 
257  template <class T>
258  void BaseText<T>::SetBaseline(const float _baseline)
259  {
260  this->baseline = _baseline;
261  this->textDirty = true;
262  }
263 
265  template <class T>
267  {
268  return this->onTop;
269  }
270 
272  template <class T>
273  void BaseText<T>::SetShowOnTop(const bool _onTop)
274  {
275  this->onTop = _onTop;
276  this->textDirty = true;
277  }
278 
280  template <class T>
282  {
284  return box;
285  }
286 
288  template <class T>
290  {
291  T::PreRender();
292  }
293 
295  template <class T>
297  {
298  T::Destroy();
299  }
300  }
301  }
302 }
303 #endif
TextVerticalAlign
Text vertical alignment.
Definition: Text.hh:49
virtual void SetBaseline(const float _baseline) override
Set the baseline height of the text.
Definition: BaseText.hh:258
virtual ignition::math::AxisAlignedBox AABB() const override
Get the axis aligned bounding box of the text.
Definition: BaseText.hh:281
void SetShowOnTop(const bool _onTop) override
True = text always is displayed ontop.
Definition: BaseText.hh:273
virtual void SetTextString(const std::string &_text) override
Set the text to display.
Definition: BaseText.hh:174
virtual void SetColor(const ignition::math::Color &_color) override
Set the text color.
Definition: BaseText.hh:189
virtual std::string TextString() const override
Get the displayed text.
Definition: BaseText.hh:167
virtual TextHorizontalAlign HorizontalAlignment() const override
Get the horizontal alignment of the text.
Definition: BaseText.hh:227
Represents a billboard text geometry that is always facing the camera.
Definition: Text.hh:62
virtual void SetTextAlignment(const TextHorizontalAlign &_hAlign, const TextVerticalAlign &_vAlign) override
Set the alignment of the text.
Definition: BaseText.hh:241
virtual void SetSpaceWidth(const float _width) override
Set the width of spaces between words.
Definition: BaseText.hh:219
virtual float CharHeight() const override
Get the height of the characters in meters return Height of the characters.
Definition: BaseText.hh:197
STL class.
virtual void Destroy() override
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: BaseText.hh:296
virtual ~BaseText()
Destructor.
Definition: BaseText.hh:146
void SetFontName(const std::string &_font) override
Set the font.
Definition: BaseText.hh:159
std::string text
Text being displayed.
Definition: BaseText.hh:107
virtual ignition::math::Color Color() const override
Get the text color.
Definition: BaseText.hh:182
std::string FontName() const override
Get the font name.
Definition: BaseText.hh:152
BaseText()
Constructor.
Definition: BaseText.hh:140
virtual float SpaceWidth() const override
Get the width of spaces between words.
Definition: BaseText.hh:212
TextHorizontalAlign
Text Horizontal alignment.
Definition: Text.hh:37
virtual float Baseline() const override
Get the baseline height in meters.
Definition: BaseText.hh:251
static const Color White
virtual bool ShowOnTop() const override
Get whether the is displayed above other objects.
Definition: BaseText.hh:266
Base implementation of a text geometry.
Definition: BaseText.hh:32
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: BaseText.hh:289
virtual void SetCharHeight(const float _height) override
Set the height of the character in meters.
Definition: BaseText.hh:204
virtual TextVerticalAlign VerticalAlignment() const override
Get the vertical alignment of the text.
Definition: BaseText.hh:234