Implement basic Touch support for Android

This commit is contained in:
Lorenzooone
2024-05-10 23:35:15 +02:00
parent 0d46e82331
commit b48ec6cf17
4 changed files with 34 additions and 7 deletions

View File

@@ -81,7 +81,7 @@ On MacOS, you may also be prompted to install the Apple Command Line Developer T
- __7 key__: In Joint Fullscreen mode, changes the distance from the upper screen between 0, 1/2 Max and Max.
- __I key__: Toggles BFI (Motion Blur Reduction) on/off. Best used on 120+hz monitors. DO NOT USE THIS IF YOU'RE AT RISK OF SEIZURES!!!
- __Z key__: Decreases the Menu Scaling multiplier by 0.1. 0.3 is the minimum.
- __X key__: Increases the Menu Scaling multiplier by 0.1. 5.0 is the maximum.
- __X key__: Increases the Menu Scaling multiplier by 0.1. 10.0 is the maximum.
- __R key__: Toggles extra padding on/off. It can be used to account for windows with rounded corners.
- __2 key__: Changes the Pixel Aspect Ratio (PAR) for the top screen.
- __3 key__: Changes the Pixel Aspect Ratio (PAR) for the bottom screen.

View File

@@ -67,6 +67,10 @@ private:
std::mutex* events_access;
std::chrono::time_point<std::chrono::high_resolution_clock> last_mouse_action_time;
std::chrono::time_point<std::chrono::high_resolution_clock> last_window_creation_time;
std::chrono::time_point<std::chrono::high_resolution_clock> start_touch_action_time;
bool active_touch;
bool consumed_touch_long_press;
const float touch_long_press_timer = 1.5f;
const float mouse_timeout = 5.0f;
const float v_sync_timeout = 5.0f;
CurrMenuType curr_menu = DEFAULT_MENU_TYPE;

View File

@@ -41,6 +41,9 @@ WindowScreen::WindowScreen(ScreenType stype, CaptureStatus* capture_status, Disp
this->audio_data = audio_data;
this->last_window_creation_time = std::chrono::high_resolution_clock::now();
this->last_mouse_action_time = std::chrono::high_resolution_clock::now();
this->start_touch_action_time = std::chrono::high_resolution_clock::now();
this->active_touch = false;
this->consumed_touch_long_press = false;
WindowScreen::reset_operations(future_operations);
this->done_display = true;
this->saved_buf = new VideoOutputData;
@@ -139,8 +142,8 @@ bool WindowScreen::common_poll(SFEvent &event_data) {
case 'x':
old_scaling = this->m_info.menu_scaling_factor;
this->m_info.menu_scaling_factor += 0.1;
if(this->m_info.menu_scaling_factor > 4.95)
this->m_info.menu_scaling_factor = 5.0;
if(this->m_info.menu_scaling_factor > 9.95)
this->m_info.menu_scaling_factor = 10.0;
if(old_scaling != this->m_info.menu_scaling_factor) {
this->print_notification_float("Menu Scaling", this->m_info.menu_scaling_factor, 1);
}
@@ -781,8 +784,28 @@ void WindowScreen::poll_window() {
}
events_queue.emplace(event.type, event.key.code, event.text.unicode, joystickId, event.joystickButton.button, event.joystickMove.axis, 0.0, event.mouseButton.button, mouse_x, mouse_y);
}
if(this->m_win.hasFocus())
if(this->m_win.hasFocus()) {
if(sf::Touch::isDown(0)) {
sf::Vector2i touch_pos = sf::Touch::getPosition(0, this->m_win);
if(!this->active_touch) {
this->start_touch_action_time = std::chrono::high_resolution_clock::now();
this->active_touch = true;
}
else {
auto curr_time = std::chrono::high_resolution_clock::now();
const std::chrono::duration<double> diff = curr_time - this->start_touch_action_time;
if(diff.count() > this->touch_long_press_timer) {
events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Right, touch_pos.x, touch_pos.y);
this->start_touch_action_time = std::chrono::high_resolution_clock::now();
}
}
events_queue.emplace(sf::Event::MouseButtonPressed, sf::Keyboard::Backspace, 0, 0, 0, sf::Joystick::Axis::X, 0.0, sf::Mouse::Left, touch_pos.x, touch_pos.y);
}
else
this->active_touch = false;
joystick_axis_poll(this->events_queue);
}
this->events_access->unlock();
}
}

View File

@@ -117,8 +117,8 @@ bool load_screen_info(std::string key, std::string value, std::string base, Scre
info.menu_scaling_factor = std::stod(value);
if(info.menu_scaling_factor < 0.3)
info.menu_scaling_factor = 0.3;
if(info.menu_scaling_factor > 5.0)
info.menu_scaling_factor = 5.0;
if(info.menu_scaling_factor > 10.0)
info.menu_scaling_factor = 10.0;
return true;
}
if(key == (base + "rounded_corners_fix")) {
@@ -227,7 +227,7 @@ JoystickAction get_joystick_action(uint32_t joystickId, uint32_t joy_button) {
return JOY_ACTION_CONFIRM;
if((joy_button == 2) || (joy_button == 3))
return JOY_ACTION_NEGATE;
if((joy_button == 4) || (joy_button == 5))
if((joy_button == 6) || (joy_button == 7))
return JOY_ACTION_MENU;
return JOY_ACTION_NONE;
}