|
NAMEAG_Driver —
agar low-level driver interface
SYNOPSIS#include <agar/core.h> #include <agar/gui.h> DESCRIPTIONIn Agar, low-level graphics rendering, event processing and window management is handled by modular "drivers". A simple class registration interface allows Agar to be "ported" to new platforms, environments and graphics systems. In a manner similar to Agar widgets, new Agar "drivers" may be implemented as part of an application, without need for changing the Agar source code itself.For the list of drivers included in the Agar distribution, see the AG_InitGraphics(3) manual page, under "AVAILABLE DRIVERS". The interface differs based on whether an underlying window system is available. All drivers are a subclass of AG_Driver. The AG_DriverSw subclass (for "single-window") is used by drivers that do not interface with an underlying window system. For example, the "sdlfb" and "sdlgl" drivers use the SDL 1.x API, and are therefore limited to a single window as far as the native window system is concerned). A dumb framebuffer used in an embedded device would also use the AG_DriverSw subclass. The AG_DriverMw subclass (for "multiple-window") is used by drivers that do interface with an underlying window system. In a multiple-window environment, each Agar window (e.g., each window created by AG_WindowNew(3)) is associated with a "native" window. For example, the "glx" driver uses the GLX API to create an accelerated rendering context, and also uses the Xlib API to manage windows. The part of the DRIVER INTERFACEAG_Driver *AG_DriverOpen (AG_DriverClass
*dc);
The The The The DRIVER CLASS STRUCTUREThe AG_DriverClass structure inherits from the base AG_Object(3) class, and is defined as follows:typedef struct ag_driver_class { struct ag_object_class _inherit; const char *name; /* Short name */ enum ag_driver_type type; /* Driver type */ enum ag_driver_wm_type wm; /* Window manager type */ Uint flags; /* Flags; see below */ /* Initialization */ int (*open)(void *drv, const char *spec); void (*close)(void *drv); int (*getDisplaySize)(Uint *w, Uint *h); /* Event processing */ void (*beginEventProcessing)(void *drv); int (*pendingEvents)(void *drv); int (*getNextEvent)(void *drv, AG_DriverEvent *dev); int (*processEvent)(void *drv, AG_DriverEvent *dev); void (*genericEventLoop)(void *drv); void (*endEventProcessing)(void *drv); void (*terminate)(void); /* Rendering and texture management */ void (*beginRendering)(void *drv); void (*renderWindow)(AG_Window *w); void (*endRendering)(void *drv); void (*fillRect)(void *drv, AG_Rect r, AG_Color c); void (*updateRegion)(void *drv, AG_Rect r); void (*uploadTexture)(void *drv, Uint *texID, AG_Surface *su, AG_TexCoord *tc); int (*updateTexture)(void *drv, Uint texID, AG_Surface *su, AG_TexCoord *tc); void (*deleteTexture)(void *drv, Uint texID); int (*setRefreshRate)(void *drv, int fps); /* Clipping and blending control (rendering context) */ void (*pushClipRect)(void *drv, AG_Rect r); void (*popClipRect)(void *drv); void (*pushBlendingMode)(void *drv, AG_BlendFn sFn, AG_BlendFn dFn); void (*popBlendingMode)(void *drv); /* Hardware cursor interface */ AG_Cursor *(*createCursor)(void *drv, Uint w, Uint h, const Uint8 *data, const Uint8 *mask, int xHot, int yHot); void (*freeCursor)(void *drv, AG_Cursor *curs); int (*setCursor)(void *drv, AG_Cursor *curs); void (*unsetCursor)(void *drv); int (*getCursorVisibility)(void *drv); void (*setCursorVisibility)(void *drv, int flag); /* Widget surface operations (rendering context) */ void (*blitSurface)(void *drv, AG_Widget *wid, AG_Surface *s, int x, int y); void (*blitSurfaceFrom)(void *drv, AG_Widget *wid, AG_Widget *widSrc, int s, AG_Rect *r, int x, int y); void (*blitSurfaceGL)(void *drv, AG_Widget *wid, AG_Surface *s, float w, float h); void (*blitSurfaceFromGL)(void *drv, AG_Widget *wid, int s, float w, float h); void (*blitSurfaceFlippedGL)(void *drv, AG_Widget *wid, int s, float w, float h); void (*backupSurfaces)(void *drv, AG_Widget *wid); void (*restoreSurfaces)(void *drv, AG_Widget *wid); int (*renderToSurface)(void *drv, AG_Widget *wid, AG_Surface **su); /* Rendering operations (rendering context) */ void (*putPixel)(void *drv, int x, int y, AG_Color c); void (*putPixel32)(void *drv, int x, int y, Uint32 c); void (*putPixelRGB)(void *drv, int x, int y, Uint8 r, Uint8 g, Uint8 b); void (*blendPixel)(void *drv, int x, int y, AG_Color c, AG_BlendFn sFn, AG_BlendFn dFn); void (*drawLine)(void *drv, int x1, int y1, int x2, int y2, AG_Color C); void (*drawLineH)(void *drv, int x1, int x2, int y, AG_Color C); void (*drawLineV)(void *drv, int x, int y1, int y2, AG_Color C); void (*drawLineBlended)(void *drv, int x1, int y1, int x2, int y2, AG_Color C, AG_BlendFn sFn, AG_BlendFn dFn); void (*drawArrowUp)(void *drv, int x, int y, int h, AG_Color C[2]); void (*drawArrowDown)(void *drv, int x, int y, int h, AG_Color C[2]); void (*drawArrowLeft)(void *drv, int x, int y, int h, AG_Color C[2]); void (*drawArrowRight)(void *drv, int x, int y, int h, AG_Color C[2]); void (*drawBoxRounded)(void *drv, AG_Rect r, int z, int rad, AG_Color C[3]); void (*drawBoxRoundedTop)(void *drv, AG_Rect r, int z, int rad, AG_Color C[3]); void (*drawCircle)(void *drv, int x, int y, int r, AG_Color C); void (*drawCircle2)(void *drv, int x, int y, int r, AG_Color C); void (*drawRectFilled)(void *drv, AG_Rect r, AG_Color C); void (*drawRectBlended)(void *drv, AG_Rect r, AG_Color C, AG_BlendFn sFn, AG_BlendFn dFn); void (*drawRectDithered)(void *drv, AG_Rect r, AG_Color C); void (*updateGlyph)(void *drv, AG_Glyph *gl); void (*drawGlyph)(void *drv, const AG_Glyph *gl, int x, int y); /* Display list management (GL driver specific) */ void (*deleteList)(void *drv, Uint listID); } AG_DriverClass; The type field should be set to
The wm field may be set to
Acceptable values for the flags field include:
The The The The
The The The The The The The
The
The following operations are optional and provide Agar with access over hardware cursors. See AG_Cursor(3) for details on the Agar cursor control interface. The The The The following operations form the backend of the AG_Widget(3) surface operations such as AG_WidgetBlitFrom(3). They all accept a AG_Widget argument, and coordinate arguments are always with respect to the widget's local coordinate system. The The The The
The
The The The The EVENT PROCESSINGintAG_PendingEvents (AG_Driver
*drv);
/* Requires Agar compiled --with-sdl */ int AG_SDL_TranslateEvent (AG_Driver
*drv, const SDL_Event
*ev, AG_DriverEvent
*dev);
Low-level driver events are represented by the AG_DriverEvent structure, which provides the public members type and win. The win member is a pointer to the corresponding AG_Window(3) (for single-window drivers, win is always NULL). The type field is an enum that can take on the values:
The
The The drv argument
EXAMPLESThe following code fragment implements a basic event loop. It retrieves pending events, examines them, and forwards them to Agar for processing:AG_DriverEvent ev; while (AG_PendingEvents(NULL) > 0) { if (AG_GetNextEvent(NULL, &ev)) { switch (ev.type) { case AG_DRIVER_MOUSE_BUTTON_DOWN: printf("Click at %d,%d\n", dev.data.button.x, dev.data.button.y); break; case AG_DRIVER_KEY_DOWN: printf("Key pressed: %d\n", (int)dev.data.key.ks); break; default: break; } if (AG_ProcessEvent(NULL, &ev) == -1) break; } } SEE ALSOAG_GL(3), AG_InitGraphics(3), AG_Intro(3), AG_Widget(3), AG_Window(3)HISTORYTheAG_Driver interface first appeared in Agar 1.4.0.
Visit the GSP FreeBSD Man Page Interface. |