Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / CDTestFramework / AntTweakBar / include / AntTweakBar.h
1 // ----------------------------------------------------------------------------
2 //
3 //  @file       AntTweakBar.h
4 //
5 //  @brief      AntTweakBar is a light and intuitive graphical user interface 
6 //              that can be readily integrated into OpenGL and DirectX 
7 //              applications in order to interactively tweak parameters.
8 //
9 //  @author     Philippe Decaudin - http://www.antisphere.com
10 //
11 //  @doc        http://www.antisphere.com/Wiki/tools:anttweakbar
12 //
13 //  @license    This file is part of the AntTweakBar library.
14 //              AntTweakBar is a free software released under the zlib license.
15 //              For conditions of distribution and use, see License.txt
16 //
17 // ----------------------------------------------------------------------------
18
19
20 #if !defined TW_INCLUDED
21 #define TW_INCLUDED
22
23 #define TW_STATIC 1                                     //no dynamic link library (DLL) hell
24 #define TW_NO_LIB_PRAGMA 1  //no magic linking nonsense, thank you
25
26 #include <stddef.h>
27
28 #define TW_VERSION  115 // Version Mmm : M=Major mm=minor (e.g., 102 is version 1.02)
29
30
31 #ifdef  __cplusplus
32 #   if defined(_MSC_VER)
33 #       pragma warning(push)
34 #       pragma warning(disable: 4995 4530)
35 #       include <string>
36 #       pragma warning(pop)
37 #   else
38 #       include <string>
39 #   endif
40     extern "C" {
41 #endif  // __cplusplus
42
43
44 // ----------------------------------------------------------------------------
45 //  OS specific definitions
46 // ----------------------------------------------------------------------------
47
48 #if (defined(_WIN32) || defined(_WIN64)) && !defined(TW_STATIC)
49 #   define TW_CALL          __stdcall
50 #   define TW_CDECL_CALL    __cdecl
51 #   define TW_EXPORT_API    __declspec(dllexport)
52 #   define TW_IMPORT_API    __declspec(dllimport)
53 #else
54 #   define TW_CALL
55 #   define TW_CDECL_CALL
56 #   define TW_EXPORT_API
57 #   define TW_IMPORT_API
58 #endif
59
60 #if defined TW_EXPORTS
61 #   define TW_API TW_EXPORT_API
62 #elif defined TW_STATIC
63 #   define TW_API
64 #   if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA)
65 #       ifdef _WIN64
66 #           pragma comment(lib, "AntTweakBarStatic64")
67 #       else
68 #           pragma comment(lib, "AntTweakBarStatic")
69 #       endif
70 #   endif
71 #else
72 #   define TW_API TW_IMPORT_API
73 #   if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA)
74 #       ifdef _WIN64
75 #           pragma comment(lib, "AntTweakBar64")
76 #       else
77 #           pragma comment(lib, "AntTweakBar")
78 #       endif
79 #   endif
80 #endif
81
82
83 // ----------------------------------------------------------------------------
84 //  Bar functions and definitions
85 // ----------------------------------------------------------------------------
86
87 typedef struct CTwBar TwBar; // structure CTwBar is not exposed.
88
89 TW_API TwBar *      TW_CALL TwNewBar(const char *barName);
90 TW_API int          TW_CALL TwDeleteBar(TwBar *bar);
91 TW_API int          TW_CALL TwDeleteAllBars();
92 TW_API int          TW_CALL TwSetTopBar(const TwBar *bar);
93 TW_API TwBar *      TW_CALL TwGetTopBar();
94 TW_API int          TW_CALL TwSetBottomBar(const TwBar *bar);
95 TW_API TwBar *      TW_CALL TwGetBottomBar();
96 TW_API const char * TW_CALL TwGetBarName(TwBar *bar);
97 TW_API int          TW_CALL TwGetBarCount();
98 TW_API TwBar *      TW_CALL TwGetBarByIndex(int barIndex);
99 TW_API TwBar *      TW_CALL TwGetBarByName(const char *barName);
100 TW_API int          TW_CALL TwRefreshBar(TwBar *bar);
101
102 // ----------------------------------------------------------------------------
103 //  Var functions and definitions
104 // ----------------------------------------------------------------------------
105
106 typedef enum ETwType
107 {
108     TW_TYPE_UNDEF   = 0,
109 #ifdef __cplusplus
110     TW_TYPE_BOOLCPP = 1,
111 #endif // __cplusplus
112     TW_TYPE_BOOL8   = 2,
113     TW_TYPE_BOOL16,
114     TW_TYPE_BOOL32,
115     TW_TYPE_CHAR,
116     TW_TYPE_INT8,
117     TW_TYPE_UINT8,
118     TW_TYPE_INT16,
119     TW_TYPE_UINT16,
120     TW_TYPE_INT32,
121     TW_TYPE_UINT32,
122     TW_TYPE_FLOAT,
123     TW_TYPE_DOUBLE,
124     TW_TYPE_COLOR32,    // 32 bits color. Order is RGBA if API is OpenGL or Direct3D10, and inversed if API is Direct3D9 (can be modified by defining 'colorOrder=...', see doc)
125     TW_TYPE_COLOR3F,    // 3 floats color. Order is RGB.
126     TW_TYPE_COLOR4F,    // 4 floats color. Order is RGBA.
127     TW_TYPE_CDSTRING,   // Null-terminated C Dynamic String (pointer to an array of char dynamically allocated with malloc/realloc/strdup)
128 #ifdef __cplusplus
129 # if defined(_MSC_VER) && (_MSC_VER > 1500)
130     TW_TYPE_STDSTRING = (0x2ffe0000+sizeof(std::string)),  // VS2010 or higher C++ STL string (std::string)
131 # else
132     TW_TYPE_STDSTRING = (0x2fff0000+sizeof(std::string)),  // C++ STL string (std::string)
133 # endif
134 #endif // __cplusplus
135     TW_TYPE_QUAT4F = TW_TYPE_CDSTRING+2, // 4 floats encoding a quaternion {qx,qy,qz,qs}
136     TW_TYPE_QUAT4D,     // 4 doubles encoding a quaternion {qx,qy,qz,qs}
137     TW_TYPE_DIR3F,      // direction vector represented by 3 floats
138     TW_TYPE_DIR3D       // direction vector represented by 3 doubles
139 } TwType;
140 #define TW_TYPE_CSSTRING(n) ((TwType)(0x30000000+((n)&0xfffffff))) // Null-terminated C Static String of size n (defined as char[n], with n<2^28)
141
142 typedef void (TW_CALL * TwSetVarCallback)(const void *value, void *clientData);
143 typedef void (TW_CALL * TwGetVarCallback)(void *value, void *clientData);
144 typedef void (TW_CALL * TwButtonCallback)(void *clientData);
145
146 TW_API int      TW_CALL TwAddVarRW(TwBar *bar, const char *name, TwType type, void *var, const char *def);
147 TW_API int      TW_CALL TwAddVarRO(TwBar *bar, const char *name, TwType type, const void *var, const char *def);
148 TW_API int      TW_CALL TwAddVarCB(TwBar *bar, const char *name, TwType type, TwSetVarCallback setCallback, TwGetVarCallback getCallback, void *clientData, const char *def);
149 TW_API int      TW_CALL TwAddButton(TwBar *bar, const char *name, TwButtonCallback callback, void *clientData, const char *def);
150 TW_API int      TW_CALL TwAddSeparator(TwBar *bar, const char *name, const char *def);
151 TW_API int      TW_CALL TwRemoveVar(TwBar *bar, const char *name);
152 TW_API int      TW_CALL TwRemoveAllVars(TwBar *bar);
153
154 typedef struct CTwEnumVal
155 {
156     int           Value;
157     const char *  Label;
158 } TwEnumVal;
159 typedef struct CTwStructMember
160 {
161     const char *  Name;
162     TwType        Type;
163     size_t        Offset;
164     const char *  DefString;
165 } TwStructMember;
166 typedef void (TW_CALL * TwSummaryCallback)(char *summaryString, size_t summaryMaxLength, const void *value, void *clientData);
167
168 TW_API int      TW_CALL TwDefine(const char *def);
169 TW_API TwType   TW_CALL TwDefineEnum(const char *name, const TwEnumVal *enumValues, unsigned int nbValues);
170 TW_API TwType   TW_CALL TwDefineEnumFromString(const char *name, const char *enumString);
171 TW_API TwType   TW_CALL TwDefineStruct(const char *name, const TwStructMember *structMembers, unsigned int nbMembers, size_t structSize, TwSummaryCallback summaryCallback, void *summaryClientData);
172
173 typedef void (TW_CALL * TwCopyCDStringToClient)(char **destinationClientStringPtr, const char *sourceString);
174 TW_API void     TW_CALL TwCopyCDStringToClientFunc(TwCopyCDStringToClient copyCDStringFunc);
175 TW_API void     TW_CALL TwCopyCDStringToLibrary(char **destinationLibraryStringPtr, const char *sourceClientString);
176 #ifdef __cplusplus
177 typedef void (TW_CALL * TwCopyStdStringToClient)(std::string& destinationClientString, const std::string& sourceString);
178 TW_API void     TW_CALL TwCopyStdStringToClientFunc(TwCopyStdStringToClient copyStdStringToClientFunc);
179 TW_API void     TW_CALL TwCopyStdStringToLibrary(std::string& destinationLibraryString, const std::string& sourceClientString);
180 #endif // __cplusplus
181
182 typedef enum ETwParamValueType
183 {
184     TW_PARAM_INT32,
185     TW_PARAM_FLOAT,
186     TW_PARAM_DOUBLE,
187     TW_PARAM_CSTRING // Null-terminated array of char (ie, c-string)
188 } TwParamValueType;
189 TW_API int      TW_CALL TwGetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int outValueMaxCount, void *outValues);
190 TW_API int      TW_CALL TwSetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int inValueCount, const void *inValues);
191
192
193 // ----------------------------------------------------------------------------
194 //  Management functions and definitions
195 // ----------------------------------------------------------------------------
196
197 typedef enum ETwGraphAPI
198 {
199     TW_OPENGL           = 1,
200     TW_DIRECT3D9        = 2,
201     TW_DIRECT3D10       = 3,
202     TW_DIRECT3D11       = 4,
203     TW_OPENGL_CORE      = 5
204 } TwGraphAPI;
205
206 TW_API int      TW_CALL TwInit(TwGraphAPI graphAPI, void *device);
207 TW_API int      TW_CALL TwTerminate();
208
209 TW_API int      TW_CALL TwDraw();
210 TW_API int      TW_CALL TwWindowSize(int width, int height);
211
212 TW_API int      TW_CALL TwSetCurrentWindow(int windowID); // multi-windows support
213 TW_API int      TW_CALL TwGetCurrentWindow();
214 TW_API int      TW_CALL TwWindowExists(int windowID);
215
216 typedef enum ETwKeyModifier
217 {
218     TW_KMOD_NONE        = 0x0000,   // same codes as SDL keysym.mod
219     TW_KMOD_SHIFT       = 0x0003,
220     TW_KMOD_CTRL        = 0x00c0,
221     TW_KMOD_ALT         = 0x0100,
222     TW_KMOD_META        = 0x0c00
223 } TwKeyModifier;
224 typedef enum EKeySpecial
225 {
226     TW_KEY_BACKSPACE    = '\b',
227     TW_KEY_TAB          = '\t',
228     TW_KEY_CLEAR        = 0x0c,
229     TW_KEY_RETURN       = '\r',
230     TW_KEY_PAUSE        = 0x13,
231     TW_KEY_ESCAPE       = 0x1b,
232     TW_KEY_SPACE        = ' ',
233     TW_KEY_DELETE       = 0x7f,
234     TW_KEY_UP           = 273,      // same codes and order as SDL 1.2 keysym.sym
235     TW_KEY_DOWN,
236     TW_KEY_RIGHT,
237     TW_KEY_LEFT,
238     TW_KEY_INSERT,
239     TW_KEY_HOME,
240     TW_KEY_END,
241     TW_KEY_PAGE_UP,
242     TW_KEY_PAGE_DOWN,
243     TW_KEY_F1,
244     TW_KEY_F2,
245     TW_KEY_F3,
246     TW_KEY_F4,
247     TW_KEY_F5,
248     TW_KEY_F6,
249     TW_KEY_F7,
250     TW_KEY_F8,
251     TW_KEY_F9,
252     TW_KEY_F10,
253     TW_KEY_F11,
254     TW_KEY_F12,
255     TW_KEY_F13,
256     TW_KEY_F14,
257     TW_KEY_F15,
258     TW_KEY_LAST
259 } TwKeySpecial;
260
261 TW_API int      TW_CALL TwKeyPressed(int key, int modifiers);
262 TW_API int      TW_CALL TwKeyTest(int key, int modifiers);
263
264 typedef enum ETwMouseAction
265 {
266     TW_MOUSE_RELEASED,
267     TW_MOUSE_PRESSED  
268 } TwMouseAction;
269 typedef enum ETwMouseButtonID
270 {
271     TW_MOUSE_LEFT       = 1,    // same code as SDL_BUTTON_LEFT
272     TW_MOUSE_MIDDLE     = 2,    // same code as SDL_BUTTON_MIDDLE
273     TW_MOUSE_RIGHT      = 3     // same code as SDL_BUTTON_RIGHT
274 } TwMouseButtonID;
275
276 TW_API int      TW_CALL TwMouseButton(TwMouseAction action, TwMouseButtonID button);
277 TW_API int      TW_CALL TwMouseMotion(int mouseX, int mouseY);
278 TW_API int      TW_CALL TwMouseWheel(int pos);
279
280 TW_API const char * TW_CALL TwGetLastError();
281 typedef void (TW_CALL * TwErrorHandler)(const char *errorMessage);
282 TW_API void     TW_CALL TwHandleErrors(TwErrorHandler errorHandler);
283
284
285 // ----------------------------------------------------------------------------
286 //  Helper functions to translate events from some common window management
287 //  frameworks to AntTweakBar.
288 //  They call TwKeyPressed, TwMouse* and TwWindowSize for you (implemented in
289 //  files TwEventWin.c TwEventSDL*.c TwEventGLFW.c TwEventGLUT.c)
290 // ----------------------------------------------------------------------------
291
292 // For Windows message proc
293 #ifndef _W64    // Microsoft specific (detection of 64 bits portability issues)
294 #   define _W64
295 #endif  // _W64
296 #ifdef _WIN64
297     TW_API int  TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned __int64 _W64 wParam, __int64 _W64 lParam);
298 #else
299     TW_API int  TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned int _W64 wParam, int _W64 lParam);
300 #endif
301 #define TwEventWin32    TwEventWin // For compatibility with AntTweakBar versions prior to 1.11
302
303 // For libSDL event loop
304 TW_API int      TW_CALL TwEventSDL(const void *sdlEvent, unsigned char sdlMajorVersion, unsigned char sdlMinorVersion);
305
306 // For GLFW event callbacks
307 // You should define GLFW_CDECL before including AntTweakBar.h if your version of GLFW uses cdecl calling convensions
308 #ifdef GLFW_CDECL
309     TW_API int TW_CDECL_CALL TwEventMouseButtonGLFWcdecl(int glfwButton, int glfwAction);
310     TW_API int TW_CDECL_CALL TwEventKeyGLFWcdecl(int glfwKey, int glfwAction);
311     TW_API int TW_CDECL_CALL TwEventCharGLFWcdecl(int glfwChar, int glfwAction);
312     TW_API int TW_CDECL_CALL TwEventMousePosGLFWcdecl(int mouseX, int mouseY);
313     TW_API int TW_CDECL_CALL TwEventMouseWheelGLFWcdecl(int wheelPos);
314 #   define TwEventMouseButtonGLFW TwEventMouseButtonGLFWcdecl
315 #   define TwEventKeyGLFW         TwEventKeyGLFWcdecl
316 #   define TwEventCharGLFW        TwEventCharGLFWcdecl
317 #   define TwEventMousePosGLFW    TwEventMousePosGLFWcdecl
318 #   define TwEventMouseWheelGLFW  TwEventMouseWheelGLFWcdecl
319 #else
320     TW_API int  TW_CALL TwEventMouseButtonGLFW(int glfwButton, int glfwAction);
321     TW_API int  TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction);
322     TW_API int  TW_CALL TwEventCharGLFW(int glfwChar, int glfwAction);
323 #   define TwEventMousePosGLFW     TwMouseMotion
324 #   define TwEventMouseWheelGLFW   TwMouseWheel
325 #endif
326
327 // For GLUT event callbacks (Windows calling convention for GLUT callbacks is cdecl)
328 #if defined(_WIN32) || defined(_WIN64)
329 #   define TW_GLUT_CALL TW_CDECL_CALL
330 #else
331 #   define TW_GLUT_CALL
332 #endif
333 TW_API int TW_GLUT_CALL TwEventMouseButtonGLUT(int glutButton, int glutState, int mouseX, int mouseY);
334 TW_API int TW_GLUT_CALL TwEventMouseMotionGLUT(int mouseX, int mouseY);
335 TW_API int TW_GLUT_CALL TwEventKeyboardGLUT(unsigned char glutKey, int mouseX, int mouseY);
336 TW_API int TW_GLUT_CALL TwEventSpecialGLUT(int glutKey, int mouseX, int mouseY);
337 TW_API int TW_CALL      TwGLUTModifiersFunc(int (TW_CALL *glutGetModifiersFunc)(void));
338 typedef void (TW_GLUT_CALL *GLUTmousebuttonfun)(int glutButton, int glutState, int mouseX, int mouseY);
339 typedef void (TW_GLUT_CALL *GLUTmousemotionfun)(int mouseX, int mouseY);
340 typedef void (TW_GLUT_CALL *GLUTkeyboardfun)(unsigned char glutKey, int mouseX, int mouseY);
341 typedef void (TW_GLUT_CALL *GLUTspecialfun)(int glutKey, int mouseX, int mouseY);
342
343 // For SFML event loop
344 TW_API int      TW_CALL TwEventSFML(const void *sfmlEvent, unsigned char sfmlMajorVersion, unsigned char sfmlMinorVersion);
345
346 // For X11 event loop
347 #if defined(_UNIX)
348     TW_API int TW_CDECL_CALL TwEventX11(void *xevent);
349 #endif
350
351 // ----------------------------------------------------------------------------
352 //  Make sure the types have the right sizes
353 // ----------------------------------------------------------------------------
354
355 #define TW_COMPILE_TIME_ASSERT(name, x) typedef int TW_DUMMY_ ## name[(x) * 2 - 1]
356
357 TW_COMPILE_TIME_ASSERT(TW_CHAR,    sizeof(char)    == 1);
358 TW_COMPILE_TIME_ASSERT(TW_SHORT,   sizeof(short)   == 2);
359 TW_COMPILE_TIME_ASSERT(TW_INT,     sizeof(int)     == 4);
360 TW_COMPILE_TIME_ASSERT(TW_FLOAT,   sizeof(float)   == 4);
361 TW_COMPILE_TIME_ASSERT(TW_DOUBLE,  sizeof(double)  == 8);
362
363 // Check pointer size on Windows
364 #if !defined(_WIN64) && defined(_WIN32)
365     // If the following assert failed, the platform is not 32-bit and _WIN64 is not defined.
366     // When targetting 64-bit Windows platform, _WIN64 must be defined.
367     TW_COMPILE_TIME_ASSERT(TW_PTR32, sizeof(void*) == 4);
368 #elif defined(_WIN64)
369     // If the following assert failed, _WIN64 is defined but the targeted platform is not 64-bit.
370     TW_COMPILE_TIME_ASSERT(TW_PTR64, sizeof(void*) == 8);
371 #endif
372
373 //  ---------------------------------------------------------------------------
374
375
376 #ifdef  __cplusplus
377     }   // extern "C"
378 #endif  // __cplusplus
379
380
381 #endif  // !defined TW_INCLUDED