1 // ----------------------------------------------------------------------------
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.
9 // @author Philippe Decaudin - http://www.antisphere.com
11 // @doc http://www.antisphere.com/Wiki/tools:anttweakbar
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
17 // ----------------------------------------------------------------------------
20 #if !defined TW_INCLUDED
23 #define TW_STATIC 1 //no dynamic link library (DLL) hell
24 #define TW_NO_LIB_PRAGMA 1 //no magic linking nonsense, thank you
28 #define TW_VERSION 115 // Version Mmm : M=Major mm=minor (e.g., 102 is version 1.02)
32 # if defined(_MSC_VER)
33 # pragma warning(push)
34 # pragma warning(disable: 4995 4530)
44 // ----------------------------------------------------------------------------
45 // OS specific definitions
46 // ----------------------------------------------------------------------------
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)
55 # define TW_CDECL_CALL
56 # define TW_EXPORT_API
57 # define TW_IMPORT_API
60 #if defined TW_EXPORTS
61 # define TW_API TW_EXPORT_API
62 #elif defined TW_STATIC
64 # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA)
66 # pragma comment(lib, "AntTweakBarStatic64")
68 # pragma comment(lib, "AntTweakBarStatic")
72 # define TW_API TW_IMPORT_API
73 # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA)
75 # pragma comment(lib, "AntTweakBar64")
77 # pragma comment(lib, "AntTweakBar")
83 // ----------------------------------------------------------------------------
84 // Bar functions and definitions
85 // ----------------------------------------------------------------------------
87 typedef struct CTwBar TwBar; // structure CTwBar is not exposed.
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);
102 // ----------------------------------------------------------------------------
103 // Var functions and definitions
104 // ----------------------------------------------------------------------------
111 #endif // __cplusplus
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)
129 # if defined(_MSC_VER) && (_MSC_VER > 1500)
130 TW_TYPE_STDSTRING = (0x2ffe0000+sizeof(std::string)), // VS2010 or higher C++ STL string (std::string)
132 TW_TYPE_STDSTRING = (0x2fff0000+sizeof(std::string)), // C++ STL string (std::string)
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
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)
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);
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);
154 typedef struct CTwEnumVal
159 typedef struct CTwStructMember
164 const char * DefString;
166 typedef void (TW_CALL * TwSummaryCallback)(char *summaryString, size_t summaryMaxLength, const void *value, void *clientData);
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);
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);
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
182 typedef enum ETwParamValueType
187 TW_PARAM_CSTRING // Null-terminated array of char (ie, c-string)
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);
193 // ----------------------------------------------------------------------------
194 // Management functions and definitions
195 // ----------------------------------------------------------------------------
197 typedef enum ETwGraphAPI
206 TW_API int TW_CALL TwInit(TwGraphAPI graphAPI, void *device);
207 TW_API int TW_CALL TwTerminate();
209 TW_API int TW_CALL TwDraw();
210 TW_API int TW_CALL TwWindowSize(int width, int height);
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);
216 typedef enum ETwKeyModifier
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
224 typedef enum EKeySpecial
226 TW_KEY_BACKSPACE = '\b',
229 TW_KEY_RETURN = '\r',
231 TW_KEY_ESCAPE = 0x1b,
233 TW_KEY_DELETE = 0x7f,
234 TW_KEY_UP = 273, // same codes and order as SDL 1.2 keysym.sym
261 TW_API int TW_CALL TwKeyPressed(int key, int modifiers);
262 TW_API int TW_CALL TwKeyTest(int key, int modifiers);
264 typedef enum ETwMouseAction
269 typedef enum ETwMouseButtonID
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
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);
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);
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 // ----------------------------------------------------------------------------
292 // For Windows message proc
293 #ifndef _W64 // Microsoft specific (detection of 64 bits portability issues)
297 TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned __int64 _W64 wParam, __int64 _W64 lParam);
299 TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned int _W64 wParam, int _W64 lParam);
301 #define TwEventWin32 TwEventWin // For compatibility with AntTweakBar versions prior to 1.11
303 // For libSDL event loop
304 TW_API int TW_CALL TwEventSDL(const void *sdlEvent, unsigned char sdlMajorVersion, unsigned char sdlMinorVersion);
306 // For GLFW event callbacks
307 // You should define GLFW_CDECL before including AntTweakBar.h if your version of GLFW uses cdecl calling convensions
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
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
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
331 # define TW_GLUT_CALL
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);
343 // For SFML event loop
344 TW_API int TW_CALL TwEventSFML(const void *sfmlEvent, unsigned char sfmlMajorVersion, unsigned char sfmlMinorVersion);
346 // For X11 event loop
348 TW_API int TW_CDECL_CALL TwEventX11(void *xevent);
351 // ----------------------------------------------------------------------------
352 // Make sure the types have the right sizes
353 // ----------------------------------------------------------------------------
355 #define TW_COMPILE_TIME_ASSERT(name, x) typedef int TW_DUMMY_ ## name[(x) * 2 - 1]
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);
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);
373 // ---------------------------------------------------------------------------
378 #endif // __cplusplus
381 #endif // !defined TW_INCLUDED