appkit  1.5.1
RoadNarrows Robotics Application Kit
rnr::WinCvMouse Class Reference

Window OpenCV Mouse base class. More...

#include <WinCvMouse.h>

Public Member Functions

 WinCvMouse ()
 Default contructor.
 
virtual ~WinCvMouse ()
 Destructor.
 
void bind (Win *pWin)
 Bind the mouse to the given window. More...
 
void unbind ()
 Unbind the mouse instance from the currently bound window.
 
int getCurrentEvent ()
 Get the current mouse event. More...
 
void setCurrentEvent (int nEvent)
 Set the current mouse event. More...
 
void enableMouseDrag ()
 Enable mouse drag operations.
 
void disableMouseDrag ()
 Disable mouse drag operations.
 
CvPoint getMousePoint ()
 Get the most recently recorded mouse position. More...
 

Static Protected Member Functions

static void onMouse (int event, int x, int y, int flags, void *param)
 Mouse event callback handler. More...
 

Protected Attributes

Winm_pWin
 mouse actions are bound to this windo
 
int m_nCurrentEvent
 current (user) menu event
 
CvPoint m_ptMouse
 mouse point
 
bool m_bDrag
 enable mouse drag operation
 
bool m_bDragState
 [not] within drag operation
 

Detailed Description

Window OpenCV Mouse base class.

This class supports mouse operations on an OpenCV widget region of the window.

Definition at line 81 of file WinCvMouse.h.

Member Function Documentation

void WinCvMouse::bind ( Win pWin)

Bind the mouse to the given window.

Any previously bound mouse instance is unbound. This mouse state is reset.

Parameters
pWinPointer to binding window.

Definition at line 103 of file WinCvMouse.cxx.

References rnr::nopoint(), and rnr::UIEventNone.

104 {
105  if( m_pWin != NULL )
106  {
107  unbind();
108  }
109 
110  m_pWin = pWin;
112  m_ptMouse = nopoint;
113  m_bDrag = false;
114  m_bDragState = false;
115 
117 }
Win * m_pWin
mouse actions are bound to this windo
Definition: WinCvMouse.h:158
void unbind()
Unbind the mouse instance from the currently bound window.
Definition: WinCvMouse.cxx:119
bool m_bDrag
enable mouse drag operation
Definition: WinCvMouse.h:161
const cv::Point nopoint(-1,-1)
integer 2D "No Point"
no action
Definition: Win.h:115
CvPoint m_ptMouse
mouse point
Definition: WinCvMouse.h:160
int m_nCurrentEvent
current (user) menu event
Definition: WinCvMouse.h:159
bool m_bDragState
[not] within drag operation
Definition: WinCvMouse.h:162
void registerCvImageMouseCallback(MouseCbFunc_T funcCb, void *param, uint_t uImgIndex=0)
Register application mouse event callback.
Definition: Win.h:584
static void onMouse(int event, int x, int y, int flags, void *param)
Mouse event callback handler.
Definition: WinCvMouse.cxx:129
int rnr::WinCvMouse::getCurrentEvent ( )
inline

Get the current mouse event.

Returns
Current event.

Definition at line 114 of file WinCvMouse.h.

References m_nCurrentEvent.

115  {
116  return m_nCurrentEvent;
117  }
int m_nCurrentEvent
current (user) menu event
Definition: WinCvMouse.h:159
CvPoint rnr::WinCvMouse::getMousePoint ( )
inline

Get the most recently recorded mouse position.

Returns
Mouse point in screen coordinates.

Definition at line 152 of file WinCvMouse.h.

References m_ptMouse.

153  {
154  return m_ptMouse;
155  }
CvPoint m_ptMouse
mouse point
Definition: WinCvMouse.h:160
void WinCvMouse::onMouse ( int  event,
int  x,
int  y,
int  flags,
void *  param 
)
staticprotected

Mouse event callback handler.

Parameters
eventMouse event.
xWindow mouse x coordinate. A value of -1 indicates out-of-region event.
yWindow mouse y coordinate. A value of -1 indicates out-of-region event.
flagsExtra flags
paramApplication specific parameter (this).

Definition at line 129 of file WinCvMouse.cxx.

References m_bDrag, m_bDragState, m_nCurrentEvent, m_ptMouse, rnr::UIEventClick, rnr::UIEventDragEnd, rnr::UIEventDragging, rnr::UIEventDragStart, and rnr::UIEventNone.

130 {
131  WinCvMouse *pMouse = (WinCvMouse *)param;
132 
133  pMouse->m_nCurrentEvent = UIEventNone;
134 
135  // drag the mouse events enabled
136  switch( event )
137  {
138  case CV_EVENT_MOUSEMOVE:
139  if( pMouse->m_bDrag && pMouse->m_bDragState )
140  {
141  pMouse->m_ptMouse.x = x;
142  pMouse->m_ptMouse.y = y;
144  }
145  break;
146 
147  case CV_EVENT_LBUTTONUP:
148  if( pMouse->m_bDrag )
149  {
150  pMouse->m_ptMouse.x = x;
151  pMouse->m_ptMouse.y = y;
152  pMouse->m_bDragState = false;
154  }
155  break;
156 
157  case CV_EVENT_LBUTTONDOWN:
158  pMouse->m_ptMouse.x = x;
159  pMouse->m_ptMouse.y = y;
160 
161  if( pMouse->m_bDrag )
162  {
163  pMouse->m_bDragState = true;
165  }
166  else
167  {
168  pMouse->m_nCurrentEvent = UIEventClick;
169  }
170  break;
171 
172  default:
173  break;
174  }
175 }
dragging mouse
Definition: Win.h:118
bool m_bDrag
enable mouse drag operation
Definition: WinCvMouse.h:161
start of mouse drag
Definition: Win.h:117
no action
Definition: Win.h:115
mouse click
Definition: Win.h:116
CvPoint m_ptMouse
mouse point
Definition: WinCvMouse.h:160
int m_nCurrentEvent
current (user) menu event
Definition: WinCvMouse.h:159
bool m_bDragState
[not] within drag operation
Definition: WinCvMouse.h:162
Window OpenCV Mouse base class.
Definition: WinCvMouse.h:81
end of mouse drag
Definition: Win.h:119
void rnr::WinCvMouse::setCurrentEvent ( int  nEvent)
inline

Set the current mouse event.

Parameters
nEventEvent unique identifier.

Definition at line 124 of file WinCvMouse.h.

References m_nCurrentEvent.

125  {
126  m_nCurrentEvent = nEvent;
127  }
int m_nCurrentEvent
current (user) menu event
Definition: WinCvMouse.h:159

The documentation for this class was generated from the following files: