mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-12-27 19:25:58 +00:00
EmuWindow: Added infrastructure code to enable touchpad support.
This commit is contained in:
parent
1a904ded40
commit
543232436f
|
@ -5,6 +5,8 @@
|
|||
#include "emu_window.h"
|
||||
#include "video_core/video_core.h"
|
||||
|
||||
bool EmuWindow::touch_pressed = false;
|
||||
|
||||
void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) {
|
||||
Service::HID::PadState mapped_key = KeyMap::GetPadKey(key);
|
||||
|
||||
|
@ -17,7 +19,68 @@ void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
|
|||
Service::HID::PadButtonRelease(mapped_key);
|
||||
}
|
||||
|
||||
EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, unsigned height) {
|
||||
/**
|
||||
* Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout
|
||||
* @param layout FramebufferLayout object describing the framebuffer size and screen positions
|
||||
* @param framebuffer_x Framebuffer x-coordinate to check
|
||||
* @param framebuffer_y Framebuffer y-coordinate to check
|
||||
* @return True if the coordinates are within the touchpad, otherwise false
|
||||
*/
|
||||
static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x,
|
||||
unsigned framebuffer_y) {
|
||||
|
||||
return (framebuffer_y >= layout.bottom_screen.top &&
|
||||
framebuffer_y < layout.bottom_screen.bottom &&
|
||||
framebuffer_x >= layout.bottom_screen.left &&
|
||||
framebuffer_x < layout.bottom_screen.right);
|
||||
}
|
||||
|
||||
void EmuWindow::TouchPressed(const FramebufferLayout& layout, unsigned framebuffer_x,
|
||||
unsigned framebuffer_y) {
|
||||
|
||||
if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) {
|
||||
u16 touch_x = VideoCore::kScreenBottomWidth * (framebuffer_x - layout.bottom_screen.left) /
|
||||
(layout.bottom_screen.right - layout.bottom_screen.left);
|
||||
u16 touch_y = VideoCore::kScreenBottomHeight * (framebuffer_y - layout.bottom_screen.top) /
|
||||
(layout.bottom_screen.bottom - layout.bottom_screen.top);
|
||||
|
||||
Service::HID::TouchPress(touch_x, touch_y);
|
||||
Service::HID::TouchUpdateComplete();
|
||||
|
||||
touch_pressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void EmuWindow::TouchReleased(const FramebufferLayout& layout, unsigned framebuffer_x,
|
||||
unsigned framebuffer_y) {
|
||||
|
||||
if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) {
|
||||
|
||||
Service::HID::TouchRelease();
|
||||
Service::HID::TouchUpdateComplete();
|
||||
|
||||
touch_pressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
void EmuWindow::TouchMoved(const FramebufferLayout& layout, unsigned framebuffer_x,
|
||||
unsigned framebuffer_y) {
|
||||
|
||||
if (touch_pressed) {
|
||||
if (IsWithinTouchscreen(layout, framebuffer_x, framebuffer_y)) {
|
||||
EmuWindow::TouchPressed(layout, framebuffer_x, framebuffer_y);
|
||||
} else {
|
||||
Service::HID::TouchRelease();
|
||||
Service::HID::TouchUpdateComplete();
|
||||
|
||||
touch_pressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width,
|
||||
unsigned height) {
|
||||
|
||||
ASSERT(width > 0);
|
||||
ASSERT(height > 0);
|
||||
|
||||
|
|
|
@ -76,6 +76,33 @@ public:
|
|||
/// Signals a key release action to the HID module
|
||||
static void KeyReleased(KeyMap::HostDeviceKey key);
|
||||
|
||||
/**
|
||||
* Signal that a touch pressed event has occurred (e.g. mouse click pressed)
|
||||
* @param layout FramebufferLayout object describing the framebuffer size and screen positions
|
||||
* @param framebuffer_x Framebuffer x-coordinate that was pressed
|
||||
* @param framebuffer_y Framebuffer y-coordinate that was pressed
|
||||
*/
|
||||
static void TouchPressed(const FramebufferLayout& layout, unsigned framebuffer_x,
|
||||
unsigned framebuffer_y);
|
||||
|
||||
/**
|
||||
* Signal that a touch released event has occurred (e.g. mouse click released)
|
||||
* @param layout FramebufferLayout object describing the framebuffer size and screen positions
|
||||
* @param framebuffer_x Framebuffer x-coordinate that was released
|
||||
* @param framebuffer_y Framebuffer y-coordinate that was released
|
||||
*/
|
||||
static void TouchReleased(const FramebufferLayout& layout, unsigned framebuffer_x,
|
||||
unsigned framebuffer_y);
|
||||
|
||||
/**
|
||||
* Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window)
|
||||
* @param layout FramebufferLayout object describing the framebuffer size and screen positions
|
||||
* @param framebuffer_x Framebuffer x-coordinate
|
||||
* @param framebuffer_y Framebuffer y-coordinate
|
||||
*/
|
||||
static void TouchMoved(const FramebufferLayout& layout, unsigned framebuffer_x,
|
||||
unsigned framebuffer_y);
|
||||
|
||||
/**
|
||||
* Returns currently active configuration.
|
||||
* @note Accesses to the returned object need not be consistent because it may be modified in another thread
|
||||
|
@ -168,4 +195,6 @@ private:
|
|||
|
||||
WindowConfig config; ///< Internal configuration (changes pending for being applied in ProcessConfigurationChanges)
|
||||
WindowConfig active_config; ///< Internal active configuration
|
||||
|
||||
static bool touch_pressed; ///< True if touchpad area is currently pressed, otherwise false
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue