AntTweakBar.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 them.
  8. //
  9. // @author Philippe Decaudin - http://www.antisphere.com
  10. // @date 2005/09/20
  11. //
  12. // @doc http://www.antisphere.com/Wiki/tools:anttweakbar
  13. //
  14. // @license This file is part of the AntTweakBar library.
  15. // AntTweakBar is a free software released under the zlib license.
  16. // For conditions of distribution and use, see License.txt
  17. //
  18. // ----------------------------------------------------------------------------
  19. #if !defined TW_INCLUDED
  20. #define TW_INCLUDED
  21. #include <stddef.h>
  22. #define TW_VERSION 113 // Version Mmm : M=Major mm=minor (e.g., 102 is version 1.02)
  23. #ifdef __cplusplus
  24. # if defined(_MSC_VER)
  25. # pragma warning(push)
  26. # pragma warning(disable: 4995 4530)
  27. # include <string>
  28. # pragma warning(pop)
  29. # else
  30. # include <string>
  31. # endif
  32. extern "C" {
  33. #endif // __cplusplus
  34. // ----------------------------------------------------------------------------
  35. // OS specific definitions
  36. // ----------------------------------------------------------------------------
  37. #if defined(_WIN32) || defined(_WIN64)
  38. # define TW_CALL __stdcall
  39. # define TW_EXPORT_API __declspec(dllexport)
  40. # define TW_IMPORT_API __declspec(dllimport)
  41. #else
  42. # define TW_CALL
  43. # define TW_EXPORT_API
  44. # define TW_IMPORT_API
  45. #endif
  46. #if defined TW_EXPORTS
  47. # define TW_API TW_EXPORT_API
  48. #elif defined TW_STATIC
  49. # define TW_API
  50. # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA)
  51. # pragma comment(lib, "AntTweakBarStatic")
  52. # endif
  53. #else
  54. # define TW_API TW_IMPORT_API
  55. # if defined(_MSC_VER) && !defined(TW_NO_LIB_PRAGMA)
  56. # pragma comment(lib, "AntTweakBar")
  57. # endif
  58. #endif
  59. // ----------------------------------------------------------------------------
  60. // Bar functions and definitions
  61. // ----------------------------------------------------------------------------
  62. typedef struct CTwBar TwBar; // structure CTwBar is not exposed.
  63. TW_API TwBar * TW_CALL TwNewBar(const char *barName);
  64. TW_API int TW_CALL TwDeleteBar(TwBar *bar);
  65. TW_API int TW_CALL TwDeleteAllBars();
  66. TW_API int TW_CALL TwSetTopBar(const TwBar *bar);
  67. TW_API TwBar * TW_CALL TwGetTopBar();
  68. TW_API int TW_CALL TwSetBottomBar(const TwBar *bar);
  69. TW_API TwBar * TW_CALL TwGetBottomBar();
  70. TW_API const char * TW_CALL TwGetBarName(TwBar *bar);
  71. TW_API int TW_CALL TwGetBarCount();
  72. TW_API TwBar * TW_CALL TwGetBarByIndex(int barIndex);
  73. TW_API TwBar * TW_CALL TwGetBarByName(const char *barName);
  74. TW_API int TW_CALL TwRefreshBar(TwBar *bar);
  75. // ----------------------------------------------------------------------------
  76. // Var functions and definitions
  77. // ----------------------------------------------------------------------------
  78. typedef enum ETwType
  79. {
  80. TW_TYPE_UNDEF = 0,
  81. #ifdef __cplusplus
  82. TW_TYPE_BOOLCPP = 1,
  83. #endif // __cplusplus
  84. TW_TYPE_BOOL8 = 2,
  85. TW_TYPE_BOOL16,
  86. TW_TYPE_BOOL32,
  87. TW_TYPE_CHAR,
  88. TW_TYPE_INT8,
  89. TW_TYPE_UINT8,
  90. TW_TYPE_INT16,
  91. TW_TYPE_UINT16,
  92. TW_TYPE_INT32,
  93. TW_TYPE_UINT32,
  94. TW_TYPE_FLOAT,
  95. TW_TYPE_DOUBLE,
  96. 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)
  97. TW_TYPE_COLOR3F, // 3 floats color. Order is RGB.
  98. TW_TYPE_COLOR4F, // 4 floats color. Order is RGBA.
  99. TW_TYPE_CDSTRING, // Null-terminated C Dynamic String (pointer to an array of char dynamically allocated with malloc/realloc/strdup)
  100. #ifdef __cplusplus
  101. TW_TYPE_STDSTRING = (0x2fff0000+sizeof(std::string)), // C++ STL string (std::string)
  102. #endif // __cplusplus
  103. TW_TYPE_QUAT4F = TW_TYPE_CDSTRING+2, // 4 floats encoding a quaternion {qx,qy,qz,qs}
  104. TW_TYPE_QUAT4D, // 4 doubles encoding a quaternion {qx,qy,qz,qs}
  105. TW_TYPE_DIR3F, // direction vector represented by 3 floats
  106. TW_TYPE_DIR3D // direction vector represented by 3 doubles
  107. } TwType;
  108. #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)
  109. typedef void (TW_CALL * TwSetVarCallback)(const void *value, void *clientData);
  110. typedef void (TW_CALL * TwGetVarCallback)(void *value, void *clientData);
  111. typedef void (TW_CALL * TwButtonCallback)(void *clientData);
  112. TW_API int TW_CALL TwAddVarRW(TwBar *bar, const char *name, TwType type, void *var, const char *def);
  113. TW_API int TW_CALL TwAddVarRO(TwBar *bar, const char *name, TwType type, const void *var, const char *def);
  114. TW_API int TW_CALL TwAddVarCB(TwBar *bar, const char *name, TwType type, TwSetVarCallback setCallback, TwGetVarCallback getCallback, void *clientData, const char *def);
  115. TW_API int TW_CALL TwAddButton(TwBar *bar, const char *name, TwButtonCallback callback, void *clientData, const char *def);
  116. TW_API int TW_CALL TwAddSeparator(TwBar *bar, const char *name, const char *def);
  117. TW_API int TW_CALL TwRemoveVar(TwBar *bar, const char *name);
  118. TW_API int TW_CALL TwRemoveAllVars(TwBar *bar);
  119. typedef struct CTwEnumVal
  120. {
  121. int Value;
  122. const char * Label;
  123. } TwEnumVal;
  124. typedef struct CTwStructMember
  125. {
  126. const char * Name;
  127. TwType Type;
  128. size_t Offset;
  129. const char * DefString;
  130. } TwStructMember;
  131. typedef void (TW_CALL * TwSummaryCallback)(char *summaryString, size_t summaryMaxLength, const void *value, void *clientData);
  132. TW_API int TW_CALL TwDefine(const char *def);
  133. TW_API TwType TW_CALL TwDefineEnum(const char *name, const TwEnumVal *enumValues, unsigned int nbValues);
  134. TW_API TwType TW_CALL TwDefineStruct(const char *name, const TwStructMember *structMembers, unsigned int nbMembers, size_t structSize, TwSummaryCallback summaryCallback, void *summaryClientData);
  135. typedef void (TW_CALL * TwCopyCDStringToClient)(char **destinationClientStringPtr, const char *sourceString);
  136. TW_API void TW_CALL TwCopyCDStringToClientFunc(TwCopyCDStringToClient copyCDStringFunc);
  137. TW_API void TW_CALL TwCopyCDStringToLibrary(char **destinationLibraryStringPtr, const char *sourceClientString);
  138. #ifdef __cplusplus
  139. typedef void (TW_CALL * TwCopyStdStringToClient)(std::string& destinationClientString, const std::string& sourceString);
  140. TW_API void TW_CALL TwCopyStdStringToClientFunc(TwCopyStdStringToClient copyStdStringToClientFunc);
  141. TW_API void TW_CALL TwCopyStdStringToLibrary(std::string& destinationLibraryString, const std::string& sourceClientString);
  142. #endif // __cplusplus
  143. typedef enum ETwParamValueType
  144. {
  145. TW_PARAM_INT32,
  146. TW_PARAM_FLOAT,
  147. TW_PARAM_DOUBLE,
  148. TW_PARAM_CSTRING // Null-terminated array of char (ie, c-string)
  149. } TwParamValueType;
  150. TW_API int TW_CALL TwGetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int outValueMaxCount, void *outValues);
  151. TW_API int TW_CALL TwSetParam(TwBar *bar, const char *varName, const char *paramName, TwParamValueType paramValueType, unsigned int inValueCount, const void *inValues);
  152. // ----------------------------------------------------------------------------
  153. // Managment functions and definitions
  154. // ----------------------------------------------------------------------------
  155. typedef enum ETwGraphAPI
  156. {
  157. TW_OPENGL = 1,
  158. TW_DIRECT3D9 = 2,
  159. TW_DIRECT3D10 = 3
  160. } TwGraphAPI;
  161. TW_API int TW_CALL TwInit(TwGraphAPI graphAPI, void *device);
  162. TW_API int TW_CALL TwTerminate();
  163. TW_API int TW_CALL TwDraw();
  164. TW_API int TW_CALL TwWindowSize(int width, int height);
  165. typedef enum ETwKeyModifier
  166. {
  167. TW_KMOD_NONE = 0x0000, // same codes as SDL keysym.mod
  168. TW_KMOD_SHIFT = 0x0003,
  169. TW_KMOD_CTRL = 0x00c0,
  170. TW_KMOD_ALT = 0x0100,
  171. TW_KMOD_META = 0x0c00
  172. } TwKeyModifier;
  173. typedef enum EKeySpecial
  174. {
  175. TW_KEY_BACKSPACE = '\b',
  176. TW_KEY_TAB = '\t',
  177. TW_KEY_CLEAR = 0x0c,
  178. TW_KEY_RETURN = '\r',
  179. TW_KEY_PAUSE = 0x13,
  180. TW_KEY_ESCAPE = 0x1b,
  181. TW_KEY_SPACE = ' ',
  182. TW_KEY_DELETE = 0x7f,
  183. TW_KEY_UP = 273, // same codes and order as SDL keysym.sym
  184. TW_KEY_DOWN,
  185. TW_KEY_RIGHT,
  186. TW_KEY_LEFT,
  187. TW_KEY_INSERT,
  188. TW_KEY_HOME,
  189. TW_KEY_END,
  190. TW_KEY_PAGE_UP,
  191. TW_KEY_PAGE_DOWN,
  192. TW_KEY_F1,
  193. TW_KEY_F2,
  194. TW_KEY_F3,
  195. TW_KEY_F4,
  196. TW_KEY_F5,
  197. TW_KEY_F6,
  198. TW_KEY_F7,
  199. TW_KEY_F8,
  200. TW_KEY_F9,
  201. TW_KEY_F10,
  202. TW_KEY_F11,
  203. TW_KEY_F12,
  204. TW_KEY_F13,
  205. TW_KEY_F14,
  206. TW_KEY_F15,
  207. TW_KEY_LAST
  208. } TwKeySpecial;
  209. TW_API int TW_CALL TwKeyPressed(int key, int modifiers);
  210. typedef enum ETwMouseAction
  211. {
  212. TW_MOUSE_RELEASED,
  213. TW_MOUSE_PRESSED
  214. } TwMouseAction;
  215. typedef enum ETwMouseButtonID
  216. {
  217. TW_MOUSE_LEFT = 1, // same code as SDL_BUTTON_LEFT
  218. TW_MOUSE_MIDDLE = 2, // same code as SDL_BUTTON_MIDDLE
  219. TW_MOUSE_RIGHT = 3 // same code as SDL_BUTTON_RIGHT
  220. } TwMouseButtonID;
  221. TW_API int TW_CALL TwMouseButton(TwMouseAction action, TwMouseButtonID button);
  222. TW_API int TW_CALL TwMouseMotion(int mouseX, int mouseY);
  223. TW_API int TW_CALL TwMouseWheel(int pos);
  224. TW_API const char * TW_CALL TwGetLastError();
  225. typedef void (TW_CALL * TwErrorHandler)(const char *errorMessage);
  226. TW_API void TW_CALL TwHandleErrors(TwErrorHandler errorHandler);
  227. // ----------------------------------------------------------------------------
  228. // Helper functions to translate events from some common window management
  229. // frameworks to AntTweakBar.
  230. // They call TwKeyPressed, TwMouse* and TwWindowSize for you (implemented in
  231. // files TwEventWin.c TwEventSDL.c TwEventGLFW.c TwEventGLUT.c)
  232. // ----------------------------------------------------------------------------
  233. // For Windows message proc
  234. #ifndef _W64 // Microsoft specific (detection of 64 bits portability problems)
  235. # define _W64
  236. #endif // _W64
  237. TW_API int TW_CALL TwEventWin(void *wnd, unsigned int msg, unsigned int _W64 wParam, int _W64 lParam);
  238. #define TwEventWin32 TwEventWin // For compatibility with AntTweakBar versions prior to 1.11
  239. // For libSDL event loop
  240. TW_API int TW_CALL TwEventSDL(const void *sdlEvent);
  241. // For GLFW event callbacks
  242. TW_API int TW_CALL TwEventMouseButtonGLFW(int glfwButton, int glfwAction);
  243. TW_API int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction);
  244. TW_API int TW_CALL TwEventCharGLFW(int glfwChar, int glfwAction);
  245. #define TwEventMousePosGLFW TwMouseMotion
  246. #define TwEventMouseWheelGLFW TwMouseWheel
  247. // For GLUT event callbacks (Windows calling convention for GLUT callbacks is cdecl)
  248. #if defined(_WIN32) || defined(_WIN64)
  249. # define TW_GLUT_CALL __cdecl
  250. #else
  251. # define TW_GLUT_CALL
  252. #endif
  253. TW_API int TW_GLUT_CALL TwEventMouseButtonGLUT(int glutButton, int glutState, int mouseX, int mouseY);
  254. TW_API int TW_GLUT_CALL TwEventMouseMotionGLUT(int mouseX, int mouseY);
  255. TW_API int TW_GLUT_CALL TwEventKeyboardGLUT(unsigned char glutKey, int mouseX, int mouseY);
  256. TW_API int TW_GLUT_CALL TwEventSpecialGLUT(int glutKey, int mouseX, int mouseY);
  257. TW_API int TW_CALL TwGLUTModifiersFunc(int (TW_CALL *glutGetModifiersFunc)(void));
  258. typedef void (TW_GLUT_CALL *GLUTmousebuttonfun)(int glutButton, int glutState, int mouseX, int mouseY);
  259. typedef void (TW_GLUT_CALL *GLUTmousemotionfun)(int mouseX, int mouseY);
  260. typedef void (TW_GLUT_CALL *GLUTkeyboardfun)(unsigned char glutKey, int mouseX, int mouseY);
  261. typedef void (TW_GLUT_CALL *GLUTspecialfun)(int glutKey, int mouseX, int mouseY);
  262. // ----------------------------------------------------------------------------
  263. // Make sure the types have the right sizes
  264. // ----------------------------------------------------------------------------
  265. #define TW_COMPILE_TIME_ASSERT(name, x) typedef int TW_DUMMY_ ## name[(x) * 2 - 1]
  266. TW_COMPILE_TIME_ASSERT(CHAR, sizeof(char) == 1);
  267. TW_COMPILE_TIME_ASSERT(SHORT, sizeof(short) == 2);
  268. TW_COMPILE_TIME_ASSERT(INT, sizeof(int) == 4);
  269. TW_COMPILE_TIME_ASSERT(FLOAT, sizeof(float) == 4);
  270. TW_COMPILE_TIME_ASSERT(DOUBLE, sizeof(double) == 8);
  271. // ---------------------------------------------------------------------------
  272. #ifdef __cplusplus
  273. } // extern "C"
  274. #endif // __cplusplus
  275. #endif // !defined TW_INCLUDED