Version | 0.2.0 |
---|
A drawable region that receives events.
A view can be thought of as a window, but does not necessarily correspond to a top-level window in a desktop environment. For example, a view can be embedded in some other window, or represent an embedded system where there is no concept of multiple windows at all.
Typedefs | |
typedef struct PuglViewImpl | PuglView |
typedef struct PuglBackendImpl | PuglBackend |
typedef uintptr_t | PuglNativeWindow |
typedef void * | PuglHandle |
typedef PuglStatus(* | PuglEventFunc) (PuglView *view, const PuglEvent *event) |
Enumerations | |
enum | PuglViewHint |
enum | PuglViewHintValue |
Setup | |
PuglView * | puglNewView (PuglWorld *world) |
void | puglFreeView (PuglView *view) |
PuglWorld * | puglGetWorld (PuglView *view) |
void | puglSetHandle (PuglView *view, PuglHandle handle) |
PuglHandle | puglGetHandle (PuglView *view) |
PuglStatus | puglSetBackend (PuglView *view, const PuglBackend *backend) |
PuglStatus | puglSetEventFunc (PuglView *view, PuglEventFunc eventFunc) |
PuglStatus | puglSetViewHint (PuglView *view, PuglViewHint hint, int value) |
Frame | |
PuglRect | puglGetFrame (const PuglView *view) |
PuglStatus | puglSetFrame (PuglView *view, PuglRect frame) |
PuglStatus | puglSetMinSize (PuglView *view, int width, int height) |
PuglStatus | puglSetAspectRatio (PuglView *view, int minX, int minY, int maxX, int maxY) |
Windows | |
PuglStatus | puglSetWindowTitle (PuglView *view, const char *title) |
PuglStatus | puglSetParentWindow (PuglView *view, PuglNativeWindow parent) |
PuglStatus | puglSetTransientFor (PuglView *view, PuglNativeWindow parent) |
PuglStatus | puglCreateWindow (PuglView *view, const char *title) |
PuglStatus | puglShowWindow (PuglView *view) |
PuglStatus | puglHideWindow (PuglView *view) |
bool | puglGetVisible (PuglView *view) |
PuglNativeWindow | puglGetNativeWindow (PuglView *view) |
Graphics | |
Functions for working with the graphics context and scheduling redisplays. | |
void * | puglGetContext (PuglView *view) |
PuglStatus | puglEnterContext (PuglView *view, bool drawing) |
PuglStatus | puglLeaveContext (PuglView *view, bool drawing) |
PuglStatus | puglPostRedisplay (PuglView *view) |
PuglStatus | puglPostRedisplayRect (PuglView *view, PuglRect rect) |
Interaction | |
PuglStatus | puglGrabFocus (PuglView *view) |
bool | puglHasFocus (const PuglView *view) |
PuglStatus | puglSetClipboard (PuglView *view, const char *type, const void *data, size_t len) |
const void * | puglGetClipboard (PuglView *view, const char **type, size_t *len) |
PuglStatus | puglRequestAttention (PuglView *view) |
typedef struct PuglViewImpl PuglView |
A drawable region that receives events.
typedef struct PuglBackendImpl PuglBackend |
A graphics backend.
The backend dictates how graphics are set up for a view, and how drawing is performed. A backend must be set by calling puglSetBackend() before realising a view.
If you are using a local copy of Pugl, it is possible to implement a custom backend. See the definition of PuglBackendImpl
in the source code for details.
typedef uintptr_t PuglNativeWindow |
A native window handle.
X11: This is a Window
.
MacOS: This is a pointer to an NSView*
.
Windows: This is a HWND
.
typedef void* PuglHandle |
Handle for opaque user data.
typedef PuglStatus(* PuglEventFunc) (PuglView *view, const PuglEvent *event) |
A function called when an event occurs.
enum PuglViewHint |
A hint for configuring a view.
enum PuglViewHintValue |
Create a new view.
A newly created view does not correspond to a real system view or window. It must first be configured, then be realised by calling puglCreateWindow().
void puglFreeView | ( | PuglView * | view | ) |
Free a view created with puglNewView().
void puglSetHandle | ( | PuglView * | view, |
PuglHandle | handle | ||
) |
Set the user data for a view.
This is usually a pointer to a struct that contains all the state which must be accessed by a view. Everything needed to process events should be stored here, not in static variables.
The handle is opaque to Pugl and is not interpreted in any way.
PuglHandle puglGetHandle | ( | PuglView * | view | ) |
Get the user data for a view.
PuglStatus puglSetBackend | ( | PuglView * | view, |
const PuglBackend * | backend | ||
) |
Set the graphics backend to use for a view.
This must be called once to set the graphics backend before calling puglCreateWindow().
Pugl includes the following backends:
Note that backends are modular and not compiled into the main Pugl library to avoid unnecessary dependencies. To use a particular backend, applications must link against the appropriate backend library, or be sure to compile in the appropriate code if using a local copy of Pugl.
PuglStatus puglSetEventFunc | ( | PuglView * | view, |
PuglEventFunc | eventFunc | ||
) |
Set the function to call when an event occurs.
PuglStatus puglSetViewHint | ( | PuglView * | view, |
PuglViewHint | hint, | ||
int | value | ||
) |
Set a hint to configure window properties.
This only has an effect when called before puglCreateWindow().
Get the current position and size of the view.
The position is in screen coordinates with an upper left origin.
PuglStatus puglSetFrame | ( | PuglView * | view, |
PuglRect | frame | ||
) |
Set the current position and size of the view.
The position is in screen coordinates with an upper left origin.
PuglStatus puglSetMinSize | ( | PuglView * | view, |
int | width, | ||
int | height | ||
) |
Set the minimum size of the view.
If an initial minimum size is known, this should be called before puglCreateWindow() to avoid stutter, though it can be called afterwards as well.
PuglStatus puglSetAspectRatio | ( | PuglView * | view, |
int | minX, | ||
int | minY, | ||
int | maxX, | ||
int | maxY | ||
) |
Set the window aspect ratio range.
The x and y values here represent a ratio of width to height. To set a fixed aspect ratio, set the minimum and maximum values to the same ratio.
Note that setting different minimum and maximum constraints does not currenty work on MacOS (the minimum is used), so only setting a fixed aspect ratio works properly across all platforms.
If an initial aspect ratio is known, this should be called before puglCreateWindow() to avoid stutter, though it can be called afterwards as well.
PuglStatus puglSetWindowTitle | ( | PuglView * | view, |
const char * | title | ||
) |
Set the title of the window.
This only makes sense for non-embedded views that will have a corresponding top-level window, and sets the title, typically displayed in the title bar or in window switchers.
PuglStatus puglSetParentWindow | ( | PuglView * | view, |
PuglNativeWindow | parent | ||
) |
Set the parent window for embedding a view in an existing window.
This must be called before puglCreateWindow(), reparenting is not supported.
PuglStatus puglSetTransientFor | ( | PuglView * | view, |
PuglNativeWindow | parent | ||
) |
Set the transient parent of the window.
Set this for transient children like dialogs, to have them properly associated with their parent window. This should be called before puglCreateWindow().
PuglStatus puglCreateWindow | ( | PuglView * | view, |
const char * | title | ||
) |
Realise a view by creating a corresponding system view or window.
The view should be fully configured using the above functions before this is called. This function may only be called once per view.
PuglStatus puglShowWindow | ( | PuglView * | view | ) |
Show the current window.
If the window is currently hidden, it will be shown and possibly raised to the top depending on the platform.
PuglStatus puglHideWindow | ( | PuglView * | view | ) |
Hide the current window.
bool puglGetVisible | ( | PuglView * | view | ) |
Return true iff the view is currently visible.
PuglNativeWindow puglGetNativeWindow | ( | PuglView * | view | ) |
Return the native window handle.
void* puglGetContext | ( | PuglView * | view | ) |
Get the graphics context.
This is a backend-specific context used for drawing if the backend graphics API requires one. It is only available during an expose.
NULL
.cairo_t
. PuglStatus puglEnterContext | ( | PuglView * | view, |
bool | drawing | ||
) |
Enter the graphics context.
Note that, unlike some similar libraries, Pugl automatically enters and leaves the graphics context when required and application should not normally do this. Drawing in Pugl is only allowed during the processing of an expose event.
However, this can be used to enter the graphics context elsewhere, for example to call any GL functions during setup.
view | The view being entered. |
drawing | If true, prepare for drawing. |
PuglStatus puglLeaveContext | ( | PuglView * | view, |
bool | drawing | ||
) |
Leave the graphics context.
This must be called after puglEnterContext() with a matching drawing
parameter.
view | The view being left. |
drawing | If true, finish drawing, for example by swapping buffers. |
PuglStatus puglPostRedisplay | ( | PuglView * | view | ) |
Request a redisplay for the entire view.
This will cause an expose event to be dispatched later. If called from within the event handler, the expose should arrive at the end of the current event loop iteration, though this is not strictly guaranteed on all platforms. If called elsewhere, an expose will be enqueued to be processed in the next event loop iteration.
PuglStatus puglPostRedisplayRect | ( | PuglView * | view, |
PuglRect | rect | ||
) |
Request a redisplay of the given rectangle within the view.
This has the same semantics as puglPostRedisplay(), but allows giving a precise region for redrawing only a portion of the view.
PuglStatus puglGrabFocus | ( | PuglView * | view | ) |
Grab the keyboard input focus.
bool puglHasFocus | ( | const PuglView * | view | ) |
Return whether view
has the keyboard input focus.
PuglStatus puglSetClipboard | ( | PuglView * | view, |
const char * | type, | ||
const void * | data, | ||
size_t | len | ||
) |
Set the clipboard contents.
This sets the system clipboard contents, which can be retrieved with puglGetClipboard() or pasted into other applications.
view | The view. |
type | The MIME type of the data, "text/plain" is assumed if NULL . |
data | The data to copy to the clipboard. |
len | The length of data in bytes (including terminator if necessary). |
const void* puglGetClipboard | ( | PuglView * | view, |
const char ** | type, | ||
size_t * | len | ||
) |
Get the clipboard contents.
This gets the system clipboard contents, which may have been set with puglSetClipboard() or copied from another application.
view | The view. | |
[out] | type | Set to the MIME type of the data. |
[out] | len | Set to the length of the data in bytes. |
PuglStatus puglRequestAttention | ( | PuglView * | view | ) |
Request user attention.
This hints to the system that the window or application requires attention from the user. The exact effect depends on the platform, but is usually something like a flashing task bar entry or bouncing application icon.