3es  0.7
3estext2d.h
1 //
2 // author: Kazys Stepanas
3 //
4 #ifndef _3ESTEXT2D_H_
5 #define _3ESTEXT2D_H_
6 
7 #include "3es-core.h"
8 
9 #include "3esshape.h"
10 
11 #include <cstdint>
12 #include <cstring>
13 
14 namespace tes
15 {
20  class _3es_coreAPI Text2D : public Shape
21  {
22  public:
23  //Text2D(const char *text, uint16_t textLength, const V3Arg &pos = V3Arg(0, 0, 0));
24  Text2D(const char *text, const V3Arg &pos = V3Arg(0, 0, 0));
25  //Text2D(const char *text, uint16_t textLength, uint32_t id, const V3Arg &pos = V3Arg(0, 0, 0));
26  Text2D(const char *text, uint32_t id, const V3Arg &pos = V3Arg(0, 0, 0));
27  //Text2D(const char *text, uint16_t textLength, uint32_t id, uint16_t category, const V3Arg &pos = V3Arg(0, 0, 0));
31  Text2D(const char *text, uint32_t id, uint16_t category, const V3Arg &pos = V3Arg(0, 0, 0));
32 
33  ~Text2D();
34 
35  bool inWorldSpace() const;
36  Text2D &setInWorldSpace(bool worldSpace);
37 
38  inline char *text() const { return _text; }
39  inline uint16_t textLength() const { return _textLength; }
40 
41  Text2D &setText(const char *text, uint16_t textLength);
42 
43  virtual bool writeCreate(PacketWriter &stream) const override;
44 
45  Shape *clone() const override;
46 
47  protected:
48  void onClone(Text2D *copy) const;
49 
50  private:
51  char *_text;
52  uint16_t _textLength;
53  };
54 
55 
56  //inline Text2D::Text2D(const char *text, uint16_t textLength, const V3Arg &pos)
57  // : Shape(SIdText2D)
58  // , _text(nullptr)
59  // , _textLength(0)
60  //{
61  // setPosition(pos);
62  // setText(text, textLength);
63  //}
64 
65 
66  inline Text2D::Text2D(const char *text, const V3Arg &pos)
67  : Shape(SIdText2D)
68  , _text(nullptr)
69  , _textLength(0)
70  {
71  setPosition(pos);
72  setText(text, (uint16_t)strlen(text));
73  }
74 
75 
76  //inline Text2D::Text2D(const char *text, uint16_t textLength, uint32_t id, const V3Arg &pos)
77  // : Shape(SIdText2D, id)
78  // , _text(nullptr)
79  // , _textLength(0)
80  //{
81  // setPosition(pos);
82  // setText(text, textLength);
83  //}
84 
85 
86  inline Text2D::Text2D(const char *text, uint32_t id, const V3Arg &pos)
87  : Shape(SIdText2D, id)
88  , _text(nullptr)
89  , _textLength(0)
90  {
91  setPosition(pos);
92  setText(text, (uint16_t)strlen(text));
93  }
94 
95 
96  //inline Text2D::Text2D(const char *text, uint16_t textLength, uint32_t id, uint16_t category, const V3Arg &pos)
97  // : Shape(SIdText2D, id, category)
98  // , _text(nullptr)
99  // , _textLength(0)
100  //{
101  // setPosition(pos);
102  // setText(text, textLength);
103  //}
104 
105 
106  inline Text2D::Text2D(const char *text, uint32_t id, uint16_t category, const V3Arg &pos)
107  : Shape(SIdText2D, id, category)
108  , _text(nullptr)
109  , _textLength(0)
110  {
111  setPosition(pos);
112  setText(text, (uint16_t)strlen(text));
113  }
114 
115 
116  inline bool Text2D::inWorldSpace() const
117  {
118  return (_data.flags & Text2DFWorldSpace) != 0;
119  }
120 
121 
122  inline Text2D &Text2D::setInWorldSpace(bool worldSpace)
123  {
124  _data.flags &= ~Text2DFWorldSpace;
125  _data.flags |= Text2DFWorldSpace * !!worldSpace;
126  return *this;
127  }
128 }
129 
130 #endif // _3ESTEXT2D_H_
A base class for encapsulating a shape which is to be represented remotely.
Definition: 3esshape.h:39
Position is given in world space and mapped to screen space.
Definition: 3esmessages.h:118
Definition: 3esbounds.h:13
A shape which renders screen space text, optionally positioned in 3D.
Definition: 3estext2d.h:20
A helper structure used to convert from float or double pointers to Vector3f arguments.
Definition: 3esv3arg.h:14
uint16_t flags
Flags controlling the appearance and creation of the object.
Definition: 3esmessages.h:406
A utility class for writing payload data to a PacketHeader.
Definition: 3espacketwriter.h:34