![]() |
![]()
| ![]() |
![]()
NAME
SYNOPSIS#include <agar/core.h> #include <agar/gui.h> DESCRIPTIONAgar implements low-level access to the graphics hardware, event processing and window management using a modular driver interface. The class registration interface allows Agar to be "ported" to new platforms, environments and graphics systems. New drivers can be implemented as part of an application or third-party library, without need for changes in the Agar 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 (at least not directly) 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 native window. Another example would be a simple framebuffer in an embedded device, which might also use AG_DriverSw. When a single-window driver is used, Agar provides an internal window manager. The AG_DriverMw subclass (for "multiple-window") is used by drivers that talk to some underlying window system. In a multiple-window environment, each AG_Window(3) is associated with a "native" window on the system. For example, the "glx" driver uses the Xlib API to manage windows and the GLX extension to create accelerated rendering contexts. The event processing functions of
DRIVER INTERFACEAG_Driver *
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; /* Driver class options */ /* Initialization */ int (*open)(void *d, const char *spec); void (*close)(void *d); int (*getDisplaySize)(Uint *w, Uint *h); /* Event processing */ void (*beginEventProcessing)(void *d); int (*pendingEvents)(void *d); int (*getNextEvent)(void *d, AG_DriverEvent *dev); int (*processEvent)(void *d, AG_DriverEvent *dev); void (*genericEventLoop)(void *d); void (*endEventProcessing)(void *d); void (*terminate)(void); /* Rendering and texture management */ void (*beginRendering)(void *d); void (*renderWindow)(AG_Window *w); void (*endRendering)(void *d); void (*fillRect)(void *d, const AG_Rect *r, const AG_Color *c); void (*updateRegion)(void *d, const AG_Rect *r); void (*uploadTexture)(void *d, Uint *id, AG_Surface *s, AG_TexCoord *c); void (*updateTexture)(void *d, Uint id, AG_Surface *s, AG_TexCoord *c); void (*deleteTexture)(void *d, Uint id); int (*setRefreshRate)(void *d, int fps); /* Clipping and blending controls */ void (*pushClipRect)(void *d, const AG_Rect *r); void (*popClipRect)(void *d); void (*pushBlendingMode)(void *d, AG_AlphaFn s, AG_AlphaFn d); void (*popBlendingMode)(void *d); /* Hardware cursor interface */ AG_Cursor *(*createCursor)(void *d, Uint w, Uint h, const Uint8 *data, const Uint8 *mask, int xHot, int yHot); void (*freeCursor)(void *d, AG_Cursor *curs); int (*setCursor)(void *d, AG_Cursor *curs); void (*unsetCursor)(void *d); int (*getCursorVisibility)(void *d); void (*setCursorVisibility)(void *d, int flag); /* Widget surface operations */ void (*blitSurface)(void *d, AG_Widget *wid, AG_Surface *s, int x, int y); void (*blitSurfaceFrom)(void *d, AG_Widget *wid, int s, const AG_Rect *r, int x, int y); #ifdef HAVE_OPENGL void (*blitSurfaceGL)(void *d, AG_Widget *wid, AG_Surface *s, float w, float h); void (*blitSurfaceFromGL)(void *d, AG_Widget *wid, int surface, float w, float h); void (*blitSurfaceFlippedGL)(void *d, AG_Widget *wid, int surface, float w, float h); #endif void (*backupSurfaces)(void *d, AG_Widget *wid); void (*restoreSurfaces)(void *d, AG_Widget *wid); int (*renderToSurface)(void *d, AG_Widget *wid, AG_Surface **s); /* Rendering operations */ void (*putPixel)(void *d, int x, int y, const AG_Color *c); void (*putPixel32)(void *d, int x, int y, Uint32 px); void (*putPixelRGB8)(void *d, int x, int y, Uint8 r, Uint8 g, Uint8 b); #if AG_MODEL == AG_LARGE void (*putPixel64)(void *d, int x, int y, Uint64 px); void (*putPixelRGB16)(void *d, int x, int y, Uint16 r, Uint16 g, Uint16 b); #endif void (*blendPixel)(void *d, int x, int y, const AG_Color *c, AG_AlphaFn fnSrc, AG_AlphaFn fnDst); void (*drawLine)(void *d, int x1, int y1, int x2, int y2, const AG_Color *c); void (*drawLineH)(void *d, int x1, int x2, int y, const AG_Color *c); void (*drawLineV)(void *d, int x, int y1, int y2, const AG_Color *c); void (*drawLineBlended)(void *d, int x1, int y1, int x2, int y2, const AG_Color *c, AG_AlphaFn fnSrc, AG_AlphaFn fnDst); void (*drawLineW)(void *d, int x1, int y1, int x2, int y2, const AG_Color *c, float width); void (*drawLineW_Sti16)(void *d, int x1, int y1, int x2, int y2, const AG_Color *c, float width, Uint16 mask); void (*drawTriangle)(void *d, const AG_Pt *v1, const AG_Pt *v2, const AG_Pt *v3, const AG_Color *c); void (*drawPolygon)(void *d, const AG_Pt *pts, Uint nPts, const AG_Color *c); void (*drawPolygonSti32)(void *d, const AG_Pt *pts, Uint nPts, const AG_Color *c, const Uint8 *stipple); void (*drawArrow)(void *d, float angle, int x, int y, int h, const AG_Color *c1, const AG_Color *c2); void (*drawBoxRounded)(void *d, const AG_Rect *r, int z, int radius, const AG_Color *c1, const AG_Color *c2); void (*drawBoxRoundedTop)(void *d, const AG_Rect *r, int z, int radius, const AG_Color *c1, const AG_Color *c2, const AG_Color *c3); void (*drawCircle)(void *d, int x, int y, int radius, const AG_Color *c); void (*drawCircleFilled)(void *d, int x, int y, int radius, const AG_Color *c); void (*drawRectFilled)(void *d, const AG_Rect *r, const AG_Color *c); void (*drawRectBlended)(void *d, const AG_Rect *r, const AG_Color *c, AG_AlphaFn fnSrc, AG_AlphaFn fnDst); void (*drawRectDithered)(void *d, const AG_Rect *r, const AG_Color *c); /* Typography */ void (*updateGlyph)(void *d, AG_Glyph *gl); void (*drawGlyph)(void *d, const AG_Glyph *gl, int x, int y); /* Display list management */ void (*deleteList)(void *d, Uint listID); /* Clipboard integration */ char *(*getClipboardText)(void *d); int (*setClipboardText)(void *d, const char *text); /* Mouse auto-capture control */ void (*setMouseAutoCapture)(void *d, int state); } 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 optional
The optional
The optional
EVENTSint
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
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.button.x, dev.button.y); break; case AG_DRIVER_KEY_DOWN: printf("Key pressed: %d\n", (int)dev.key.ks); break; default: break; } if (AG_ProcessEvent(NULL, &ev) == -1) break; } } SEE ALSOAG_DriverSw(3), AG_DriverMw(3), AG_GL(3), AG_InitGraphics(3), AG_Intro(3), AG_Widget(3), AG_Window(3) HISTORYThe
|