4 #include "canvascv/colors.h" 5 #include "canvascv/consts.h" 7 #include "shapes/shape.h" 8 #include "widgets/widget.h" 9 #include "shapes/shapefactory.h" 10 #include "widgets/widgetfactory.h" 11 #include "widgets/text.h" 12 #include "widgets/layoutbase.h" 47 Canvas(
const std::string &winNameVal, cv::Size sizeVal = cv::Size());
60 void redrawOn(
const cv::Mat &src, cv::Mat &dst);
100 std::shared_ptr<Shape>
createShape(std::string type,
const cv::Point &pos = cv::Point(0,0));
112 std::shared_ptr<T>
createShape(
const cv::Point &pos = cv::Point(0,0));
144 void deleteShape(
const std::shared_ptr<Shape> &shape);
150 void deleteWidget(
const std::shared_ptr<Widget> &widget);
196 void getShapes(std::list<std::shared_ptr<T>> &result);
204 std::shared_ptr<Shape>
getShape(
int id);
212 void getShapes(
const cv::Point &pos, std::list<std::shared_ptr<Shape>> &result);
217 hasScreenText =
false;
223 hasStatusMsg =
false;
240 double scale = Consts::DEFAULT_FONT_SCALE,
241 int thickness = Consts::DEFAULT_FONT_THICKNESS,
243 int fontFace = Consts::DEFAULT_FONT);
259 double scale = Consts::DEFAULT_FONT_SCALE,
260 int thickness = Consts::DEFAULT_FONT_THICKNESS,
262 int fontFace = Consts::DEFAULT_FONT);
274 void setSize(
const cv::Size &value);
279 virtual void addWidget(
const std::shared_ptr<Widget> &widget);
280 virtual std::shared_ptr<Widget>
rmvWidget(
const std::shared_ptr<Widget> &widget);
286 void setOn(
bool value);
298 void imshow(InputArray mat);
321 void applyTheme(
bool applyToCanvasText =
false);
333 static void fatal(
string errorMsg,
int exitStatus);
339 virtual void recalc() {}
344 virtual const cv::Rect getBoundaries()
const;
353 StatusMsgGrd(
Canvas &val) : c(val) {}
358 c.setStatusMsg(c.activeWidget->getStatusMsg());
360 else if (c.activeShape)
362 c.setStatusMsg(c.activeShape->getStatusMsg());
366 c.setStatusMsg(c.defaultStatusMsg);
372 friend class StatusMsgGrd;
380 void consumeKey(
int &key);
382 void setStatusMsg(
const std::string &msg);
384 virtual bool setDirtyLayout();
386 void broadcastCreate(
Shape *shape);
387 void broadcastModify(
Shape *shape);
388 void broadcastDelete(
Shape *shape);
390 void processNewShape();
397 std::shared_ptr<Text> screenText;
398 std::shared_ptr<Text> statusMsg;
399 std::string defaultStatusMsg;
400 std::string shapeType;
402 cv::Mat latestFrameSrc;
404 std::list<std::shared_ptr<Shape>> shapes;
405 std::list<std::shared_ptr<Widget>> widgets;
406 std::shared_ptr<Shape> activeShape;
407 std::shared_ptr<Widget> activeWidget;
408 std::list<CBCanvasShape> createNotifs;
409 std::list<CBCanvasShape> modifyNotifs;
410 std::list<CBCanvasShape> deleteNotifs;
412 friend void operator >> (
const cv::FileNode& n,
Canvas& value)
414 read( n, value,
Canvas());
417 friend void write(cv::FileStorage& fs,
const std::string&,
const Canvas& x);
418 friend void read(
const cv::FileNode& node,
Canvas& x,
const Canvas&);
425 shapes.push_back(shape);
427 ((
Shape*)shape.get())->setReady();
428 ((
Shape*)shape.get())->setLocked(
false);
429 ((
Shape*)shape.get())->lostFocus();
437 for (
auto &shape : shapes)
439 std::shared_ptr<T> derived = std::dynamic_pointer_cast<T>(shape);
442 result.push_back(derived);
447 void writeShapes(cv::FileStorage& fs,
const std::string&,
const Canvas& x);
448 void readShapes(
const cv::FileNode& node,
Canvas& x,
const Canvas&);
452 #define CCV_STR(X) ((std::stringstream&)(std::stringstream() << X)).str() 453 #define CCV_C_STR(X) CCV_STR(X).c_str() static const cv::Scalar Black
   RGB: (0,0,0) HEX: #000000
