appkit  1.5.1
RoadNarrows Robotics Application Kit
WinCvMouse.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Link: https://github.com/roadnarrows-robotics/rnr-sdk
6 //
7 // Library: librnr_win
8 //
9 // File: WinCvMouse.h
10 //
11 /*! \file
12  *
13  * $LastChangedDate: 2013-05-08 08:22:06 -0600 (Wed, 08 May 2013) $
14  * $Rev: 2920 $
15  *
16  * \brief RoadNarrows Robotics base OpenCV Mouse class interface.
17  *
18  * \author Robin Knight (robin.knight@roadnarrows.com)
19  * \author Daniel Packard (daniel@roadnarrows.com)
20  *
21  * \par Copyright
22  * \h_copy 2011-2017. RoadNarrows LLC.\n
23  * http://www.roadnarrows.com\n
24  * All Rights Reserved
25  */
26 /*
27  * @EulaBegin@
28  *
29  * Permission is hereby granted, without written agreement and without
30  * license or royalty fees, to use, copy, modify, and distribute this
31  * software and its documentation for any purpose, provided that
32  * (1) The above copyright notice and the following two paragraphs
33  * appear in all copies of the source code and (2) redistributions
34  * including binaries reproduces these notices in the supporting
35  * documentation. Substantial modifications to this software may be
36  * copyrighted by their authors and need not follow the licensing terms
37  * described here, provided that the new terms are clearly indicated in
38  * all files where they apply.
39  *
40  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
41  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
42  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
43  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
44  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
45  * THE POSSIBILITY OF SUCH DAMAGE.
46  *
47  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
48  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
49  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
50  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
51  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
52  *
53  * @EulaEnd@
54  */
55 ////////////////////////////////////////////////////////////////////////////////
56 
57 #ifndef _RNR_WIN_CV_MOUSE_H
58 #define _RNR_WIN_CV_MOUSE_H
59 
60 #include "rnr/rnrconfig.h"
61 
62 #include "opencv2/core/core.hpp"
63 
64 #include "rnr/appkit/Win.h"
65 
66 /*!
67  * \brief RoadNarrows Robotics
68  */
69 namespace rnr
70 {
71  //...........................................................................
72  // Class WinCvMouse
73  //...........................................................................
74 
75  /*!
76  * \brief Window OpenCV Mouse base class.
77  *
78  * This class supports mouse operations on an OpenCV widget region of the
79  * window.
80  */
81  class WinCvMouse
82  {
83  public:
84  /*!
85  * \brief Default contructor.
86  */
87  WinCvMouse();
88 
89  /*!
90  * \brief Destructor.
91  */
92  virtual ~WinCvMouse();
93 
94  /*!
95  * \brief Bind the mouse to the given window.
96  *
97  * Any previously bound mouse instance is unbound. This mouse state is
98  * reset.
99  *
100  * \param pWin Pointer to binding window.
101  */
102  void bind(Win *pWin);
103 
104  /*!
105  * \brief Unbind the mouse instance from the currently bound window.
106  */
107  void unbind();
108 
109  /*!
110  * \brief Get the current mouse event.
111  *
112  * \return Current event.
113  */
115  {
116  return m_nCurrentEvent;
117  }
118 
119  /*!
120  * \brief Set the current mouse event.
121  *
122  * \param nEvent Event unique identifier.
123  */
124  void setCurrentEvent(int nEvent)
125  {
126  m_nCurrentEvent = nEvent;
127  }
128 
129  /*!
130  * \brief Enable mouse drag operations.
131  */
133  {
134  m_bDrag = true;
135  m_bDragState = false;
136  }
137 
138  /*!
139  * \brief Disable mouse drag operations.
140  */
142  {
143  m_bDrag = false;
144  m_bDragState = false;
145  }
146 
147  /*!
148  * \brief Get the most recently recorded mouse position.
149  *
150  * \return Mouse point in screen coordinates.
151  */
152  CvPoint getMousePoint()
153  {
154  return m_ptMouse;
155  }
156 
157  protected:
158  Win *m_pWin; ///< mouse actions are bound to this windo
159  int m_nCurrentEvent; ///< current (user) menu event
160  CvPoint m_ptMouse; ///< mouse point
161  bool m_bDrag; ///< enable mouse drag operation
162  bool m_bDragState; ///< [not] within drag operation
163 
164  /*!
165  * \brief Mouse event callback handler.
166  *
167  * \param event Mouse event.
168  * \param x Window mouse x coordinate.
169  * A value of -1 indicates out-of-region event.
170  * \param y Window mouse y coordinate.
171  * A value of -1 indicates out-of-region event.
172  * \param flags Extra flags
173  * \param param Application specific parameter (this).
174  */
175  static void onMouse(int event, int x, int y, int flags, void *param);
176  };
177 
178 } // namespace
179 
180 
181 #endif // _RNR_WIN_CV_MOUSE_H
void bind(Win *pWin)
Bind the mouse to the given window.
Definition: WinCvMouse.cxx:103
Win * m_pWin
mouse actions are bound to this windo
Definition: WinCvMouse.h:158
virtual ~WinCvMouse()
Destructor.
Definition: WinCvMouse.cxx:95
void unbind()
Unbind the mouse instance from the currently bound window.
Definition: WinCvMouse.cxx:119
void disableMouseDrag()
Disable mouse drag operations.
Definition: WinCvMouse.h:141
WinCvMouse()
Default contructor.
Definition: WinCvMouse.cxx:86
void enableMouseDrag()
Enable mouse drag operations.
Definition: WinCvMouse.h:132
bool m_bDrag
enable mouse drag operation
Definition: WinCvMouse.h:161
RoadNarrows Robotics Win abstract base class interface.
CvPoint getMousePoint()
Get the most recently recorded mouse position.
Definition: WinCvMouse.h:152
CvPoint m_ptMouse
mouse point
Definition: WinCvMouse.h:160
int m_nCurrentEvent
current (user) menu event
Definition: WinCvMouse.h:159
int getCurrentEvent()
Get the current mouse event.
Definition: WinCvMouse.h:114
RNR Win window abstract base class.
Definition: Win.h:211
bool m_bDragState
[not] within drag operation
Definition: WinCvMouse.h:162
Window OpenCV Mouse base class.
Definition: WinCvMouse.h:81
void setCurrentEvent(int nEvent)
Set the current mouse event.
Definition: WinCvMouse.h:124
RoadNarrows Robotics.
Definition: Camera.h:74
static void onMouse(int event, int x, int y, int flags, void *param)
Mouse event callback handler.
Definition: WinCvMouse.cxx:129