opensurgsim
OsgTextRepresentation.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
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 #ifndef SURGSIM_GRAPHICS_OSGTEXTREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGTEXTREPRESENTATION_H
18 
19 #include <string>
20 
21 #include "SurgSim/Graphics/OsgRepresentation.h"
22 #include "SurgSim/Graphics/TextRepresentation.h"
23 #include "SurgSim/DataStructures/OptionalValue.h"
24 
25 #include <osg/Vec3>
26 #include <boost/thread/mutex.hpp>
27 
28 #if defined(_MSC_VER)
29 #pragma warning(push)
30 #pragma warning(disable:4250)
31 #endif
32 
33 namespace osg
34 {
35 class Geode;
36 }
37 
38 namespace osgText
39 {
40 class Text;
41 }
42 
43 namespace SurgSim
44 {
45 namespace Framework
46 {
47 class Asset;
48 }
49 namespace Graphics
50 {
51 class OsgFont;
52 
53 SURGSIM_STATIC_REGISTRATION(OsgTextRepresentation);
54 
57 {
58 public:
61  explicit OsgTextRepresentation(const std::string& name);
62 
65 
66  friend class OsgTextRepresentationTests_MaximumWidth_Test;
67 
69 
70  void setLocation(double x, double y) override;
71  void getLocation(double* x, double* y) const override;
72 
73  void setMaximumWidth(double width) override;
74  double getMaximumWidth() override;
75 
76  void setText(const std::string& text) override;
77  std::string getText() const override;
78 
79  void loadFont(const std::string& fileName) override;
80  void setFont(std::shared_ptr<SurgSim::Framework::Asset> font) override;
81  std::shared_ptr<Font> getFont() const override;
82 
83  void setColor(SurgSim::Math::Vector4d color) override;
84  SurgSim::Math::Vector4d getColor() const override;
85 
86  void setFontSize(double size) override;
87  double getFontSize() const override;
88 
89  void setUseScreenSpace(bool value) override;
90  bool isUsingScreenSpace() const override;
91 
92  enum Anchor
93  {
94  ANCHOR_TOP_LEFT,
95  ANCHOR_CENTER
96  };
97 
98  void setAnchor(int anchor);
99  int getAnchor() const;
100 
101  void setDrawBackground(bool value) override;
102  bool isDrawingBackground() const override;
103 
104  void setBackgroundColor(Math::Vector4d color) override;
105  Math::Vector4d getBackgroundColor() override;
106 
107  void setBackgroundMargin(double margin) override;
108  double getBackgroundMargin() const override;
109 
110  static std::shared_ptr<OsgMaterial> getDefaultMaterial();
111 
112 protected:
113 
114  void doUpdate(double dt) override;
115  bool doInitialize() override;
116 
117  void setOptionalMaximumWidth(SurgSim::DataStructures::OptionalValue<double> maximum) override;
118  SurgSim::DataStructures::OptionalValue<double> getOptionalMaximumWidth() override;
119 
120 private:
121  osg::ref_ptr<osg::Geode> m_geode;
122  osg::ref_ptr<osgText::Text> m_textNode;
123 
124  std::string m_text;
125  std::shared_ptr<OsgFont> m_font;
127 
128  double m_characterSize;
129 
130  int m_drawMode;
131 
132  boost::mutex m_parameterMutex;
133  bool m_needUpdate;
134 
135  SurgSim::Math::Vector3d m_offset;
136 };
137 
138 }; // Graphics
139 }; // SurgSim
140 
141 #if defined(_MSC_VER)
142 #pragma warning(pop)
143 #endif
144 
145 #endif
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
A text to be displayed on the screen in screen space coordinates, use setPose() to set the position b...
Definition: TextRepresentation.h:39
Definition: OsgFont.h:23
Definition: OsgImGuiHandler.h:8
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
Osg implementation of the TextRepresentation, to be used with OsgFont assets.
Definition: OsgTextRepresentation.h:56