CanvasCV: CanvasCV-doxygen/src/canvascv/shapes/textbox.h Source File
CanvasCV  1.0.0
textbox.h
1 #ifndef TEXTBOX_H
2 #define TEXTBOX_H
3 
4 #include "handle.h"
5 #include "shape.h"
6 #include "shapefactory.h"
7 
8 #include <string>
9 #include <memory>
10 
11 namespace canvascv
12 {
13 
19 class TextBox : public Shape
20 {
21 public:
23  const std::string & getText() const;
24 
26  void setText(const std::string &value);
27 
29  void setTL(const cv::Point &value);
30 
32  int getFontFace() const;
33 
35  void setFontFace(int value);
36 
38  double getFontScale() const;
39 
41  void setFontScale(double value);
42 
44  int getFontThickness() const;
45 
47  void setFontThickness(int value);
48 
50  cv::Scalar getFontColor() const;
51 
53  void setFontColor(const cv::Scalar &value);
54 
55  virtual bool isAtPos(const cv::Point &pos)
56  {
57  return rect.contains(pos);
58  }
59 
60  virtual std::list<Handle *> getConnectionTargets();
61  virtual std::shared_ptr<Shape> getShape(int id);
62 
63  virtual void translate(const cv::Point &offset);
64 
65  virtual const char *getType() const;
66 
67  static const char * type;
68 
69 protected:
70  friend class ShapeFactory;
71  template <class T> friend class ShapeFactoryT;
72 
73  TextBox(const cv::Point &pos);
74 
75  virtual void writeInternals(cv::FileStorage &fs) const;
76  virtual void readInternals(const cv::FileNode &node);
77  void registerCBs();
78 
79  virtual void draw(cv::Mat &canvas);
80  virtual bool mousePressed(const cv::Point &pos, bool onCreate = false);
81  virtual bool mouseMoved(const cv::Point &pos);
82  virtual bool mouseReleased(const cv::Point &pos);
83 
84  virtual bool keyPressed(int &key);
85  virtual void lostFocus();
86 
87  virtual const string &getCreateStatusMsg() const;
88  virtual const string &getEditStatusMsg() const;
89 private:
90  void recalcRect();
91 
92  std::string text;
93  std::string prevText;
94  int fontFace;
95  double fontScale;
96  int fontThickness;
97  cv::Scalar fontColor;
98  int baseline;
99  std::shared_ptr<Handle> topLeft;
100  cv::Rect rect;
101 };
102 
103 }
104 
109 #endif // TEXTBOX_H
The ShapeFactory class.
Definition: shapefactory.h:24
void setText(const std::string &value)
set the displayed text
cv::Scalar getFontColor() const
get the font color
int getFontThickness() const
get the thickness of the font
virtual void draw(cv::Mat &canvas)
draw shape on the canvas
void setFontFace(int value)
set the font used
virtual const char * getType() const
getType is always implemented by derived to return the same static pointer per shape.
The Shape class hierarchy is for geomertric user interaction.
Definition: shape.h:32
void setFontColor(const cv::Scalar &value)
set the font color
virtual bool keyPressed(int &key)
keyPressed will be called by Canvas for active shapes
const std::string & getText() const
get the displayed text
virtual bool mouseReleased(const cv::Point &pos)
mouseReleased
virtual bool mousePressed(const cv::Point &pos, bool onCreate=false)
mousePressed
virtual bool mouseMoved(const cv::Point &pos)
mouseMoved
void setFontThickness(int value)
set the thickness of the font
void setTL(const cv::Point &value)
set position (top left corner)
int getFontFace() const
get the font used
virtual std::shared_ptr< Shape > getShape(int id)
getShape
double getFontScale() const
get the scale of the used font
The ShapeFactoryT class.
Definition: shapefactory.h:45
virtual bool isAtPos(const cv::Point &pos)
returns true if shape is at pos, false otherwise
Definition: textbox.h:55
void setFontScale(double value)
set the scale of the used font
This namespace holds all the classes of the CanvasCV library.
Definition: canvas.h:20
virtual std::list< Handle * > getConnectionTargets()
getConnectionTargets
The TextBox class.
Definition: textbox.h:19
virtual void lostFocus()
lostFocus is called by Canvas if we&#39;re in it and just became non-active