CanvasCV: CanvasCV-doxygen/src/canvascv/shapes/compoundshape.h Source File
CanvasCV  1.0.0
compoundshape.h
1 #ifndef COMPOUNDSHAPE_H
2 #define COMPOUNDSHAPE_H
3 
4 #include "shape.h"
5 #include "shapefactory.h"
6 #include "canvascv/colors.h"
7 
8 #include <list>
9 #include <memory>
10 
11 namespace canvascv
12 {
13 
20 class CompoundShape : public Shape
21 {
22 public:
23 
24  virtual void setOutlineColor(const cv::Scalar &value);
25  virtual void setFillColor(const cv::Scalar &value);
26  virtual void setThickness(int value);
27  virtual void setLineType(int value);
28  virtual void setLocked(bool value);
29  virtual void setVisible(bool value);
30 
31  virtual std::shared_ptr<Shape> getShape(int id);
32 
33  virtual void translate(const cv::Point &offset);
34 protected:
35  virtual ~CompoundShape() {} // force inheritance
36 
37  virtual void reloadPointers(const std::list<Shape*> &, std::list<Shape*>::const_iterator &)
38  {}
39 
40  virtual void draw(cv::Mat &canvas);
41  virtual bool mousePressed(const cv::Point &pos, bool onCreate = false);
42  virtual bool mouseMoved(const cv::Point &pos);
43  virtual bool mouseReleased(const cv::Point &pos);
44 
45  virtual bool keyPressed(int &key);
46  virtual void lostFocus();
47 
48  virtual const string &getCreateStatusMsg() const;
49  virtual const string &getEditStatusMsg() const;
50 
51  void setActive(Shape* shape);
52  Shape* getActive();
53 
54  template <class T>
55  T* addShape(cv::Point pos);
56 
57  bool rmvShape(Shape *shape);
58 
59  virtual void writeInternals(cv::FileStorage &fs) const;
60  virtual void readInternals(const cv::FileNode &node);
61 
62  virtual void setReady();
63 
64 private:
65  std::shared_ptr<Shape> active;
66  std::list<std::shared_ptr<Shape>> shapes;
67 };
68 
69 template <class T> inline
70 T* CompoundShape::addShape(cv::Point pos)
71 {
72  T *ret = dynamic_cast<T*>(ShapeFactoryT<T>::newShape(pos));
73  shapes.push_back(std::shared_ptr<Shape>(ret));
74  return ret;
75 }
76 
77 }
78 
79 #endif // COMPOUNDSHAPE_H
virtual void setThickness(int value)
set line thickness to use when drawing
virtual void setLineType(int value)
set the line type (LINE_4, LINE_8, LINE_AA)
virtual std::shared_ptr< Shape > getShape(int id)
getShape
The Shape class hierarchy is for geomertric user interaction.
Definition: shape.h:32
virtual void draw(cv::Mat &canvas)
draw shape on the canvas
The CompoundShape class.
Definition: compoundshape.h:20
virtual bool keyPressed(int &key)
keyPressed will be called by Canvas for active shapes
virtual void setLocked(bool value)
set the shape lock state (can/can&#39;t be moved/edited)
This namespace holds all the classes of the CanvasCV library.
Definition: canvas.h:20
static T * newShape(const cv::Point &pos)
create a shape by compile time type at a certain initial pos (don&#39;t use directly. Use Canvas::createS...
Definition: shapefactory.h:68
virtual void setFillColor(const cv::Scalar &value)
set the fill color (fill color is not very useful for shapes right now)
virtual bool mouseMoved(const cv::Point &pos)
mouseMoved
virtual void setVisible(bool value)
set the shape visible state
virtual void setOutlineColor(const cv::Scalar &value)
set the outline color
virtual bool mousePressed(const cv::Point &pos, bool onCreate=false)
mousePressed
virtual bool mouseReleased(const cv::Point &pos)
mouseReleased
virtual void lostFocus()
lostFocus is called by Canvas if we&#39;re in it and just became non-active