From 0304e1ab2c76ad15403604e059fb0857ba2769b1 Mon Sep 17 00:00:00 2001 From: Rens Date: Fri, 7 Feb 2014 22:38:11 +0100 Subject: [PATCH 1/4] make example optional --- CMakeLists.txt | 17 +++-------------- examples/CMakeLists.txt | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 examples/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 8700ab4..500d303 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,18 +15,7 @@ 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) +if (AntTweakTools_BUILD_EXAMPLES) + add_subdirectory(examples) +endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..7cbd407 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,15 @@ +add_executable(TwAdvanced1 TwAdvanced1.cpp) +target_link_libraries(TwAdvanced1 AntTweakBar GLU glfw) + +add_executable(TwSimpleGLFW TwSimpleGLFW.cpp) +target_link_libraries(TwSimpleGLFW AntTweakBar GLU glfw) + +add_executable(TwSimpleGLUT TwSimpleGLUT.cpp) +target_link_libraries(TwSimpleGLUT AntTweakBar GLU glut) + +add_executable(TwSimpleSDL TwSimpleSDL.cpp) +target_link_libraries(TwSimpleSDL AntTweakBar GLU SDL) + +add_executable(TwString TwString.cpp) +target_link_libraries(TwString AntTweakBar glfw) + From ac08fcba7dc1fa0914e0c73314c8a4c8db5cb1b8 Mon Sep 17 00:00:00 2001 From: Rens Date: Fri, 7 Feb 2014 22:52:40 +0100 Subject: [PATCH 2/4] change to veresion 3 of glfw --- src/TwEventGLFW.cpp | 59 +++------------------------------------------ 1 file changed, 3 insertions(+), 56 deletions(-) diff --git a/src/TwEventGLFW.cpp b/src/TwEventGLFW.cpp index 41ca727..3af9dd5 100755 --- a/src/TwEventGLFW.cpp +++ b/src/TwEventGLFW.cpp @@ -14,7 +14,8 @@ // // --------------------------------------------------------------------------- -#include +#include +#include // note: AntTweakBar.dll does not need to link with GLFW, // it just needs some definitions for its helper functions. @@ -44,54 +45,12 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) { int handled = 0; - // Register of modifiers state - if( glfwAction==GLFW_PRESS ) - { - switch( glfwKey ) - { - case GLFW_KEY_LSHIFT: - case GLFW_KEY_RSHIFT: - g_KMod |= TW_KMOD_SHIFT; - break; - case GLFW_KEY_LCTRL: - case GLFW_KEY_RCTRL: - g_KMod |= TW_KMOD_CTRL; - break; - case GLFW_KEY_LALT: - case GLFW_KEY_RALT: - g_KMod |= TW_KMOD_ALT; - break; - } - } - else - { - switch( glfwKey ) - { - case GLFW_KEY_LSHIFT: - case GLFW_KEY_RSHIFT: - g_KMod &= ~TW_KMOD_SHIFT; - break; - case GLFW_KEY_LCTRL: - case GLFW_KEY_RCTRL: - g_KMod &= ~TW_KMOD_CTRL; - break; - case GLFW_KEY_LALT: - case GLFW_KEY_RALT: - g_KMod &= ~TW_KMOD_ALT; - break; - } - } - // Process key pressed if( glfwAction==GLFW_PRESS ) { int mod = g_KMod; int testkp = ((mod&TW_KMOD_CTRL) || (mod&TW_KMOD_ALT)) ? 1 : 0; - if( (mod&TW_KMOD_CTRL) && glfwKey>0 && glfwKey=GLFW_KEY_SPECIAL ) - { int k = 0; if( glfwKey>=GLFW_KEY_F1 && glfwKey<=GLFW_KEY_F15 ) @@ -102,9 +61,6 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) { switch( glfwKey ) { - case GLFW_KEY_ESC: - k = TW_KEY_ESCAPE; - break; case GLFW_KEY_UP: k = TW_KEY_UP; break; @@ -129,15 +85,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 +123,7 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) if( k>0 ) handled = TwKeyPressed(k, mod); - } + } return handled; From 33d2e037ce97123fdbe968b4dff89277464537b0 Mon Sep 17 00:00:00 2001 From: Rens Date: Sat, 8 Feb 2014 16:27:33 +0100 Subject: [PATCH 3/4] its now compatable with glfw2 and glfw3 --- CMakeLists.txt | 1 + examples/CMakeLists.txt | 16 ++++++--- src/TwEventGLFW.cpp | 73 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 83 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 500d303..ab22a1d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ ADD_DEFINITIONS(-D_UNIX) add_library(AntTweakBar ${SOURCES}) target_link_libraries(AntTweakBar GL) +set(AntTweakTools_BUILD_EXAMPLES TRUE) if (AntTweakTools_BUILD_EXAMPLES) add_subdirectory(examples) endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7cbd407..c9113f0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,15 +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 AntTweakBar GLU glfw) +target_link_libraries(TwAdvanced1 ${LIBS} GLU glfw) add_executable(TwSimpleGLFW TwSimpleGLFW.cpp) -target_link_libraries(TwSimpleGLFW AntTweakBar GLU glfw) +target_link_libraries(TwSimpleGLFW ${LIBS} GLU glfw) add_executable(TwSimpleGLUT TwSimpleGLUT.cpp) -target_link_libraries(TwSimpleGLUT AntTweakBar GLU glut) +target_link_libraries(TwSimpleGLUT ${LIBS} GLU glut) add_executable(TwSimpleSDL TwSimpleSDL.cpp) -target_link_libraries(TwSimpleSDL AntTweakBar GLU SDL) +target_link_libraries(TwSimpleSDL ${LIBS} GLU SDL) add_executable(TwString TwString.cpp) -target_link_libraries(TwString AntTweakBar glfw) +target_link_libraries(TwString ${LIBS} glfw) diff --git a/src/TwEventGLFW.cpp b/src/TwEventGLFW.cpp index 3af9dd5..f10315d 100755 --- a/src/TwEventGLFW.cpp +++ b/src/TwEventGLFW.cpp @@ -14,8 +14,16 @@ // // --------------------------------------------------------------------------- -#include +#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. @@ -45,12 +53,56 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) { int handled = 0; +#if GLFW_VERSION_MAJOR == 2 + // Register of modifiers state + if( glfwAction==GLFW_PRESS ) + { + switch( glfwKey ) + { + case GLFW_KEY_LSHIFT: + case GLFW_KEY_RSHIFT: + g_KMod |= TW_KMOD_SHIFT; + break; + case GLFW_KEY_LCTRL: + case GLFW_KEY_RCTRL: + g_KMod |= TW_KMOD_CTRL; + break; + case GLFW_KEY_LALT: + case GLFW_KEY_RALT: + g_KMod |= TW_KMOD_ALT; + break; + } + } + else + { + switch( glfwKey ) + { + case GLFW_KEY_LSHIFT: + case GLFW_KEY_RSHIFT: + g_KMod &= ~TW_KMOD_SHIFT; + break; + case GLFW_KEY_LCTRL: + case GLFW_KEY_RCTRL: + g_KMod &= ~TW_KMOD_CTRL; + break; + case GLFW_KEY_LALT: + case GLFW_KEY_RALT: + g_KMod &= ~TW_KMOD_ALT; + break; + } + } // 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 ) @@ -61,6 +113,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; @@ -123,7 +189,10 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) if( k>0 ) handled = TwKeyPressed(k, mod); - + +#if GLFW_VERSION_MAJOR == 2 + } +#endif } return handled; From ce787b50d06c2bfc0309fe5b13ca35e17569366f Mon Sep 17 00:00:00 2001 From: Rens Date: Sat, 8 Feb 2014 17:35:50 +0100 Subject: [PATCH 4/4] fix missig #endif, change build exampel to option --- CMakeLists.txt | 4 ++-- src/TwEventGLFW.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab22a1d..676658f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,8 +15,8 @@ ADD_DEFINITIONS(-D_UNIX) add_library(AntTweakBar ${SOURCES}) target_link_libraries(AntTweakBar GL) -set(AntTweakTools_BUILD_EXAMPLES TRUE) -if (AntTweakTools_BUILD_EXAMPLES) +Option(AntTweakBar_BUILD_EXAMPLES "Build the AntTweakBarexample programs" ON) +if (AntTweakBar_BUILD_EXAMPLES) add_subdirectory(examples) endif() diff --git a/src/TwEventGLFW.cpp b/src/TwEventGLFW.cpp index f10315d..6f381c9 100755 --- a/src/TwEventGLFW.cpp +++ b/src/TwEventGLFW.cpp @@ -91,6 +91,7 @@ int TW_CALL TwEventKeyGLFW(int glfwKey, int glfwAction) break; } } +#endif // Process key pressed if( glfwAction==GLFW_PRESS ) {