diff --git a/include/wx/event.h b/include/wx/event.h index 70852f9965..c9d95501d8 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -1915,25 +1915,21 @@ public: wxPanGestureEvent(wxWindowID winid = 0) : wxGestureEvent(winid, wxEVT_GESTURE_PAN) { - m_deltaX = 0; - m_deltaY = 0; } - wxPanGestureEvent(const wxPanGestureEvent& event) : wxGestureEvent(event) + wxPanGestureEvent(const wxPanGestureEvent& event) + : wxGestureEvent(event), + m_delta(event.m_delta) { - m_deltaX = event.m_deltaX; - m_deltaY = event.m_deltaY; } - int GetDeltaX() const { return m_deltaX; } - void SetDeltaX(int DeltaX) { m_deltaX = DeltaX; } - int GetDeltaY() const { return m_deltaY; } - void SetDeltaY(int DeltaY) { m_deltaY = DeltaY; } + wxPoint GetDelta() const { return m_delta; } + void SetDelta(const wxPoint& delta) { m_delta = delta; } virtual wxEvent *Clone() const { return new wxPanGestureEvent(*this); } private: - int m_deltaX, m_deltaY; + wxPoint m_delta; wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPanGestureEvent); }; diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 1de7a1359c..7f710a5870 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -362,13 +362,13 @@ public: // Common gesture event initialization, returns true if it is the initial // event (GF_BEGIN set in flags), false otherwise. - bool InitGestureEvent(wxGestureEvent& event, int x, int y, WXDWORD flags); + bool InitGestureEvent(wxGestureEvent& event, const wxPoint& pt, WXDWORD flags); - bool HandlePanGesture(int x, int y, WXDWORD flags); - bool HandleZoomGesture(int x, int y, WXDWORD fingerDistance, WXDWORD flags); - bool HandleRotateGesture(int x, int y, WXDWORD angleArgument, WXDWORD flags); - bool HandleTwoFingerTap(int x, int y, WXDWORD flags); - bool HandlePressAndTap(int x, int y, WXDWORD flags); + bool HandlePanGesture(const wxPoint& pt, WXDWORD flags); + bool HandleZoomGesture(const wxPoint& pt, WXDWORD fingerDistance, WXDWORD flags); + bool HandleRotateGesture(const wxPoint& pt, WXDWORD angleArgument, WXDWORD flags); + bool HandleTwoFingerTap(const wxPoint& pt, WXDWORD flags); + bool HandlePressAndTap(const wxPoint& pt, WXDWORD flags); bool HandleChar(WXWPARAM wParam, WXLPARAM lParam); bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam); diff --git a/interface/wx/event.h b/interface/wx/event.h index 53030db240..13460cf42e 100644 --- a/interface/wx/event.h +++ b/interface/wx/event.h @@ -3726,24 +3726,14 @@ public: wxPanGestureEvent(wxWindowID winid = 0); /** - Returns the horizontal component of the distance covered since the previous Pan event. + Returns the distance covered since the previous panning event. */ - int GetDeltaX() const; + wxPoint GetDelta() const; /** - Returns the vertical component of the distance covered since the previous Pan event. + Sets the distance covered since the previous panning event. */ - int GetDeltaY() const; - - /** - Sets the horizontal component of the distance covered since the previous Pan event. - */ - int SetDeltaX(int DeltaX); - - /** - Sets the vertical component of the distance covered since the previous Pan event. - */ - int SetDeltaY(int DeltaY); + void SetDelta(const wxPoint& delta); }; diff --git a/samples/event/gestures.cpp b/samples/event/gestures.cpp index 6a0425668a..ae32890feb 100644 --- a/samples/event/gestures.cpp +++ b/samples/event/gestures.cpp @@ -86,19 +86,22 @@ void MyGesturePanel::OnPan(wxPanGestureEvent& event) wxLogMessage("Pan gesture started\n"); } - wxLogMessage("Pan gesture performed with deltaX = %d and deltaY = %d, with current position (%d,%d)\n", - event.GetDeltaX(), event.GetDeltaY(), event.GetPosition().x, event.GetPosition().y); + const wxPoint delta = event.GetDelta(); + wxLogMessage("Pan gesture performed with delta = (%d,%d), " + "with current position (%d,%d)", + delta.x, delta.y, + event.GetPosition().x, event.GetPosition().y); - // Transform the distance using the tranpose of the matrix, + // Transform the distance using the transpose of the matrix, // in order to translate the image to match the screen coordinates wxMatrix2D m; m_affineMatrix.Get(&m, NULL); - wxPoint2DDouble delta(m.m_11 * event.GetDeltaX() + m.m_12 * event.GetDeltaY(), - m.m_21 * event.GetDeltaX() + m.m_22 * event.GetDeltaY()); + wxPoint2DDouble deltaD(m.m_11 * delta.x + m.m_12 * delta.y, + m.m_21 * delta.x + m.m_22 * delta.y); // Add it to the total translation - m_translateDistance += delta; + m_translateDistance += deltaD; if ( event.IsGestureEnd() ) { diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 55f2717c7f..c05ccb0651 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -2998,22 +2998,22 @@ pan_gesture_callback(GtkGesture* gesture, GtkPanDirection direction, gdouble off { case GTK_PAN_DIRECTION_UP: data->m_allowedGestures |= vertical_pan; - event.SetDeltaY(-delta); + event.SetDelta(wxPoint(0, -delta)); break; case GTK_PAN_DIRECTION_DOWN: data->m_allowedGestures |= vertical_pan; - event.SetDeltaY(delta); + event.SetDelta(wxPoint(0, delta)); break; case GTK_PAN_DIRECTION_RIGHT: data->m_allowedGestures |= horizontal_pan; - event.SetDeltaX(delta); + event.SetDelta(wxPoint(delta, 0)); break; case GTK_PAN_DIRECTION_LEFT: data->m_allowedGestures |= horizontal_pan; - event.SetDeltaX(-delta); + event.SetDelta(wxPoint(-delta, 0)); break; } diff --git a/src/msw/window.cpp b/src/msw/window.cpp index bbf245837f..9fb00bffeb 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3220,47 +3220,49 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result, wxLogDebug("This is Not the window targeted by this gesture!"); } - int x = gestureInfo.ptsLocation.x; - int y = gestureInfo.ptsLocation.y; - ScreenToClient(&x, &y); + const wxPoint pt = ScreenToClient + ( + wxPoint(gestureInfo.ptsLocation.x, + gestureInfo.ptsLocation.y) + ); // dwID field is used to determine the type of gesture switch ( gestureInfo.dwID ) { case GID_PAN: - // (x,y) is the current position of the pan - processed = HandlePanGesture(x, y, gestureInfo.dwFlags); + // Point contains the current position of the pan. + processed = HandlePanGesture(pt, gestureInfo.dwFlags); break; case GID_ZOOM: - // (x,y) is the mid-point of 2 fingers and ullArgument + // Point is the mid-point of 2 fingers and ullArgument // contains the distance between the fingers in its lower // half processed = HandleZoomGesture ( - x, y, + pt, static_cast(gestureInfo.ullArguments), gestureInfo.dwFlags ); break; case GID_ROTATE: - // (x,y) is the center point of rotation and ullArguments + // Point is the center point of rotation and ullArguments // contains the angle of rotation processed = HandleRotateGesture ( - x, y, + pt, static_cast(gestureInfo.ullArguments), gestureInfo.dwFlags ); break; case GID_TWOFINGERTAP: - processed = HandleTwoFingerTap(x, y, gestureInfo.dwFlags); + processed = HandleTwoFingerTap(pt, gestureInfo.dwFlags); break; case GID_PRESSANDTAP: - processed = HandlePressAndTap(x, y, gestureInfo.dwFlags); + processed = HandlePressAndTap(pt, gestureInfo.dwFlags); break; } @@ -5648,12 +5650,12 @@ void wxWindowMSW::GenerateMouseLeave() // --------------------------------------------------------------------------- bool wxWindowMSW::InitGestureEvent(wxGestureEvent& event, - int x, int y, + const wxPoint& pt, WXDWORD flags) { event.SetEventObject(this); event.SetTimestamp(::GetMessageTime()); - event.SetPosition(wxPoint(x, y)); + event.SetPosition(pt); if ( flags & GF_BEGIN ) event.SetGestureStart(); @@ -5664,36 +5666,31 @@ bool wxWindowMSW::InitGestureEvent(wxGestureEvent& event, return (flags & GF_BEGIN) != 0; } -bool wxWindowMSW::HandlePanGesture(int x, int y, WXDWORD flags) +bool wxWindowMSW::HandlePanGesture(const wxPoint& pt, WXDWORD flags) { // wxEVT_GESTURE_PAN wxPanGestureEvent event(GetId()); - // These are used to calculate the pan delta - static int s_previousLocationX, s_previousLocationY; + // This is used to calculate the pan delta. + static wxPoint s_previousLocation; // If the gesture has just started, store the current point to determine // the pan delta later on. - if ( InitGestureEvent(event, x, y, flags) ) + if ( InitGestureEvent(event, pt, flags) ) { - s_previousLocationX = x; - s_previousLocationY = y; + s_previousLocation = pt; } // Determine the horizontal and vertical changes - int DeltaX = x - s_previousLocationX, DeltaY = y - s_previousLocationY; - - event.SetDeltaX(DeltaX); - event.SetDeltaY(DeltaY); + event.SetDelta(pt - s_previousLocation); // Update the last gesture event point - s_previousLocationX = x; - s_previousLocationY = y; + s_previousLocation = pt; return HandleWindowEvent(event); } -bool wxWindowMSW::HandleZoomGesture(int x, int y, +bool wxWindowMSW::HandleZoomGesture(const wxPoint& pt, WXDWORD fingerDistance, WXDWORD flags) { @@ -5701,14 +5698,14 @@ bool wxWindowMSW::HandleZoomGesture(int x, int y, wxZoomGestureEvent event(GetId()); // These are used to calculate the center of the zoom and zoom factor - static int s_previousLocationX, s_previousLocationY, s_intialFingerDistance; + static wxPoint s_previousLocation; + static int s_intialFingerDistance; // This flag indicates that the gesture has just started, store the current // point and distance between the fingers for future calculations. - if ( InitGestureEvent(event, x, y, flags) ) + if ( InitGestureEvent(event, pt, flags) ) { - s_previousLocationX = x; - s_previousLocationY = y; + s_previousLocation = pt; s_intialFingerDistance = fingerDistance; } @@ -5717,32 +5714,28 @@ bool wxWindowMSW::HandleZoomGesture(int x, int y, // is usually some error, which can cause the center to shift slightly. So, // it is recommended to take the average of center of fingers in the // current and last positions. - wxPoint pt; - pt.x = (s_previousLocationX + x) / 2; - pt.y = (s_previousLocationY + y) / 2; + const wxPoint ptCenter = (s_previousLocation + pt)/2; const double zoomFactor = (double) fingerDistance / s_intialFingerDistance; event.SetZoomFactor(zoomFactor); - // This is not a gesture point but the center of a zoom - event.SetPosition(pt); + event.SetPosition(ptCenter); // Update gesture event point - s_previousLocationX = x; - s_previousLocationY = y; + s_previousLocation = pt; return HandleWindowEvent(event); } -bool wxWindowMSW::HandleRotateGesture(int x, int y, +bool wxWindowMSW::HandleRotateGesture(const wxPoint& pt, WXDWORD angleArgument, WXDWORD flags) { // wxEVT_GESTURE_ROTATE wxRotateGestureEvent event(GetId()); - if ( InitGestureEvent(event, x, y, flags) ) + if ( InitGestureEvent(event, pt, flags) ) { event.SetRotationAngle(angleArgument); } @@ -5769,21 +5762,21 @@ bool wxWindowMSW::HandleRotateGesture(int x, int y, return HandleWindowEvent(event); } -bool wxWindowMSW::HandleTwoFingerTap(int x, int y, WXDWORD flags) +bool wxWindowMSW::HandleTwoFingerTap(const wxPoint& pt, WXDWORD flags) { // wxEVT_TWO_FINGER_TAP wxTwoFingerTapEvent event(GetId()); - InitGestureEvent(event, x, y, flags); + InitGestureEvent(event, pt, flags); return HandleWindowEvent(event); } -bool wxWindowMSW::HandlePressAndTap(int x, int y, WXDWORD flags) +bool wxWindowMSW::HandlePressAndTap(const wxPoint& pt, WXDWORD flags) { wxPressAndTapEvent event(GetId()); - InitGestureEvent(event, x, y, flags); + InitGestureEvent(event, pt, flags); return HandleWindowEvent(event); } diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 16f44d1eec..8901482c27 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -1525,13 +1525,12 @@ void wxWidgetCocoaImpl::PanGestureEvent(NSPanGestureRecognizer* panGestureRecogn nspoint = [panGestureRecognizer translationInView:m_osxView]; pt = wxFromNSPoint(m_osxView, nspoint); - static int s_lastLocationX = 0, s_lastLocationY = 0; + static wxPoint s_lastLocation; if ( gestureState == NSGestureRecognizerStateBegan ) { wxevent.SetGestureStart(); - s_lastLocationX = 0; - s_lastLocationY = 0; + s_lastLocation = wxPoint(0, 0); } if ( gestureState == NSGestureRecognizerStateEnded ) @@ -1539,12 +1538,10 @@ void wxWidgetCocoaImpl::PanGestureEvent(NSPanGestureRecognizer* panGestureRecogn wxevent.SetGestureEnd(); } - // Set the offsets - wxevent.SetDeltaX(pt.x - s_lastLocationX); - wxevent.SetDeltaY(pt.y - s_lastLocationY); + // Set the offset + wxevent.SetDelta(pt - s_lastLocation); - s_lastLocationX = pt.x; - s_lastLocationY = pt.y; + s_lastLocation = pt; GetWXPeer()->HandleWindowEvent(wxevent); }