From 8dcc99279e54d0d044813e12deb0c55633a6c277 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 20 Nov 2025 22:24:21 +0100 Subject: Adjust some pen driver comments. Made global variables private. --- FL/core/pen_events.H | 23 ++++++++++++++--------- src/Fl_cocoa.mm | 12 +++++++----- src/drivers/Cocoa/Fl_Cocoa_Pen_Events.mm | 20 +++++++++----------- test/penpal.cxx | 2 +- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/FL/core/pen_events.H b/FL/core/pen_events.H index c20cfa438..48ce47034 100644 --- a/FL/core/pen_events.H +++ b/FL/core/pen_events.H @@ -287,7 +287,7 @@ inline bool driver_traits(Trait bits) { \brief Query traits of the current pen or stylus. The value returned by this function may change when pens change or when more information becomes known about the currently used pen. - \param[in] pen_id a now pen ID as returned from event_pen_id(), + \param[in] pen_id a know pen ID as returned from event_pen_id(), or 0 for the current pen \return a bitfield of supported traits */ @@ -296,7 +296,7 @@ FL_EXPORT extern Trait pen_traits(int pen_id = 0); /** \brief Return true if the corresponding bit is set in the pen traits. \param[in] bits check for one or more trait bits - \param[in] pen_id a now pen ID as returned from event_pen_id(), + \param[in] pen_id a know pen ID as returned from event_pen_id(), or 0 for the current pen \return true if any bit is set */ @@ -305,10 +305,10 @@ inline bool pen_traits(Trait bits, int pen_id = 0) { } /** - \brief Receive a Pen::ENTER event when the pen moves inside this widget. - Multiple widgets can subscribe to pen events, but every widget must only - subscribe once. - \param widget Widget to subscribe to pen events + \brief Receives a Pen::ENTER event when the pen enters this widget. + Multiple widgets may subscribe to pen events. Additional subscription + requests for the same widget are ignored. + \param widget The widget subscribing to pen events. */ FL_EXPORT extern void subscribe(Fl_Widget* widget); @@ -391,8 +391,13 @@ FL_EXPORT extern double event_tilt_x(); FL_EXPORT extern double event_tilt_y(); /** - \brief Returns the pens axial rotation in degrees. - \return Twist angle in degrees, defaults to 0.0 . + \brief Returns the pen's axial rotation in degrees. + The twist angle is reported in degrees, with: + - 0° : pen’s “top” (the button side) facing upward + - +180° : twisted halfway clockwise, looking at the end of the pen toward the tip + - –180° → twisted half way counter clockwise + So the full range is usually –180° to +180°. + \return Twist angle in degrees, defaults to 0.0. \see Trait::TWIST */ FL_EXPORT extern double event_twist(); @@ -412,7 +417,7 @@ FL_EXPORT extern double event_proximity(); FL_EXPORT extern State event_state(); /** - \brief Return true if the corresponding bit is set in the event state. + \brief Return true if any of the bits are set in the event state. \param[in] bits check for one or more event state bits \return true if any bit is set */ diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 348007aa3..382abc5b8 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -1068,10 +1068,12 @@ static bool cocoaTabletHandler(NSEvent *theEvent, bool lock) } namespace Fl { +namespace Private { // Global mouse position at mouse down event int e_x_down { 0 }; int e_y_down { 0 }; -}; +}; // namespace Private +}; // namespace Fl /* * Cocoa Mouse Button Handler @@ -1135,8 +1137,8 @@ static void cocoaMouseHandler(NSEvent *theEvent) case NSEventTypeOtherMouseDown: sendEvent = FL_PUSH; Fl::e_is_click = 1; - Fl::e_x_down = (int)pos.x; - Fl::e_y_down = (int)pos.y; + Fl::Private::e_x_down = (int)pos.x; + Fl::Private::e_y_down = (int)pos.y; if ([theEvent clickCount] > 1) Fl::e_clicks++; else @@ -1161,8 +1163,8 @@ static void cocoaMouseHandler(NSEvent *theEvent) case NSEventTypeOtherMouseDragged: { if ( !sendEvent ) { sendEvent = FL_MOVE; // Fl::handle will convert into FL_DRAG - if ( (fabs(pos.x - Fl::e_x_down) > 5) || - (fabs(pos.y - Fl::e_y_down) > 5)) + if ( (fabs(pos.x - Fl::Private::e_x_down) > 5) || + (fabs(pos.y - Fl::Private::e_y_down) > 5)) Fl::e_is_click = 0; } mods_to_e_state( mods ); diff --git a/src/drivers/Cocoa/Fl_Cocoa_Pen_Events.mm b/src/drivers/Cocoa/Fl_Cocoa_Pen_Events.mm index 7b122eec0..c2840a41e 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Pen_Events.mm +++ b/src/drivers/Cocoa/Fl_Cocoa_Pen_Events.mm @@ -76,7 +76,7 @@ public: return it->second; } } - /* Remove a subscriber form the list. */ + /* Remove a subscriber from the list. */ void remove(Fl_Widget *w) { auto it = find(w); if (it != end()) { @@ -130,15 +130,15 @@ static struct EventData ev; namespace Fl { +namespace Private { // Global mouse position at mouse down event extern int e_x_down; extern int e_y_down; +}; // namespace Private namespace Pen { - // The event data that is made available to the user during event handling struct EventData e; - } // namespace Pen } // namespace Fl @@ -303,8 +303,7 @@ static int pen_send_all(int event, State trigger) { /* Convert the NSEvent button number to Fl::Pen::State, */ -static State button_to_trigger(NSInteger button, bool down) -{ +static State button_to_trigger(NSInteger button, bool down) { switch (button) { case 0: if ( (ev.state & (State::ERASER_DOWN | State::ERASER_HOVERS)) != State::NONE ) { @@ -326,8 +325,7 @@ static State button_to_trigger(NSInteger button, bool down) capabilityMask is useless, because it is vendor defined If a modal window is open, AppKit will send window specific events only there. */ -bool fl_cocoa_tablet_handler(NSEvent *event, Fl_Window *eventWindow) -{ +bool fl_cocoa_tablet_handler(NSEvent *event, Fl_Window *eventWindow) { // Quick access to the main type. auto type = [event type]; @@ -493,8 +491,8 @@ bool fl_cocoa_tablet_handler(NSEvent *event, Fl_Window *eventWindow) State trigger = button_to_trigger([event buttonNumber], true); if ([event buttonNumber] == 0) { Fl::e_is_click = 1; - Fl::e_x_down = (int)ev.x; - Fl::e_y_down = (int)ev.y; + Fl::Private::e_x_down = (int)ev.x; + Fl::Private::e_y_down = (int)ev.y; if ([event clickCount] > 1) Fl::e_clicks++; else @@ -515,8 +513,8 @@ bool fl_cocoa_tablet_handler(NSEvent *event, Fl_Window *eventWindow) pen_send(receiver, Fl::Pen::BUTTON_RELEASE, trigger, event_data_copied); } else if (is_motion) { if ( Fl::e_is_click && - ( (fabs((int)ev.x - Fl::e_x_down) > 5) || - (fabs((int)ev.y - Fl::e_y_down) > 5) ) ) + ( (fabs((int)ev.x - Fl::Private::e_x_down) > 5) || + (fabs((int)ev.y - Fl::Private::e_y_down) > 5) ) ) Fl::e_is_click = 0; if (pushed) { pen_send(receiver, Fl::Pen::DRAW, State::NONE, event_data_copied); diff --git a/test/penpal.cxx b/test/penpal.cxx index 4ace5cbe9..69d6e280d 100644 --- a/test/penpal.cxx +++ b/test/penpal.cxx @@ -42,7 +42,7 @@ Fl_Window *cvwin { nullptr }; // // The canvas interface implements incremental drawing and handles draw events. -// It also implement pressure sensitive drawing with a pen or stylus. +// It also implements pressure sensitive drawing with a pen or stylus. // And it implements an overlay plane that visualizes pen event data. // class CanvasInterface { -- cgit v1.2.3