From b2443410a0a67d5fd7454864512b8fc3987a35ed Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Tue, 4 Nov 2025 20:38:53 +0100 Subject: [PATCH] Add Pen event handler stub. This is a fallback for platforms that don't support pens and tablets yet. --- FL/core/pen_events.H | 56 ++++++++++++----- src/CMakeLists.txt | 4 ++ src/drivers/Stubs/Fl_Stubs_Pen_Events.cxx | 73 +++++++++++++++++++++++ 3 files changed, 117 insertions(+), 16 deletions(-) create mode 100644 src/drivers/Stubs/Fl_Stubs_Pen_Events.cxx diff --git a/FL/core/pen_events.H b/FL/core/pen_events.H index 901cafe69..b5746cb4f 100644 --- a/FL/core/pen_events.H +++ b/FL/core/pen_events.H @@ -59,6 +59,8 @@ namespace Pen { If a bit is clear, the corresponding event value will not be set. */ enum Features : uint32_t { + /// Return this if this implementation of FLTK does not support pens and tablets. + NONE = 0x0000, /// Set if FLTK supports tablets and pens on this platform SUPPORTED = 0x0001, /// Set if the system found a pen and/or tablet device @@ -362,43 +364,65 @@ FL_EXPORT extern State event_trigger(); } // namespace Fl /** - * \brief Bitwise OR operator for Features enum. - * \param lhs Left-hand side feature flags - * \param rhs Right-hand side feature flags - * \return Combined feature flags + \brief Bitwise OR operator for Features enum. + \param lhs Left-hand side feature flags + \param rhs Right-hand side feature flags + \return Combined feature flags */ inline constexpr Fl::Pen::Features operator|(Fl::Pen::Features lhs, Fl::Pen::Features rhs) { return static_cast(static_cast(lhs) | static_cast(rhs)); } /** - * \brief Bitwise AND operator for Features enum. - * \param lhs Left-hand side feature flags - * \param rhs Right-hand side feature flags - * \return Intersection of feature flags + \brief Bitwise AND operator for Features enum. + \param lhs Left-hand side feature flags + \param rhs Right-hand side feature flags + \return Intersection of feature flags */ inline constexpr Fl::Pen::Features operator&(Fl::Pen::Features lhs, Fl::Pen::Features rhs) { return static_cast(static_cast(lhs) & static_cast(rhs)); } /** - * \brief Bitwise OR operator for State enum. - * \param lhs Left-hand side state flags - * \param rhs Right-hand side state flags - * \return Combined state flags + \brief Bitwise OR assignment operator for Features enum. + \param lhs Left-hand side feature flags (modified in place) + \param rhs Right-hand side feature flags + \return Reference to modified lhs + */ +inline Fl::Pen::Features& operator|=(Fl::Pen::Features& lhs, Fl::Pen::Features rhs) { + lhs = lhs | rhs; + return lhs; +} + +/** + \brief Bitwise OR operator for State enum. + \param lhs Left-hand side state flags + \param rhs Right-hand side state flags + \return Combined state flags */ inline constexpr Fl::Pen::State operator|(Fl::Pen::State lhs, Fl::Pen::State rhs) { return static_cast(static_cast(lhs) | static_cast(rhs)); } /** - * \brief Bitwise AND operator for State enum. - * \param lhs Left-hand side state flags - * \param rhs Right-hand side state flags - * \return Intersection of state flags + \brief Bitwise AND operator for State enum. + \param lhs Left-hand side state flags + \param rhs Right-hand side state flags + \return Intersection of state flags */ inline constexpr Fl::Pen::State operator&(Fl::Pen::State lhs, Fl::Pen::State rhs) { return static_cast(static_cast(lhs) & static_cast(rhs)); } +/** + \brief Bitwise OR assignment operator for State enum. + \param lhs Left-hand side state flags (modified in place) + \param rhs Right-hand side state flags + \return Reference to modified lhs + */ +inline Fl::Pen::State& operator|=(Fl::Pen::State& lhs, Fl::Pen::State rhs) { + lhs = lhs | rhs; + return lhs; +} + #endif // !Fl_core_pen_events_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6ff191010..d7ab4354d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -241,6 +241,7 @@ if(FLTK_USE_X11 AND NOT FLTK_USE_WAYLAND) drivers/Xlib/Fl_Xlib_Copy_Surface_Driver.cxx drivers/Xlib/Fl_Xlib_Image_Surface_Driver.cxx drivers/X11/fl_X11_platform_init.cxx + drivers/Stubs/Fl_Stubs_Pen_Events.cxx Fl_x.cxx fl_dnd_x.cxx Fl_Native_File_Chooser_FLTK.cxx @@ -317,6 +318,7 @@ elseif(FLTK_USE_WAYLAND) drivers/Wayland/fl_wayland_clipboard_dnd.cxx drivers/Wayland/fl_wayland_platform_init.cxx drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx + drivers/Stubs/Fl_Stubs_Pen_Events.cxx Fl_Native_File_Chooser_FLTK.cxx Fl_Native_File_Chooser_GTK.cxx ) @@ -369,6 +371,7 @@ elseif(APPLE) drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx drivers/Posix/Fl_Posix_System_Driver.cxx drivers/Darwin/Fl_Darwin_System_Driver.cxx + drivers/Stubs/Fl_Stubs_Pen_Events.cxx Fl_get_key_mac.cxx drivers/Darwin/fl_macOS_platform_init.cxx ) @@ -403,6 +406,7 @@ else() drivers/GDI/Fl_GDI_Graphics_Driver_vertex.cxx drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx + drivers/Stubs/Fl_Stubs_Pen_Events.cxx Fl_win32.cxx fl_dnd_win32.cxx Fl_Native_File_Chooser_WIN32.cxx diff --git a/src/drivers/Stubs/Fl_Stubs_Pen_Events.cxx b/src/drivers/Stubs/Fl_Stubs_Pen_Events.cxx new file mode 100644 index 000000000..f4c2e364e --- /dev/null +++ b/src/drivers/Stubs/Fl_Stubs_Pen_Events.cxx @@ -0,0 +1,73 @@ +// +// Definition of default Pen/Tablet event driver. +// +// Copyright 2025 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// + + +#include +#include +#include +#include + +class Fl_Widget; + +namespace Fl { + +namespace Pen { + +// double e_pressure_; + +} // namespace Pen + +} // namespace Fl + + +using namespace Fl::Pen; + +Features Fl::Pen::features() { return NONE; } + +void Fl::Pen::subscribe(Fl_Widget*, bool) { } + +void Fl::Pen::unsubscribe(Fl_Widget*) { } + +void Fl::Pen::grab(Fl_Widget*) { } + +void Fl::Pen::release() { } + +double Fl::Pen::event_x() { return static_cast(Fl::event_x()); } + +double Fl::Pen::event_y() { return static_cast(Fl::event_y()); } + +double Fl::Pen::event_x_root() { return static_cast(Fl::event_x_root()); } + +double Fl::Pen::event_y_root() { return static_cast(Fl::event_y_root()); } + +int Fl::Pen::event_id() { return -1; } + +double Fl::Pen::event_pressure() { return 0.0; } + +double Fl::Pen::event_tangential_pressure() { return 0.0; } + +double Fl::Pen::event_tilt_x() { return 0.0; } + +double Fl::Pen::event_tilt_y() { return 0.0; } + +double Fl::Pen::event_twist() { return 0.0; } + +double Fl::Pen::event_proximity() { return 0.0; } + +State Fl::Pen::event_state() { return static_cast(0); } + +State Fl::Pen::event_trigger() { return static_cast(0); } +