xvWidgets
Widget.hpp
1 #pragma once
2 
10 #include <opencv2/core.hpp>
11 #include <vector>
12 #include <list>
13 #include <mutex>
14 
15 #if defined(wxUSE_GUI)
16 #include <wx/gdicmn.h>
17 #elif defined(QT_GUI_LIB)
18 #include <QPoint>
19 #endif
20 
21 
22 namespace xv {
23 
24 #if defined(wxUSE_GUI)
25  typedef wxPoint gui_point_t;
26 #elif defined(QT_GUI_LIB)
27  typedef QPoint gui_point_t;
28 #endif
29 
30  class Point;
31  class ImagePanel;
32  class Image;
33  int distance(gui_point_t, gui_point_t);
34 
35 
40 class Widget{
41  friend ImagePanel;
42 public:
44  virtual void addChild(Widget &, bool readOnly = true);
45 
47  virtual void render(const cv::Mat&);
48 
50  virtual void paint(const cv::Mat&) = 0;
51 
53  virtual bool contains(const gui_point_t&);
54 
56  virtual void onMouseDown(const gui_point_t&);
57 
59  virtual void onMouseMove(const gui_point_t&);
60 
62  virtual void onMouseUp(const gui_point_t&);
63 
65  void startDragging(){ m_dragging = true; };
66 
68  void stopDragging(){ m_dragging = false; };
69 
71  bool isDragging(){ return m_dragging; };
72 
74  virtual void setMouseOver(bool mouseOver){ m_mouseOver = mouseOver; };
75 
77  virtual bool isMouseOver(){ return m_mouseOver; };
78 
80  virtual bool isReadOnly(){ return m_readonly; };
81 
83  virtual void setPosition(gui_point_t position);
84 
86  virtual gui_point_t position();
87 
89  bool isMouseOverButton(gui_point_t mousePosition, gui_point_t buttonPosition);
90 
92  void hide();
93 
94 protected:
96  std::list<Widget*> m_children;
97 
99  static const int LINE_THICKNESS;
100 
102  static const int MARGIN;
103 
105  static const int BUTTON_RADIUS;
106 
108  static const gui_point_t OK_POSITION;
109 
111  static const gui_point_t CANCEL_POSITION;
112 
114  static const cv::Scalar FOREGROUND_COLOR;
115 
117  static const cv::Scalar HIGHLIGHT_COLOR;
118 
120  static const cv::Scalar AFFIRMATIVE_COLOR;
121 
123  static const cv::Scalar NEGATIVE_COLOR;
124 
125  virtual ~Widget() = 0;
126 
128  Widget *m_parent = NULL;
129 
131  std::vector<gui_point_t> m_contour;
132 
133  bool m_dragging = false;
134  bool m_canceling = false;
135  bool m_accepting = false;
137  bool m_mouseOver = false;
138  bool m_undefined = false;
139  bool m_positioned = false;
140  bool m_readonly = false;
142  gui_point_t m_position;
143 private:
145  virtual void paintButtons(const cv::Mat&);
146 
147 };
148 
149 }
bool m_dragging
Definition: Widget.hpp:133
bool m_canceling
Definition: Widget.hpp:134
static const cv::Scalar AFFIRMATIVE_COLOR
Color associated with OK/accept action.
Definition: Widget.hpp:120
std::list< Widget * > m_children
Other widgets inside the widget.
Definition: Widget.hpp:96
static const int MARGIN
Generic margin around widget.
Definition: Widget.hpp:102
virtual void addChild(Widget &, bool readOnly=true)
Add a child widget.
bool isDragging()
Check if the user is dragging the widget.
Definition: Widget.hpp:71
bool m_positioned
Definition: Widget.hpp:139
static const int BUTTON_RADIUS
Used to define the size of buttons.
Definition: Widget.hpp:105
bool m_readonly
Definition: Widget.hpp:140
bool m_mouseOver
Definition: Widget.hpp:137
bool m_accepting
Definition: Widget.hpp:135
virtual gui_point_t position()
Get the current position.
void stopDragging()
Signal that the user stopped dragging the widget.
Definition: Widget.hpp:68
Widget * m_parent
Pointer to the parent image used to display the widget.
Definition: Widget.hpp:128
virtual void setMouseOver(bool mouseOver)
Signal that the user placed the mouse pointer over the widget.
Definition: Widget.hpp:74
void hide()
Make it disappear from an Image.
virtual bool contains(const gui_point_t &)
Check if point is inside the widget.
virtual void onMouseDown(const gui_point_t &)
The user clicked the left mouse button over the widget.
virtual void paint(const cv::Mat &)=0
Display widget in output mode (without OK/Cancel buttons)
Class used to display images and as container of widgets.
Definition: ImagePanel.hpp:32
virtual bool isMouseOver()
Check if the mouse pointer is over the widget.
Definition: Widget.hpp:77
static const int LINE_THICKNESS
The thickness of contour lines.
Definition: Widget.hpp:99
static const gui_point_t CANCEL_POSITION
Offset of the Cancel button in relation to the widget position.
Definition: Widget.hpp:111
Definition: Angle.hpp:8
bool m_undefined
Definition: Widget.hpp:138
gui_point_t m_position
Definition: Widget.hpp:142
static const cv::Scalar NEGATIVE_COLOR
Color associated with Cancel/reject action.
Definition: Widget.hpp:123
static const gui_point_t OK_POSITION
Offset of the OK button in relation to the widget position.
Definition: Widget.hpp:108
virtual void render(const cv::Mat &)
Display widget in input mode (with OK/Cancel buttons)
virtual void onMouseMove(const gui_point_t &)
The user moved the mouse pointer over the widget.
virtual bool isReadOnly()
Check if Widget is read-only.
Definition: Widget.hpp:80
std::vector< gui_point_t > m_contour
The contours of area occupied by the widget.
Definition: Widget.hpp:131
virtual void onMouseUp(const gui_point_t &)
The user released the left mouse button over the widget.
Base class for all Widgets.
Definition: Widget.hpp:40
static const cv::Scalar FOREGROUND_COLOR
Color used to draw main components of widget.
Definition: Widget.hpp:114
void startDragging()
Signal that the user started dragging the widget.
Definition: Widget.hpp:65
virtual void setPosition(gui_point_t position)
Move the widget to a point in an image.
static const cv::Scalar HIGHLIGHT_COLOR
Color used to draw a few important components of the widget.
Definition: Widget.hpp:117
bool isMouseOverButton(gui_point_t mousePosition, gui_point_t buttonPosition)
Check if the mouse pointer is over a button.