mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 22:14:34 +00:00
Transformed glfwEnable/Disable/SetCursorMode into glfwGetInputMode/SetInputMode.
This commit is contained in:
parent
011ef7463a
commit
ce288a8939
@ -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 );
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -567,7 +568,8 @@ 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 int glfwGetInputMode(GLFWwindow window, int mode);
|
||||
GLFWAPI void glfwSetInputMode(GLFWwindow window, int mode, int value);
|
||||
GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* xoffset, int* yoffset);
|
||||
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun);
|
||||
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
|
||||
@ -593,10 +595,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
|
||||
|
@ -274,7 +274,6 @@ version of GLFW.</p>
|
||||
<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>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;
|
||||
}
|
||||
}
|
||||
|
232
src/input.c
232
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 //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@ -278,6 +394,77 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// 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 scroll offset 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;
|
||||
@ -276,7 +276,7 @@ int _glfwPlatformInit(void);
|
||||
int _glfwPlatformTerminate(void);
|
||||
const char* _glfwPlatformGetVersionString(void);
|
||||
|
||||
// Enable/Disable
|
||||
// Input
|
||||
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
||||
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user