Refactor MSW gesture events initialization
Don't repeat the same code for initializing events in several different functions but put it in a helper InitGestureEvent() function and just call it from the event-specific handlers.
This commit is contained in:
@@ -360,6 +360,10 @@ public:
|
|||||||
bool HandleMouseWheel(wxMouseWheelAxis axis,
|
bool HandleMouseWheel(wxMouseWheelAxis axis,
|
||||||
WXWPARAM wParam, WXLPARAM lParam);
|
WXWPARAM wParam, WXLPARAM lParam);
|
||||||
|
|
||||||
|
// 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 HandlePanGesture(int x, int y, WXDWORD flags);
|
bool HandlePanGesture(int x, int y, WXDWORD flags);
|
||||||
bool HandleZoomGesture(int x, int y, WXDWORD fingerDistance, WXDWORD flags);
|
bool HandleZoomGesture(int x, int y, WXDWORD fingerDistance, WXDWORD flags);
|
||||||
bool HandleRotateGesture(int x, int y, WXDWORD angleArgument, WXDWORD flags);
|
bool HandleRotateGesture(int x, int y, WXDWORD angleArgument, WXDWORD flags);
|
||||||
|
@@ -5647,6 +5647,23 @@ void wxWindowMSW::GenerateMouseLeave()
|
|||||||
// Gesture events
|
// Gesture events
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool wxWindowMSW::InitGestureEvent(wxGestureEvent& event,
|
||||||
|
int x, int y,
|
||||||
|
WXDWORD flags)
|
||||||
|
{
|
||||||
|
event.SetEventObject(this);
|
||||||
|
event.SetTimestamp(::GetMessageTime());
|
||||||
|
event.SetPosition(wxPoint(x, y));
|
||||||
|
|
||||||
|
if ( flags & GF_BEGIN )
|
||||||
|
event.SetGestureStart();
|
||||||
|
|
||||||
|
if ( flags & GF_END )
|
||||||
|
event.SetGestureEnd();
|
||||||
|
|
||||||
|
return (flags & GF_BEGIN) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool wxWindowMSW::HandlePanGesture(int x, int y, WXDWORD flags)
|
bool wxWindowMSW::HandlePanGesture(int x, int y, WXDWORD flags)
|
||||||
{
|
{
|
||||||
// wxEVT_GESTURE_PAN
|
// wxEVT_GESTURE_PAN
|
||||||
@@ -5655,26 +5672,17 @@ bool wxWindowMSW::HandlePanGesture(int x, int y, WXDWORD flags)
|
|||||||
// These are used to calculate the pan delta
|
// These are used to calculate the pan delta
|
||||||
static int s_previousLocationX, s_previousLocationY;
|
static int s_previousLocationX, s_previousLocationY;
|
||||||
|
|
||||||
// This flag indicates that the gesture has just started
|
// If the gesture has just started, store the current point to determine
|
||||||
// Store the current point to determine the pan delta later on
|
// the pan delta later on.
|
||||||
if ( flags & GF_BEGIN )
|
if ( InitGestureEvent(event, x, y, flags) )
|
||||||
{
|
{
|
||||||
s_previousLocationX = x;
|
s_previousLocationX = x;
|
||||||
s_previousLocationY = y;
|
s_previousLocationY = y;
|
||||||
event.SetGestureStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( flags & GF_END )
|
|
||||||
{
|
|
||||||
event.SetGestureEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the horizontal and vertical changes
|
// Determine the horizontal and vertical changes
|
||||||
int DeltaX = x - s_previousLocationX, DeltaY = y - s_previousLocationY;
|
int DeltaX = x - s_previousLocationX, DeltaY = y - s_previousLocationY;
|
||||||
|
|
||||||
event.SetEventObject(this);
|
|
||||||
event.SetTimestamp(::GetMessageTime());
|
|
||||||
event.SetPosition(wxPoint(x, y));
|
|
||||||
event.SetDeltaX(DeltaX);
|
event.SetDeltaX(DeltaX);
|
||||||
event.SetDeltaY(DeltaY);
|
event.SetDeltaY(DeltaY);
|
||||||
|
|
||||||
@@ -5697,17 +5705,11 @@ bool wxWindowMSW::HandleZoomGesture(int x, int y,
|
|||||||
|
|
||||||
// This flag indicates that the gesture has just started, store the current
|
// This flag indicates that the gesture has just started, store the current
|
||||||
// point and distance between the fingers for future calculations.
|
// point and distance between the fingers for future calculations.
|
||||||
if ( flags & GF_BEGIN )
|
if ( InitGestureEvent(event, x, y, flags) )
|
||||||
{
|
{
|
||||||
s_previousLocationX = x;
|
s_previousLocationX = x;
|
||||||
s_previousLocationY = y;
|
s_previousLocationY = y;
|
||||||
s_intialFingerDistance = fingerDistance;
|
s_intialFingerDistance = fingerDistance;
|
||||||
event.SetGestureStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( flags & GF_END )
|
|
||||||
{
|
|
||||||
event.SetGestureEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate center point of the zoom. Human beings are not very good at
|
// Calculate center point of the zoom. Human beings are not very good at
|
||||||
@@ -5722,8 +5724,6 @@ bool wxWindowMSW::HandleZoomGesture(int x, int y,
|
|||||||
const double zoomFactor = (double) fingerDistance / s_intialFingerDistance;
|
const double zoomFactor = (double) fingerDistance / s_intialFingerDistance;
|
||||||
|
|
||||||
event.SetZoomFactor(zoomFactor);
|
event.SetZoomFactor(zoomFactor);
|
||||||
event.SetEventObject(this);
|
|
||||||
event.SetTimestamp(::GetMessageTime());
|
|
||||||
|
|
||||||
// This is not a gesture point but the center of a zoom
|
// This is not a gesture point but the center of a zoom
|
||||||
event.SetPosition(pt);
|
event.SetPosition(pt);
|
||||||
@@ -5742,13 +5742,7 @@ bool wxWindowMSW::HandleRotateGesture(int x, int y,
|
|||||||
// wxEVT_GESTURE_ROTATE
|
// wxEVT_GESTURE_ROTATE
|
||||||
wxRotateGestureEvent event(GetId());
|
wxRotateGestureEvent event(GetId());
|
||||||
|
|
||||||
// This flag indicates that the gesture has just started
|
if ( !InitGestureEvent(event, x, y, flags) )
|
||||||
if ( flags & GF_BEGIN )
|
|
||||||
{
|
|
||||||
event.SetGestureStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Use angleArgument to obtain the cumulative angle since the gesture
|
// Use angleArgument to obtain the cumulative angle since the gesture
|
||||||
// was first started. This angle is in radians and MSW returns negative
|
// was first started. This angle is in radians and MSW returns negative
|
||||||
@@ -5768,15 +5762,6 @@ bool wxWindowMSW::HandleRotateGesture(int x, int y,
|
|||||||
event.SetRotationAngle(angle);
|
event.SetRotationAngle(angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( flags & GF_END )
|
|
||||||
{
|
|
||||||
event.SetGestureEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
event.SetEventObject(this);
|
|
||||||
event.SetTimestamp(::GetMessageTime());
|
|
||||||
event.SetPosition(wxPoint(x, y));
|
|
||||||
|
|
||||||
return HandleWindowEvent(event);
|
return HandleWindowEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5785,19 +5770,7 @@ bool wxWindowMSW::HandleTwoFingerTap(int x, int y, WXDWORD flags)
|
|||||||
// wxEVT_TWO_FINGER_TAP
|
// wxEVT_TWO_FINGER_TAP
|
||||||
wxTwoFingerTapEvent event(GetId());
|
wxTwoFingerTapEvent event(GetId());
|
||||||
|
|
||||||
if ( flags & GF_BEGIN )
|
InitGestureEvent(event, x, y, flags);
|
||||||
{
|
|
||||||
event.SetGestureStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
event.SetEventObject(this);
|
|
||||||
event.SetTimestamp(::GetMessageTime());
|
|
||||||
event.SetPosition(wxPoint(x, y));
|
|
||||||
|
|
||||||
if ( flags & GF_END )
|
|
||||||
{
|
|
||||||
event.SetGestureEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
return HandleWindowEvent(event);
|
return HandleWindowEvent(event);
|
||||||
}
|
}
|
||||||
@@ -5806,19 +5779,7 @@ bool wxWindowMSW::HandlePressAndTap(int x, int y, WXDWORD flags)
|
|||||||
{
|
{
|
||||||
wxPressAndTapEvent event(GetId());
|
wxPressAndTapEvent event(GetId());
|
||||||
|
|
||||||
if ( flags & GF_BEGIN )
|
InitGestureEvent(event, x, y, flags);
|
||||||
{
|
|
||||||
event.SetGestureStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
event.SetEventObject(this);
|
|
||||||
event.SetTimestamp(::GetMessageTime());
|
|
||||||
event.SetPosition(wxPoint(x, y));
|
|
||||||
|
|
||||||
if ( flags & GF_END )
|
|
||||||
{
|
|
||||||
event.SetGestureEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
return HandleWindowEvent(event);
|
return HandleWindowEvent(event);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user