diff --git a/CMakeLists.txt b/CMakeLists.txt index 8700ab4..676658f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,18 +15,8 @@ ADD_DEFINITIONS(-D_UNIX) add_library(AntTweakBar ${SOURCES}) target_link_libraries(AntTweakBar GL) -add_executable(TwAdvanced1 examples/TwAdvanced1.cpp) -target_link_libraries(TwAdvanced1 AntTweakBar GLU glfw) - -add_executable(TwSimpleGLFW examples/TwSimpleGLFW.cpp) -target_link_libraries(TwSimpleGLFW AntTweakBar GLU glfw) - -add_executable(TwSimpleGLUT examples/TwSimpleGLUT.cpp) -target_link_libraries(TwSimpleGLUT AntTweakBar GLU glut) - -add_executable(TwSimpleSDL examples/TwSimpleSDL.cpp) -target_link_libraries(TwSimpleSDL AntTweakBar GLU SDL) - -add_executable(TwString examples/TwString.cpp) -target_link_libraries(TwString AntTweakBar glfw) +Option(AntTweakBar_BUILD_EXAMPLES "Build the AntTweakBarexample programs" ON) +if (AntTweakBar_BUILD_EXAMPLES) + add_subdirectory(examples) +endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..c9113f0 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,21 @@ + +set(LIBS AntTweakBar) +if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") + LIST (APPEND LIBS X11) +endif() + +add_executable(TwAdvanced1 TwAdvanced1.cpp) +target_link_libraries(TwAdvanced1 ${LIBS} GLU glfw) + +add_executable(TwSimpleGLFW TwSimpleGLFW.cpp) +target_link_libraries(TwSimpleGLFW ${LIBS} GLU glfw) + +add_executable(TwSimpleGLUT TwSimpleGLUT.cpp) +target_link_libraries(TwSimpleGLUT ${LIBS} GLU glut) + +add_executable(TwSimpleSDL TwSimpleSDL.cpp) +target_link_libraries(TwSimpleSDL ${LIBS} GLU SDL) + +add_executable(TwString TwString.cpp) +target_link_libraries(TwString ${LIBS} glfw) + diff --git a/src/TwEventGLFW.cpp b/src/TwEventGLFW.cpp index 41ca727..6f381c9 100755 --- a/src/TwEventGLFW.cpp +++ b/src/TwEventGLFW.cpp @@ -14,7 +14,16 @@ // // --------------------------------------------------------------------------- +#ifndef GLFW_VERSION_MAJOR +#define GLFW_VERSION_MAJOR 2 +#endif + +#if GLFW_VERSION_MAJOR == 2 #include +#elif GLFW_VERSION_MAJOR == 3 +#include +#endif + // note: AntTweakBar.dll does not need to link with GLFW, // it just needs some definitions for its helper functions. @@ -44,6 +53,7 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) { int handled = 0; +#if GLFW_VERSION_MAJOR == 2 // Register of modifiers state if( glfwAction==GLFW_PRESS ) { @@ -81,17 +91,19 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) break; } } - +#endif // Process key pressed if( glfwAction==GLFW_PRESS ) { int mod = g_KMod; int testkp = ((mod&TW_KMOD_CTRL) || (mod&TW_KMOD_ALT)) ? 1 : 0; +#if GLFW_VERSION_MAJOR == 2 if( (mod&TW_KMOD_CTRL) && glfwKey>0 && glfwKey=GLFW_KEY_SPECIAL ) { +#endif int k = 0; if( glfwKey>=GLFW_KEY_F1 && glfwKey<=GLFW_KEY_F15 ) @@ -102,9 +114,20 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) { switch( glfwKey ) { +#if GLFW_VERSION_MAJOR == 2 case GLFW_KEY_ESC: k = TW_KEY_ESCAPE; break; + case GLFW_KEY_DEL: + k = TW_KEY_DELETE; + break; + case GLFW_KEY_PAGEUP: + k = TW_KEY_PAGE_UP; + break; + case GLFW_KEY_PAGEDOWN: + k = TW_KEY_PAGE_DOWN; + break; +#endif case GLFW_KEY_UP: k = TW_KEY_UP; break; @@ -129,15 +152,6 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) case GLFW_KEY_INSERT: k = TW_KEY_INSERT; break; - case GLFW_KEY_DEL: - k = TW_KEY_DELETE; - break; - case GLFW_KEY_PAGEUP: - k = TW_KEY_PAGE_UP; - break; - case GLFW_KEY_PAGEDOWN: - k = TW_KEY_PAGE_DOWN; - break; case GLFW_KEY_HOME: k = TW_KEY_HOME; break; @@ -176,7 +190,10 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) if( k>0 ) handled = TwKeyPressed(k, mod); + +#if GLFW_VERSION_MAJOR == 2 } +#endif } return handled;