Add mouse event handling

This commit is contained in:
Cameron Gutman 2016-02-13 02:16:45 -05:00
parent b5b6329c9d
commit 4db53bd4ed
3 changed files with 61 additions and 0 deletions

View File

@ -20,6 +20,7 @@ SOURCES = \
$(COMMON_C_SOURCE) \ $(COMMON_C_SOURCE) \
libchelper.c \ libchelper.c \
main.cpp \ main.cpp \
input.cpp \
# Build rules generated by macros from common.mk: # Build rules generated by macros from common.mk:

58
input.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "moonlight.hpp"
#include "ppapi/c/ppb_input_event.h"
#include "ppapi/cpp/input_event.h"
#include <Limelight.h>
static int ConvertPPButtonToLiButton(PP_InputEvent_MouseButton ppButton) {
switch (ppButton) {
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
return BUTTON_LEFT;
case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
return BUTTON_MIDDLE;
case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
return BUTTON_RIGHT;
default:
return 0;
}
}
bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
switch (event.GetType()) {
case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
pp::MouseInputEvent mouseEvent(event);
LiSendMouseButtonEvent(ConvertPPButtonToLiButton(mouseEvent.GetButton()), BUTTON_ACTION_PRESS);
return true;
}
case PP_INPUTEVENT_TYPE_MOUSEMOVE: {
pp::MouseInputEvent mouseEvent(event);
pp::Point posDelta = mouseEvent.GetMovement();
LiSendMouseMoveEvent(posDelta.x(), posDelta.y());
return true;
}
case PP_INPUTEVENT_TYPE_MOUSEUP: {
pp::MouseInputEvent mouseEvent(event);
LiSendMouseButtonEvent(ConvertPPButtonToLiButton(mouseEvent.GetButton()), BUTTON_ACTION_RELEASE);
return true;
}
case PP_INPUTEVENT_TYPE_WHEEL: {
pp::WheelInputEvent wheelEvent(event);
// FIXME: Handle fractional scroll ticks
LiSendScrollEvent((signed char) wheelEvent.GetTicks().y());
return true;
}
default: {
return false;
}
}
}

View File

@ -12,4 +12,6 @@ class MoonlightInstance : public pp::Instance {
} }
virtual ~MoonlightInstance(); virtual ~MoonlightInstance();
bool HandleInputEvent(const pp::InputEvent& event);
}; };