Merge pull request #2122 from adishavit:feature-HandleMouseWheel
This commit is contained in:
		@@ -208,6 +208,26 @@ Sets mouse handler for the specified window
 | 
			
		||||
    :param userdata: The optional parameter passed to the callback.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
getMouseWheelDelta
 | 
			
		||||
------------------
 | 
			
		||||
Gets the mouse-wheel motion delta, when handling mouse-wheel events EVENT_MOUSEWHEEL and EVENT_MOUSEHWHEEL.
 | 
			
		||||
 | 
			
		||||
.. ocv:function:: int getMouseWheelDelta(int flags)
 | 
			
		||||
 | 
			
		||||
    :param flags: The mouse callback flags parameter.
 | 
			
		||||
 | 
			
		||||
For regular mice with a scroll-wheel, delta will be a multiple of 120. The value 120 corresponds to a one notch rotation of the wheel or the threshold for action to be taken and one such action should occur for each delta.
 | 
			
		||||
Some high-precision mice with higher-resolution freely-rotating wheels may generate smaller values.
 | 
			
		||||
 | 
			
		||||
For EVENT_MOUSEWHEEL positive and negative values mean forward and backward scrolling, respectively.
 | 
			
		||||
For EVENT_MOUSEHWHEEL, where available, positive and negative values mean right and left scrolling, respectively.
 | 
			
		||||
 | 
			
		||||
With the C API, the macro CV_GET_WHEEL_DELTA(flags) can be used alternatively.
 | 
			
		||||
 | 
			
		||||
.. note::
 | 
			
		||||
 | 
			
		||||
    Mouse-wheel events are currently supported only on Windows.
 | 
			
		||||
 | 
			
		||||
setTrackbarPos
 | 
			
		||||
------------------
 | 
			
		||||
Sets the trackbar position.
 | 
			
		||||
 
 | 
			
		||||
@@ -76,7 +76,9 @@ enum { EVENT_MOUSEMOVE      = 0,
 | 
			
		||||
       EVENT_MBUTTONUP      = 6,
 | 
			
		||||
       EVENT_LBUTTONDBLCLK  = 7,
 | 
			
		||||
       EVENT_RBUTTONDBLCLK  = 8,
 | 
			
		||||
       EVENT_MBUTTONDBLCLK  = 9
 | 
			
		||||
       EVENT_MBUTTONDBLCLK  = 9,
 | 
			
		||||
       EVENT_MOUSEWHEEL     = 10,
 | 
			
		||||
       EVENT_MOUSEHWHEEL    = 11
 | 
			
		||||
     };
 | 
			
		||||
 | 
			
		||||
enum { EVENT_FLAG_LBUTTON   = 1,
 | 
			
		||||
@@ -137,6 +139,8 @@ CV_EXPORTS_W double getWindowProperty(const String& winname, int prop_id);
 | 
			
		||||
//! assigns callback for mouse events
 | 
			
		||||
CV_EXPORTS void setMouseCallback(const String& winname, MouseCallback onMouse, void* userdata = 0);
 | 
			
		||||
 | 
			
		||||
CV_EXPORTS int getMouseWheelDelta(int flags);
 | 
			
		||||
 | 
			
