Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
WinRT: made mouse button events include the correct button type (left…
…, right, middle, x1, or x2)
  • Loading branch information
DavidLudwig committed Feb 10, 2013
1 parent 893f11d commit 6c6bc7f
Showing 1 changed file with 97 additions and 6 deletions.
103 changes: 97 additions & 6 deletions src/video/windowsrt/SDL_WinRTApp.cpp
Expand Up @@ -14,6 +14,7 @@ extern "C" {
#include "SDL_log.h"
}

#include <string>
#include <unordered_map>

// TODO, WinRT: Remove reference(s) to BasicTimer.h
Expand All @@ -34,11 +35,13 @@ static SDL_WinRT_MainFunction SDL_WinRT_main = nullptr;
// SDL_CreateWindow().
SDL_WinRTApp ^ SDL_WinRTGlobalApp = nullptr;

using namespace std;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Devices::Input;
using namespace Windows::UI::Core;
using namespace Windows::UI::Input;
using namespace Windows::System;
using namespace Windows::Foundation;
using namespace Windows::Graphics::Display;
Expand Down Expand Up @@ -174,19 +177,107 @@ void SDL_WinRTApp::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
m_windowClosed = true;
}

void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
static Uint8
WINRT_GetSDLButtonForPointerPoint(PointerPoint ^ pt)
{
if (m_sdlWindowData)
switch (pt->Properties->PointerUpdateKind)
{
SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, SDL_BUTTON_LEFT);
case PointerUpdateKind::LeftButtonPressed:
case PointerUpdateKind::LeftButtonReleased:
return SDL_BUTTON_LEFT;

case PointerUpdateKind::RightButtonPressed:
case PointerUpdateKind::RightButtonReleased:
return SDL_BUTTON_RIGHT;

case PointerUpdateKind::MiddleButtonPressed:
case PointerUpdateKind::MiddleButtonReleased:
return SDL_BUTTON_MIDDLE;

case PointerUpdateKind::XButton1Pressed:
case PointerUpdateKind::XButton1Released:
return SDL_BUTTON_X1;

case PointerUpdateKind::XButton2Pressed:
case PointerUpdateKind::XButton2Released:
return SDL_BUTTON_X2;

default:
break;
}

return 0;
}

void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
static const char *
WINRT_ConvertPointerUpdateKindToString(PointerUpdateKind kind)
{
if (m_sdlWindowData)
switch (kind)
{
SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, SDL_BUTTON_LEFT);
case PointerUpdateKind::Other:
return "Other";
case PointerUpdateKind::LeftButtonPressed:
return "LeftButtonPressed";
case PointerUpdateKind::LeftButtonReleased:
return "LeftButtonReleased";
case PointerUpdateKind::RightButtonPressed:
return "RightButtonPressed";
case PointerUpdateKind::RightButtonReleased:
return "RightButtonReleased";
case PointerUpdateKind::MiddleButtonPressed:
return "MiddleButtonPressed";
case PointerUpdateKind::MiddleButtonReleased:
return "MiddleButtonReleased";
case PointerUpdateKind::XButton1Pressed:
return "XButton1Pressed";
case PointerUpdateKind::XButton1Released:
return "XButton1Released";
case PointerUpdateKind::XButton2Pressed:
return "XButton2Pressed";
case PointerUpdateKind::XButton2Released:
return "XButton2Released";
}

return "";
}

static void
WINRT_LogPointerEvent(const string & header, PointerEventArgs ^ args)
{
PointerPoint ^ pt = args->CurrentPoint;
SDL_Log("%s: Position={%f,%f}, FrameId=%d, PointerId=%d, PointerUpdateKind=%s\n",
header.c_str(),
pt->Position.X, pt->Position.Y,
pt->FrameId,
pt->PointerId,
WINRT_ConvertPointerUpdateKindToString(args->CurrentPoint->Properties->PointerUpdateKind));
}

void SDL_WinRTApp::OnPointerPressed(CoreWindow^ sender, PointerEventArgs^ args)
{
#if 0
WINRT_LogPointerEvent("mouse down", args);
#endif

if (m_sdlWindowData) {
Uint8 button = WINRT_GetSDLButtonForPointerPoint(args->CurrentPoint);
if (button) {
SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_PRESSED, button);
}
}
}

void SDL_WinRTApp::OnPointerReleased(CoreWindow^ sender, PointerEventArgs^ args)
{
#if 0
WINRT_LogPointerEvent("mouse up", args);
#endif

if (m_sdlWindowData) {
Uint8 button = WINRT_GetSDLButtonForPointerPoint(args->CurrentPoint);
if (button) {
SDL_SendMouseButton(m_sdlWindowData->sdlWindow, SDL_RELEASED, button);
}
}
}

Expand Down

0 comments on commit 6c6bc7f

Please sign in to comment.