Gazebo Rendering

API Reference

6.6.3
gz/rendering/base/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 GZ_RENDERING_BASE_BASETEXT_HH_
18 #define GZ_RENDERING_BASE_BASETEXT_HH_
19 
20 #include <string>
21 #include "gz/rendering/Text.hh"
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 gz::math::Color &_color)
62  override;
63 
64  // Documentation inherited.
65  public: virtual gz::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 gz::math::AxisAlignedBox AABB() const override;
102 
104  protected: std::string fontName = "Liberation Sans";
105 
107  protected: std::string text;
108 
110  protected: gz::math::Color color = gz::math::Color::White;
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>
182  gz::math::Color BaseText<T>::Color() const
183  {
184  return this->color;
185  }
186 
188  template <class T>
189  void BaseText<T>::SetColor(const gz::math::Color &_color)
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>
281  gz::math::AxisAlignedBox BaseText<T>::AABB() const
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
Represents a billboard text geometry that is always facing the camera.
Definition: gz/rendering/Text.hh:62
STL class.
float charHeight
Character height in meters.
Definition: gz/rendering/base/BaseText.hh:113
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: gz/rendering/base/BaseText.hh:289
std::string text
Text being displayed.
Definition: gz/rendering/base/BaseText.hh:107
BaseText()
Constructor.
Definition: gz/rendering/base/BaseText.hh:140
bool onTop
True for text to be displayed on top of other objects in the scene.
Definition: gz/rendering/base/BaseText.hh:130
float spaceWidth
Width of space between letters.
Definition: gz/rendering/base/BaseText.hh:116
TextHorizontalAlign horizontalAlign
Horizontal alignment.
Definition: gz/rendering/base/BaseText.hh:119
virtual bool ShowOnTop() const override
Get whether the is displayed above other objects.
Definition: gz/rendering/base/BaseText.hh:266
virtual TextVerticalAlign VerticalAlignment() const override
Get the vertical alignment of the text.
Definition: gz/rendering/base/BaseText.hh:234
virtual void SetCharHeight(const float _height) override
Set the height of the character in meters.
Definition: gz/rendering/base/BaseText.hh:204
TextVerticalAlign
Text vertical alignment.
Definition: gz/rendering/Text.hh:49
float baseline
Baseline height in meters.
Definition: gz/rendering/base/BaseText.hh:126
bool textDirty
Flag to indicate text properties have changed.
Definition: gz/rendering/base/BaseText.hh:133
std::string fontName
Font name, such as "Liberation Sans".
Definition: gz/rendering/base/BaseText.hh:104
virtual TextHorizontalAlign HorizontalAlignment() const override
Get the horizontal alignment of the text.
Definition: gz/rendering/base/BaseText.hh:227
virtual void SetTextString(const std::string &_text) override
Set the text to display.
Definition: gz/rendering/base/BaseText.hh:174
virtual ~BaseText()
Destructor.
Definition: gz/rendering/base/BaseText.hh:146
void SetFontName(const std::string &_font) override
Set the font.
Definition: gz/rendering/base/BaseText.hh:159
Base implementation of a text geometry.
Definition: gz/rendering/base/BaseText.hh:32
std::string FontName() const override
Get the font name.
Definition: gz/rendering/base/BaseText.hh:152
virtual void SetBaseline(const float _baseline) override
Set the baseline height of the text.
Definition: gz/rendering/base/BaseText.hh:258
virtual void SetSpaceWidth(const float _width) override
Set the width of spaces between words.
Definition: gz/rendering/base/BaseText.hh:219
virtual gz::math::AxisAlignedBox AABB() const override
Get the axis aligned bounding box of the text.
Definition: gz/rendering/base/BaseText.hh:281
TextVerticalAlign verticalAlign
Vertical alignment.
Definition: gz/rendering/base/BaseText.hh:123
virtual float Baseline() const override
Get the baseline height in meters.
Definition: gz/rendering/base/BaseText.hh:251
virtual void SetTextAlignment(const TextHorizontalAlign &_hAlign, const TextVerticalAlign &_vAlign) override
Set the alignment of the text.
Definition: gz/rendering/base/BaseText.hh:241
virtual float CharHeight() const override
Get the height of the characters in meters return Height of the characters.
Definition: gz/rendering/base/BaseText.hh:197
virtual void SetColor(const gz::math::Color &_color) override
Set the text color.
Definition: gz/rendering/base/BaseText.hh:189
virtual float SpaceWidth() const override
Get the width of spaces between words.
Definition: gz/rendering/base/BaseText.hh:212
TextHorizontalAlign
Text Horizontal alignment.
Definition: gz/rendering/Text.hh:37
virtual gz::math::Color Color() const override
Get the text color.
Definition: gz/rendering/base/BaseText.hh:182
virtual void Destroy() override
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: gz/rendering/base/BaseText.hh:296
void SetShowOnTop(const bool _onTop) override
True = text always is displayed ontop.
Definition: gz/rendering/base/BaseText.hh:273
gz::math::Color color
Text color.
Definition: gz/rendering/base/BaseText.hh:110
virtual std::string TextString() const override
Get the displayed text.
Definition: gz/rendering/base/BaseText.hh:167