in SharedContent/cpp/GameContent/MoveLookController.cpp [179:313]
void MoveLookController::OnPointerPressed(
_In_ CoreWindow^ /* sender */,
_In_ PointerEventArgs^ args
)
{
PointerPoint^ point = args->CurrentPoint;
uint32 pointerID = point->PointerId;
Point pointerPosition = point->Position;
PointerPointProperties^ pointProperties = point->Properties;
auto pointerDevice = point->PointerDevice;
auto pointerDeviceType = pointerDevice->PointerDeviceType;
XMFLOAT2 position = XMFLOAT2(pointerPosition.X, pointerPosition.Y);
#ifdef MOVELOOKCONTROLLER_TRACE
DebugTrace(L"%-7s (%d) at (%4.0f, %4.0f)", L"Pressed", pointerID, position.x, position.y);
#endif
switch (m_state)
{
case MoveLookControllerState::WaitForInput:
if (position.x > m_buttonUpperLeft.x &&
position.x < m_buttonLowerRight.x &&
position.y > m_buttonUpperLeft.y &&
position.y < m_buttonLowerRight.y)
{
// Wait until button released before setting variable.
m_buttonPointerID = pointerID;
m_buttonInUse = true;
#ifdef MOVELOOKCONTROLLER_TRACE
DebugTrace(L"\tWaitForInput(%d) - BUTTON in USE", pointerID);
#endif
}
break;
case MoveLookControllerState::Active:
switch (pointerDeviceType)
{
case Windows::Devices::Input::PointerDeviceType::Touch:
if (position.x > m_moveUpperLeft.x &&
position.x < m_moveLowerRight.x &&
position.y > m_moveUpperLeft.y &&
position.y < m_moveLowerRight.y)
{
// This pointer is in the move control.
if (!m_moveInUse)
{
// There is not an active pointer in this control yet.
// Process a DPad touch down event.
m_moveFirstDown = position; // Save location of initial contact.
m_movePointerID = pointerID; // Store the pointer using this control.
m_moveInUse = true;
}
}
else if (position.x > m_fireUpperLeft.x &&
position.x < m_fireLowerRight.x &&
position.y > m_fireUpperLeft.y &&
position.y < m_fireLowerRight.y)
{
// This pointer is in the fire control.
if (!m_fireInUse)
{
m_fireLastPoint = position;
m_firePointerID = pointerID;
m_fireInUse = true;
if (!m_autoFire)
{
m_firePressed = true;
}
}
}
else
{
if (!m_lookInUse)
{
// There is not an active pointer in this control yet.
m_lookLastPoint = position; // Save point for later move.
m_lookPointerID = pointerID; // Store the pointer using this control.
m_lookLastDelta.x = m_lookLastDelta.y = 0; // These are for smoothing.
m_lookInUse = true;
}
}
break;
default:
bool rightButton = pointProperties->IsRightButtonPressed;
bool leftButton = pointProperties->IsLeftButtonPressed;
if (!m_autoFire && (!m_mouseLeftInUse && leftButton))
{
m_firePressed = true;
}
if (!m_mouseInUse)
{
m_mouseInUse = true;
m_mouseLastPoint = position;
m_mousePointerID = pointerID;
m_mouseLeftInUse = leftButton;
m_mouseRightInUse = rightButton;
m_lookLastDelta.x = m_lookLastDelta.y = 0; // These are for smoothing.
}
else
{
#ifdef MOVELOOKCONTROLLER_TRACE
DebugTrace(L"\tWARNING: OnPointerPressed() Mouse aleady in use (%d-%s%s) and new event id: %d %s%s",
m_mousePointerID,
m_mouseLeftInUse ? "L" : "",
m_mouseRightInUse ? "R" : "",
pointerID,
leftButton ? "L" : "",
rightButton ? "R" : ""
);
#endif
}
break;
}
#ifdef MOVELOOKCONTROLLER_TRACE
DebugTrace(
L"\t%s%s%s %s%s%s",
m_moveInUse ? L"Move " : L"",
m_lookInUse ? L"Look " : L"",
m_fireInUse ? L"Fire " : L"",
m_mouseInUse ? L"Mouse:" : L"",
m_mouseLeftInUse ? L"L" : L"-",
m_mouseRightInUse ? L"R" : L"-"
);
#endif
break;
}
#ifdef MOVELOOKCONTROLLER_TRACE
DebugTrace(L"\n");
#endif
return;
}