Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pugl.h 8.5KB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. Copyright 2012 David Robillard <http://drobilla.net>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. /**
  15. @file pugl.h API for Pugl, a minimal portable API for OpenGL.
  16. */
  17. #ifndef PUGL_H_INCLUDED
  18. #define PUGL_H_INCLUDED
  19. #include <stdint.h>
  20. /*
  21. This API is pure portable C and contains no platform specific elements, or
  22. even a GL dependency. However, unfortunately GL includes vary across
  23. platforms so they are included here to allow for pure portable programs.
  24. */
  25. #ifdef __APPLE__
  26. # include "OpenGL/gl.h"
  27. #else
  28. # ifdef _WIN32
  29. # include <windows.h> /* Broken Windows GL headers require this */
  30. # endif
  31. # include "GL/gl.h"
  32. #endif
  33. #ifdef PUGL_SHARED
  34. # ifdef _WIN32
  35. # define PUGL_LIB_IMPORT __declspec(dllimport)
  36. # define PUGL_LIB_EXPORT __declspec(dllexport)
  37. # else
  38. # define PUGL_LIB_IMPORT __attribute__((visibility("default")))
  39. # define PUGL_LIB_EXPORT __attribute__((visibility("default")))
  40. # endif
  41. # ifdef PUGL_INTERNAL
  42. # define PUGL_API PUGL_LIB_EXPORT
  43. # else
  44. # define PUGL_API PUGL_LIB_IMPORT
  45. # endif
  46. #else
  47. # define PUGL_API
  48. #endif
  49. #ifndef __cplusplus
  50. # include <stdbool.h>
  51. #endif
  52. /**
  53. @defgroup pugl Pugl
  54. A minimal portable API for OpenGL.
  55. @{
  56. */
  57. /**
  58. An OpenGL view.
  59. */
  60. typedef struct PuglViewImpl PuglView;
  61. /**
  62. A native window handle.
  63. On X11, this is a Window.
  64. On OSX, this is an NSView*.
  65. On Windows, this is a HWND.
  66. */
  67. typedef intptr_t PuglNativeWindow;
  68. /**
  69. Return status code.
  70. */
  71. typedef enum {
  72. PUGL_SUCCESS = 0
  73. } PuglStatus;
  74. /**
  75. Convenience symbols for ASCII control characters.
  76. */
  77. typedef enum {
  78. PUGL_CHAR_BACKSPACE = 0x08,
  79. PUGL_CHAR_ESCAPE = 0x1B,
  80. PUGL_CHAR_DELETE = 0x7F
  81. } PuglChar;
  82. /**
  83. Special (non-Unicode) keyboard keys.
  84. */
  85. typedef enum {
  86. PUGL_KEY_F1 = 1,
  87. PUGL_KEY_F2,
  88. PUGL_KEY_F3,
  89. PUGL_KEY_F4,
  90. PUGL_KEY_F5,
  91. PUGL_KEY_F6,
  92. PUGL_KEY_F7,
  93. PUGL_KEY_F8,
  94. PUGL_KEY_F9,
  95. PUGL_KEY_F10,
  96. PUGL_KEY_F11,
  97. PUGL_KEY_F12,
  98. PUGL_KEY_LEFT,
  99. PUGL_KEY_UP,
  100. PUGL_KEY_RIGHT,
  101. PUGL_KEY_DOWN,
  102. PUGL_KEY_PAGE_UP,
  103. PUGL_KEY_PAGE_DOWN,
  104. PUGL_KEY_HOME,
  105. PUGL_KEY_END,
  106. PUGL_KEY_INSERT,
  107. PUGL_KEY_SHIFT,
  108. PUGL_KEY_CTRL,
  109. PUGL_KEY_ALT,
  110. PUGL_KEY_SUPER
  111. } PuglKey;
  112. /**
  113. Keyboard modifier flags.
  114. */
  115. typedef enum {
  116. PUGL_MOD_SHIFT = 1, /**< Shift key */
  117. PUGL_MOD_CTRL = 1 << 1, /**< Control key */
  118. PUGL_MOD_ALT = 1 << 2, /**< Alt/Option key */
  119. PUGL_MOD_SUPER = 1 << 3 /**< Mod4/Command/Windows key */
  120. } PuglMod;
  121. /**
  122. Handle for opaque user data.
  123. */
  124. typedef void* PuglHandle;
  125. /**
  126. A function called when the window is closed.
  127. */
  128. typedef void (*PuglCloseFunc)(PuglView* view);
  129. /**
  130. A function called to draw the view contents with OpenGL.
  131. */
  132. typedef void (*PuglDisplayFunc)(PuglView* view);
  133. /**
  134. A function called when a key is pressed or released.
  135. @param view The view the event occured in.
  136. @param press True if the key was pressed, false if released.
  137. @param key Unicode point of the key pressed.
  138. */
  139. typedef void (*PuglKeyboardFunc)(PuglView* view, bool press, uint32_t key);
  140. /**
  141. A function called when the pointer moves.
  142. @param view The view the event occured in.
  143. @param x The window-relative x coordinate of the pointer.
  144. @param y The window-relative y coordinate of the pointer.
  145. */
  146. typedef void (*PuglMotionFunc)(PuglView* view, int x, int y);
  147. /**
  148. A function called when a mouse button is pressed or released.
  149. @param view The view the event occured in.
  150. @param button The button number (1 = left, 2 = middle, 3 = right).
  151. @param press True if the key was pressed, false if released.
  152. @param x The window-relative x coordinate of the pointer.
  153. @param y The window-relative y coordinate of the pointer.
  154. */
  155. typedef void (*PuglMouseFunc)(
  156. PuglView* view, int button, bool press, int x, int y);
  157. /**
  158. A function called when the view is resized.
  159. @param view The view being resized.
  160. @param width The new view width.
  161. @param height The new view height.
  162. */
  163. typedef void (*PuglReshapeFunc)(PuglView* view, int width, int height);
  164. /**
  165. A function called on scrolling (e.g. mouse wheel or track pad).
  166. The distances used here are in "lines", a single tick of a clicking mouse
  167. wheel. For example, @p dy = 1.0 scrolls 1 line up. Some systems and
  168. devices support finer resolution and/or higher values for fast scrolls,
  169. so programs should handle any value gracefully.
  170. @param view The view being scrolled.
  171. @param dx The scroll x distance.
  172. @param dx The scroll y distance.
  173. */
  174. typedef void (*PuglScrollFunc)(PuglView* view, float dx, float dy);
  175. /**
  176. A function called when a special key is pressed or released.
  177. This callback allows the use of keys that do not have unicode points. Note
  178. that some non-printable keys
  179. @param view The view the event occured in.
  180. @param press True if the key was pressed, false if released.
  181. @param key The key pressed.
  182. */
  183. typedef void (*PuglSpecialFunc)(PuglView* view, bool press, PuglKey key);
  184. /**
  185. Create a new GL window.
  186. @param parent Parent window, or 0 for top level.
  187. @param title Window title, or NULL.
  188. @param width Window width in pixels.
  189. @param height Window height in pixels.
  190. @param resizable Whether window should be user resizable.
  191. */
  192. PUGL_API PuglView*
  193. puglCreate(PuglNativeWindow parent,
  194. const char* title,
  195. int width,
  196. int height,
  197. bool resizable,
  198. bool addToDesktop = true,
  199. const char* x11Display = nullptr);
  200. /**
  201. Set the handle to be passed to all callbacks.
  202. This is generally a pointer to a struct which contains all necessary state.
  203. Everything needed in callbacks should be here, not in static variables.
  204. Note the lack of this facility makes GLUT unsuitable for plugins or
  205. non-trivial programs; this mistake is largely why Pugl exists.
  206. */
  207. PUGL_API void
  208. puglSetHandle(PuglView* view, PuglHandle handle);
  209. /**
  210. Get the handle to be passed to all callbacks.
  211. */
  212. PUGL_API PuglHandle
  213. puglGetHandle(PuglView* view);
  214. /**
  215. Get the currently active modifiers (PuglMod flags).
  216. This should only be called from an event handler.
  217. */
  218. PUGL_API int
  219. puglGetModifiers(PuglView* view);
  220. /**
  221. Ignore synthetic repeated key events.
  222. */
  223. PUGL_API void
  224. puglIgnoreKeyRepeat(PuglView* view, bool ignore);
  225. /**
  226. Set the function to call when the window is closed.
  227. */
  228. PUGL_API void
  229. puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc);
  230. /**
  231. Set the display function which should draw the UI using GL.
  232. */
  233. PUGL_API void
  234. puglSetDisplayFunc(PuglView* view, PuglDisplayFunc displayFunc);
  235. /**
  236. Set the function to call on keyboard events.
  237. */
  238. PUGL_API void
  239. puglSetKeyboardFunc(PuglView* view, PuglKeyboardFunc keyboardFunc);
  240. /**
  241. Set the function to call on mouse motion.
  242. */
  243. PUGL_API void
  244. puglSetMotionFunc(PuglView* view, PuglMotionFunc motionFunc);
  245. /**
  246. Set the function to call on mouse button events.
  247. */
  248. PUGL_API void
  249. puglSetMouseFunc(PuglView* view, PuglMouseFunc mouseFunc);
  250. /**
  251. Set the function to call on scroll events.
  252. */
  253. PUGL_API void
  254. puglSetScrollFunc(PuglView* view, PuglScrollFunc scrollFunc);
  255. /**
  256. Set the function to call on special events.
  257. */
  258. PUGL_API void
  259. puglSetSpecialFunc(PuglView* view, PuglSpecialFunc specialFunc);
  260. /**
  261. Set the function to call when the window size changes.
  262. */
  263. PUGL_API void
  264. puglSetReshapeFunc(PuglView* view, PuglReshapeFunc reshapeFunc);
  265. /**
  266. Return the native window handle.
  267. */
  268. PUGL_API PuglNativeWindow
  269. puglGetNativeWindow(PuglView* view);
  270. /**
  271. Process all pending window events.
  272. This handles input events as well as rendering, so it should be called
  273. regularly and rapidly enough to keep the UI responsive.
  274. */
  275. PUGL_API PuglStatus
  276. puglProcessEvents(PuglView* view);
  277. /**
  278. Request a redisplay on the next call to puglProcessEvents().
  279. */
  280. PUGL_API void
  281. puglPostRedisplay(PuglView* view);
  282. /**
  283. Destroy a GL window.
  284. */
  285. PUGL_API void
  286. puglDestroy(PuglView* view);
  287. /**
  288. @}
  289. */
  290. #endif /* PUGL_H_INCLUDED */