vgamepad: enable touch mouse when lightgun used

Use unique touch mouse class for iOS and Android.
Enable touch mouse for arcade lightgun games or when maple device A is a
lg. Disable it otherwise.
android: only display controllers that actually send events, including
system mouse and keyboard. Use separate Touch Mouse and System Mouse.
iOS: fix missing button input for touch mouse. Don't bubble up touch
events that hit vgampad buttons or controls.
This commit is contained in:
Flyinghead 2024-12-14 16:18:35 +01:00
parent 421245aeba
commit 20517cf0da
12 changed files with 172 additions and 81 deletions

View File

@ -93,14 +93,22 @@ public:
}
static void Register(const std::shared_ptr<GamepadDevice>& gamepad);
static void Unregister(const std::shared_ptr<GamepadDevice>& gamepad);
static int GetGamepadCount();
static std::shared_ptr<GamepadDevice> GetGamepad(int index);
static void SaveMaplePorts();
static void RampAnalog();
template<typename T>
static std::shared_ptr<T> GetGamepad()
{
Lock _(_gamepads_mutex);
for (const auto& gamepad : _gamepads)
if (dynamic_cast<T*>(gamepad.get()) != nullptr)
return std::dynamic_pointer_cast<T>(gamepad);
return {};
}
static void load_system_mappings();
bool find_mapping(int system = settings.platform.system);
virtual void resetMappingToDefault(bool arcade, bool gamepad) {

View File

@ -104,3 +104,15 @@ public:
void setButton(Button button, bool pressed);
void setWheel(int delta);
};
class TouchMouse : public SystemMouse
{
public:
TouchMouse() : SystemMouse("Flycast", -1)
{
_name = "Touch Mouse";
_unique_id = "touch_mouse";
loadMapping();
}
};

View File