Definition: colors.h:152
void setSize(const cv::Size &value)
set the Canvas size to match the cv::Mat we'll use in redrawOn;
virtual void addWidget(const std::shared_ptr< Widget > &widget)
adds the widget to this Layout after removing it from it's previous layout
void setImage(const cv::Mat &img)
setImage
void deleteWidget(const std::shared_ptr< Widget > &widget)
delete specific widget
int waitKeyEx(int delay=0)
waitKeyEx
The LayoutBase class.
Definition: layoutbase.h:14
void disableStatusMsg()
disable the bottom left text area for auto status messages
Definition: canvas.h:221
void redrawOn(const cv::Mat &src, cv::Mat &dst)
redrawOn draws the shapes on dst
void setOn(bool value)
redrawOn will do nothing if value is 'false'
The c++ std namespace.
Definition: canvas.h:462
The OpenCV namespace.
Definition: canvas.h:465
void clearWidgets()
clear all widgets from Canvas
void setDirty()
while waiting for events the Canvas is redrawn only if it is dirty
void setShapeType(std::string value)
set default shape type to draw (could be "")
Definition: canvas.h:129
The Shape class hierarchy is for geomertric user interaction.
Definition: shape.h:32
static const cv::Scalar Orange
   RGB: (255,165,0) HEX: #FFA500
Definition: colors.h:36
static void fatal(string errorMsg, int exitStatus)
fatal
void notifyOnShapeDelete(CBCanvasShape cb)
used to register for notifications on shape deletion
The ShapeFactoryT class.
Definition: shapefactory.h:45
void deleteShape(const std::shared_ptr< Shape > &shape)
delete specific shape
std::shared_ptr< Shape > getShape(int id)
getShape
void notifyOnShapeModify(CBCanvasShape cb)
used to register for notifications on shape modification (actually when it is deselected) ...
std::string getDefaultStatusMsg() const
get the default status message (active widget and shapes will override it)
bool getOn() const
is redrawOn() on/off?
static const cv::Scalar LightGray
   RGB: (211,211,211) HEX: #D3D3D3
Definition: colors.h:160
This namespace holds all the classes of the CanvasCV library.
Definition: canvas.h:20
void enableStatusMsg(cv::Scalar color=Colors::Orange, cv::Scalar bgColor=Colors::LightGray, double scale=Consts::DEFAULT_FONT_SCALE, int thickness=Consts::DEFAULT_FONT_THICKNESS, uchar alpha=80, int fontFace=Consts::DEFAULT_FONT)
enableStatusMsg enables the bottom left text area for auto status messages
std::function< void(Shape *)> CBCanvasShape
notification on shapes create/modify/delete from this Canvas instance
Definition: canvas.h:37
std::shared_ptr< Shape > createShape(std::string type, const cv::Point &pos=cv::Point(0, 0))
createShape
virtual std::shared_ptr< Widget > rmvWidget(const std::shared_ptr< Widget > &widget)
rmvWidget
void notifyOnShapeCreate(CBCanvasShape cb)
used to register for notifications on shape creation
void clearShapes()
clear all shapes from Canvas
cv::Size getSize()
get the Canvas size
void setScreenText(const std::string &msg)
manually set the screen text message. It remains until disabled or changed.
void writeShapesToFile(const std::string &filepath) const
write all the shapes currently in the Canvas to a file
void deleteActive()
delete shape currenty selected
void onMouseMove(const cv::Point &pos)
You should delegate OpenCV mouse callback events to this method.
void setDefaultStatusMsg(const std::string &msg)
set the default status message (active widget and shapes will override it)
bool onMousePress(const cv::Point &pos)
You should delegate OpenCV mouse callback events to this method - returns true if did something at po...
void readShapesFromFile(const std::string &filepath)
load all the from a file into the canvas (removing all current shapes in the process) ...
void disableScreenText()
disable the top left text area for manual user messages
Definition: canvas.h:215
std::string getShapeType() const
get default shape type to draw
Definition: canvas.h:119
void getShapes(std::list< std::shared_ptr< T >> &result)
getShapes of a specific type
Definition: canvas.h:435
~Canvas()
release all shapes and widgets. Shape callbacks are invoked doe delete.
The Canvas class is the entry point into CanvasCV.
Definition: canvas.h:33
void applyTheme(bool applyToCanvasText=false)
applyTheme
void enableScreenText(cv::Scalar color=Colors::Black, cv::Scalar bgColor=Colors::LightGray, double scale=Consts::DEFAULT_FONT_SCALE, int thickness=Consts::DEFAULT_FONT_THICKNESS, uchar alpha=80, int fontFace=Consts::DEFAULT_FONT)
enableScreenText enables the top left text area for manual user messages
void onMouseRelease(const cv::Point &pos)
You should delegate OpenCV mouse callback events to this method.
void setMouseCallback()
utility method to handle mouse events on the associated window
void imshow(InputArray mat)
utility method which uses the winName encapsulated in Canvas