SYNOPSIS
#include <agar/core.h> #include <agar/gui.h>
DESCRIPTION
In general, most Agar GUI applications will use the standard Agar-Core
event loop,
AG_EventLoop(3), since it uses the most efficient event-notification mechanism available for
the target platform (e.g.,
kqueue(2), select(2), etc.)
However, Agar-GUI applications are not required to use AG_EventLoop() at all, and may use an application-specific event loop routine. To simplify writing of custom event loops, Agar provides the AG_GetNextEvent(3), AG_ProcessEvent(3) and AG_ProcessTimeouts(3) functions. Low-level driver events are represented by the transparent, driver-independent AG_DriverEvent structure (see AG_Driver(3) for details and examples).
However, Agar-GUI applications are not required to use AG_EventLoop() at all, and may use an application-specific event loop routine. To simplify writing of custom event loops, Agar provides the AG_GetNextEvent(3), AG_ProcessEvent(3) and AG_ProcessTimeouts(3) functions. Low-level driver events are represented by the transparent, driver-independent AG_DriverEvent structure (see AG_Driver(3) for details and examples).
CUSTOM EVENT LOOP EXAMPLE
The following event loop redraws Agar windows whenever needed (the redraw
frequency being limited to some nomimal frame rate), processes input events,
and executes timer callbacks (using an inefficient delay loop):
void MY_GenericEventLoop(void *obj) { AG_Window *win; Uint32 t1, t2; t1 = AG_GetTicks(); for (;;) { t2 = AG_GetTicks(); if (t2 - t1 >= rNom) { AG_WindowDrawQueued(); t1 = AG_GetTicks(); rCur = rNom - (t1-t2); if (rCur < 1) { rCur = 1; } } else if (AG_PendingEvents(NULL)) { AG_DriverEvent dev; if (AG_GetNextEvent(NULL, &dev) == 1) AG_ProcessEvent(NULL, &dev); } else { AG_ProcessTimeouts(t2); AG_Delay(1); } AG_WindowProcessQueued(); } }
SEE ALSO
HISTORY
The
AG_CustomEventLoop routine first appeared in
Agar 1.0.
The
AG_GetNextEvent() interface appeared in
Agar 1.4.0.