@ -30,6 +30,7 @@
#include "oslib/resources.h"
#include "cfg/cfg.h"
#include "input/gamepad.h"
#include "input/mouse.h"
#include "hw/naomi/naomi_cart.h"
#include "hw/naomi/card_reader.h"
#include "hw/maple/maple_devs.h"
@ -710,6 +711,7 @@ void startGame()
enableAllControls();
serviceMode = false;
setButtonMap();
bool enableTouchMouse = false;
if (settings.platform.isConsole())
{
disableControl(Btn4);
@ -719,7 +721,7 @@ void startGame()
switch (config::MapleMainDevices[0])
{
case MDT_LightGun:
// TODO enable mouse?
enableTouchMouse = true;
disableControl(AnalogArea);
disableControl(LeftTrigger);
disableControl(RightTrigger);
@ -878,12 +880,14 @@ void startGame()
if ((usedButtons & NAOMI_START_KEY) == 0)
disableControl(Start);
}
if (settings.input.lightgunGame)
enableTouchMouse = true;
}
else
{
if (settings.input.lightgunGame)
{
// TODO enable mouse?
enableTouchMouse = true;
disableControl(A);
disableControl(X);
disableControl(Y);
@ -906,6 +910,18 @@ void startGame()
}
}
}
std::shared_ptr<TouchMouse> touchMouse = GamepadDevice::GetGamepad<TouchMouse>();
if (touchMouse != nullptr)
{
if (enableTouchMouse) {
if (touchMouse->maple_port() == -1)
touchMouse->set_maple_port(0);
}
else {
if (touchMouse->maple_port() == 0)
touchMouse->set_maple_port(-1);
}
}
}
void resetEditing() {

View File

@ -269,7 +269,7 @@ public abstract class BaseGLActivity extends Activity implements ActivityCompat.
private boolean processJoystickInput(MotionEvent event, int axis) {
float v = event.getAxisValue(axis);
return InputDeviceManager.getInstance().joystickAxisEvent(event.getDeviceId(), axis, (int)Math.round(v * 32767.f));
return InputDeviceManager.getInstance().axisEvent(event.getDeviceId(), axis, (int)Math.round(v * 32767.f));
}
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
@ -283,29 +283,29 @@ public abstract class BaseGLActivity extends Activity implements ActivityCompat.
if (range.getAxis() == MotionEvent.AXIS_HAT_X) {
float v = event.getAxisValue(MotionEvent.AXIS_HAT_X);
if (v == -1.0) {
rc |= InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_LEFT, true);
InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_RIGHT, false);
rc |= InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_LEFT, true);
InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_RIGHT, false);
}
else if (v == 1.0) {
InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_LEFT, false);
rc |= InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_RIGHT, true);
InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_LEFT, false);
rc |= InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_RIGHT, true);
} else {
InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_LEFT, false);
InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_RIGHT, false);
InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_LEFT, false);
InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_RIGHT, false);
}
}
else if (range.getAxis() == MotionEvent.AXIS_HAT_Y) {
float v = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
if (v == -1.0) {
rc |= InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_UP, true);
InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_DOWN, false);
rc |= InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_UP, true);
InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_DOWN, false);
}
else if (v == 1.0) {
InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_UP, false);
rc |= InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_DOWN, true);
InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_UP, false);
rc |= InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_DOWN, true);
} else {
InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_UP, false);
InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_DOWN, false);
InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_UP, false);
InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), KeyEvent.KEYCODE_DPAD_DOWN, false);
}
}
else
@ -329,7 +329,7 @@ public abstract class BaseGLActivity extends Activity implements ActivityCompat.
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), keyCode, false))
if (InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), keyCode, false))
return true;
if (hasKeyboard && InputDeviceManager.getInstance().keyboardEvent(keyCode, false))
return true;
@ -348,7 +348,7 @@ public abstract class BaseGLActivity extends Activity implements ActivityCompat.
}
return true;
}
if (InputDeviceManager.getInstance().joystickButtonEvent(event.getDeviceId(), keyCode, true))
if (InputDeviceManager.getInstance().buttonEvent(event.getDeviceId(), keyCode, true))
return true;
if (hasKeyboard) {

View File

@ -74,7 +74,7 @@ public class VirtualJoystickDelegate implements TouchEventHandler
case MotionEvent.ACTION_CANCEL:
mousePid = -1;
mouseButtons = 0;
InputDeviceManager.getInstance().mouseEvent(mousePos[0], mousePos[1], mouseButtons);
InputDeviceManager.getInstance().touchMouseEvent(mousePos[0], mousePos[1], mouseButtons);
return true;
case MotionEvent.ACTION_POINTER_DOWN:
@ -85,7 +85,7 @@ public class VirtualJoystickDelegate implements TouchEventHandler
mousePos[0] = Math.round(event.getX(actionIndex));
mousePos[1] = Math.round(event.getY(actionIndex));
mouseButtons = MotionEvent.BUTTON_PRIMARY; // Mouse left button down
InputDeviceManager.getInstance().mouseEvent(mousePos[0], mousePos[1], mouseButtons);
InputDeviceManager.getInstance().touchMouseEvent(mousePos[0], mousePos[1], mouseButtons);
return true;
}
return false;
@ -96,7 +96,7 @@ public class VirtualJoystickDelegate implements TouchEventHandler
if (event.getPointerId(i) == mousePid) {
mousePos[0] = Math.round(event.getX(i));
mousePos[1] = Math.round(event.getY(i));
InputDeviceManager.getInstance().mouseEvent(mousePos[0], mousePos[1], mouseButtons);
InputDeviceManager.getInstance().touchMouseEvent(mousePos[0], mousePos[1], mouseButtons);
break;
}
}
@ -108,7 +108,7 @@ public class VirtualJoystickDelegate implements TouchEventHandler
mousePos[0] = Math.round(event.getX(actionIndex));
mousePos[1] = Math.round(event.getY(actionIndex));
mouseButtons = 0;
InputDeviceManager.getInstance().mouseEvent(mousePos[0], mousePos[1], mouseButtons);
InputDeviceManager.getInstance().touchMouseEvent(mousePos[0], mousePos[1], mouseButtons);
return true;
}
break;
@ -168,7 +168,7 @@ public class VirtualJoystickDelegate implements TouchEventHandler
// Release the mouse too
mousePid = -1;
mouseButtons = 0;
InputDeviceManager.getInstance().mouseEvent(mousePos[0], mousePos[1], mouseButtons);
InputDeviceManager.getInstance().touchMouseEvent(mousePos[0], mousePos[1], mouseButtons);
// Then fall through
case MotionEvent.ACTION_POINTER_DOWN:
{

View File

@ -11,8 +11,10 @@ import com.flycast.emulator.Emulator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
@ -32,6 +34,7 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
long stopTime;
}
private Map<Integer, VibrationParams> vibParams = new HashMap<>();
private Set<Integer> knownDevices = new HashSet<>();
public InputDeviceManager()
{
@ -45,9 +48,6 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
if (hasTouchscreen)
joystickAdded(VIRTUAL_GAMEPAD_ID, null, 0, null,
null, null, getVibrator(VIRTUAL_GAMEPAD_ID) != null);
int[] ids = InputDevice.getDeviceIds();
for (int id : ids)
onInputDeviceAdded(id);
inputManager = (InputManager)applicationContext.getSystemService(Context.INPUT_SERVICE);
inputManager.registerInputDeviceListener(this, null);
}
@ -63,25 +63,6 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
@Override
public void onInputDeviceAdded(int i) {
InputDevice device = InputDevice.getDevice(i);
if (device != null && (device.getSources() & InputDevice.SOURCE_CLASS_BUTTON) == InputDevice.SOURCE_CLASS_BUTTON) {
int port = 0;
if ((device.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) {
port = this.maple_port == 3 ? 3 : this.maple_port++;
}
List<InputDevice.MotionRange> axes = device.getMotionRanges();
List<Integer> fullAxes = new ArrayList<>();
List<Integer> halfAxes = new ArrayList<>();
for (InputDevice.MotionRange range : axes) {
if (range.getMin() == 0)
halfAxes.add(range.getAxis());
else
fullAxes.add(range.getAxis());
}
joystickAdded(i, device.getName(), port, device.getDescriptor(),
ArrayUtils.toPrimitive(fullAxes.toArray(new Integer[0])), ArrayUtils.toPrimitive(halfAxes.toArray(new Integer[0])),
getVibrator(i) != null);
}
}
@Override
@ -89,6 +70,7 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
if (maple_port > 0)
maple_port--;
joystickRemoved(i);
knownDevices.remove(i);
}
@Override
@ -209,6 +191,47 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
return hasTouchscreen;
}
private boolean createDevice(int id)
{
if (id == 0)
return false;
if (knownDevices.contains(id))
return true;
InputDevice device = InputDevice.getDevice(id);
if (device == null || (device.getSources() & InputDevice.SOURCE_CLASS_BUTTON) != InputDevice.SOURCE_CLASS_BUTTON)
return false;
int port = 0;
if ((device.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) {
port = this.maple_port == 3 ? 3 : this.maple_port++;
}
List<InputDevice.MotionRange> axes = device.getMotionRanges();
List<Integer> fullAxes = new ArrayList<>();
List<Integer> halfAxes = new ArrayList<>();
for (InputDevice.MotionRange range : axes) {
if (range.getMin() == 0)
halfAxes.add(range.getAxis());
else
fullAxes.add(range.getAxis());
}
joystickAdded(id, device.getName(), port, device.getDescriptor(),
ArrayUtils.toPrimitive(fullAxes.toArray(new Integer[0])), ArrayUtils.toPrimitive(halfAxes.toArray(new Integer[0])),
getVibrator(id) != null);
knownDevices.add(id);
return true;
}
public boolean buttonEvent(int id, int button, boolean pressed)
{
if (!createDevice(id))
return false;
return joystickButtonEvent(id, button, pressed);
}
public boolean axisEvent(int id, int button, int value)
{
if (!createDevice(id))
return false;
return joystickAxisEvent(id, button, value);
}
public static InputDeviceManager getInstance() {
return INSTANCE;
}
@ -217,10 +240,11 @@ public final class InputDeviceManager implements InputManager.InputDeviceListene
public native void virtualReleaseAll();
public native void virtualJoystick(float x, float y);
public native void virtualButtonInput(int key, boolean pressed);
public native boolean joystickButtonEvent(int id, int button, boolean pressed);
public native boolean joystickAxisEvent(int id, int button, int value);
private native boolean joystickButtonEvent(int id, int button, boolean pressed);
private native boolean joystickAxisEvent(int id, int button, int value);
public native void mouseEvent(int xpos, int ypos, int buttons);
public native void mouseScrollEvent(int scrollValue);
public native void touchMouseEvent(int xpos, int ypos, int buttons);
private native void joystickAdded(int id, String name, int maple_port, String uniqueId, int[] fullAxes, int[] halfAxes, boolean rumbleEnabled);
private native void joystickRemoved(int id);
public native boolean keyboardEvent(int key, boolean pressed);

View File

@ -17,6 +17,7 @@
#endif
#include "jni_util.h"
#include "android_storage.h"
#include "http_client.h"
#include <android/log.h>
#include <android/native_window.h>
@ -35,8 +36,6 @@ namespace jni
thread_local JVMAttacher jvm_attacher;
}
#include "http_client.h"
extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_emu_JNIdc_screenCharacteristics(JNIEnv *env, jobject obj, jfloat screenDpi, jfloat refreshRate)
{
settings.display.dpi = screenDpi;

View File

@ -411,7 +411,7 @@ public:
class AndroidVirtualGamepad : public VirtualGamepad
{
public:
AndroidVirtualGamepad(bool rumbleEnabled) : VirtualGamepad("Android") {
AndroidVirtualGamepad(bool rumbleEnabled) : VirtualGamepad("Flycast") {
this->rumbleEnabled = rumbleEnabled;
}

View File

@ -23,6 +23,7 @@
#include "hw/maple/maple_if.h"
std::shared_ptr<AndroidMouse> mouse;
std::shared_ptr<TouchMouse> touchMouse;
std::shared_ptr<AndroidKeyboard> keyboard;
std::shared_ptr<AndroidVirtualGamepad> virtualGamepad;
@ -96,11 +97,6 @@ extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_periph_InputDeviceMa
{
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);
keyboard = std::make_shared<AndroidKeyboard>();
GamepadDevice::Register(keyboard);
gui_setOnScreenKeyboardCallback([](bool show) {
if (g_activity != nullptr)
jni::env()->CallVoidMethod(g_activity, showScreenKeyboardMid, show);
@ -110,9 +106,14 @@ extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_periph_InputDeviceMa
extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_periph_InputDeviceManager_joystickAdded(JNIEnv *env, jobject obj,
jint id, jstring name, jint maple_port, jstring junique_id, jintArray fullAxes, jintArray halfAxes, jboolean hasRumble)
{
if (id == AndroidVirtualGamepad::GAMEPAD_ID) {
if (id == 0)
return;
if (id == AndroidVirtualGamepad::GAMEPAD_ID)
{
virtualGamepad = std::make_shared<AndroidVirtualGamepad>(hasRumble);
GamepadDevice::Register(virtualGamepad);
touchMouse = std::make_shared<TouchMouse>();
GamepadDevice::Register(touchMouse);
}
else
{
@ -130,9 +131,12 @@ extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_periph_InputDeviceMa
extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_periph_InputDeviceManager_joystickRemoved(JNIEnv *env, jobject obj,
jint id)
{
if (id == AndroidVirtualGamepad::GAMEPAD_ID) {
if (id == AndroidVirtualGamepad::GAMEPAD_ID)
{
GamepadDevice::Unregister(virtualGamepad);
virtualGamepad.reset();
GamepadDevice::Unregister(touchMouse);
touchMouse.reset();
}
else {
std::shared_ptr<AndroidGamepadDevice> device = AndroidGamepadDevice::GetAndroidGamepad(id);
@ -169,7 +173,12 @@ extern "C" JNIEXPORT jboolean JNICALL Java_com_flycast_emulator_periph_InputDevi
}
extern "C" JNIEXPORT jboolean JNICALL Java_com_flycast_emulator_periph_InputDeviceManager_keyboardEvent(JNIEnv *env, jobject obj,
jint key, jboolean pressed) {
jint key, jboolean pressed)
{
if (keyboard == nullptr) {
keyboard = std::make_shared<AndroidKeyboard>();
GamepadDevice::Register(keyboard);
}
keyboard->input(key, pressed);
return true;
}
@ -191,9 +200,18 @@ extern "C" JNIEXPORT jboolean JNICALL Java_com_flycast_emulator_periph_InputDevi
return false;
}
static void createMouse()
{
if (mouse == nullptr) {
mouse = std::make_shared<AndroidMouse>(touchMouse == nullptr ? 0 : 1);
GamepadDevice::Register(mouse);
}
}
extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_periph_InputDeviceManager_mouseEvent(JNIEnv *env, jobject obj,
jint xpos, jint ypos, jint buttons)
{
createMouse();
mouse->setAbsPos(xpos, ypos, settings.display.width, settings.display.height);
mouse->setButton(Mouse::LEFT_BUTTON, (buttons & 1) != 0);
mouse->setButton(Mouse::RIGHT_BUTTON, (buttons & 2) != 0);
@ -201,6 +219,17 @@ extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_periph_InputDeviceMa
}
extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_periph_InputDeviceManager_mouseScrollEvent(JNIEnv *env, jobject obj,
jint scrollValue) {
jint scrollValue)
{
createMouse();
mouse->setWheel(scrollValue);
}
extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_periph_InputDeviceManager_touchMouseEvent(JNIEnv *env, jobject obj,
jint xpos, jint ypos, jint buttons)
{
touchMouse->setAbsPos(xpos, ypos, settings.display.width, settings.display.height);
touchMouse->setButton(Mouse::LEFT_BUTTON, (buttons & 1) != 0);
touchMouse->setButton(Mouse::RIGHT_BUTTON, (buttons & 2) != 0);
touchMouse->setButton(Mouse::MIDDLE_BUTTON, (buttons & 4) != 0);
}

View File

@ -24,13 +24,13 @@
#include "ios_gamepad.h"
@implementation EmulatorView {
std::shared_ptr<IOSTouchMouse> mouse;
std::shared_ptr<TouchMouse> mouse;
}
- (void)didMoveToSuperview
{
[super didMoveToSuperview];
mouse = std::make_shared<IOSTouchMouse>();
mouse = std::make_shared<TouchMouse>();
GamepadDevice::Register(mouse);
}
@ -45,8 +45,7 @@
{
UITouch *touch = [touches anyObject];
[self touchLocation:touch];
if (gui_is_open())
mouse->setButton(Mouse::LEFT_BUTTON, true);
mouse->setButton(Mouse::LEFT_BUTTON, true);
[super touchesBegan:touches withEvent:event];
}
@ -54,8 +53,7 @@
{
UITouch *touch = [touches anyObject];
[self touchLocation:touch];
if (gui_is_open())
mouse->setButton(Mouse::LEFT_BUTTON, false);
mouse->setButton(Mouse::LEFT_BUTTON, false);
[super touchesEnded:touches withEvent:event];
}

View File

@ -106,6 +106,7 @@ static CGPoint translateCoords(const CGPoint& pos, const CGSize& size)
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
{
bool forwardEvent = true;
[self startHideTimer];
for (UITouch *touch in touches)
{
@ -117,6 +118,7 @@ static CGPoint translateCoords(const CGPoint& pos, const CGSize& size)
[self resetAnalog];
joyTouch = touch;
joyBias = point;
forwardEvent = false;
continue;
}
NSValue *key = [NSValue valueWithPointer:(const void *)touch];
@ -126,17 +128,21 @@ static CGPoint translateCoords(const CGPoint& pos, const CGSize& size)
touchToButton[key] = [NSNumber numberWithInt:control];
// button down
virtualGamepad->buttonInput(control, true);
forwardEvent = false;
}
}
[super touchesBegan:touches withEvent:event];
if (forwardEvent)
[super touchesBegan:touches withEvent:event];
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
{
bool forwardEvent = true;
for (UITouch *touch in touches)
{
if (touch == joyTouch) {
[self resetAnalog];
forwardEvent = false;
continue;
}
NSValue *key = [NSValue valueWithPointer:(const void *)touch];
@ -145,13 +151,16 @@ static CGPoint translateCoords(const CGPoint& pos, const CGSize& size)
[touchToButton removeObjectForKey:key];
// button up
virtualGamepad->buttonInput(static_cast<vgamepad::ControlId>(control.intValue), false);
forwardEvent = false;
}
}
[super touchesEnded:touches withEvent:event];
if (forwardEvent)
[super touchesEnded:touches withEvent:event];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
{
bool forwardEvent = true;
[self startHideTimer];
for (UITouch *touch in touches)
{
@ -165,6 +174,7 @@ static CGPoint translateCoords(const CGPoint& pos, const CGSize& size)
point.x = std::max<CGFloat>(std::min<CGFloat>(1.0, point.x / sz), -1.0);
point.y = std::max<CGFloat>(std::min<CGFloat>(1.0, point.y / sz), -1.0);
virtualGamepad->joystickInput(point.x, point.y);
forwardEvent = false;
continue;
}
vgamepad::ControlId control = vgamepad::hitTest(point.x, point.y);
@ -179,15 +189,19 @@ static CGPoint translateCoords(const CGPoint& pos, const CGSize& size)
// button down
virtualGamepad->buttonInput(control, true);
touchToButton[key] = [NSNumber numberWithInt:control];
forwardEvent = false;
}
[super touchesMoved:touches withEvent:event];
if (forwardEvent)
[super touchesMoved:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event;
{
bool forwardEvent = true;
for (UITouch *touch in touches) {
if (touch == joyTouch) {
[self resetAnalog];
forwardEvent = false;
continue;
}
NSValue *key = [NSValue valueWithPointer:(const void *)touch];
@ -196,8 +210,10 @@ static CGPoint translateCoords(const CGPoint& pos, const CGSize& size)
[touchToButton removeObjectForKey:key];
// button up
virtualGamepad->buttonInput(static_cast<vgamepad::ControlId>(control.intValue), false);
forwardEvent = false;
}
}
[super touchesCancelled:touches withEvent:event];
if (forwardEvent)
[super touchesCancelled:touches withEvent:event];
}
@end

View File

@ -506,14 +506,3 @@ public:
return false;
}
};
class IOSTouchMouse : public SystemMouse
{
public:
IOSTouchMouse() : SystemMouse("iOS")
{
_unique_id = "ios_mouse";
_name = "Touchscreen (Mouse)";
loadMapping();
}
};