CanvasCV: CanvasCV-doxygen/src/canvascv/widgets/text.h Source File
CanvasCV  1.0.0
text.h
1 #ifndef TEXT_H
2 #define TEXT_H
3 
4 #include <opencv2/opencv.hpp>
5 #include <list>
6 #include "canvascv/colors.h"
7 #include "widget.h"
8 
9 namespace canvascv
10 {
11 
17 class Text : public Widget
18 {
19 public:
34  static std::shared_ptr<Text> create(Layout &layout, const cv::Point &pos,
35  const std::string &text = "",
36  Anchor flowAnchor = TOP,
37  Anchor layoutAnchor = TOP);
38 
40  static std::shared_ptr<Text> create(Layout &layout,
41  const std::string &text = "",
42  Anchor flowAnchor = TOP,
43  Anchor layoutAnchor = TOP);
44 
45  virtual const char *getType() const;
46 
48  std::string getText() const;
49 
51  void setText(const std::string &value);
52 
54  int getFontFace() const;
55 
57  void setFontFace(int value);
58 
60  double getFontScale() const;
61 
63  void setFontScale(double value);
64 
66  int getFontHeight() const;
67 
69  void setFontHeight(int value);
70 
72  int getMaxWidth() const;
73 
75  void setMaxWidth(int value);
76 
77  static const char *type;
78 
79  virtual const cv::Rect &getRect();
80  virtual const cv::Rect &getMinimalRect();
81 
82  Text(const cv::Point &pos);
83 
84  virtual void recalc();
85 
86  virtual void drawFG(cv::Mat &dst);
87 
88  /* TODO - write/read widgets to file for a designer app
89  virtual void writeInternals(cv::FileStorage &fs) const
90  {
91  }
92  virtual void readInternals(const cv::FileNode &node)
93  {
94  }
95  */
96 
97  int getPadding() const;
98  void setPadding(int value);
99 
100 private:
101 
102  void prepareMsgParts();
103 
104  struct StringRow
105  {
106  std::string str;
107  int width;
108  };
109 
110  int padding;
111  int doublePadding;
112  std::string msg;
113  std::list<StringRow> rows;
114  int fontHeight;
115  int fontFace;
116  double fontScale;
117  int maxWidth;
118  cv::Rect rect;
119  cv::Rect minimalRect;
120 };
121 
122 }
123 #endif // TEXT_H
void setFontFace(int value)
set the OpenCV font to use
int getMaxWidth() const
get the maxuimum allowed width of rows in pixels (0 means it&#39;s disabled)
void setText(const std::string &value)
set the current text of the Text
virtual void drawFG(cv::Mat &dst)
dst is the roi of the widget size and not the full image
static std::shared_ptr< Text > create(Layout &layout, const cv::Point &pos, const std::string &text="", Anchor flowAnchor=TOP, Anchor layoutAnchor=TOP)
create a Text widget
int getFontFace() const
get the OpenCV font used
Anchor
The Anchor enum.
Definition: widget.h:115
std::string getText() const
get the current text of the Text
top
Definition: widget.h:117
virtual void recalc()
update self so next call to &#39;draw&#39; will display correctly
This namespace holds all the classes of the CanvasCV library.
Definition: canvas.h:20
void setFontScale(double value)
set the OpenCV scale used for te font
virtual const cv::Rect & getMinimalRect()
Minimal size the widget coould have occupy.
void setFontHeight(int value)
set the font scale from a requested pixel height (with padding and internal font spaces) ...
The Layout class.
Definition: layout.h:17
The Text class.
Definition: text.h:17
double getFontScale() const
get the OpenCV scale used for te font
virtual const cv::Rect & getRect()
Actual size the widget is occupying due to Layout manager.
void setMaxWidth(int value)
set the maxuimum allowed width of rows in pixels (0 to disable max width)
The Widget class.
Definition: widget.h:28
int getFontHeight() const
get the calculated font height (with padding and internal font spaces)
virtual const char * getType() const
getType is always implemented by derived to return the same static pointer per widget.