Voyons comment gérer le pen avec la SDL3 

Grâce à la SDL3, on peut dissocier un pen d'une souris. La façon de gérer un pen est identique à celle du joystick et tout se joue dans le switch des events.

Voici les évents du pen :

   /* Pressure-sensitive pen events */
    SDL_EVENT_PEN_PROXIMITY_IN = 0x1300,  /**< Pressure-sensitive pen has become available */
    SDL_EVENT_PEN_PROXIMITY_OUT,          /**< Pressure-sensitive pen has become unavailable */
    SDL_EVENT_PEN_DOWN,                   /**< Pressure-sensitive pen touched drawing surface */
    SDL_EVENT_PEN_UP,                     /**< Pressure-sensitive pen stopped touching drawing surface */
    SDL_EVENT_PEN_BUTTON_DOWN,            /**< Pressure-sensitive pen button pressed */
    SDL_EVENT_PEN_BUTTON_UP,              /**< Pressure-sensitive pen button released */
    SDL_EVENT_PEN_MOTION,                 /**< Pressure-sensitive pen is moving on the tablet */
    SDL_EVENT_PEN_AXIS,                   /**< Pressure-sensitive pen angle/pressure/etc changed */

 

On peut donc accéder à PEN_UP et PEN_DOWN

		while(SDL_PollEvent(&event)) {
			switch (event.type) {
				case SDL_EVENT_QUIT:
					quit = true;
					break;

				case SDL_EVENT_PEN_UP:
					std::cout << "Up" << std::endl;
					break;

				case SDL_EVENT_PEN_DOWN:
					std::cout << "Down" << std::endl;
					break;

Mais aussi au déplacement du stylet grâce au PEN_MOTION

				case SDL_EVENT_PEN_MOTION:
					std::cout << "Motion" << std::endl;
					event.pmotion.x;
					event.pmotion.y;
					break;

On peut aussi gérer les éventuels boutons du stylet, en mode DOWN or UP:

				case SDL_EVENT_PEN_BUTTON_DOWN:
					std::cout << "SDL_EVENT_PEN_BUTTON_DOWN" <<std::endl;
					switch (event.pbutton.button)
					{
					case SDL_PEN_INPUT_BUTTON_1:
						std::cout << "SDL_PEN_INPUT_BUTTON_1" << std::endl;
						break;

					case SDL_PEN_INPUT_BUTTON_2:
						std::cout << "SDL_PEN_INPUT_BUTTON_2" << std::endl;
						break;

					case SDL_PEN_INPUT_BUTTON_3:
						std::cout << "SDL_PEN_INPUT_BUTTON_3" << std::endl;
						break;

					case SDL_PEN_INPUT_BUTTON_4:
						std::cout << "SDL_PEN_INPUT_BUTTON_4" << std::endl;
						break;

					default:
						break;
					}

 

On peut aussi s'intéresser au PEN_AXIS:

typedef struct SDL_PenAxisEvent
{
    SDL_EventType type;     /**< SDL_EVENT_PEN_AXIS */
    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_PenAxis axis;       /**< Axis that has changed */
    float value;            /**< New value of axis */
} SDL_PenAxisEvent;

Avec cette structure, on peut raffiner de très prêt les évènements du stylet !