Switch to new Touch interface for SFML
Some checks failed
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linux32 flags:32 name:Linux GCC 32 os:ubuntu-latest]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linux64 flags:64 name:Linux GCC x64 os:ubuntu-latest]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linuxarm32 flags:arm32 name:Linux GCC ARM 32 os:ubuntu-latest]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linuxarm64 flags:arm64 name:Linux GCC ARM 64 os:ubuntu-latest]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:macos name:macOS Apple Silicon os:macos-14]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:win32 flags:-A Win32 -DCMAKE_PARALLEL_MSVC=TRUE name:Windows VS2022 Win32 os:windows-2022]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:win64 flags:-A x64 -DCMAKE_PARALLEL_MSVC=TRUE name:Windows VS2022 x64 os:windows-2022]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:winarm64 flags:-A ARM64 -DCMAKE_PARALLEL_MSVC=TRUE name:Windows VS2022 ARM os:windows-2022]) (push) Has been cancelled
CD / Create Pi Mono Setup (push) Has been cancelled
CD / Publishing (push) Has been cancelled

This commit is contained in:
Lorenzooone
2026-01-24 18:14:53 +01:00
parent cb820ac204
commit 4bfc14dc1c
2 changed files with 29 additions and 2 deletions

View File

@@ -47,6 +47,11 @@
#include "event_structs.hpp"
#include "shaders_list.hpp"
// SFML currently does not have a define for the maximum amount of fingers...
// Make one to "fix this", though it will need code to reject extra
// fingers... :/ What a mess.
#define NUM_FINGERS_SUPPORTED 10
struct HeldTime {
std::chrono::time_point<std::chrono::high_resolution_clock> start_time;
bool started;
@@ -161,6 +166,8 @@ private:
HeldTime right_click_action;
HeldTime controller_button_action;
bool consumed_touch_long_press;
bool is_touch_currently_active[NUM_FINGERS_SUPPORTED];
sf::Vector2i touch_position[NUM_FINGERS_SUPPORTED];
const float touch_short_press_timer = 0.2f;
const float touch_long_press_timer = 1.5f;
const float mouse_timeout = 5.0f;

View File

@@ -97,8 +97,12 @@ static double FPSArrayGetAverage(FPSArray *array) {
}
void WindowScreen::init_menus() {
for(int i = 0; i < NUM_FINGERS_SUPPORTED; i++)
this->is_touch_currently_active[i] = false;
this->last_menu_change_time = std::chrono::high_resolution_clock::now();
this->last_data_format_change_time = std::chrono::high_resolution_clock::now();
this->connection_menu = new ConnectionMenu(this->text_rectangle_pool);
this->main_menu = new MainMenu(this->text_rectangle_pool);
this->video_menu = new VideoMenu(this->text_rectangle_pool);
@@ -2641,6 +2645,20 @@ void WindowScreen::poll_window(bool do_everything) {
if(this->shared_data->input_data.enable_mouse_input)
events_queue.emplace(mouse_movement->position);
}
else if(const auto* touch_began = event->getIf<sf::Event::TouchBegan>()) {
if(touch_began->finger < NUM_FINGERS_SUPPORTED) {
this->is_touch_currently_active[touch_began->finger] = true;
this->touch_position[touch_began->finger] = touch_began->position;
}
}
else if(const auto* touch_moved = event->getIf<sf::Event::TouchMoved>()) {
if(touch_moved->finger < NUM_FINGERS_SUPPORTED)
this->touch_position[touch_moved->finger] = touch_moved->position;
}
else if(const auto* touch_ended = event->getIf<sf::Event::TouchEnded>()) {
if(touch_ended->finger < NUM_FINGERS_SUPPORTED)
this->is_touch_currently_active[touch_ended->finger] = false;
}
}
}
if(this->m_win.hasFocus()) {
@@ -2658,11 +2676,11 @@ void WindowScreen::poll_window(bool do_everything) {
}
if(!found)
check_held_reset(false, this->controller_button_action);
bool touch_active = sf::Touch::isDown(0);
bool touch_active = this->is_touch_currently_active[0];
check_held_reset(touch_active, this->touch_action);
check_held_reset(touch_active, this->touch_right_click_action);
if(touch_active) {
sf::Vector2i touch_pos = sf::Touch::getPosition(0, this->m_win);
sf::Vector2i touch_pos = this->touch_position[0];
auto curr_time = std::chrono::high_resolution_clock::now();
const std::chrono::duration<double> diff = curr_time - this->touch_right_click_action.start_time;
if(diff.count() > this->touch_long_press_timer) {
@@ -2687,6 +2705,8 @@ void WindowScreen::poll_window(bool do_everything) {
}
}
else {
for(int i = 0; i < NUM_FINGERS_SUPPORTED; i++)
this->is_touch_currently_active[i] = false;
this->reset_held_times();
check_held_reset(false, this->touch_right_click_action);
}