Skip to content

Commit

Permalink
Enable mouse events for Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
mogemimi committed Nov 15, 2016
1 parent f96be39 commit 293450a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Platform.Win32/MouseWin32.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2013-2016 mogemimi. Distributed under the MIT license.

#include "MouseWin32.hpp"
#include "Pomdog/Input/MouseButtons.hpp"
#include "Pomdog/Utility/Assert.hpp"

namespace Pomdog {
Expand Down Expand Up @@ -28,6 +29,7 @@ void MouseWin32::HandleMessage(const RAWMOUSE& mouse)
GetCursorPos(&cursorPos);
ScreenToClient(windowHandle, &cursorPos);
state.Position = Point2D{ cursorPos.x, cursorPos.y };
Mouse::Moved(state.Position);
}
else if (mouse.usFlags & MOUSE_MOVE_ABSOLUTE) {
previousState.Position = state.Position;
Expand All @@ -37,11 +39,13 @@ void MouseWin32::HandleMessage(const RAWMOUSE& mouse)
GetCursorPos(&cursorPos);
ScreenToClient(windowHandle, &cursorPos);
state.Position = Point2D{ cursorPos.x, cursorPos.y };
Mouse::Moved(state.Position);
}

if (mouse.usButtonFlags & RI_MOUSE_WHEEL) {
previousState.ScrollWheel = state.ScrollWheel;
state.ScrollWheel += *(SHORT*)(&mouse.usButtonData);
Mouse::ScrollWheel(state.ScrollWheel - previousState.ScrollWheel);
}

// Not implemented
Expand All @@ -52,46 +56,56 @@ void MouseWin32::HandleMessage(const RAWMOUSE& mouse)
if (mouse.usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) {
previousState.LeftButton = state.LeftButton;
state.LeftButton = ButtonState::Pressed;
Mouse::ButtonDown(MouseButtons::LeftButton);
}
else if (mouse.usButtonFlags & RI_MOUSE_BUTTON_1_UP) {
previousState.LeftButton = state.LeftButton;
state.LeftButton = ButtonState::Released;
Mouse::ButtonUp(MouseButtons::LeftButton);
}

if (mouse.usButtonFlags & RI_MOUSE_BUTTON_2_DOWN) {
previousState.RightButton = state.RightButton;
state.RightButton = ButtonState::Pressed;
Mouse::ButtonDown(MouseButtons::RightButton);
}
else if (mouse.usButtonFlags & RI_MOUSE_BUTTON_2_UP) {
previousState.RightButton = state.RightButton;
state.RightButton = ButtonState::Released;
Mouse::ButtonUp(MouseButtons::RightButton);
}

if (mouse.usButtonFlags & RI_MOUSE_BUTTON_3_DOWN) {
previousState.MiddleButton = state.MiddleButton;
state.MiddleButton = ButtonState::Pressed;
Mouse::ButtonDown(MouseButtons::MiddleButton);
}
else if (mouse.usButtonFlags & RI_MOUSE_BUTTON_3_UP) {
previousState.MiddleButton = state.MiddleButton;
state.MiddleButton = ButtonState::Released;
Mouse::ButtonUp(MouseButtons::MiddleButton);
}

if (mouse.usButtonFlags & RI_MOUSE_BUTTON_4_DOWN) {
previousState.XButton1 = state.XButton1;
state.XButton1 = ButtonState::Pressed;
Mouse::ButtonDown(MouseButtons::XButton1);
}
else if (mouse.usButtonFlags & RI_MOUSE_BUTTON_4_UP) {
previousState.XButton1 = state.XButton1;
state.XButton1 = ButtonState::Released;
Mouse::ButtonUp(MouseButtons::XButton1);
}

if (mouse.usButtonFlags & RI_MOUSE_BUTTON_5_DOWN) {
previousState.XButton2 = state.XButton2;
state.XButton2 = ButtonState::Pressed;
Mouse::ButtonDown(MouseButtons::XButton2);
}
else if (mouse.usButtonFlags & RI_MOUSE_BUTTON_5_UP) {
previousState.XButton2 = state.XButton2;
state.XButton2 = ButtonState::Released;
Mouse::ButtonUp(MouseButtons::XButton2);
}
}

Expand Down

0 comments on commit 293450a

Please sign in to comment.