mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Merge branch 'master' of github.com:elmindreda/glfw
This commit is contained in:
commit
fcae55591e
@ -166,12 +166,9 @@ install(FILES COPYING.txt readme.html
|
||||
#--------------------------------------------------------------------
|
||||
# -- Documentation generation
|
||||
#--------------------------------------------------------------------
|
||||
#include("${GLFW_SOURCE_DIR}/documentation.cmake")
|
||||
#configure_file("${GLFW_SOURCE_DIR}/Doxyfile.in"
|
||||
# "${GLFW_BINARY_DIR}/Doxyfile"
|
||||
# IMMEDIATE @ONLY)
|
||||
#add_doxygen_target("${GLFW_BINARY_DIR}/Doxyfile")
|
||||
#add_subdirectory(docs)
|
||||
configure_file("${GLFW_SOURCE_DIR}/docs/Doxyfile.in"
|
||||
"${GLFW_BINARY_DIR}/docs/Doxyfile"
|
||||
@ONLY)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Uninstall operation
|
||||
|
1687
docs/Doxyfile.in
Normal file
1687
docs/Doxyfile.in
Normal file
File diff suppressed because it is too large
Load Diff
@ -569,7 +569,7 @@ int main( void )
|
||||
GLFWwindow window;
|
||||
|
||||
/* Init GLFW */
|
||||
if( !glfwInit() )
|
||||
if( !glfwInit(NULL) )
|
||||
{
|
||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
||||
exit( EXIT_FAILURE );
|
||||
@ -586,7 +586,7 @@ int main( void )
|
||||
}
|
||||
|
||||
glfwSetWindowSizeCallback( reshape );
|
||||
glfwEnable( window, GLFW_STICKY_KEYS );
|
||||
glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE );
|
||||
glfwSwapInterval( 1 );
|
||||
glfwSetTime( 0.0 );
|
||||
|
||||
|
@ -323,7 +323,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
GLFWwindow window;
|
||||
|
||||
if( !glfwInit() )
|
||||
if( !glfwInit(NULL) )
|
||||
{
|
||||
fprintf( stderr, "Failed to initialize GLFW\n" );
|
||||
exit( EXIT_FAILURE );
|
||||
@ -339,7 +339,7 @@ int main(int argc, char *argv[])
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
glfwEnable( window, GLFW_KEY_REPEAT );
|
||||
glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE );
|
||||
glfwSwapInterval( 1 );
|
||||
|
||||
// Parse command-line options
|
||||
|
@ -573,7 +573,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (GL_TRUE != glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "ERROR: Unable to initialize GLFW\n");
|
||||
usage();
|
||||
|
@ -442,7 +442,7 @@ int main(void)
|
||||
GLFWwindow window;
|
||||
|
||||
// Initialise GLFW
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -462,10 +462,10 @@ int main(void)
|
||||
glfwSwapInterval(1);
|
||||
|
||||
// Enable sticky keys
|
||||
glfwEnable(window, GLFW_STICKY_KEYS);
|
||||
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
||||
|
||||
// Enable mouse cursor (only needed for fullscreen mode)
|
||||
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||
|
||||
// Set callback functions
|
||||
glfwSetWindowSizeCallback(windowSizeFun);
|
||||
|
@ -15,7 +15,7 @@ int main(void)
|
||||
GLFWwindow window;
|
||||
|
||||
// Initialise GLFW
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -30,7 +30,7 @@ int main(void)
|
||||
}
|
||||
|
||||
// Ensure we can capture the escape key being pressed below
|
||||
glfwEnable(window, GLFW_STICKY_KEYS);
|
||||
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
|
||||
|
||||
// Enable vertical sync (on cards that support it)
|
||||
glfwSwapInterval(1);
|
||||
|
@ -309,13 +309,13 @@ void mouse_button_callback(GLFWwindow window, int button, int action)
|
||||
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
|
||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
|
||||
locked = GL_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
locked = GL_FALSE;
|
||||
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,7 +379,7 @@ int main(int argc, char* argv[])
|
||||
GLFWwindow window;
|
||||
double t, dt_total, t_old;
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "GLFW initialization failed\n");
|
||||
exit(EXIT_FAILURE);
|
||||
@ -396,7 +396,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
// Keyboard handler
|
||||
glfwSetKeyCallback(key_callback);
|
||||
glfwEnable(window, GLFW_KEY_REPEAT);
|
||||
glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
|
||||
|
||||
// Window resize handler
|
||||
glfwSetWindowSizeCallback(window_resize_callback);
|
||||
|
@ -427,13 +427,14 @@ extern "C" {
|
||||
#define GLFW_OPENGL_COMPAT_PROFILE 0x00000002
|
||||
#define GLFW_OPENGL_ES2_PROFILE 0x00000004
|
||||
|
||||
/* glfwEnable/glfwDisable tokens */
|
||||
/* glfwGetInputMode/glfwSetInputMode tokens */
|
||||
#define GLFW_CURSOR_MODE 0x00030001
|
||||
#define GLFW_STICKY_KEYS 0x00030002
|
||||
#define GLFW_STICKY_MOUSE_BUTTONS 0x00030003
|
||||
#define GLFW_SYSTEM_KEYS 0x00030004
|
||||
#define GLFW_KEY_REPEAT 0x00030005
|
||||
|
||||
/* glfwSetCursorMode tokens */
|
||||
/* GLFW_CURSOR_MODE values */
|
||||
#define GLFW_CURSOR_NORMAL 0x00040001
|
||||
#define GLFW_CURSOR_HIDDEN 0x00040002
|
||||
#define GLFW_CURSOR_CAPTURED 0x00040003
|
||||
@ -505,20 +506,13 @@ typedef struct
|
||||
GLFWfreefun free;
|
||||
} GLFWallocator;
|
||||
|
||||
/* Custom threading model interface */
|
||||
typedef struct
|
||||
{
|
||||
int dummy;
|
||||
} GLFWthreadmodel;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Prototypes
|
||||
*************************************************************************/
|
||||
|
||||
/* Initialization, termination and version querying */
|
||||
GLFWAPI int glfwInit(void);
|
||||
GLFWAPI int glfwInitWithModels(GLFWthreadmodel* threading, GLFWallocator* allocator);
|
||||
GLFWAPI int glfwInit(GLFWallocator* allocator);
|
||||
GLFWAPI void glfwTerminate(void);
|
||||
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev);
|
||||
GLFWAPI const char* glfwGetVersionString(void);
|
||||
@ -563,11 +557,12 @@ GLFWAPI void glfwPollEvents(void);
|
||||
GLFWAPI void glfwWaitEvents(void);
|
||||
|
||||
/* Input handling */
|
||||
GLFWAPI int glfwGetInputMode(GLFWwindow window, int mode);
|
||||
GLFWAPI void glfwSetInputMode(GLFWwindow window, int mode, int value);
|
||||
GLFWAPI int glfwGetKey(GLFWwindow window, int key);
|
||||
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button);
|
||||
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos);
|
||||
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos);
|
||||
GLFWAPI void glfwSetCursorMode(GLFWwindow window, int mode);
|
||||
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* xoffset, int* yoffset);
|
||||
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun);
|
||||
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
|
||||
@ -593,10 +588,6 @@ GLFWAPI int glfwExtensionSupported(const char* extension);
|
||||
GLFWAPI void* glfwGetProcAddress(const char* procname);
|
||||
GLFWAPI void glfwCopyContext(GLFWwindow src, GLFWwindow dst, unsigned long mask);
|
||||
|
||||
/* Enable/disable functions */
|
||||
GLFWAPI void glfwEnable(GLFWwindow window, int token);
|
||||
GLFWAPI void glfwDisable(GLFWwindow window, int token);
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Global definition cleanup
|
||||
|
@ -272,9 +272,8 @@ version of GLFW.</p>
|
||||
<li>Added <code>glfwSetWindowFocusCallback</code> function and <code>GLFWwindowfocusfun</code> type for receiving window focus events</li>
|
||||
<li>Added <code>glfwSetWindowIconifyCallback</code> function and <code>GLFWwindowiconifyfun</code> type for receiving window iconification events</li>
|
||||
<li>Added <code>glfwGetCurrentContext</code> function for retrieving the window whose OpenGL context is current</li>
|
||||
<li>Added <code>glfwInitWithModels</code> function and <code>GLFWallocator</code> and <code>GLFWthreadmodel</code> types for pluggable memory allocation and threading models</li>
|
||||
<li>Added <code>GLFWallocator</code> type and <code>glfwInit</code> parameter for pluggable memory allocator</li>
|
||||
<li>Added <code>glfwCopyContext</code> function for copying OpenGL state categories between contexts</li>
|
||||
<li>Added <code>glfwSetCursorMode</code> function for controlling per-window cursor mode, replacing <code>GLFW_MOUSE_CURSOR</code></li>
|
||||
<li>Added <code>GLFW_OPENGL_ES2_PROFILE</code> profile for creating OpenGL ES 2.0 contexts using the <code>GLX_EXT_create_context_es2_profile</code> and <code>WGL_EXT_create_context_es2_profile</code> extensions</li>
|
||||
<li>Added <code>GLFW_OPENGL_ROBUSTNESS</code> window hint and associated strategy tokens for <code>GL_ARB_robustness</code> support</li>
|
||||
<li>Added <code>GLFW_OPENGL_REVISION</code> window parameter to make up for removal of <code>glfwGetGLVersion</code></li>
|
||||
@ -293,6 +292,7 @@ version of GLFW.</p>
|
||||
<li>Replaced ad hoc build system with CMake</li>
|
||||
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
|
||||
<li>Replaced mouse wheel interface with two-dimensional scrolling interface</li>
|
||||
<li>Replaced <code>glfwEnable</code> and <code>glfwDisable</code> with <code>glfwGetInputMode</code> and <code>glfwSetInputMode</code></li>
|
||||
<li>Made Unicode character input unaffected by <code>GLFW_KEY_REPEAT</code></li>
|
||||
<li>Removed event auto-polling and the <code>GLFW_AUTO_POLL_EVENTS</code> window enable</li>
|
||||
<li>Removed the Win32 port .def files</li>
|
||||
|
@ -15,24 +15,24 @@ include_directories(${GLFW_SOURCE_DIR}/src
|
||||
${GLFW_BINARY_DIR}/src
|
||||
${GLFW_INCLUDE_DIR})
|
||||
|
||||
set(common_SOURCES enable.c error.c fullscreen.c gamma.c init.c input.c
|
||||
set(common_SOURCES error.c fullscreen.c gamma.c init.c input.c
|
||||
joystick.c opengl.c time.c window.c)
|
||||
|
||||
if(_GLFW_COCOA_NSGL)
|
||||
set(libglfw_SOURCES ${common_SOURCES} cocoa_enable.m cocoa_fullscreen.m
|
||||
cocoa_gamma.m cocoa_init.m cocoa_joystick.m
|
||||
set(libglfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.m
|
||||
cocoa_init.m cocoa_input.m cocoa_joystick.m
|
||||
cocoa_opengl.m cocoa_time.m cocoa_window.m)
|
||||
|
||||
# For some reason, CMake doesn't know about .m
|
||||
set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C)
|
||||
elseif(_GLFW_WIN32_WGL)
|
||||
set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c
|
||||
win32_gamma.c win32_init.c win32_joystick.c
|
||||
set(libglfw_SOURCES ${common_SOURCES} win32_fullscreen.c win32_gamma.c
|
||||
win32_init.c win32_input.c win32_joystick.c
|
||||
win32_opengl.c win32_time.c win32_window.c
|
||||
win32_dllmain.c)
|
||||
elseif(_GLFW_X11_GLX)
|
||||
set(libglfw_SOURCES ${common_SOURCES} x11_enable.c x11_fullscreen.c
|
||||
x11_gamma.c x11_init.c x11_joystick.c
|
||||
set(libglfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c
|
||||
x11_init.c x11_input.c x11_joystick.c
|
||||
x11_keysym2unicode.c x11_opengl.c x11_time.c
|
||||
x11_window.c)
|
||||
else()
|
||||
|
@ -393,7 +393,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
||||
|
||||
if ([event modifierFlags] & NSCommandKeyMask)
|
||||
{
|
||||
if (!window->sysKeysDisabled)
|
||||
if (window->systemKeys)
|
||||
[super keyDown:event];
|
||||
}
|
||||
else
|
||||
|
192
src/enable.c
192
src/enable.c
@ -1,192 +0,0 @@
|
||||
//========================================================================
|
||||
// GLFW - An OpenGL library
|
||||
// Platform: Any
|
||||
// API version: 3.0
|
||||
// WWW: http://www.glfw.org/
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Marcus Geelnard
|
||||
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable and disable sticky keys mode
|
||||
//========================================================================
|
||||
|
||||
static void enableStickyKeys(_GLFWwindow* window)
|
||||
{
|
||||
window->stickyKeys = GL_TRUE;
|
||||
}
|
||||
|
||||
static void disableStickyKeys(_GLFWwindow* window)
|
||||
{
|
||||
int i;
|
||||
|
||||
window->stickyKeys = GL_FALSE;
|
||||
|
||||
// Release all sticky keys
|
||||
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
||||
{
|
||||
if (window->key[i] == GLFW_STICK)
|
||||
window->key[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable and disable sticky mouse buttons mode
|
||||
//========================================================================
|
||||
|
||||
static void enableStickyMouseButtons(_GLFWwindow* window)
|
||||
{
|
||||
window->stickyMouseButtons = GL_TRUE;
|
||||
}
|
||||
|
||||
static void disableStickyMouseButtons(_GLFWwindow* window)
|
||||
{
|
||||
int i;
|
||||
|
||||
window->stickyMouseButtons = GL_FALSE;
|
||||
|
||||
// Release all sticky mouse buttons
|
||||
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
||||
{
|
||||
if (window->mouseButton[i] == GLFW_STICK)
|
||||
window->mouseButton[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable and disable system keys
|
||||
//========================================================================
|
||||
|
||||
static void enableSystemKeys(_GLFWwindow* window)
|
||||
{
|
||||
if (!window->sysKeysDisabled)
|
||||
return;
|
||||
|
||||
_glfwPlatformEnableSystemKeys(window);
|
||||
|
||||
// Indicate that system keys are no longer disabled
|
||||
window->sysKeysDisabled = GL_FALSE;
|
||||
}
|
||||
|
||||
static void disableSystemKeys(_GLFWwindow* window)
|
||||
{
|
||||
if (window->sysKeysDisabled)
|
||||
return;
|
||||
|
||||
_glfwPlatformDisableSystemKeys(window);
|
||||
|
||||
// Indicate that system keys are now disabled
|
||||
window->sysKeysDisabled = GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Enable and disable key repeat
|
||||
//========================================================================
|
||||
|
||||
static void enableKeyRepeat(_GLFWwindow* window)
|
||||
{
|
||||
window->keyRepeat = GL_TRUE;
|
||||
}
|
||||
|
||||
static void disableKeyRepeat(_GLFWwindow* window)
|
||||
{
|
||||
window->keyRepeat = GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW public API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Enable certain GLFW/window/system functions
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwEnable(GLFWwindow window, int token)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (token)
|
||||
{
|
||||
case GLFW_STICKY_KEYS:
|
||||
enableStickyKeys(window);
|
||||
break;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
enableStickyMouseButtons(window);
|
||||
break;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
enableSystemKeys(window);
|
||||
break;
|
||||
case GLFW_KEY_REPEAT:
|
||||
enableKeyRepeat(window);
|
||||
break;
|
||||
default:
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Disable certain GLFW/window/system functions
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwDisable(GLFWwindow window, int token)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (token)
|
||||
{
|
||||
case GLFW_STICKY_KEYS:
|
||||
disableStickyKeys(window);
|
||||
break;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
disableStickyMouseButtons(window);
|
||||
break;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
disableSystemKeys(window);
|
||||
break;
|
||||
case GLFW_KEY_REPEAT:
|
||||
disableKeyRepeat(window);
|
||||
break;
|
||||
default:
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
15
src/init.c
15
src/init.c
@ -67,26 +67,13 @@ void _glfwFree(void* ptr)
|
||||
// Initialize various GLFW state
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwInit(void)
|
||||
{
|
||||
return glfwInitWithModels(NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Initialize various GLFW state using custom model interfaces
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwInitWithModels(GLFWthreadmodel* threading, GLFWallocator* allocator)
|
||||
GLFWAPI int glfwInit(GLFWallocator* allocator)
|
||||
{
|
||||
if (_glfwInitialized)
|
||||
return GL_TRUE;
|
||||
|
||||
memset(&_glfwLibrary, 0, sizeof(_glfwLibrary));
|
||||
|
||||
if (threading)
|
||||
_glfwLibrary.threading = *threading;
|
||||
|
||||
if (allocator)
|
||||
{
|
||||
// Verify that the specified model is complete
|
||||
|
238
src/input.c
238
src/input.c
@ -31,6 +31,122 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Sets the cursor mode for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setCursorMode(_GLFWwindow* window, int mode)
|
||||
{
|
||||
int centerPosX, centerPosY;
|
||||
|
||||
if (mode != GLFW_CURSOR_NORMAL &&
|
||||
mode != GLFW_CURSOR_HIDDEN &&
|
||||
mode != GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (window->cursorMode == mode)
|
||||
return;
|
||||
|
||||
centerPosX = window->width / 2;
|
||||
centerPosY = window->height / 2;
|
||||
|
||||
if (mode == GLFW_CURSOR_CAPTURED)
|
||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||
_glfwInputCursorMotion(window,
|
||||
centerPosX - window->cursorPosX,
|
||||
centerPosY - window->cursorPosY);
|
||||
}
|
||||
|
||||
_glfwPlatformSetCursorMode(window, mode);
|
||||
|
||||
window->cursorMode = mode;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set sticky keys mode for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setStickyKeys(_GLFWwindow* window, int enabled)
|
||||
{
|
||||
if (window->stickyKeys == enabled)
|
||||
return;
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Release all sticky keys
|
||||
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
||||
{
|
||||
if (window->key[i] == GLFW_STICK)
|
||||
window->key[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
window->stickyKeys = enabled;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set sticky mouse buttons mode for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setStickyMouseButtons(_GLFWwindow* window, int enabled)
|
||||
{
|
||||
if (window->stickyMouseButtons == enabled)
|
||||
return;
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Release all sticky mouse buttons
|
||||
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
||||
{
|
||||
if (window->mouseButton[i] == GLFW_STICK)
|
||||
window->mouseButton[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
window->stickyMouseButtons = enabled;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set system keys for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setSystemKeys(_GLFWwindow* window, int enabled)
|
||||
{
|
||||
if (window->systemKeys == enabled)
|
||||
return;
|
||||
|
||||
if (enabled)
|
||||
_glfwPlatformEnableSystemKeys(window);
|
||||
else
|
||||
_glfwPlatformDisableSystemKeys(window);
|
||||
|
||||
window->systemKeys = enabled;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set key repeat for the specified window
|
||||
//========================================================================
|
||||
|
||||
static void setKeyRepeat(_GLFWwindow* window, int enabled)
|
||||
{
|
||||
window->keyRepeat = enabled;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -41,7 +157,7 @@
|
||||
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||
{
|
||||
GLboolean keyrepeat = GL_FALSE;
|
||||
GLboolean repeated = GL_FALSE;
|
||||
|
||||
if (key < 0 || key > GLFW_KEY_LAST)
|
||||
return;
|
||||
@ -55,12 +171,12 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||
window->key[key] = GLFW_STICK;
|
||||
else
|
||||
{
|
||||
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
|
||||
repeated = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
|
||||
window->key[key] = (char) action;
|
||||
}
|
||||
|
||||
// Call user callback function
|
||||
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
|
||||
if (_glfwLibrary.keyCallback && (window->keyRepeat || !repeated))
|
||||
_glfwLibrary.keyCallback(window, key, action);
|
||||
}
|
||||
|
||||
@ -150,6 +266,77 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
|
||||
////// GLFW public API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//========================================================================
|
||||
// Returns the specified input mode of the specified window
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwGetInputMode(GLFWwindow handle, int mode)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case GLFW_CURSOR_MODE:
|
||||
return window->cursorMode;
|
||||
case GLFW_STICKY_KEYS:
|
||||
return window->stickyKeys;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
return window->stickyMouseButtons;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
return window->systemKeys;
|
||||
case GLFW_KEY_REPEAT:
|
||||
return window->keyRepeat;
|
||||
default:
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Sets the specified input mode of the specified window
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetInputMode(GLFWwindow handle, int mode, int value)
|
||||
{
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case GLFW_CURSOR_MODE:
|
||||
setCursorMode(window, value);
|
||||
break;
|
||||
case GLFW_STICKY_KEYS:
|
||||
setStickyKeys(window, value ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
setSystemKeys(window, value ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
case GLFW_KEY_REPEAT:
|
||||
setKeyRepeat(window, value ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
default:
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Returns the state of the specified key for the specified window
|
||||
//========================================================================
|
||||
@ -300,51 +487,6 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset)
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Sets the cursor mode for the specified window
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
|
||||
{
|
||||
int centerPosX, centerPosY;
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
|
||||
if (!_glfwInitialized)
|
||||
{
|
||||
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode != GLFW_CURSOR_NORMAL &&
|
||||
mode != GLFW_CURSOR_HIDDEN &&
|
||||
mode != GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (window->cursorMode == mode)
|
||||
return;
|
||||
|
||||
centerPosX = window->width / 2;
|
||||
centerPosY = window->height / 2;
|
||||
|
||||
if (mode == GLFW_CURSOR_CAPTURED)
|
||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||
_glfwInputCursorMotion(window,
|
||||
centerPosX - window->cursorPosX,
|
||||
centerPosY - window->cursorPosY);
|
||||
}
|
||||
|
||||
_glfwPlatformSetCursorMode(window, mode);
|
||||
|
||||
window->cursorMode = mode;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Set callback function for keyboard input
|
||||
//========================================================================
|
||||
|
@ -183,7 +183,7 @@ struct _GLFWwindow
|
||||
GLboolean stickyKeys;
|
||||
GLboolean stickyMouseButtons;
|
||||
GLboolean keyRepeat;
|
||||
GLboolean sysKeysDisabled; // system keys disabled flag
|
||||
GLboolean systemKeys; // system keys enabled flag
|
||||
int cursorPosX, cursorPosY;
|
||||
int cursorMode;
|
||||
int scrollX, scrollY;
|
||||
@ -241,7 +241,6 @@ struct _GLFWlibrary
|
||||
GLFWkeyfun keyCallback;
|
||||
GLFWcharfun charCallback;
|
||||
|
||||
GLFWthreadmodel threading;
|
||||
GLFWallocator allocator;
|
||||
|
||||
GLFWgammaramp currentRamp;
|
||||
@ -276,7 +275,7 @@ int _glfwPlatformInit(void);
|
||||
int _glfwPlatformTerminate(void);
|
||||
const char* _glfwPlatformGetVersionString(void);
|
||||
|
||||
// Enable/Disable
|
||||
// Input
|
||||
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
||||
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
||||
|
||||
@ -339,14 +338,14 @@ void _glfwSetError(int error, const char* description);
|
||||
// Window management (window.c)
|
||||
void _glfwSetDefaultWindowHints(void);
|
||||
|
||||
// WIndow event notification
|
||||
// Window event notification (window.c)
|
||||
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
|
||||
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
||||
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
|
||||
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
|
||||
void _glfwInputWindowDamage(_GLFWwindow* window);
|
||||
|
||||
// Input event notification
|
||||
// Input event notification (input.c)
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
||||
void _glfwInputChar(_GLFWwindow* window, int character);
|
||||
void _glfwInputScroll(_GLFWwindow* window, int x, int y);
|
||||
|
@ -309,6 +309,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
window->height = height;
|
||||
window->mode = mode;
|
||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||
window->systemKeys = GL_TRUE;
|
||||
|
||||
// Open the actual window and create its context
|
||||
if (!_glfwPlatformOpenWindow(window, &wndconfig, &fbconfig))
|
||||
@ -330,7 +331,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
// The GLFW specification states that fullscreen windows have the cursor
|
||||
// captured by default
|
||||
if (mode == GLFW_FULLSCREEN)
|
||||
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
|
||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
|
||||
|
||||
// Clearing the front buffer to black to avoid garbage pixels left over
|
||||
// from previous uses of our bit of VRAM
|
||||
|
@ -31,8 +31,7 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
void (*glXGetProcAddress(const GLubyte* procName))();
|
||||
void (*glXGetProcAddressARB(const GLubyte* procName))();
|
||||
// This is the only glXGetProcAddress variant not declared by glxext.h
|
||||
void (*glXGetProcAddressEXT(const GLubyte* procName))();
|
||||
|
||||
|
||||
|
@ -46,13 +46,6 @@
|
||||
// extensions and not all operating systems come with an up-to-date version
|
||||
#include "../support/GL/glxext.h"
|
||||
|
||||
|
||||
// We need declarations for GLX version 1.3 or above even if the server doesn't
|
||||
// support version 1.3
|
||||
#ifndef GLX_VERSION_1_3
|
||||
#error "GLX header version 1.3 or above is required"
|
||||
#endif
|
||||
|
||||
// With XFree86, we can use the XF86VidMode extension
|
||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||
#include <X11/extensions/xf86vmode.h>
|
||||
|
@ -59,7 +59,7 @@ int main(void)
|
||||
{
|
||||
GLFWwindow window;
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -69,7 +69,7 @@ int main(void)
|
||||
int i, width, height;
|
||||
GLFWwindow window;
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -59,7 +59,7 @@ int main(void)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -298,10 +298,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||
case GLFW_KEY_R:
|
||||
{
|
||||
keyrepeat = !keyrepeat;
|
||||
if (keyrepeat)
|
||||
glfwEnable(window, GLFW_KEY_REPEAT);
|
||||
else
|
||||
glfwDisable(window, GLFW_KEY_REPEAT);
|
||||
glfwSetInputMode(window, GLFW_KEY_REPEAT, keyrepeat);
|
||||
|
||||
printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
|
||||
break;
|
||||
@ -310,10 +307,7 @@ static void key_callback(GLFWwindow window, int key, int action)
|
||||
case GLFW_KEY_S:
|
||||
{
|
||||
systemkeys = !systemkeys;
|
||||
if (systemkeys)
|
||||
glfwEnable(window, GLFW_SYSTEM_KEYS);
|
||||
else
|
||||
glfwDisable(window, GLFW_SYSTEM_KEYS);
|
||||
glfwSetInputMode(window, GLFW_SYSTEM_KEYS, systemkeys);
|
||||
|
||||
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
|
||||
break;
|
||||
@ -336,7 +330,7 @@ int main(void)
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -81,7 +81,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -75,7 +75,7 @@ int main(void)
|
||||
{
|
||||
GLFWwindow window;
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
@ -91,7 +91,7 @@ int main(void)
|
||||
}
|
||||
|
||||
glfwSwapInterval(1);
|
||||
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||
|
||||
glfwSetWindowFocusCallback(window_focus_callback);
|
||||
glfwSetKeyCallback(window_key_callback);
|
||||
|
@ -96,7 +96,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -183,7 +183,7 @@ int main(int argc, char** argv)
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -90,7 +90,7 @@ int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -94,7 +94,7 @@ int main(void)
|
||||
double update;
|
||||
|
||||
/* Initialise GLFW */
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -21,7 +21,7 @@ int main(void)
|
||||
GLFWvidmode dtmode, modes[400];
|
||||
int modecount, i;
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static GLboolean cursor_captured = GL_FALSE;
|
||||
static GLFWwindow window_handle = NULL;
|
||||
static int cursor_x;
|
||||
static int cursor_y;
|
||||
@ -44,18 +43,16 @@ static GLboolean open_window(void);
|
||||
|
||||
static void toggle_mouse_cursor(GLFWwindow window)
|
||||
{
|
||||
if (cursor_captured)
|
||||
if (glfwGetInputMode(window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED)
|
||||
{
|
||||
printf("Released cursor\n");
|
||||
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Captured cursor\n");
|
||||
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
|
||||
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
|
||||
}
|
||||
|
||||
cursor_captured = !cursor_captured;
|
||||
}
|
||||
|
||||
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
||||
@ -114,7 +111,7 @@ static GLboolean open_window(void)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -84,7 +84,7 @@ static GLboolean open_window(int width, int height, int mode)
|
||||
{
|
||||
double base;
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
return GL_FALSE;
|
||||
|
@ -117,7 +117,7 @@ int main(int argc, char** argv)
|
||||
GLuint texture;
|
||||
int x, y;
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -44,7 +44,7 @@ int main(void)
|
||||
float position;
|
||||
GLFWwindow window;
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -46,7 +46,7 @@ int main(void)
|
||||
GLboolean running = GL_TRUE;
|
||||
GLFWwindow windows[4];
|
||||
|
||||
if (!glfwInit())
|
||||
if (!glfwInit(NULL))
|
||||
{
|
||||
fprintf(stderr, "Failed to initialize GLFW: %s\n",
|
||||
glfwErrorString(glfwGetError()));
|
||||
|
Loading…
Reference in New Issue
Block a user