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.

391 lines
9.3KB

  1. /*
  2. Copyright 2012-2014 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. # ifdef _WIN32
  48. # define PUGL_API
  49. # else
  50. # define PUGL_API __attribute__((visibility("hidden")))
  51. # endif
  52. #endif
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #else
  56. # include <stdbool.h>
  57. #endif
  58. /**
  59. @defgroup pugl Pugl
  60. A minimal portable API for OpenGL.
  61. @{
  62. */
  63. /**
  64. An OpenGL view.
  65. */
  66. typedef struct PuglViewImpl PuglView;
  67. /**
  68. A native window handle.
  69. On X11, this is a Window.
  70. On OSX, this is an NSView*.
  71. On Windows, this is a HWND.
  72. */
  73. typedef intptr_t PuglNativeWindow;
  74. /**
  75. Return status code.
  76. */
  77. typedef enum {
  78. PUGL_SUCCESS = 0
  79. } PuglStatus;
  80. /**
  81. Convenience symbols for ASCII control characters.
  82. */
  83. typedef enum {
  84. PUGL_CHAR_BACKSPACE = 0x08,
  85. PUGL_CHAR_ESCAPE = 0x1B,
  86. PUGL_CHAR_DELETE = 0x7F
  87. } PuglChar;
  88. /**
  89. Special (non-Unicode) keyboard keys.
  90. */
  91. typedef enum {
  92. PUGL_KEY_F1 = 1,
  93. PUGL_KEY_F2,
  94. PUGL_KEY_F3,
  95. PUGL_KEY_F4,
  96. PUGL_KEY_F5,
  97. PUGL_KEY_F6,
  98. PUGL_KEY_F7,
  99. PUGL_KEY_F8,
  100. PUGL_KEY_F9,
  101. PUGL_KEY_F10,
  102. PUGL_KEY_F11,
  103. PUGL_KEY_F12,
  104. PUGL_KEY_LEFT,
  105. PUGL_KEY_UP,
  106. PUGL_KEY_RIGHT,
  107. PUGL_KEY_DOWN,
  108. PUGL_KEY_PAGE_UP,
  109. PUGL_KEY_PAGE_DOWN,
  110. PUGL_KEY_HOME,
  111. PUGL_KEY_END,
  112. PUGL_KEY_INSERT,
  113. PUGL_KEY_SHIFT,
  114. PUGL_KEY_CTRL,
  115. PUGL_KEY_ALT,
  116. PUGL_KEY_SUPER
  117. } PuglKey;
  118. /**
  119. Keyboard modifier flags.
  120. */
  121. typedef enum {
  122. PUGL_MOD_SHIFT = 1, /**< Shift key */
  123. PUGL_MOD_CTRL = 1 << 1, /**< Control key */
  124. PUGL_MOD_ALT = 1 << 2, /**< Alt/Option key */
  125. PUGL_MOD_SUPER = 1 << 3 /**< Mod4/Command/Windows key */
  126. } PuglMod;
  127. /**
  128. Handle for opaque user data.
  129. */
  130. typedef void* PuglHandle;
  131. /**
  132. A function called when the window is closed.
  133. */
  134. typedef void (*PuglCloseFunc)(PuglView* view);
  135. /**
  136. A function called to draw the view contents with OpenGL.
  137. */
  138. typedef void (*PuglDisplayFunc)(PuglView* view);
  139. /**
  140. A function called when a key is pressed or released.
  141. @param view The view the event occured in.
  142. @param press True if the key was pressed, false if released.
  143. @param key Unicode point of the key pressed.
  144. */
  145. typedef void (*PuglKeyboardFunc)(PuglView* view, bool press, uint32_t key);
  146. /**
  147. A function called when the pointer moves.
  148. @param view The view the event occured in.
  149. @param x The window-relative x coordinate of the pointer.
  150. @param y The window-relative y coordinate of the pointer.
  151. */
  152. typedef void (*PuglMotionFunc)(PuglView* view, int x, int y);
  153. /**
  154. A function called when a mouse button is pressed or released.
  155. @param view The view the event occured in.
  156. @param button The button number (1 = left, 2 = middle, 3 = right).
  157. @param press True if the key was pressed, false if released.
  158. @param x The window-relative x coordinate of the pointer.
  159. @param y The window-relative y coordinate of the pointer.
  160. */
  161. typedef void (*PuglMouseFunc)(
  162. PuglView* view, int button, bool press, int x, int y);
  163. /**
  164. A function called when the view is resized.
  165. @param view The view being resized.
  166. @param width The new view width.
  167. @param height The new view height.
  168. */
  169. typedef void (*PuglReshapeFunc)(PuglView* view, int width, int height);
  170. /**
  171. A function called on scrolling (e.g. mouse wheel or track pad).
  172. The distances used here are in "lines", a single tick of a clicking mouse
  173. wheel. For example, @p dy = 1.0 scrolls 1 line up. Some systems and
  174. devices support finer resolution and/or higher values for fast scrolls,
  175. so programs should handle any value gracefully.
  176. @param view The view being scrolled.
  177. @param x The window-relative x coordinate of the pointer.
  178. @param y The window-relative y coordinate of the pointer.
  179. @param dx The scroll x distance.
  180. @param dx The scroll y distance.
  181. */
  182. typedef void (*PuglScrollFunc)(PuglView* view, int x, int y, float dx, float dy);
  183. /**
  184. A function called when a special key is pressed or released.
  185. This callback allows the use of keys that do not have unicode points.
  186. Note that some are non-printable keys.
  187. @param view The view the event occured in.
  188. @param press True if the key was pressed, false if released.
  189. @param key The key pressed.
  190. */
  191. typedef void (*PuglSpecialFunc)(PuglView* view, bool press, PuglKey key);
  192. /**
  193. Create a Pugl context.
  194. To create a window, call the various puglInit* functions as necessary, then
  195. call puglCreateWindow().
  196. */
  197. PUGL_API PuglView*
  198. puglInit(void);
  199. /**
  200. Set the parent window before creating a window (for embedding).
  201. */
  202. PUGL_API void
  203. puglInitWindowParent(PuglView* view, PuglNativeWindow parent);
  204. /**
  205. Set the window size before creating a window.
  206. */
  207. PUGL_API void
  208. puglInitWindowSize(PuglView* view, int width, int height);
  209. /**
  210. Enable or disable resizing before creating a window.
  211. */
  212. PUGL_API void
  213. puglInitUserResizable(PuglView* view, bool resizable);
  214. /**
  215. Create a window with the settings given by the various puglInit functions.
  216. @return 1 (pugl does not currently support multiple windows).
  217. */
  218. PUGL_API int
  219. puglCreateWindow(PuglView* view, const char* title);
  220. /**
  221. Show the current window.
  222. */
  223. PUGL_API void
  224. puglShowWindow(PuglView* view);
  225. /**
  226. Hide the current window.
  227. */
  228. PUGL_API void
  229. puglHideWindow(PuglView* view);
  230. /**
  231. Set the handle to be passed to all callbacks.
  232. This is generally a pointer to a struct which contains all necessary state.
  233. Everything needed in callbacks should be here, not in static variables.
  234. Note the lack of this facility makes GLUT unsuitable for plugins or
  235. non-trivial programs; this mistake is largely why Pugl exists.
  236. */
  237. PUGL_API void
  238. puglSetHandle(PuglView* view, PuglHandle handle);
  239. /**
  240. Get the handle to be passed to all callbacks.
  241. */
  242. PUGL_API PuglHandle
  243. puglGetHandle(PuglView* view);
  244. /**
  245. Return the timestamp (if any) of the currently-processing event.
  246. */
  247. PUGL_API uint32_t
  248. puglGetEventTimestamp(PuglView* view);
  249. /**
  250. Get the currently active modifiers (PuglMod flags).
  251. This should only be called from an event handler.
  252. */
  253. PUGL_API int
  254. puglGetModifiers(PuglView* view);
  255. /**
  256. Ignore synthetic repeated key events.
  257. */
  258. PUGL_API void
  259. puglIgnoreKeyRepeat(PuglView* view, bool ignore);
  260. /**
  261. Set the function to call when the window is closed.
  262. */
  263. PUGL_API void
  264. puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc);
  265. /**
  266. Set the display function which should draw the UI using GL.
  267. */
  268. PUGL_API void
  269. puglSetDisplayFunc(PuglView* view, PuglDisplayFunc displayFunc);
  270. /**
  271. Set the function to call on keyboard events.
  272. */
  273. PUGL_API void
  274. puglSetKeyboardFunc(PuglView* view, PuglKeyboardFunc keyboardFunc);
  275. /**
  276. Set the function to call on mouse motion.
  277. */
  278. PUGL_API void
  279. puglSetMotionFunc(PuglView* view, PuglMotionFunc motionFunc);
  280. /**
  281. Set the function to call on mouse button events.
  282. */
  283. PUGL_API void
  284. puglSetMouseFunc(PuglView* view, PuglMouseFunc mouseFunc);
  285. /**
  286. Set the function to call on scroll events.
  287. */
  288. PUGL_API void
  289. puglSetScrollFunc(PuglView* view, PuglScrollFunc scrollFunc);
  290. /**
  291. Set the function to call on special events.
  292. */
  293. PUGL_API void
  294. puglSetSpecialFunc(PuglView* view, PuglSpecialFunc specialFunc);
  295. /**
  296. Set the function to call when the window size changes.
  297. */
  298. PUGL_API void
  299. puglSetReshapeFunc(PuglView* view, PuglReshapeFunc reshapeFunc);
  300. /**
  301. Return the native window handle.
  302. */
  303. PUGL_API PuglNativeWindow
  304. puglGetNativeWindow(PuglView* view);
  305. /**
  306. Process all pending window events.
  307. This handles input events as well as rendering, so it should be called
  308. regularly and rapidly enough to keep the UI responsive.
  309. */
  310. PUGL_API PuglStatus
  311. puglProcessEvents(PuglView* view);
  312. /**
  313. Request a redisplay on the next call to puglProcessEvents().
  314. */
  315. PUGL_API void
  316. puglPostRedisplay(PuglView* view);
  317. /**
  318. Destroy a GL window.
  319. */
  320. PUGL_API void
  321. puglDestroy(PuglView* view);
  322. /**
  323. @}
  324. */
  325. #ifdef __cplusplus
  326. } /* extern "C" */
  327. #endif
  328. #endif /* PUGL_H_INCLUDED */