summaryrefslogtreecommitdiff
path: root/pugl/pugl.h
blob: a7646209c2b77d15c92a9ed99b9bb71f5ecc2fe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
  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, bool down,
                              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.
   @param resizable Whether window should be user resizable.
*/
PuglWindow*
puglCreate(PuglNativeWindow parent,
           const char*      title,
           int              width,
           int              height,
           bool             resizable);

/**
   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 */