Event Handling

Event Handling Overview

ProGUI operates on an event-driven model. User interactions (like mouse clicks, keyboard input), system events (like window resizing or DPI changes), and internal operations (like drawing or animation updates) trigger events. Your application reacts to these events by providing specific functions, called event handlers or callbacks.

The primary function for reacting to events is AddEventHandler(). You use this to associate one of your procedures with a specific event type on a specific object (either a Window or a Widget). When that event occurs for that object, ProGUI will call your procedure.

When an event handler is called, it typically receives information about the event through an `*eventData` parameter. This parameter points to a structure containing details relevant to the event (e.g., mouse coordinates for a mouse event, new DPI values for a DPI change event). The specific structure type depends on the `EventType`.

ProGUI also provides a DispatchEvent() function, which is primarily used internally by the library to trigger the registered handlers, but can potentially be used by developers to simulate events if needed.

Event Types

These are the constants used to identify different events:

Animation Event States

The #PG_Event_Animate event uses the `state` field in its PG_EventAnimate data structure to indicate the phase of the animation:

Event Data Structures

The `*eventData` pointer passed to event handlers points to one of the following structures, depending on the `EventType`: