Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
text_billboard.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_TEXT_BILLBOARD__
4 #define SCENEVIEW_TEXT_BILLBOARD__
5 
6 #include <memory>
7 #include <string>
8 
9 #include <QFont>
10 
11 #include <sceneview/font_resource.hpp>
12 #include <sceneview/geometry_resource.hpp>
13 #include <sceneview/material_resource.hpp>
14 #include <sceneview/resource_manager.hpp>
15 #include <sceneview/scene.hpp>
16 
17 namespace sv {
18 
19 class TextBillboardDrawable;
20 class DrawNode;
21 class GroupNode;
22 class Viewport;
23 
43  public:
44  enum HAlignment {
45  kLeft = 4,
46  kHCenter = 5,
47  kRight = 6,
48  };
49 
50  enum VAlignment {
51  kBottom,
52  kVCenter,
53  kTop,
54  };
55 
56  enum YDirection {
57  kNegative = -1,
58  kPositive = 1
59  };
60 
61  typedef std::shared_ptr<TextBillboard> Ptr;
62 
63  static Ptr Create(Viewport* viewport, GroupNode* parent);
64 
65  ~TextBillboard();
66 
67  void SetText(const QString& text);
68 
79  void SetFont(const QFont& font);
80 
87  void SetLineHeight(float height);
88 
92  void SetTextColor(const QColor& color);
93 
100  void SetBackgroundColor(const QColor& color);
101 
111  void SetAlignment(HAlignment horizontal, VAlignment vertical);
112 
113  void SetYDirection(YDirection direction);
114 
115  GroupNode* Node() { return node_; }
116 
117  private:
118  TextBillboard(Viewport* viewport,
119  GroupNode* parent);
120 
121  void Recompute();
122 
123  Viewport* viewport_;
124  ResourceManager::Ptr resources_;
125  Scene::Ptr scene_;
126 
127  GroupNode* parent_;
128  GroupNode* node_;
129 
130  FontResource::Ptr font_resource_;
131  MaterialResource::Ptr bg_material_;
132  GeometryResource::Ptr rect_geom_;
133  MaterialResource::Ptr text_material_;
134  GeometryResource::Ptr text_geom_;
135  DrawNode* draw_node_;
136 
137  VAlignment v_align_;
138  HAlignment h_align_;
139  float line_height_;
140  YDirection y_dir_ = kNegative;
141 
142  float margin_top_;
143  float margin_left_;
144  float margin_bottom_;
145  float margin_right_;
146 
147  QFont qfont_;
148  std::string text_;
149 
150  TextBillboardDrawable* bg_drawable_;
151  TextBillboardDrawable* text_drawable_;
152  TextBillboardDrawable* depth_write_drawable_;
153 };
154 
155 } // namespace sv
156 
157 #endif // SCENEVIEW_TEXT_BILLBOARD__
A scene graph node that can have children.
Definition: group_node.hpp:26
void SetTextColor(const QColor &color)
Sets the foreground text color.
void SetFont(const QFont &font)
Sets the font.
void SetAlignment(HAlignment horizontal, VAlignment vertical)
Sets the text alignment.
Scene node that contains a list of drawable objects.
Definition: draw_node.hpp:26
void SetBackgroundColor(const QColor &color)
Sets the background color.
Widget that draws a scene and manages Renderer and InputHandler objects.
Definition: viewport.hpp:27
A text display that always faces the camera.
Definition: text_billboard.hpp:42
void SetLineHeight(float height)
Control text size by varying nominal line height.