sdl: hide mouse in fullscreen. fix & refactor mouse devices
support rawinput mouse wheel simplify mapping load
This commit is contained in:
parent
e07977eea9
commit
5f5d31730c
|
@ -152,7 +152,7 @@ void MapleConfigMap::GetAbsCoordinates(int& x, int& y)
|
|||
y = mo_y_abs[playerNum()];
|
||||
}
|
||||
|
||||
void MapleConfigMap::GetMouseInput(u32& buttons, int& x, int& y, int& wheel)
|
||||
void MapleConfigMap::GetMouseInput(u8& buttons, int& x, int& y, int& wheel)
|
||||
{
|
||||
int playerNum = this->playerNum();
|
||||
buttons = mo_buttons[playerNum];
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
void SetVibration(float power, float inclination, u32 duration_ms);
|
||||
void GetInput(PlainJoystickState* pjs);
|
||||
void GetAbsCoordinates(int& x, int& y);
|
||||
void GetMouseInput(u32& buttons, int& x, int& y, int& wheel);
|
||||
void GetMouseInput(u8& buttons, int& x, int& y, int& wheel);
|
||||
void SetImage(u8 *img);
|
||||
|
||||
private:
|
||||
|
|
|
@ -1107,7 +1107,7 @@ struct maple_keyboard : maple_base
|
|||
// bit 1: Right button (B)
|
||||
// bit 2: Left button (A)
|
||||
// bit 3: Wheel button
|
||||
u32 mo_buttons[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
|
||||
u8 mo_buttons[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
// Relative mouse coordinates [-512:511]
|
||||
f32 mo_x_delta[4];
|
||||
f32 mo_y_delta[4];
|
||||
|
@ -1171,14 +1171,19 @@ struct maple_mouse : maple_base
|
|||
|
||||
case MDCF_GetCondition:
|
||||
{
|
||||
u32 buttons;
|
||||
u8 buttons;
|
||||
int x, y, wheel;
|
||||
config->GetMouseInput(buttons, x, y, wheel);
|
||||
|
||||
w32(MFID_9_Mouse);
|
||||
//struct data
|
||||
//int32 buttons ; digital buttons bitfield (little endian)
|
||||
w32(buttons);
|
||||
// buttons (RLDUSABC, where A is left btn, B is right, and S is middle/scrollwheel)
|
||||
w8(buttons);
|
||||
// options
|
||||
w8(0);
|
||||
// axes overflow
|
||||
w8(0);
|
||||
// reserved
|
||||
w8(0);
|
||||
//int16 axis1 ; horizontal movement (0-$3FF) (little endian)
|
||||
w16(mo_cvt(x));
|
||||
//int16 axis2 ; vertical movement (0-$3FF) (little endian)
|
||||
|
|
|
@ -167,7 +167,7 @@ extern u8 EEPROM[0x100];
|
|||
void load_naomi_eeprom();
|
||||
|
||||
// Mouse position and buttons
|
||||
extern u32 mo_buttons[4];
|
||||
extern u8 mo_buttons[4];
|
||||
extern s32 mo_x_abs[4];
|
||||
extern s32 mo_y_abs[4];
|
||||
extern f32 mo_x_delta[4];
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "oslib/oslib.h"
|
||||
#include "rend/gui.h"
|
||||
#include "emulator.h"
|
||||
#include "hw/maple/maple_devs.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
|
@ -446,6 +447,54 @@ void GamepadDevice::SaveMaplePorts()
|
|||
}
|
||||
}
|
||||
|
||||
void Mouse::setAbsPos(int x, int y, int width, int height) {
|
||||
SetMousePosition(x, y, width, height, maple_port());
|
||||
}
|
||||
|
||||
void Mouse::setRelPos(int deltax, int deltay) {
|
||||
SetRelativeMousePosition(deltax, deltay, maple_port());
|
||||
}
|
||||
|
||||
void Mouse::setWheel(int delta) {
|
||||
if (maple_port() >= 0 && maple_port() < ARRAY_SIZE(mo_wheel_delta))
|
||||
mo_wheel_delta[maple_port()] += delta;
|
||||
}
|
||||
|
||||
void Mouse::setButton(Button button, bool pressed)
|
||||
{
|
||||
if (maple_port() >= 0 && maple_port() < ARRAY_SIZE(mo_buttons))
|
||||
{
|
||||
if (pressed)
|
||||
mo_buttons[maple_port()] &= ~(1 << (int)button);
|
||||
else
|
||||
mo_buttons[maple_port()] |= 1 << (int)button;
|
||||
}
|
||||
if (gui_is_open() && !is_detecting_input())
|
||||
// Don't register mouse clicks as gamepad presses when gui is open
|
||||
// This makes the gamepad presses to be handled first and the mouse position to be ignored
|
||||
return;
|
||||
gamepad_btn_input(button, pressed);
|
||||
}
|
||||
|
||||
|
||||
void SystemMouse::setAbsPos(int x, int y, int width, int height) {
|
||||
gui_set_mouse_position(x, y);
|
||||
Mouse::setAbsPos(x, y, width, height);
|
||||
}
|
||||
|
||||
void SystemMouse::setButton(Button button, bool pressed) {
|
||||
int uiBtn = (int)button - 1;
|
||||
if (uiBtn < 2)
|
||||
uiBtn ^= 1;
|
||||
gui_set_mouse_button(uiBtn, pressed);
|
||||
Mouse::setButton(button, pressed);
|
||||
}
|
||||
|
||||
void SystemMouse::setWheel(int delta) {
|
||||
gui_set_mouse_wheel(delta * 35);
|
||||
Mouse::setWheel(delta);
|
||||
}
|
||||
|
||||
#ifdef TEST_AUTOMATION
|
||||
#include "cfg/option.h"
|
||||
static bool replay_inited;
|
||||
|
|
|
@ -70,7 +70,15 @@ protected:
|
|||
: _api_name(api_name), _maple_port(maple_port), _input_detected(nullptr), _remappable(remappable)
|
||||
{
|
||||
}
|
||||
|
||||
bool find_mapping(const char *custom_mapping = nullptr);
|
||||
void loadMapping() {
|
||||
if (!find_mapping())
|
||||
input_mapper = getDefaultMapping();
|
||||
}
|
||||
virtual std::shared_ptr<InputMapping> getDefaultMapping() {
|
||||
return std::make_shared<IdentityInputMapping>();
|
||||
}
|
||||
|
||||
virtual void load_axis_min_max(u32 axis) {}
|
||||
bool is_detecting_input() { return _input_detected != nullptr; }
|
||||
|
@ -108,3 +116,73 @@ extern s8 joyx[4], joyy[4];
|
|||
extern s8 joyrx[4], joyry[4];
|
||||
|
||||
void UpdateVibration(u32 port, float power, float inclination, u32 duration_ms);
|
||||
|
||||
class MouseInputMapping : public InputMapping
|
||||
{
|
||||
public:
|
||||
MouseInputMapping()
|
||||
{
|
||||
name = "Mouse";
|
||||
set_button(DC_BTN_A, 2); // Left
|
||||
set_button(DC_BTN_B, 1); // Right
|
||||
set_button(DC_BTN_START, 3); // Middle
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
};
|
||||
|
||||
class Mouse : public GamepadDevice
|
||||
{
|
||||
protected:
|
||||
Mouse(const char *apiName, int maplePort = 0) : GamepadDevice(maplePort, apiName) {
|
||||
this->_name = "Mouse";
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<InputMapping> getDefaultMapping() override {
|
||||
return std::make_shared<MouseInputMapping>();
|
||||
}
|
||||
|
||||
public:
|
||||
enum Button {
|
||||
LEFT_BUTTON = 2,
|
||||
RIGHT_BUTTON = 1,
|
||||
MIDDLE_BUTTON = 3,
|
||||
BUTTON_4 = 4,
|
||||
BUTTON_5 = 5
|
||||
};
|
||||
|
||||
virtual const char *get_button_name(u32 code) override
|
||||
{
|
||||
switch((Button)code)
|
||||
{
|
||||
case LEFT_BUTTON:
|
||||
return "Left Button";
|
||||
case RIGHT_BUTTON:
|
||||
return "Right Button";
|
||||
case MIDDLE_BUTTON:
|
||||
return "Middle Button";
|
||||
case BUTTON_4:
|
||||
return "Button 4";
|
||||
case BUTTON_5:
|
||||
return "Button 5";
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void setAbsPos(int x, int y, int width, int height);
|
||||
void setRelPos(int deltax, int deltay);
|
||||
void setButton(Button button, bool pressed);
|
||||
void setWheel(int delta);
|
||||
};
|
||||
|
||||
class SystemMouse : public Mouse
|
||||
{
|
||||
protected:
|
||||
SystemMouse(const char *apiName, int maplePort = 0) : Mouse(apiName, maplePort) {}
|
||||
|
||||
public:
|
||||
void setAbsPos(int x, int y, int width, int height);
|
||||
void setButton(Button button, bool pressed);
|
||||
void setWheel(int delta);
|
||||
};
|
||||
|
|
|
@ -50,11 +50,12 @@ class KeyboardDevice : public GamepadDevice
|
|||
{
|
||||
protected:
|
||||
KeyboardDevice(int maple_port, const char* apiName, bool remappable = true)
|
||||
: GamepadDevice(maple_port, apiName, remappable)
|
||||
{
|
||||
: GamepadDevice(maple_port, apiName, remappable) {
|
||||
_name = "Keyboard";
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<KeyboardInputMapping>();
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<InputMapping> getDefaultMapping() override {
|
||||
return std::make_shared<KeyboardInputMapping>();
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
input_mapper = std::make_shared<InputMapping>(*input_mapper);
|
||||
}
|
||||
else
|
||||
input_mapper = std::make_shared<DefaultEvdevInputMapping>();
|
||||
input_mapper = getDefaultMapping();
|
||||
input_mapper->name = _name + " mapping";
|
||||
save_mapping();
|
||||
}
|
||||
|
@ -96,6 +96,10 @@ public:
|
|||
close(_fd);
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<InputMapping> getDefaultMapping() override {
|
||||
return std::make_shared<DefaultEvdevInputMapping>();
|
||||
}
|
||||
|
||||
virtual void rumble(float power, float inclination, u32 duration_ms) override
|
||||
{
|
||||
vib_inclination = inclination * power;
|
||||
|
|
|
@ -27,67 +27,13 @@
|
|||
static Window x11_win;
|
||||
Display *x11_disp;
|
||||
|
||||
class MouseInputMapping : public InputMapping
|
||||
class X11Mouse : public SystemMouse
|
||||
{
|
||||
public:
|
||||
MouseInputMapping()
|
||||
X11Mouse() : SystemMouse("X11")
|
||||
{
|
||||
name = "X11 Mouse";
|
||||
set_button(DC_BTN_A, Button1);
|
||||
set_button(DC_BTN_B, Button3);
|
||||
set_button(DC_BTN_START, Button2);
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
};
|
||||
|
||||
class X11Mouse : public GamepadDevice
|
||||
{
|
||||
public:
|
||||
X11Mouse(int maple_port) : GamepadDevice(maple_port, "X11")
|
||||
{
|
||||
_name = "Mouse";
|
||||
_unique_id = "x11_mouse";
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<MouseInputMapping>();
|
||||
}
|
||||
|
||||
bool gamepad_btn_input(u32 code, bool pressed) override
|
||||
{
|
||||
if (gui_is_open() && !is_detecting_input())
|
||||
// Don't register mouse clicks as gamepad presses when gui is open
|
||||
// This makes the gamepad presses to be handled first and the mouse position to be ignored
|
||||
// TODO Make this generic
|
||||
return false;
|
||||
else
|
||||
return GamepadDevice::gamepad_btn_input(code, pressed);
|
||||
}
|
||||
|
||||
virtual const char *get_button_name(u32 code) override
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case Button1:
|
||||
return "Left Button";
|
||||
case Button2:
|
||||
return "Middle Button";
|
||||
case Button3:
|
||||
return "Right Button";
|
||||
case Button4:
|
||||
return "Scroll Up";
|
||||
case Button5:
|
||||
return "Scroll Down";
|
||||
case 6:
|
||||
return "Scroll Left";
|
||||
case 7:
|
||||
return "Scroll Right";
|
||||
case 8:
|
||||
return "Button 4";
|
||||
case 9:
|
||||
return "Button 5";
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
loadMapping();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -268,62 +214,38 @@ void input_x11_handle()
|
|||
break;
|
||||
|
||||
case FocusOut:
|
||||
{
|
||||
if (capturing_mouse)
|
||||
x11_uncapture_mouse();
|
||||
capturing_mouse = false;
|
||||
}
|
||||
if (capturing_mouse)
|
||||
x11_uncapture_mouse();
|
||||
capturing_mouse = false;
|
||||
break;
|
||||
|
||||
case ButtonPress:
|
||||
case ButtonRelease:
|
||||
gui_set_mouse_position(e.xbutton.x, e.xbutton.y);
|
||||
x11Mouse->gamepad_btn_input(e.xbutton.button, e.type == ButtonPress);
|
||||
switch (e.xbutton.button)
|
||||
{
|
||||
u32 button_mask = 0;
|
||||
switch (e.xbutton.button)
|
||||
{
|
||||
case Button1: // Left button
|
||||
gui_set_mouse_button(0, e.type == ButtonPress);
|
||||
button_mask = 1 << 2;
|
||||
break;
|
||||
case Button2: // Middle button
|
||||
gui_set_mouse_button(2, e.type == ButtonPress);
|
||||
button_mask = 1 << 3;
|
||||
break;
|
||||
case Button3: // Right button
|
||||
gui_set_mouse_button(1, e.type == ButtonPress);
|
||||
button_mask = 1 << 1;
|
||||
break;
|
||||
case Button4: // Mouse wheel up
|
||||
gui_set_mouse_wheel(-16);
|
||||
mo_wheel_delta[0] -= 16;
|
||||
break;
|
||||
case Button5: // Mouse wheel down
|
||||
gui_set_mouse_wheel(16);
|
||||
mo_wheel_delta[0] += 16;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (button_mask)
|
||||
{
|
||||
if (e.type == ButtonPress)
|
||||
mo_buttons[0] &= ~button_mask;
|
||||
else
|
||||
mo_buttons[0] |= button_mask;
|
||||
}
|
||||
case Button1: // Left button
|
||||
x11Mouse->setButton(Mouse::LEFT_BUTTON, e.type == ButtonPress);
|
||||
break;
|
||||
case Button2: // Middle button
|
||||
x11Mouse->setButton(Mouse::MIDDLE_BUTTON, e.type == ButtonPress);
|
||||
break;
|
||||
case Button3: // Right button
|
||||
x11Mouse->setButton(Mouse::RIGHT_BUTTON, e.type == ButtonPress);
|
||||
break;
|
||||
case Button4: // Mouse wheel up
|
||||
x11Mouse->setWheel(-1);
|
||||
break;
|
||||
case Button5: // Mouse wheel down
|
||||
x11Mouse->setWheel(1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* no break */
|
||||
|
||||
case MotionNotify:
|
||||
gui_set_mouse_position(e.xmotion.x, e.xmotion.y);
|
||||
// For Light gun
|
||||
SetMousePosition(e.xmotion.x, e.xmotion.y, x11_width, x11_height);
|
||||
// For mouse
|
||||
x11Mouse->setAbsPos(e.xmotion.x, e.xmotion.y, x11_width, x11_height);
|
||||
mouse_moved = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +268,7 @@ void input_x11_init()
|
|||
{
|
||||
x11Keyboard = std::make_shared<X11Keyboard>(0);
|
||||
GamepadDevice::Register(x11Keyboard);
|
||||
x11Mouse = std::make_shared<X11Mouse>(0);
|
||||
x11Mouse = std::make_shared<X11Mouse>();
|
||||
GamepadDevice::Register(x11Mouse);
|
||||
}
|
||||
|
||||
|
|
|
@ -141,8 +141,7 @@ public:
|
|||
//E8-FF Reserved
|
||||
|
||||
_unique_id = "x11_keyboard";
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<KeyboardInputMapping>();
|
||||
loadMapping();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
119
core/sdl/sdl.cpp
119
core/sdl/sdl.cpp
|
@ -94,13 +94,15 @@ static void emuEventCallback(Event event)
|
|||
gameRunning = false;
|
||||
if (!config::UseRawInput)
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
else
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
SDL_SetWindowTitle(window, "Flycast");
|
||||
break;
|
||||
case Event::Resume:
|
||||
gameRunning = true;
|
||||
captureMouse(mouseCaptured);
|
||||
if (window_fullscreen && !mouseCaptured)
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -182,40 +184,11 @@ void input_sdl_init()
|
|||
#endif
|
||||
}
|
||||
|
||||
inline void SDLMouse::setMouseAbsPos(int x, int y) {
|
||||
if (maple_port() < 0)
|
||||
return;
|
||||
|
||||
inline void SDLMouse::setAbsPos(int x, int y) {
|
||||
int width, height;
|
||||
SDL_GetWindowSize(window, &width, &height);
|
||||
if (width != 0 && height != 0)
|
||||
SetMousePosition(x, y, width, height, maple_port());
|
||||
}
|
||||
|
||||
inline void SDLMouse::setMouseRelPos(int deltax, int deltay) {
|
||||
if (maple_port() < 0)
|
||||
return;
|
||||
SetRelativeMousePosition(deltax, deltay, maple_port());
|
||||
}
|
||||
|
||||
#define SET_FLAG(field, mask, expr) (field) = ((expr) ? ((field) & ~(mask)) : ((field) | (mask)))
|
||||
|
||||
inline void SDLMouse::setMouseButton(u32 button, bool pressed) {
|
||||
if (maple_port() < 0)
|
||||
return;
|
||||
|
||||
switch (button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:
|
||||
SET_FLAG(mo_buttons[maple_port()], 1 << 2, pressed);
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
SET_FLAG(mo_buttons[maple_port()], 1 << 1, pressed);
|
||||
break;
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
SET_FLAG(mo_buttons[maple_port()], 1 << 3, pressed);
|
||||
break;
|
||||
}
|
||||
Mouse::setAbsPos(x, y, width, height);
|
||||
}
|
||||
|
||||
void input_sdl_handle()
|
||||
|
@ -238,9 +211,17 @@ void input_sdl_handle()
|
|||
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN && (event.key.keysym.mod & KMOD_ALT))
|
||||
{
|
||||
if (window_fullscreen)
|
||||
{
|
||||
SDL_SetWindowFullscreen(window, 0);
|
||||
if (!gameRunning || !mouseCaptured)
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
if (gameRunning)
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
}
|
||||
window_fullscreen = !window_fullscreen;
|
||||
}
|
||||
else if (event.type == SDL_KEYDOWN && (event.key.keysym.mod & KMOD_LALT) && (event.key.keysym.mod & KMOD_LCTRL))
|
||||
|
@ -268,6 +249,16 @@ void input_sdl_handle()
|
|||
theDXContext.resize();
|
||||
#endif
|
||||
}
|
||||
else if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
|
||||
{
|
||||
if (window_fullscreen && gameRunning)
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
}
|
||||
else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
|
||||
{
|
||||
if (window_fullscreen)
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
|
@ -332,12 +323,14 @@ void input_sdl_handle()
|
|||
if (!config::UseRawInput)
|
||||
{
|
||||
if (mouseCaptured && gameRunning)
|
||||
sdl_mouse->setMouseRelPos(event.motion.xrel, event.motion.yrel);
|
||||
sdl_mouse->setRelPos(event.motion.xrel, event.motion.yrel);
|
||||
else
|
||||
sdl_mouse->setMouseAbsPos(event.motion.x, event.motion.y);
|
||||
sdl_mouse->setMouseButton(SDL_BUTTON_LEFT, event.motion.state & SDL_BUTTON_LMASK);
|
||||
sdl_mouse->setMouseButton(SDL_BUTTON_RIGHT, event.motion.state & SDL_BUTTON_RMASK);
|
||||
sdl_mouse->setMouseButton(SDL_BUTTON_MIDDLE, event.motion.state & SDL_BUTTON_MMASK);
|
||||
sdl_mouse->setAbsPos(event.motion.x, event.motion.y);
|
||||
sdl_mouse->setButton(Mouse::LEFT_BUTTON, event.motion.state & SDL_BUTTON_LMASK);
|
||||
sdl_mouse->setButton(Mouse::RIGHT_BUTTON, event.motion.state & SDL_BUTTON_RMASK);
|
||||
sdl_mouse->setButton(Mouse::MIDDLE_BUTTON, event.motion.state & SDL_BUTTON_MMASK);
|
||||
sdl_mouse->setButton(Mouse::BUTTON_4, event.motion.state & SDL_BUTTON_X1MASK);
|
||||
sdl_mouse->setButton(Mouse::BUTTON_5, event.motion.state & SDL_BUTTON_X2MASK);
|
||||
}
|
||||
else if (mouseCaptured && gameRunning)
|
||||
{
|
||||
|
@ -352,37 +345,31 @@ void input_sdl_handle()
|
|||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
gui_set_mouse_position(event.button.x, event.button.y);
|
||||
int button;
|
||||
switch (event.button.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:
|
||||
button = 0;
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
button = 1;
|
||||
break;
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
button = 2;
|
||||
break;
|
||||
case SDL_BUTTON_X1:
|
||||
button = 3;
|
||||
break;
|
||||
default:
|
||||
button = -1;
|
||||
break;
|
||||
}
|
||||
if (button != -1)
|
||||
gui_set_mouse_button(button, event.button.state == SDL_PRESSED);
|
||||
}
|
||||
gui_set_mouse_position(event.button.x, event.button.y);
|
||||
gui_set_mouse_button(event.button.button - 1, event.button.state == SDL_PRESSED);
|
||||
checkRawInput();
|
||||
if (!config::UseRawInput)
|
||||
{
|
||||
if (!mouseCaptured || !gameRunning)
|
||||
sdl_mouse->setMouseAbsPos(event.button.x, event.button.y);
|
||||
sdl_mouse->setMouseButton(event.button.button, event.button.state == SDL_PRESSED);
|
||||
sdl_mouse->gamepad_btn_input(event.button.button, event.button.state == SDL_PRESSED);
|
||||
sdl_mouse->setAbsPos(event.button.x, event.button.y);
|
||||
bool pressed = event.button.state == SDL_PRESSED;
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT:
|
||||
sdl_mouse->setButton(Mouse::LEFT_BUTTON, pressed);
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
sdl_mouse->setButton(Mouse::RIGHT_BUTTON, pressed);
|
||||
break;
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
sdl_mouse->setButton(Mouse::MIDDLE_BUTTON, pressed);
|
||||
break;
|
||||
case SDL_BUTTON_X1:
|
||||
sdl_mouse->setButton(Mouse::BUTTON_4, pressed);
|
||||
break;
|
||||
case SDL_BUTTON_X2:
|
||||
sdl_mouse->setButton(Mouse::BUTTON_5, pressed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -390,7 +377,7 @@ void input_sdl_handle()
|
|||
gui_set_mouse_wheel(-event.wheel.y * 35);
|
||||
checkRawInput();
|
||||
if (!config::UseRawInput)
|
||||
mo_wheel_delta[0] -= event.wheel.y * 35;
|
||||
sdl_mouse->setWheel(-event.wheel.y);
|
||||
break;
|
||||
#endif
|
||||
case SDL_JOYDEVICEADDED:
|
||||
|
|
|
@ -110,10 +110,7 @@ public:
|
|||
_unique_id = "sdl_joystick_" + std::to_string(sdl_joystick_instance);
|
||||
INFO_LOG(INPUT, "SDL: Opened joystick %d on port %d: '%s' unique_id=%s", sdl_joystick_instance, maple_port, _name.c_str(), _unique_id.c_str());
|
||||
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<DefaultInputMapping>(joystick_idx);
|
||||
else
|
||||
INFO_LOG(INPUT, "using custom mapping '%s'", input_mapper->name.c_str());
|
||||
loadMapping();
|
||||
sdl_haptic = SDL_HapticOpenFromJoystick(sdl_joystick);
|
||||
if (SDL_HapticRumbleInit(sdl_haptic) != 0)
|
||||
{
|
||||
|
@ -193,62 +190,16 @@ private:
|
|||
|
||||
std::map<SDL_JoystickID, std::shared_ptr<SDLGamepad>> SDLGamepad::sdl_gamepads;
|
||||
|
||||
class MouseInputMapping : public InputMapping
|
||||
class SDLMouse : public Mouse
|
||||
{
|
||||
public:
|
||||
MouseInputMapping()
|
||||
{
|
||||
name = "SDL Mouse";
|
||||
set_button(DC_BTN_A, SDL_BUTTON_LEFT);
|
||||
set_button(DC_BTN_B, SDL_BUTTON_RIGHT);
|
||||
set_button(DC_BTN_START, SDL_BUTTON_MIDDLE);
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
};
|
||||
|
||||
class SDLMouse : public GamepadDevice
|
||||
{
|
||||
public:
|
||||
SDLMouse() : GamepadDevice(0, "SDL")
|
||||
SDLMouse() : Mouse("SDL")
|
||||
{
|
||||
this->_name = "Default Mouse";
|
||||
this->_unique_id = "sdl_mouse";
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<MouseInputMapping>();
|
||||
loadMapping();
|
||||
}
|
||||
|
||||
bool gamepad_btn_input(u32 code, bool pressed) override
|
||||
{
|
||||
if (gui_is_open() && !is_detecting_input())
|
||||
// Don't register mouse clicks as gamepad presses when gui is open
|
||||
// This makes the gamepad presses to be handled first and the mouse position to be ignored
|
||||
// TODO Make this generic
|
||||
return false;
|
||||
else
|
||||
return GamepadDevice::gamepad_btn_input(code, pressed);
|
||||
}
|
||||
|
||||
virtual const char *get_button_name(u32 code) override
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:
|
||||
return "Left Button";
|
||||
case SDL_BUTTON_RIGHT:
|
||||
return "Right Button";
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
return "Middle Button";
|
||||
case SDL_BUTTON_X1:
|
||||
return "X1 Button";
|
||||
case SDL_BUTTON_X2:
|
||||
return "X2 Button";
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void setMouseAbsPos(int x, int y);
|
||||
void setMouseRelPos(int deltax, int deltay);
|
||||
void setMouseButton(u32 button, bool pressed);
|
||||
void setAbsPos(int x, int y);
|
||||
};
|
||||
|
||||
|
|
|
@ -7,8 +7,7 @@ class SDLKeyboardDevice : public KeyboardDeviceTemplate<SDL_Scancode>
|
|||
public:
|
||||
SDLKeyboardDevice(int maple_port) : KeyboardDeviceTemplate(maple_port, "SDL") {
|
||||
_unique_id = "sdl_keyboard";
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<KeyboardInputMapping>();
|
||||
loadMapping();
|
||||
}
|
||||
|
||||
virtual const char *get_button_name(u32 code) override
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#define CALLBACK
|
||||
#endif
|
||||
|
||||
extern int screen_width, screen_height;
|
||||
HWND getNativeHwnd();
|
||||
|
||||
namespace rawinput {
|
||||
|
@ -33,8 +34,6 @@ static std::map<HANDLE, std::shared_ptr<RawMouse>> mice;
|
|||
static std::map<HANDLE, std::shared_ptr<RawKeyboard>> keyboards;
|
||||
static HWND hWnd;
|
||||
|
||||
#define SET_FLAG(field, mask, expr) (field) = ((expr) ? ((field) & ~(mask)) : ((field) | (mask)))
|
||||
|
||||
const u8 Ps2toUsb[0x80] {
|
||||
// 00
|
||||
0xff,
|
||||
|
@ -198,42 +197,22 @@ const u8 Ps2toUsbE0[][2] {
|
|||
};
|
||||
|
||||
RawMouse::RawMouse(int maple_port, const std::string& name, const std::string& uniqueId, HANDLE handle) :
|
||||
GamepadDevice(maple_port, "RAW"), handle(handle)
|
||||
Mouse("RAW", maple_port), handle(handle)
|
||||
{
|
||||
this->_name = name;
|
||||
this->_unique_id = uniqueId;
|
||||
std::replace(this->_unique_id.begin(), this->_unique_id.end(), '=', '_');
|
||||
std::replace(this->_unique_id.begin(), this->_unique_id.end(), '[', '_');
|
||||
std::replace(this->_unique_id.begin(), this->_unique_id.end(), ']', '_');
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<RawMouseInputMapping>();
|
||||
loadMapping();
|
||||
|
||||
SetMousePosition(screen_width / 2, screen_height / 2, screen_width, screen_height, maple_port);
|
||||
setAbsPos(screen_width / 2, screen_height / 2, screen_width, screen_height);
|
||||
}
|
||||
|
||||
void RawMouse::buttonInput(u32 buttonId, u16 flags, u16 downFlag, u16 upFlag) {
|
||||
if (flags & downFlag)
|
||||
gamepad_btn_input(buttonId, true);
|
||||
else if (flags & upFlag)
|
||||
gamepad_btn_input(buttonId, false);
|
||||
|
||||
if (maple_port() >= 0 && (flags & (downFlag | upFlag)))
|
||||
{
|
||||
switch (buttonId)
|
||||
{
|
||||
case 0: // left button
|
||||
SET_FLAG(mo_buttons[maple_port()], 1 << 2, flags & downFlag);
|
||||
break;
|
||||
case 1: // middle button
|
||||
SET_FLAG(mo_buttons[maple_port()], 1 << 3, flags & downFlag);
|
||||
break;
|
||||
case 2: // right button
|
||||
SET_FLAG(mo_buttons[maple_port()], 1 << 1, flags & downFlag);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void RawMouse::buttonInput(Button button, u16 flags, u16 downFlag, u16 upFlag)
|
||||
{
|
||||
if (flags & (downFlag | upFlag))
|
||||
setButton(button, flags & downFlag);
|
||||
}
|
||||
|
||||
void RawMouse::updateState(RAWMOUSE* state)
|
||||
|
@ -246,23 +225,17 @@ void RawMouse::updateState(RAWMOUSE* state)
|
|||
|
||||
POINT pt { long(state->lLastX / 65535.0f * width), long(state->lLastY / 65535.0f * height) };
|
||||
ScreenToClient(getNativeHwnd(), &pt);
|
||||
SetMousePosition(pt.x, pt.y, screen_width, screen_height, maple_port());
|
||||
setAbsPos(pt.x, pt.y, screen_width, screen_height);
|
||||
}
|
||||
else if (state->lLastX != 0 || state->lLastY != 0)
|
||||
SetRelativeMousePosition(state->lLastX, state->lLastY, maple_port());
|
||||
buttonInput(0, state->usButtonFlags, RI_MOUSE_LEFT_BUTTON_DOWN, RI_MOUSE_LEFT_BUTTON_UP);
|
||||
buttonInput(1, state->usButtonFlags, RI_MOUSE_MIDDLE_BUTTON_DOWN, RI_MOUSE_MIDDLE_BUTTON_UP);
|
||||
buttonInput(2, state->usButtonFlags, RI_MOUSE_RIGHT_BUTTON_DOWN, RI_MOUSE_RIGHT_BUTTON_UP);
|
||||
buttonInput(3, state->usButtonFlags, RI_MOUSE_BUTTON_4_DOWN, RI_MOUSE_BUTTON_4_UP);
|
||||
buttonInput(4, state->usButtonFlags, RI_MOUSE_BUTTON_5_DOWN, RI_MOUSE_BUTTON_5_UP);
|
||||
if (state->usButtonFlags & RI_MOUSE_WHEEL)
|
||||
{
|
||||
// TODO wheel
|
||||
// if ((SHORT)state->usButtonData > 0)
|
||||
// InterlockedExchange(&mouse->whl_u, 1);
|
||||
// else if ((SHORT)state->usButtonData < 0)
|
||||
// InterlockedExchange(&mouse->whl_d, 1);
|
||||
}
|
||||
setRelPos(state->lLastX, state->lLastY);
|
||||
buttonInput(LEFT_BUTTON, state->usButtonFlags, RI_MOUSE_LEFT_BUTTON_DOWN, RI_MOUSE_LEFT_BUTTON_UP);
|
||||
buttonInput(MIDDLE_BUTTON, state->usButtonFlags, RI_MOUSE_MIDDLE_BUTTON_DOWN, RI_MOUSE_MIDDLE_BUTTON_UP);
|
||||
buttonInput(RIGHT_BUTTON, state->usButtonFlags, RI_MOUSE_RIGHT_BUTTON_DOWN, RI_MOUSE_RIGHT_BUTTON_UP);
|
||||
buttonInput(BUTTON_4, state->usButtonFlags, RI_MOUSE_BUTTON_4_DOWN, RI_MOUSE_BUTTON_4_UP);
|
||||
buttonInput(BUTTON_5, state->usButtonFlags, RI_MOUSE_BUTTON_5_DOWN, RI_MOUSE_BUTTON_5_UP);
|
||||
if ((state->usButtonFlags & RI_MOUSE_WHEEL))
|
||||
setWheel(-(short)state->usButtonData / WHEEL_DELTA);
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK rawWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
|
|
|
@ -21,63 +21,17 @@
|
|||
#include "rend/gui.h"
|
||||
#include <windows.h>
|
||||
|
||||
extern int screen_width, screen_height;
|
||||
|
||||
namespace rawinput {
|
||||
|
||||
class RawMouseInputMapping : public InputMapping
|
||||
{
|
||||
public:
|
||||
RawMouseInputMapping()
|
||||
{
|
||||
name = "Mouse";
|
||||
set_button(DC_BTN_A, 0); // Left
|
||||
set_button(DC_BTN_B, 2); // Right
|
||||
set_button(DC_BTN_START, 1);// Middle
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
};
|
||||
|
||||
class RawMouse : public GamepadDevice
|
||||
class RawMouse : public Mouse
|
||||
{
|
||||
public:
|
||||
RawMouse(int maple_port, const std::string& name, const std::string& uniqueId, HANDLE handle);
|
||||
|
||||
bool gamepad_btn_input(u32 code, bool pressed) override
|
||||
{
|
||||
if (gui_is_open() && !is_detecting_input())
|
||||
// Don't register mouse clicks as gamepad presses when gui is open
|
||||
// This makes the gamepad presses to be handled first and the mouse position to be ignored
|
||||
// TODO Make this generic
|
||||
return false;
|
||||
else
|
||||
return GamepadDevice::gamepad_btn_input(code, pressed);
|
||||
}
|
||||
|
||||
const char *get_button_name(u32 code) override
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case 0:
|
||||
return "Left Button";
|
||||
case 2:
|
||||
return "Right Button";
|
||||
case 1:
|
||||
return "Middle Button";
|
||||
case 3:
|
||||
return "Button 4";
|
||||
case 4:
|
||||
return "Button 5";
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void updateState(RAWMOUSE* state);
|
||||
|
||||
private:
|
||||
void buttonInput(u32 buttonId, u16 flags, u16 downFlag, u16 upFlag);
|
||||
void buttonInput(Button button, u16 flags, u16 downFlag, u16 upFlag);
|
||||
|
||||
HANDLE handle = NULL;
|
||||
};
|
||||
|
@ -93,8 +47,7 @@ public:
|
|||
std::replace(this->_unique_id.begin(), this->_unique_id.end(), '=', '_');
|
||||
std::replace(this->_unique_id.begin(), this->_unique_id.end(), '[', '_');
|
||||
std::replace(this->_unique_id.begin(), this->_unique_id.end(), ']', '_');
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<KeyboardInputMapping>();
|
||||
loadMapping();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -4,13 +4,14 @@
|
|||
#include "hw/mem/vmem32.h"
|
||||
#include "stdclass.h"
|
||||
#include "cfg/cfg.h"
|
||||
#include "xinput_gamepad.h"
|
||||
#include "win_keyboard.h"
|
||||
#include "hw/sh4/dyna/blockmanager.h"
|
||||
#include "log/LogManager.h"
|
||||
#include "wsi/context.h"
|
||||
#if defined(USE_SDL)
|
||||
#include "sdl/sdl.h"
|
||||
#else
|
||||
#include "xinput_gamepad.h"
|
||||
#endif
|
||||
#include "hw/maple/maple_devs.h"
|
||||
#include "emulator.h"
|
||||
|
@ -166,7 +167,7 @@ static void checkRawInput()
|
|||
rawinput::term();
|
||||
keyboard = std::make_shared<Win32KeyboardDevice>(0);
|
||||
GamepadDevice::Register(keyboard);
|
||||
mouse = std::make_shared<WinMouse>(0);
|
||||
mouse = std::make_shared<WinMouse>();
|
||||
GamepadDevice::Register(mouse);
|
||||
}
|
||||
}
|
||||
|
@ -390,34 +391,23 @@ static LRESULT CALLBACK WndProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM
|
|||
switch (message)
|
||||
{
|
||||
case WM_LBUTTONDOWN:
|
||||
if (!mouseCaptured && !config::UseRawInput)
|
||||
mouse->gamepad_btn_input(0, true);
|
||||
gui_set_mouse_button(0, true);
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (!mouseCaptured && !config::UseRawInput)
|
||||
mouse->gamepad_btn_input(0, false);
|
||||
gui_set_mouse_button(0, false);
|
||||
mouse->setButton(Mouse::LEFT_BUTTON, message == WM_LBUTTONDOWN);
|
||||
gui_set_mouse_button(0, message == WM_LBUTTONDOWN);
|
||||
break;
|
||||
|
||||
case WM_MBUTTONDOWN:
|
||||
if (!mouseCaptured && !config::UseRawInput)
|
||||
mouse->gamepad_btn_input(1, true);
|
||||
gui_set_mouse_button(2, true);
|
||||
break;
|
||||
case WM_MBUTTONUP:
|
||||
if (!mouseCaptured && !config::UseRawInput)
|
||||
mouse->gamepad_btn_input(1, false);
|
||||
gui_set_mouse_button(2, false);
|
||||
mouse->setButton(Mouse::MIDDLE_BUTTON, message == WM_MBUTTONDOWN);
|
||||
gui_set_mouse_button(2, message == WM_MBUTTONDOWN);
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
if (!mouseCaptured && !config::UseRawInput)
|
||||
mouse->gamepad_btn_input(2, true);
|
||||
gui_set_mouse_button(1, true);
|
||||
break;
|
||||
case WM_RBUTTONUP:
|
||||
if (!mouseCaptured && !config::UseRawInput)
|
||||
mouse->gamepad_btn_input(2, false);
|
||||
gui_set_mouse_button(1, false);
|
||||
mouse->setButton(Mouse::RIGHT_BUTTON, message == WM_RBUTTONDOWN);
|
||||
gui_set_mouse_button(1, message == WM_RBUTTONDOWN);
|
||||
break;
|
||||
}
|
||||
if (mouseCaptured)
|
||||
|
@ -433,24 +423,23 @@ static LRESULT CALLBACK WndProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM
|
|||
{
|
||||
int xPos = GET_X_LPARAM(lParam);
|
||||
int yPos = GET_Y_LPARAM(lParam);
|
||||
SetMousePosition(xPos, yPos, screen_width, screen_height);
|
||||
mouse->setAbsPos(xPos, yPos, screen_width, screen_height);
|
||||
|
||||
mo_buttons[0] = 0xffffffff;
|
||||
if (wParam & MK_LBUTTON)
|
||||
mo_buttons[0] &= ~(1 << 2);
|
||||
mouse->setButton(Button::LEFT_BUTTON, true);
|
||||
if (wParam & MK_MBUTTON)
|
||||
mo_buttons[0] &= ~(1 << 3);
|
||||
mouse->setButton(Button::MIDDLE_BUTTON, true);
|
||||
if (wParam & MK_RBUTTON)
|
||||
mo_buttons[0] &= ~(1 << 1);
|
||||
mouse->setButton(Button::RIGHT_BUTTON, true);
|
||||
}
|
||||
if (message != WM_MOUSEMOVE)
|
||||
return 0;
|
||||
break;
|
||||
case WM_MOUSEWHEEL:
|
||||
gui_set_mouse_wheel(-(float)GET_WHEEL_DELTA_WPARAM(wParam)/(float)WHEEL_DELTA * 16);
|
||||
gui_set_mouse_wheel(-(float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA * 16);
|
||||
checkRawInput();
|
||||
if (!config::UseRawInput)
|
||||
mo_wheel_delta[0] -= (float)GET_WHEEL_DELTA_WPARAM(wParam)/(float)WHEEL_DELTA * 16;
|
||||
mouse->setWheel(-GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA);
|
||||
break;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
|
|
|
@ -43,6 +43,10 @@ public:
|
|||
_unique_id = buf;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<InputMapping> getDefaultMapping() override {
|
||||
return std::make_shared<XInputMapping>();
|
||||
}
|
||||
|
||||
void ReadInput()
|
||||
{
|
||||
update_rumble();
|
||||
|
@ -137,15 +141,8 @@ public:
|
|||
else
|
||||
_name = joycaps.szPname;
|
||||
INFO_LOG(INPUT, "xinput: Opened controller '%s' on port %d", _name.c_str(), _xinput_port);
|
||||
if (!find_mapping())
|
||||
{
|
||||
input_mapper = std::make_shared<XInputMapping>();
|
||||
input_mapper->name = _name + " mapping";
|
||||
save_mapping();
|
||||
INFO_LOG(INPUT, "using default mapping");
|
||||
}
|
||||
else
|
||||
INFO_LOG(INPUT, "using custom mapping '%s'n", input_mapper->name.c_str());
|
||||
loadMapping();
|
||||
|
||||
GamepadDevice::Register(xinput_gamepads[_xinput_port]);
|
||||
}
|
||||
|
||||
|
@ -206,56 +203,13 @@ private:
|
|||
|
||||
std::vector<std::shared_ptr<XInputGamepadDevice>> XInputGamepadDevice::xinput_gamepads(XUSER_MAX_COUNT);
|
||||
|
||||
class MouseInputMapping : public InputMapping
|
||||
class WinMouse : public Mouse
|
||||
{
|
||||
public:
|
||||
MouseInputMapping()
|
||||
WinMouse() : Mouse("win32")
|
||||
{
|
||||
name = "Mouse";
|
||||
set_button(DC_BTN_A, 0); // Left
|
||||
set_button(DC_BTN_B, 2); // Right
|
||||
set_button(DC_BTN_START, 1);// Middle
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
};
|
||||
|
||||
class WinMouse : public GamepadDevice
|
||||
{
|
||||
public:
|
||||
WinMouse(int maple_port) : GamepadDevice(maple_port, "win32")
|
||||
{
|
||||
_name = "Mouse";
|
||||
_unique_id = "win_mouse";
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<MouseInputMapping>();
|
||||
}
|
||||
~WinMouse() override = default;
|
||||
|
||||
bool gamepad_btn_input(u32 code, bool pressed) override
|
||||
{
|
||||
if (gui_is_open() && !is_detecting_input())
|
||||
// Don't register mouse clicks as gamepad presses when gui is open
|
||||
// This makes the gamepad presses to be handled first and the mouse position to be ignored
|
||||
// TODO Make this generic
|
||||
return false;
|
||||
else
|
||||
return GamepadDevice::gamepad_btn_input(code, pressed);
|
||||
}
|
||||
|
||||
const char *get_button_name(u32 code) override
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case 0:
|
||||
return "Left Button";
|
||||
case 2:
|
||||
return "Right Button";
|
||||
case 1:
|
||||
return "Middle Button";
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
loadMapping();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -137,6 +137,8 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_emu_JNIdc_screenDpi(JNIEnv *env
|
|||
|
||||
extern int screen_width,screen_height;
|
||||
|
||||
std::shared_ptr<AndroidMouse> mouse;
|
||||
|
||||
float vjoy_pos[15][8];
|
||||
|
||||
extern bool print_stats;
|
||||
|
@ -575,6 +577,9 @@ JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_init(
|
|||
{
|
||||
input_device_manager = env->NewGlobalRef(obj);
|
||||
input_device_manager_rumble = env->GetMethodID(env->GetObjectClass(obj), "rumble", "(IFFI)Z");
|
||||
// FIXME Don't connect it by default or any screen touch will register as button A press
|
||||
mouse = std::make_shared<AndroidMouse>(-1);
|
||||
GamepadDevice::Register(mouse);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_joystickAdded(JNIEnv *env, jobject obj, jint id, jstring name, jint maple_port, jstring junique_id)
|
||||
|
@ -628,21 +633,10 @@ JNIEXPORT jboolean JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_j
|
|||
|
||||
JNIEXPORT void JNICALL Java_com_reicast_emulator_periph_InputDeviceManager_mouseEvent(JNIEnv *env, jobject obj, jint xpos, jint ypos, jint buttons)
|
||||
{
|
||||
gui_set_mouse_position(xpos, ypos);
|
||||
gui_set_mouse_button(0, buttons & 1);
|
||||
gui_set_mouse_button(1, buttons & 2);
|
||||
gui_set_mouse_button(2, buttons & 4);
|
||||
SetMousePosition(xpos, ypos, screen_width, screen_height);
|
||||
mo_buttons[0] = 0xFFFF;
|
||||
if (buttons & 1) // Left
|
||||
mo_buttons[0] &= ~4;
|
||||
if (buttons & 2) // Right
|
||||
mo_buttons[0] &= ~2;
|
||||
if (buttons & 4) // Middle
|
||||
mo_buttons[0] &= ~8;
|
||||
mouse_gamepad.gamepad_btn_input(1, (buttons & 1) != 0);
|
||||
mouse_gamepad.gamepad_btn_input(2, (buttons & 2) != 0);
|
||||
mouse_gamepad.gamepad_btn_input(4, (buttons & 4) != 0);
|
||||
mouse->setAbsPos(xpos, ypos, screen_width, screen_height);
|
||||
mouse->setButton(Mouse::LEFT_BUTTON, (buttons & 1) != 0);
|
||||
mouse->setButton(Mouse::RIGHT_BUTTON, (buttons & 2) != 0);
|
||||
mouse->setButton(Mouse::MIDDLE_BUTTON, (buttons & 4) != 0);
|
||||
}
|
||||
|
||||
static jobject g_activity;
|
||||
|
|
|
@ -128,23 +128,24 @@ public:
|
|||
axis_min_values[DC_AXIS_RT] = 0;
|
||||
axis_ranges[DC_AXIS_RT] = 255;
|
||||
}
|
||||
else if (!find_mapping())
|
||||
{
|
||||
if (_name == "SHIELD Remote")
|
||||
input_mapper = std::make_shared<ShieldRemoteInputMapping>();
|
||||
else
|
||||
input_mapper = std::make_shared<DefaultInputMapping>();
|
||||
save_mapping();
|
||||
INFO_LOG(INPUT, "using default mapping");
|
||||
}
|
||||
else
|
||||
INFO_LOG(INPUT, "using custom mapping '%s'", input_mapper->name.c_str());
|
||||
{
|
||||
loadMapping();
|
||||
save_mapping();
|
||||
}
|
||||
}
|
||||
virtual ~AndroidGamepadDevice() override
|
||||
{
|
||||
INFO_LOG(INPUT, "Android: Joystick '%s' on port %d disconnected", _name.c_str(), maple_port());
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<InputMapping> getDefaultMapping() override {
|
||||
if (_name == "SHIELD Remote")
|
||||
return std::make_shared<ShieldRemoteInputMapping>();
|
||||
else
|
||||
return std::make_shared<DefaultInputMapping>();
|
||||
}
|
||||
|
||||
virtual const char *get_button_name(u32 code) override
|
||||
{
|
||||
switch(code)
|
||||
|
@ -307,65 +308,13 @@ private:
|
|||
|
||||
std::map<int, std::shared_ptr<AndroidGamepadDevice>> AndroidGamepadDevice::android_gamepads;
|
||||
|
||||
class MouseInputMapping : public InputMapping
|
||||
class AndroidMouse : public SystemMouse
|
||||
{
|
||||
public:
|
||||
MouseInputMapping()
|
||||
AndroidMouse(int maple_port) : SystemMouse("Android", maple_port)
|
||||
{
|
||||
name = "Android Mouse";
|
||||
set_button(DC_BTN_A, 1);
|
||||
set_button(DC_BTN_B, 2);
|
||||
set_button(DC_BTN_START, 4);
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
};
|
||||
|
||||
class AndroidMouseGamepadDevice : public GamepadDevice
|
||||
{
|
||||
public:
|
||||
AndroidMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "Android")
|
||||
{
|
||||
_name = "Mouse";
|
||||
_unique_id = "android_mouse";
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<MouseInputMapping>();
|
||||
}
|
||||
|
||||
bool gamepad_btn_input(u32 code, bool pressed) override
|
||||
{
|
||||
if (gui_is_open() && !is_detecting_input())
|
||||
// Don't register mouse clicks as gamepad presses when gui is open
|
||||
// This makes the gamepad presses to be handled first and the mouse position to be ignored
|
||||
// TODO Make this generic
|
||||
return false;
|
||||
else
|
||||
return GamepadDevice::gamepad_btn_input(code, pressed);
|
||||
}
|
||||
|
||||
virtual const char *get_button_name(u32 code) override
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case 1:
|
||||
return "Left Button";
|
||||
case 2:
|
||||
return "Right Button";
|
||||
case 4:
|
||||
return "Middle Button";
|
||||
case 8:
|
||||
return "Back Button";
|
||||
case 16:
|
||||
return "Forward Button";
|
||||
case 32:
|
||||
return "Stylus Primary";
|
||||
case 64:
|
||||
return "Stylus Second";
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
loadMapping();
|
||||
}
|
||||
};
|
||||
// FIXME Don't connect it by default or any screen touch will register as button A press
|
||||
AndroidMouseGamepadDevice mouse_gamepad(-1);
|
||||
|
||||
|
|
|
@ -97,22 +97,18 @@ class EmuGLView: NSOpenGLView, NSWindowDelegate {
|
|||
}
|
||||
override func mouseDown(with event: NSEvent) {
|
||||
emu_mouse_buttons(1, true)
|
||||
pmo_buttons[0] &= ~(1 << 2)
|
||||
setMousePos(event)
|
||||
}
|
||||
override func mouseUp(with event: NSEvent) {
|
||||
emu_mouse_buttons(1, false)
|
||||
pmo_buttons[0] |= 1 << 2;
|
||||
setMousePos(event)
|
||||
}
|
||||
override func rightMouseDown(with event: NSEvent) {
|
||||
emu_mouse_buttons(2, true)
|
||||
pmo_buttons[0] &= ~(1 << 1)
|
||||
setMousePos(event)
|
||||
}
|
||||
override func rightMouseUp(with event: NSEvent) {
|
||||
emu_mouse_buttons(2, false)
|
||||
pmo_buttons[0] |= 1 << 1
|
||||
setMousePos(event)
|
||||
}
|
||||
// Not dispatched by default. Need to set Window.acceptsMouseMovedEvents to true
|
||||
|
@ -120,21 +116,19 @@ class EmuGLView: NSOpenGLView, NSWindowDelegate {
|
|||
setMousePos(event)
|
||||
}
|
||||
override func mouseDragged(with event: NSEvent) {
|
||||
pmo_buttons[0] &= ~(1 << 2)
|
||||
emu_mouse_buttons(1, true)
|
||||
setMousePos(event)
|
||||
}
|
||||
override func rightMouseDragged(with event: NSEvent) {
|
||||
pmo_buttons[0] &= ~(1 << 1)
|
||||
emu_mouse_buttons(2, true)
|
||||
setMousePos(event)
|
||||
}
|
||||
override func otherMouseDown(with event: NSEvent) {
|
||||
emu_mouse_buttons(3, true)
|
||||
pmo_buttons[0] &= ~(1 << 2)
|
||||
setMousePos(event)
|
||||
}
|
||||
override func otherMouseUp(with event: NSEvent) {
|
||||
emu_mouse_buttons(3, false)
|
||||
pmo_buttons[0] |= 1 << 2
|
||||
setMousePos(event)
|
||||
}
|
||||
override func scrollWheel(with event: NSEvent) {
|
||||
|
|
|
@ -28,7 +28,6 @@ void emu_set_mouse_position(int x, int y, int width, int height);
|
|||
void emu_mouse_wheel(float v);
|
||||
|
||||
bool emu_frame_pending();
|
||||
extern unsigned int *pmo_buttons;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -31,8 +31,7 @@
|
|||
#include "rend/mainui.h"
|
||||
|
||||
static std::shared_ptr<OSXKeyboard> keyboard(0);
|
||||
static std::shared_ptr<OSXMouseGamepadDevice> mouse_gamepad(0);
|
||||
unsigned int *pmo_buttons;
|
||||
static std::shared_ptr<OSXMouse> mouse;
|
||||
static UInt32 keyboardModifiers;
|
||||
|
||||
int darw_printf(const char* text, ...)
|
||||
|
@ -85,8 +84,8 @@ void os_SetupInput()
|
|||
|
||||
keyboard = std::make_shared<OSXKeyboard>(0);
|
||||
GamepadDevice::Register(keyboard);
|
||||
mouse_gamepad = std::make_shared<OSXMouseGamepadDevice>(0);
|
||||
GamepadDevice::Register(mouse_gamepad);
|
||||
mouse = std::make_shared<OSXMouse>();
|
||||
GamepadDevice::Register(mouse);
|
||||
}
|
||||
|
||||
void common_linux_setup();
|
||||
|
@ -139,9 +138,6 @@ int emu_single_frame(int w, int h)
|
|||
|
||||
void emu_gles_init(int width, int height)
|
||||
{
|
||||
// work around https://bugs.swift.org/browse/SR-12263
|
||||
pmo_buttons = mo_buttons;
|
||||
|
||||
char *home = getenv("HOME");
|
||||
if (home != NULL)
|
||||
{
|
||||
|
@ -259,20 +255,32 @@ void emu_character_input(const char *characters) {
|
|||
|
||||
void emu_mouse_buttons(int button, bool pressed)
|
||||
{
|
||||
gui_set_mouse_button(button - 1, pressed);
|
||||
mouse_gamepad->gamepad_btn_input(button, pressed);
|
||||
Mouse::Button dcButton;
|
||||
switch (button) {
|
||||
case 1:
|
||||
dcButton = Mouse::LEFT_BUTTON;
|
||||
break;
|
||||
case 2:
|
||||
dcButton = Mouse::RIGHT_BUTTON;
|
||||
break;
|
||||
case 3:
|
||||
dcButton = Mouse::MIDDLE_BUTTON;
|
||||
break;
|
||||
default:
|
||||
dcButton = Mouse::BUTTON_4;
|
||||
break;
|
||||
}
|
||||
mouse->setButton(dcButton, pressed);
|
||||
}
|
||||
|
||||
void emu_mouse_wheel(float v)
|
||||
{
|
||||
mo_wheel_delta[0] += v;
|
||||
gui_set_mouse_wheel(v);
|
||||
mouse->setWheel((int)v);
|
||||
}
|
||||
|
||||
void emu_set_mouse_position(int x, int y, int width, int height)
|
||||
{
|
||||
gui_set_mouse_position(x, y);
|
||||
SetMousePosition(x, y, width, height);
|
||||
mouse->setAbsPos(x, y, width, height);
|
||||
}
|
||||
|
||||
std::string os_Locale(){
|
||||
|
|
|
@ -7,55 +7,13 @@
|
|||
//
|
||||
#include "input/gamepad_device.h"
|
||||
|
||||
class MouseInputMapping : public InputMapping
|
||||
class OSXMouse : public SystemMouse
|
||||
{
|
||||
public:
|
||||
MouseInputMapping()
|
||||
OSXMouse() : SystemMouse("OSX")
|
||||
{
|
||||
name = "OSX Mouse";
|
||||
set_button(DC_BTN_A, 1); // Left button
|
||||
set_button(DC_BTN_B, 2); // Right button
|
||||
set_button(DC_BTN_START, 3); // Other button
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
};
|
||||
|
||||
class OSXMouseGamepadDevice : public GamepadDevice
|
||||
{
|
||||
public:
|
||||
OSXMouseGamepadDevice(int maple_port) : GamepadDevice(maple_port, "OSX")
|
||||
{
|
||||
_name = "Mouse";
|
||||
_unique_id = "osx_mouse";
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<MouseInputMapping>();
|
||||
}
|
||||
|
||||
bool gamepad_btn_input(u32 code, bool pressed) override
|
||||
{
|
||||
if (gui_is_open() && !is_detecting_input())
|
||||
// Don't register mouse clicks as gamepad presses when gui is open
|
||||
// This makes the gamepad presses to be handled first and the mouse position to be ignored
|
||||
// TODO Make this generic
|
||||
return false;
|
||||
else
|
||||
return GamepadDevice::gamepad_btn_input(code, pressed);
|
||||
}
|
||||
|
||||
virtual const char *get_button_name(u32 code) override
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case 1:
|
||||
return "Left Button";
|
||||
case 2:
|
||||
return "Right Button";
|
||||
case 3:
|
||||
return "Other Button";
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
loadMapping();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -15,8 +15,7 @@ public:
|
|||
{
|
||||
_name = "Keyboard";
|
||||
_unique_id = "osx_keyboard";
|
||||
if (!find_mapping())
|
||||
input_mapper = std::make_shared<KeyboardInputMapping>();
|
||||
loadMapping();
|
||||
|
||||
//04-1D Letter keys A-Z (in alphabetic order)
|
||||
kb_map[kVK_ANSI_A] = 0x04;
|
||||
|
|
Loading…
Reference in New Issue