Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add glfw version 3 support for AntTweakBar #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

21 changes: 21 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

37 changes: 27 additions & 10 deletions src/TwEventGLFW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@
//
// ---------------------------------------------------------------------------

#ifndef GLFW_VERSION_MAJOR
#define GLFW_VERSION_MAJOR 2
#endif

#if GLFW_VERSION_MAJOR == 2
#include <GL/glfw.h>
#elif GLFW_VERSION_MAJOR == 3
#include <GLFW/glfw3.h>
#endif

// note: AntTweakBar.dll does not need to link with GLFW,
// it just needs some definitions for its helper functions.

Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 ) // CTRL cases
handled = TwKeyPressed(glfwKey, mod);
else if( glfwKey>=GLFW_KEY_SPECIAL )
{
#endif
int k = 0;

if( glfwKey>=GLFW_KEY_F1 && glfwKey<=GLFW_KEY_F15 )
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down