diff options
author | David Robillard <d@drobilla.net> | 2012-04-28 23:34:25 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-04-28 23:34:25 +0000 |
commit | 43083a0ca80a876286b6a6ef39ec6f10c9b6f9bf (patch) | |
tree | cd835b2ce67291826979ce6fa8a15de046bc6151 /pugl/pugl.h | |
parent | 0ed09c95b5d94eb4e109bd402de00c46036b8239 (diff) | |
download | pugl-43083a0ca80a876286b6a6ef39ec6f10c9b6f9bf.tar.gz pugl-43083a0ca80a876286b6a6ef39ec6f10c9b6f9bf.tar.bz2 pugl-43083a0ca80a876286b6a6ef39ec6f10c9b6f9bf.zip |
Initial import.
Diffstat (limited to 'pugl/pugl.h')
-rw-r--r-- | pugl/pugl.h | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h new file mode 100644 index 0000000..853a754 --- /dev/null +++ b/pugl/pugl.h @@ -0,0 +1,154 @@ +/* + Copyright 2012 David Robillard <http://drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/** + @file pugl.h API for Pugl, a portable micro-framework for GL UIs. +*/ + +#ifndef PUGL_H_INCLUDED +#define PUGL_H_INCLUDED + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#else +# include <stdbool.h> +#endif + +typedef struct PuglWindowImpl PuglWindow; + +/** + A native window handle. + + For X11, this is a Window. +*/ +typedef intptr_t PuglNativeWindow; + +typedef enum { + PUGL_SUCCESS = 0 +} PuglStatus; + +/** + Handle for opaque user data. +*/ +typedef void* PuglHandle; + +typedef void (*PuglCloseFunc)(PuglWindow* handle); +typedef void (*PuglDisplayFunc)(PuglWindow* handle); +typedef void (*PuglKeyboardFunc)(PuglWindow* handle, bool press, uint32_t key); +typedef void (*PuglMotionFunc)(PuglWindow* handle, int x, int y); +typedef void (*PuglMouseFunc)(PuglWindow* handle, + int button, int state, + int x, int y); +typedef void (*PuglReshapeFunc)(PuglWindow* handle, int width, int height); + +/** + Create a new GL window. + @param parent Parent window, or 0 for top level. + @param title Window title, or NULL. + @param width Window width in pixels. + @param height Window height in pixels. +*/ +PuglWindow* +puglCreate(PuglNativeWindow parent, const char* title, int width, int height); + +/** + Set the handle to be passed to all callbacks. + + This is generally a pointer to a struct which contains all necessary state. + Everything needed in callbacks should be here, not in static variables. + + Note the lack of this facility makes GLUT unsuitable for plugins or + non-trivial programs; this mistake is largely why Pugl exists. +*/ +void +puglSetHandle(PuglWindow* window, PuglHandle handle); + +/** + Get the handle to be passed to all callbacks. +*/ +PuglHandle +puglGetHandle(PuglWindow* window); + +/** + Set the function to call when the window is closed. +*/ +void +puglSetCloseFunc(PuglWindow* window, PuglCloseFunc closeFunc); + +/** + Set the display function which should draw the UI using GL. +*/ +void +puglSetDisplayFunc(PuglWindow* window, PuglDisplayFunc displayFunc); + +/** + Set the function to call on keyboard events. +*/ +void +puglSetKeyboardFunc(PuglWindow* window, PuglKeyboardFunc keyboardFunc); + +/** + Set the function to call on mouse motion. +*/ +void +puglSetMotionFunc(PuglWindow* window, PuglMotionFunc motionFunc); + +/** + Set the function to call on mouse button events. +*/ +void +puglSetMouseFunc(PuglWindow* window, PuglMouseFunc mouseFunc); + +/** + Set the function to call when the window size changes. +*/ +void +puglSetReshapeFunc(PuglWindow* window, PuglReshapeFunc reshapeFunc); + +/** + Return the native window handle. +*/ +PuglNativeWindow +puglGetNativeWindow(PuglWindow* win); + +/** + Process all pending window events. + + This handles input events as well as rendering, so it should be called + regularly and rapidly enough to keep the UI responsive. +*/ +PuglStatus +puglProcessEvents(PuglWindow* win); + +/** + Request a redisplay on the next call to puglProcessEvents(). +*/ +void +puglPostRedisplay(PuglWindow* win); + +/** + Destroy a GL window. +*/ +void +puglDestroy(PuglWindow* win); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* PUGL_H_INCLUDED */ |