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 is also used by custom widgets to trigger events such as #PG_Event_Action (and can potentially be used by developers to simulate events if needed).

Core Event Functions

Event Types

These are the constants used to identify different events:

Note on Global Window Events: Events such as #PG_Event_WindowClose, #PG_Event_WindowActivate, #PG_Event_WindowDeactivate, #PG_Event_WindowMinimize, #PG_Event_WindowMaximize, #PG_Event_WindowRestore, and #PG_Event_WindowTitle are classified internally as global window events. If you bind these event types directly to a child Widget, ProGUI will automatically route the parent window’s event down to that Widget.

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: