FreeBSD Manual Pages
AG_CUSTOMEVENTLOOP(3) Library Functions Manual AG_CUSTOMEVENTLOOP(3) NAME AG_CustomEventLoop -- agar GUI custom event loop example 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-no- tification 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) func- tions. Low-level driver events are represented by the transparent, driver-independent AG_DriverEvent structure (see AG_Driver(3) for de- tails and examples). CUSTOM EVENT LOOP EXAMPLE The following event loop redraws Agar windows whenever needed (the re- draw frequency being limited to some nomimal frame rate), processes in- put 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 AG_Delay(3), AG_Driver(3), AG_Event(3), AG_EventLoop(3), AG_Timer(3), AG_Window(3) HISTORY The AG_CustomEventLoop routine first appeared in Agar 1.0. The AG_GetNextEvent() interface appeared in Agar 1.4.0. Agar 1.7 December 21, 2022 AG_CUSTOMEVENTLOOP(3)
NAME | SYNOPSIS | DESCRIPTION | CUSTOM EVENT LOOP EXAMPLE | SEE ALSO | HISTORY
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=AG_CustomEventLoop&sektion=3&manpath=FreeBSD+Ports+14.3.quarterly>
