1
//========================================================================
2
// GLFW - An OpenGL framework
6
// WWW: http://glfw.sourceforge.net
7
//------------------------------------------------------------------------
8
// Copyright (c) 2002-2006 Camilla Berglund
10
// This software is provided 'as-is', without any express or implied
11
// warranty. In no event will the authors be held liable for any damages
12
// arising from the use of this software.
14
// Permission is granted to anyone to use this software for any purpose,
15
// including commercial applications, and to alter it and redistribute it
16
// freely, subject to the following restrictions:
18
// 1. The origin of this software must not be misrepresented; you must not
19
// claim that you wrote the original software. If you use this software
20
// in a product, an acknowledgment in the product documentation would
21
// be appreciated but is not required.
23
// 2. Altered source versions must be plainly marked as such, and must not
24
// be misrepresented as being the original software.
26
// 3. This notice may not be removed or altered from any source
29
//========================================================================
34
//========================================================================
36
//========================================================================
38
GLFWAPI int GLFWAPIENTRY glfwGetKey( int key )
40
// Is GLFW initialized?
41
if( !_glfwInitialized || !_glfwWin.Opened )
47
if( key < 0 || key > GLFW_KEY_LAST )
52
if( _glfwInput.Key[ key ] == GLFW_STICK )
54
// Sticky mode: release key now
55
_glfwInput.Key[ key ] = GLFW_RELEASE;
59
return (int) _glfwInput.Key[ key ];
63
//========================================================================
64
// glfwGetMouseButton()
65
//========================================================================
67
GLFWAPI int GLFWAPIENTRY glfwGetMouseButton( int button )
69
// Is GLFW initialized?
70
if( !_glfwInitialized || !_glfwWin.Opened )
75
// Is it a valid mouse button?
76
if( button < 0 || button > GLFW_MOUSE_BUTTON_LAST )
81
if( _glfwInput.MouseButton[ button ] == GLFW_STICK )
83
// Sticky mode: release mouse button now
84
_glfwInput.MouseButton[ button ] = GLFW_RELEASE;
88
return (int) _glfwInput.MouseButton[ button ];
92
//========================================================================
94
//========================================================================
96
GLFWAPI void GLFWAPIENTRY glfwGetMousePos( int *xpos, int *ypos )
98
// Is GLFW initialized?
99
if( !_glfwInitialized || !_glfwWin.Opened )
104
// Return mouse position
107
*xpos = _glfwInput.MousePosX;
111
*ypos = _glfwInput.MousePosY;
116
//========================================================================
118
//========================================================================
120
GLFWAPI void GLFWAPIENTRY glfwSetMousePos( int xpos, int ypos )
122
// Is GLFW initialized?
123
if( !_glfwInitialized || !_glfwWin.Opened )
128
// Don't do anything if the mouse position did not change
129
if( xpos == _glfwInput.MousePosX && ypos == _glfwInput.MousePosY )
134
// Set GLFW mouse position
135
_glfwInput.MousePosX = xpos;
136
_glfwInput.MousePosY = ypos;
138
// If we have a locked mouse, do not change cursor position
139
if( _glfwWin.MouseLock )
144
// Update physical cursor position
145
_glfwPlatformSetMouseCursorPos( xpos, ypos );
149
//========================================================================
150
// glfwGetMouseWheel()
151
//========================================================================
153
GLFWAPI int GLFWAPIENTRY glfwGetMouseWheel( void )
155
// Is GLFW initialized?
156
if( !_glfwInitialized || !_glfwWin.Opened )
161
// Return mouse wheel position
162
return _glfwInput.WheelPos;
166
//========================================================================
167
// glfwSetMouseWheel()
168
//========================================================================
170
GLFWAPI void GLFWAPIENTRY glfwSetMouseWheel( int pos )
172
// Is GLFW initialized?
173
if( !_glfwInitialized || !_glfwWin.Opened )
178
// Set mouse wheel position
179
_glfwInput.WheelPos = pos;
183
//========================================================================
184
// glfwSetKeyCallback() - Set callback function for keyboard input
185
//========================================================================
187
GLFWAPI void GLFWAPIENTRY glfwSetKeyCallback( GLFWkeyfun cbfun )
189
// Is GLFW initialized?
190
if( !_glfwInitialized || !_glfwWin.Opened )
195
// Set callback function
196
_glfwWin.KeyCallback = cbfun;
200
//========================================================================
201
// glfwSetCharCallback() - Set callback function for character input
202
//========================================================================
204
GLFWAPI void GLFWAPIENTRY glfwSetCharCallback( GLFWcharfun cbfun )
206
// Is GLFW initialized?
207
if( !_glfwInitialized || !_glfwWin.Opened )
212
// Set callback function
213
_glfwWin.CharCallback = cbfun;
217
//========================================================================
218
// glfwSetMouseButtonCallback() - Set callback function for mouse clicks
219
//========================================================================
221
GLFWAPI void GLFWAPIENTRY glfwSetMouseButtonCallback( GLFWmousebuttonfun cbfun )
223
// Is GLFW initialized?
224
if( !_glfwInitialized || !_glfwWin.Opened )
229
// Set callback function
230
_glfwWin.MouseButtonCallback = cbfun;
234
//========================================================================
235
// glfwSetMousePosCallback() - Set callback function for mouse moves
236
//========================================================================
238
GLFWAPI void GLFWAPIENTRY glfwSetMousePosCallback( GLFWmouseposfun cbfun )
240
// Is GLFW initialized?
241
if( !_glfwInitialized || !_glfwWin.Opened )
246
// Set callback function
247
_glfwWin.MousePosCallback = cbfun;
249
// Call the callback function to let the application know the current
253
cbfun( _glfwInput.MousePosX, _glfwInput.MousePosY );
258
//========================================================================
259
// glfwSetMouseWheelCallback() - Set callback function for mouse wheel
260
//========================================================================
262
GLFWAPI void GLFWAPIENTRY glfwSetMouseWheelCallback( GLFWmousewheelfun cbfun )
264
// Is GLFW initialized?
265
if( !_glfwInitialized || !_glfwWin.Opened )
270
// Set callback function
271
_glfwWin.MouseWheelCallback = cbfun;
273
// Call the callback function to let the application know the current
274
// mouse wheel position
277
cbfun( _glfwInput.WheelPos );