SDL_PenMotionEvent(3type)

πŸ’– SDL_PenMotionEvent β€” a datatype, bestie πŸ’–

okay so this is from the SDL3 DATATYPES corner of the SDL3 manual, and it's literally the page for SDL_PenMotionEvent(3type). it's giving "pen goes wiggle, struct tells you about it". no cap. πŸ–ŠοΈβœ¨


🌸 NAME 🌸

SDL_PenMotionEvent β€” the pressure-sensitive pen motion event structure (you'll find it living at event.pmotion.*, iykyk) πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_events.h>

typedef struct SDL_PenMotionEvent
{
    SDL_EventType type; /**< SDL_EVENT_PEN_MOTION */
    Uint32 reserved;
    Uint64 timestamp;   /**< In nanoseconds, populated using SDL_GetTicksNS() */
    SDL_WindowID windowID; /**< The window with pen focus, if any */
    SDL_PenID which;        /**< The pen instance id */
    SDL_PenInputFlags pen_state;   /**< Complete pen input state at time of event */
    float x;                /**< X coordinate, relative to window */
    float y;                /**< Y coordinate, relative to window */
    SDL_PenDeviceType device_type; /**< the device type of the pen, if known (added in 3.4.18). */
} SDL_PenMotionEvent;

so yeah, that's the whole struct, verbatim, every field accounted for, we do not skip a single one here πŸ’…

  • type β€” always SDL_EVENT_PEN_MOTION, that's the whole personality of this event 🫢
  • reserved β€” reserved. don't touch it. it's not for you, bestie πŸ™ˆ
  • timestamp β€” in nanoseconds, populated using SDL_GetTicksNS(). yes, nanoseconds, we're precise like that ⭐
  • windowID β€” the window with pen focus, if any. "if any" is doing a lot of work there 😭
  • which β€” the pen instance id πŸ–ŠοΈ
  • pen_state β€” the complete pen input state at time of event. the whole vibe check, captured in one field 🌈
  • x β€” X coordinate, relative to window πŸ“
  • y β€” Y coordinate, relative to window πŸ“
  • device_type β€” the device type of the pen, if known (added in 3.4.18). lowkey a newer field, we love growth πŸ‘‘

πŸ’œ DESCRIPTION πŸ’œ

okay so here's the tea β˜• depending on the hardware, you may get motion events when the pen is not touching a tablet β€” that's for tracking a pen even when it isn't drawing. so like, the pen is hovering, being mysterious, main character energy, and you're still getting motion events. iconic honestly. ✨

so how do you know if the pen is actually "drawing"?? you should either:

  • listen for SDL_EVENT_PEN_DOWN and SDL_EVENT_PEN_UP events, or
  • check pen_state & SDL_PEN_INPUT_DOWN

either way, do that when you're dealing with pen motion. that's the move. periodt. πŸ’…

ngl, don't just assume a motion event means the pen is down β€” the hardware might be tracking a hovering pen, and that's a whole different situation 🫢

πŸŽ€ AVAILABILITY πŸŽ€

This struct is available since SDL 3.2.0. yes bestie, it's been around, it's not new-new, it's just that one field that's newer πŸ‘‘


that's the whole page, fr fr πŸ’– thanks for reading to the end, you ate that. this was brought to you by Simple Directmedia Layer, version SDL 3.4.18, and yes the manual section is SDL_PenMotionEvent(3type) in case you need to cite your sources. slay, bye πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from