~ubuntu-branches/ubuntu/trusty/teeworlds/trusty-updates

« back to all changes in this revision

Viewing changes to src/engine/external/glfw/lib/input.c

  • Committer: Bazaar Package Importer
  • Author(s): Jack Coulter
  • Date: 2008-04-13 18:48:12 UTC
  • Revision ID: james.westby@ubuntu.com-20080413184812-efc80waq2er6p1bs
Tags: upstream-0.4.2
ImportĀ upstreamĀ versionĀ 0.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
// GLFW - An OpenGL framework
 
3
// File:        input.c
 
4
// Platform:    Any
 
5
// API version: 2.6
 
6
// WWW:         http://glfw.sourceforge.net
 
7
//------------------------------------------------------------------------
 
8
// Copyright (c) 2002-2006 Camilla Berglund
 
9
//
 
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.
 
13
//
 
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:
 
17
//
 
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.
 
22
//
 
23
// 2. Altered source versions must be plainly marked as such, and must not
 
24
//    be misrepresented as being the original software.
 
25
//
 
26
// 3. This notice may not be removed or altered from any source
 
27
//    distribution.
 
28
//
 
29
//========================================================================
 
30
 
 
31
#include "internal.h"
 
32
 
 
33
 
 
34
//========================================================================
 
35
// glfwGetKey()
 
36
//========================================================================
 
37
 
 
38
GLFWAPI int GLFWAPIENTRY glfwGetKey( int key )
 
39
{
 
40
    // Is GLFW initialized?
 
41
    if( !_glfwInitialized || !_glfwWin.Opened )
 
42
    {
 
43
        return GLFW_RELEASE;
 
44
    }
 
45
 
 
46
    // Is it a valid key?
 
47
    if( key < 0 || key > GLFW_KEY_LAST )
 
48
    {
 
49
        return GLFW_RELEASE;
 
50
    }
 
51
 
 
52
    if( _glfwInput.Key[ key ] == GLFW_STICK )
 
53
    {
 
54
        // Sticky mode: release key now
 
55
        _glfwInput.Key[ key ] = GLFW_RELEASE;
 
56
        return GLFW_PRESS;
 
57
    }
 
58
 
 
59
    return (int) _glfwInput.Key[ key ];
 
60
}
 
61
 
 
62
 
 
63
//========================================================================
 
64
// glfwGetMouseButton()
 
65
//========================================================================
 
66
 
 
67
GLFWAPI int GLFWAPIENTRY glfwGetMouseButton( int button )
 
68
{
 
69
    // Is GLFW initialized?
 
70
    if( !_glfwInitialized || !_glfwWin.Opened )
 
71
    {
 
72
        return GLFW_RELEASE;
 
73
    }
 
74
 
 
75
    // Is it a valid mouse button?
 
76
    if( button < 0 || button > GLFW_MOUSE_BUTTON_LAST )
 
77
    {
 
78
        return GLFW_RELEASE;
 
79
    }
 
80
 
 
81
    if( _glfwInput.MouseButton[ button ] == GLFW_STICK )
 
82
    {
 
83
        // Sticky mode: release mouse button now
 
84
        _glfwInput.MouseButton[ button ] = GLFW_RELEASE;
 
85
        return GLFW_PRESS;
 
86
    }
 
87
 
 
88
    return (int) _glfwInput.MouseButton[ button ];
 
89
}
 
90
 
 
91
 
 
92
//========================================================================
 
93
// glfwGetMousePos()
 
94
//========================================================================
 
95
 
 
96
GLFWAPI void GLFWAPIENTRY glfwGetMousePos( int *xpos, int *ypos )
 
97
{
 
98
    // Is GLFW initialized?
 
99
    if( !_glfwInitialized || !_glfwWin.Opened )
 
100
    {
 
101
        return;
 
102
    }
 
103
 
 
104
    // Return mouse position
 
105
    if( xpos != NULL )
 
106
    {
 
107
        *xpos = _glfwInput.MousePosX;
 
108
    }
 
109
    if( ypos != NULL )
 
110
    {
 
111
        *ypos = _glfwInput.MousePosY;
 
112
    }
 
113
}
 
114
 
 
115
 
 
116
//========================================================================
 
117
// glfwSetMousePos()
 
118
//========================================================================
 
119
 
 
120
GLFWAPI void GLFWAPIENTRY glfwSetMousePos( int xpos, int ypos )
 
121
{
 
122
    // Is GLFW initialized?
 
123
    if( !_glfwInitialized || !_glfwWin.Opened )
 
124
    {
 
125
        return;
 
126
    }
 
127
 
 
128
    // Don't do anything if the mouse position did not change
 
129
    if( xpos == _glfwInput.MousePosX && ypos == _glfwInput.MousePosY )
 
130
    {
 
131
        return;
 
132
    }
 
133
 
 
134
    // Set GLFW mouse position
 
135
    _glfwInput.MousePosX = xpos;
 
136
    _glfwInput.MousePosY = ypos;
 
137
 
 
138
    // If we have a locked mouse, do not change cursor position
 
139
    if( _glfwWin.MouseLock )
 
140
    {
 
141
        return;
 
142
    }
 
143
 
 
144
    // Update physical cursor position
 
145
    _glfwPlatformSetMouseCursorPos( xpos, ypos );
 
146
}
 