		||||
CV_EXPORTS int createTrackbar(const String& trackbarname, const String& winname,
 | 
			
		||||
                              int* value, int count,
 | 
			
		||||
                              TrackbarCallback onChange = 0,
 | 
			
		||||
 
 | 
			
		||||
@@ -170,7 +170,9 @@ enum
 | 
			
		||||
    CV_EVENT_MBUTTONUP      =6,
 | 
			
		||||
    CV_EVENT_LBUTTONDBLCLK  =7,
 | 
			
		||||
    CV_EVENT_RBUTTONDBLCLK  =8,
 | 
			
		||||
    CV_EVENT_MBUTTONDBLCLK  =9
 | 
			
		||||
    CV_EVENT_MBUTTONDBLCLK  =9,
 | 
			
		||||
    CV_EVENT_MOUSEWHEEL     =10,
 | 
			
		||||
    CV_EVENT_MOUSEHWHEEL    =11
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
@@ -183,6 +185,9 @@ enum
 | 
			
		||||
    CV_EVENT_FLAG_ALTKEY    =32
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define CV_GET_WHEEL_DELTA(flags) ((short)((flags >> 16) & 0xffff)) // upper 16 bits
 | 
			
		||||
 | 
			
		||||
typedef void (CV_CDECL *CvMouseCallback )(int event, int x, int y, int flags, void* param);
 | 
			
		||||
 | 
			
		||||
/* assign callback for mouse events */
 | 
			
		||||
 
 | 
			
		||||
@@ -216,6 +216,11 @@ void cv::setMouseCallback( const String& windowName, MouseCallback onMouse, void
 | 
			
		||||
    cvSetMouseCallback(windowName.c_str(), onMouse, param);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int cv::getMouseWheelDelta( int flags )
 | 
			
		||||
{
 | 
			
		||||
    return CV_GET_WHEEL_DELTA(flags);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int cv::startWindowThread()
 | 
			
		||||
{
 | 
			
		||||
    return cvStartWindowThread();
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,7 @@
 | 
			
		||||
//M*/
 | 
			
		||||
 | 
			
		||||
#include "precomp.hpp"
 | 
			
		||||
#include <windowsx.h> // required for GET_X_LPARAM() and GET_Y_LPARAM() macros
 | 
			
		||||
 | 
			
		||||
#if defined WIN32 || defined _WIN32
 | 
			
		||||
 | 
			
		||||
@@ -1377,6 +1378,39 @@ MainWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
 | 
			
		||||
            SetFocus(window->hwnd);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case WM_MOUSEWHEEL:
 | 
			
		||||
    case WM_MOUSEHWHEEL:
 | 
			
		||||
       if( window->on_mouse )
 | 
			
		||||
       {
 | 
			
		||||
          int flags = (wParam & MK_LBUTTON      ? CV_EVENT_FLAG_LBUTTON  : 0)|
 | 
			
		||||
                      (wParam & MK_RBUTTON      ? CV_EVENT_FLAG_RBUTTON  : 0)|
 | 
			
		||||
                      (wParam & MK_MBUTTON      ? CV_EVENT_FLAG_MBUTTON  : 0)|
 | 
			
		||||
                      (wParam & MK_CONTROL      ? CV_EVENT_FLAG_CTRLKEY  : 0)|
 | 
			
		||||
                      (wParam & MK_SHIFT        ? CV_EVENT_FLAG_SHIFTKEY : 0)|
 | 
			
		||||
                      (GetKeyState(VK_MENU) < 0 ? CV_EVENT_FLAG_ALTKEY   : 0);
 | 
			
		||||
          int event = (uMsg == WM_MOUSEWHEEL    ? CV_EVENT_MOUSEWHEEL    : CV_EVENT_MOUSEHWHEEL);
 | 
			
		||||
 | 
			
		||||
          // Set the wheel delta of mouse wheel to be in the upper word of 'event'
 | 
			
		||||
          int delta = GET_WHEEL_DELTA_WPARAM(wParam);
 | 
			
		||||
          flags |= (delta << 16);
 | 
			
		||||
 | 
			
		||||
          POINT pt;
 | 
			
		||||
          pt.x = GET_X_LPARAM( lParam );
 | 
			
		||||
          pt.y = GET_Y_LPARAM( lParam );
 | 
			
		||||
          ::ScreenToClient(hwnd, &pt); // Convert screen coordinates to client coordinates.
 | 
			
		||||
 | 
			
		||||
          RECT rect;
 | 
			
		||||
          GetClientRect( window->hwnd, &rect );
 | 
			
		||||
 | 
			
		||||
          SIZE size = {0,0};
 | 
			
		||||
          icvGetBitmapData( window, &size, 0, 0 );
 | 
			
		||||
 | 
			
		||||
          window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1),
 | 
			
		||||
                                   pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags,
 | 
			
		||||
                                   window->on_mouse_param );
 | 
			
		||||
       }
 | 
			
		||||
       break;
 | 
			
		||||
 | 
			
		||||
    case WM_ERASEBKGND:
 | 
			
		||||
        {
 | 
			
		||||
            RECT cr, tr, wrc;
 | 
			
		||||
@@ -1474,8 +1508,8 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
 | 
			
		||||
            if( uMsg == WM_LBUTTONUP || uMsg == WM_RBUTTONUP || uMsg == WM_MBUTTONUP )
 | 
			
		||||
                ReleaseCapture();
 | 
			
		||||
 | 
			
		||||
            pt.x = LOWORD( lParam );
 | 
			
		||||
            pt.y = HIWORD( lParam );
 | 
			
		||||
            pt.x = GET_X_LPARAM( lParam );
 | 
			
		||||
            pt.y = GET_Y_LPARAM( lParam );
 | 
			
		||||
 | 
			
		||||
            GetClientRect( window->hwnd, &rect );
 | 
			
		||||
            icvGetBitmapData( window, &size, 0, 0 );
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user