147
 
 
148
 
 
149
//========================================================================
 
150
// glfwGetMouseWheel()
 
151
//========================================================================
 
152
 
 
153
GLFWAPI int GLFWAPIENTRY glfwGetMouseWheel( void )
 
154
{
 
155
    // Is GLFW initialized?
 
156
    if( !_glfwInitialized || !_glfwWin.Opened )
 
157
    {
 
158
        return 0;
 
159
    }
 
160
 
 
161
    // Return mouse wheel position
 
162
    return _glfwInput.WheelPos;
 
163
}
 
164
 
 
165
 
 
166
//========================================================================
 
167
// glfwSetMouseWheel()
 
168
//========================================================================
 
169
 
 
170
GLFWAPI void GLFWAPIENTRY glfwSetMouseWheel( int pos )
 
171
{
 
172
    // Is GLFW initialized?
 
173
    if( !_glfwInitialized || !_glfwWin.Opened )
 
174
    {
 
175
        return;
 
176
    }
 
177
 
 
178
    // Set mouse wheel position
 
179
    _glfwInput.WheelPos = pos;
 
180
}
 
181
 
 
182
 
 
183
//========================================================================
 
184
// glfwSetKeyCallback() - Set callback function for keyboard input
 
185
//========================================================================
 
186
 
 
187
GLFWAPI void GLFWAPIENTRY glfwSetKeyCallback( GLFWkeyfun cbfun )
 
188
{
 
189
    // Is GLFW initialized?
 
190
    if( !_glfwInitialized || !_glfwWin.Opened )
 
191
    {
 
192
        return;
 
193
    }
 
194
 
 
195
    // Set callback function
 
196
    _glfwWin.KeyCallback = cbfun;
 
197
}
 
198
 
 
199
 
 
200
//========================================================================
 
201
// glfwSetCharCallback() - Set callback function for character input
 
202
//========================================================================
 
203
 
 
204
GLFWAPI void GLFWAPIENTRY glfwSetCharCallback( GLFWcharfun cbfun )
 
205
{
 
206
    // Is GLFW initialized?
 
207
    if( !_glfwInitialized || !_glfwWin.Opened )
 
208
    {
 
209
        return;
 
210
    }
 
211
 
 
212
    // Set callback function
 
213
    _glfwWin.CharCallback = cbfun;
 
214
}
 
215
 
 
216
 
 
217
//========================================================================
 
218
// glfwSetMouseButtonCallback() - Set callback function for mouse clicks
 
219
//========================================================================
 
220
 
 
221
GLFWAPI void GLFWAPIENTRY glfwSetMouseButtonCallback( GLFWmousebuttonfun cbfun )
 
222
{
 
223
    // Is GLFW initialized?
 
224
    if( !_glfwInitialized || !_glfwWin.Opened )
 
225
    {
 
226
        return;
 
227
    }
 
228
 
 
229
    // Set callback function
 
230
    _glfwWin.MouseButtonCallback = cbfun;
 
231
}
 
232
 
 
233
 
 
234
//========================================================================
 
235
// glfwSetMousePosCallback() - Set callback function for mouse moves
 
236
//========================================================================
 
237
 
 
238
GLFWAPI void GLFWAPIENTRY glfwSetMousePosCallback( GLFWmouseposfun cbfun )
 
239
{
 
240
    // Is GLFW initialized?
 
241
    if( !_glfwInitialized || !_glfwWin.Opened )
 
242
    {
 
243
        return;
 
244
    }
 
245
 
 
246
    // Set callback function
 
247
    _glfwWin.MousePosCallback = cbfun;
 
248
 
 
249
    // Call the callback function to let the application know the current
 
250
    // mouse position
 
251
    if( cbfun )
 
252
    {
 
253
        cbfun( _glfwInput.MousePosX, _glfwInput.MousePosY );
 
254
    }
 
255
}
 
256
 
 
257
 
 
258
//========================================================================
 
259
// glfwSetMouseWheelCallback() - Set callback function for mouse wheel
 
260
//========================================================================
 
261
 
 
262
GLFWAPI void GLFWAPIENTRY glfwSetMouseWheelCallback( GLFWmousewheelfun cbfun )
 
263
{
 
264
    // Is GLFW initialized?
 
265
    if( !_glfwInitialized || !_glfwWin.Opened )
 
266
    {
 
267
        return;
 
268
    }
 
269
 
 
270
    // Set callback function
 
271
    _glfwWin.MouseWheelCallback = cbfun;
 
272
 
 
273
    // Call the callback function to let the application know the current
 
274
    // mouse wheel position
 
275
    if( cbfun )
 
276
    {
 
277
        cbfun( _glfwInput.WheelPos );
 
278
    }
 
279
}
 
280