Added more input functions to clarify internal API.

This commit is contained in:
Camilla Berglund 2011-10-09 17:10:40 +02:00
parent 792034c42d
commit d0840bdea1
5 changed files with 109 additions and 104 deletions

View File

@ -67,11 +67,8 @@
NSRect contentRect = NSRect contentRect =
[window->NS.window contentRectForFrameRect:[window->NS.window frame]]; [window->NS.window contentRectForFrameRect:[window->NS.window frame]];
window->width = contentRect.size.width;
window->height = contentRect.size.height;
if (_glfwLibrary.windowSizeCallback) _glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height);
_glfwLibrary.windowSizeCallback(window, window->width, window->height);
} }
- (void)windowDidMove:(NSNotification *)notification - (void)windowDidMove:(NSNotification *)notification
@ -87,24 +84,17 @@
mainScreenHeight - contentRect.origin.y - mainScreenHeight - contentRect.origin.y -
mainScreenOrigin.y - window->height); mainScreenOrigin.y - window->height);
window->positionX = flippedPos.x; _glfwInputWindowPos(window, flippedPos.x, flippedPos.y);
window->positionY = flippedPos.y;
} }
- (void)windowDidMiniaturize:(NSNotification *)notification - (void)windowDidMiniaturize:(NSNotification *)notification
{ {
window->iconified = GL_TRUE; _glfwInputWindowIconify(window, GL_TRUE);
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
} }
- (void)windowDidDeminiaturize:(NSNotification *)notification - (void)windowDidDeminiaturize:(NSNotification *)notification
{ {
window->iconified = GL_FALSE; _glfwInputWindowIconify(window, GL_FALSE);
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
} }
- (void)windowDidBecomeKey:(NSNotification *)notification - (void)windowDidBecomeKey:(NSNotification *)notification
@ -349,24 +339,15 @@ static int convertMacKeyCode(unsigned int macKeyCode)
- (void)mouseMoved:(NSEvent *)event - (void)mouseMoved:(NSEvent *)event
{ {
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ _glfwInputCursorMotion(window, [event deltaX], [event deltaY]);
window->mousePosX += [event deltaX];
window->mousePosY += [event deltaY];
}
else else
{ {
NSPoint p = [event locationInWindow]; NSPoint p = [event locationInWindow];
// Cocoa coordinate system has origin at lower left // Cocoa coordinate system has origin at lower left
window->mousePosX = p.x; p.y = [[window->NS.window contentView] bounds].size.height - p.y;
window->mousePosY = [[window->NS.window contentView] bounds].size.height - p.y;
}
if (_glfwLibrary.mousePosCallback) _glfwInputCursorMotion(window, p.x, p.y);
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
} }
} }

View File

@ -339,12 +339,18 @@ void _glfwSetError(int error, const char* description);
// Window management (window.c) // Window management (window.c)
void _glfwSetDefaultWindowHints(void); void _glfwSetDefaultWindowHints(void);
// Input handling (window.c) // WIndow event notification
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);
// Input event notification
void _glfwInputKey(_GLFWwindow* window, int key, int action); void _glfwInputKey(_GLFWwindow* window, int key, int action);
void _glfwInputChar(_GLFWwindow* window, int character); void _glfwInputChar(_GLFWwindow* window, int character);
void _glfwInputScroll(_GLFWwindow* window, int x, int y); void _glfwInputScroll(_GLFWwindow* window, int x, int y);
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action); void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated); void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y);
// OpenGL context helpers (opengl.c) // OpenGL context helpers (opengl.c)
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions); int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);

View File

@ -852,15 +852,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
} }
_glfwInputWindowFocus(window, active); _glfwInputWindowFocus(window, active);
_glfwInputWindowIconify(window, iconified);
if (iconified != window->iconified)
{
window->iconified = iconified;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
}
return 0; return 0;
} }
@ -1006,32 +998,27 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (newMouseX != window->Win32.oldMouseX || if (newMouseX != window->Win32.oldMouseX ||
newMouseY != window->Win32.oldMouseY) newMouseY != window->Win32.oldMouseY)
{ {
int x, y;
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (_glfwLibrary.activeWindow != window) if (_glfwLibrary.activeWindow != window)
return 0; return 0;
window->mousePosX += newMouseX - x += newMouseX - window->Win32.oldMouseX;
window->Win32.oldMouseX; y += newMouseY - window->Win32.oldMouseY;
window->mousePosY += newMouseY -
window->Win32.oldMouseY;
} }
else else
{ {
window->mousePosX = newMouseX; x = newMouseX;
window->mousePosY = newMouseY; x = newMouseY;
} }
window->Win32.oldMouseX = newMouseX; window->Win32.oldMouseX = newMouseX;
window->Win32.oldMouseY = newMouseY; window->Win32.oldMouseY = newMouseY;
window->Win32.cursorCentered = GL_FALSE; window->Win32.cursorCentered = GL_FALSE;
if (_glfwLibrary.mousePosCallback) _glfwInputCursorMotion(window, x, y);
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
}
} }
return 0; return 0;
@ -1053,9 +1040,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_SIZE: case WM_SIZE:
{ {
window->width = LOWORD(lParam);
window->height = HIWORD(lParam);
// If window is in cursor capture mode, update clipping rect // If window is in cursor capture mode, update clipping rect
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
@ -1064,21 +1048,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
ClipCursor(&ClipWindowRect); ClipCursor(&ClipWindowRect);
} }
if (_glfwLibrary.windowSizeCallback) _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
{
_glfwLibrary.windowSizeCallback(window,
window->width,
window->height);
}
return 0; return 0;
} }
case WM_MOVE: case WM_MOVE:
{ {
window->positionX = LOWORD(lParam);
window->positionY = HIWORD(lParam);
// If window is in cursor capture mode, update clipping rect // If window is in cursor capture mode, update clipping rect
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
@ -1086,6 +1061,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (GetWindowRect(window->Win32.handle, &ClipWindowRect)) if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect); ClipCursor(&ClipWindowRect);
} }
_glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam));
return 0; return 0;
} }

View File

@ -182,6 +182,28 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
} }
//========================================================================
// Register cursor moves
//========================================================================
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
{
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
window->mousePosX += x;
window->mousePosY += y;
}
else
{
window->mousePosX = x;
window->mousePosY = y;
}
if (_glfwLibrary.mousePosCallback)
_glfwLibrary.mousePosCallback(window, x, y);
}
//======================================================================== //========================================================================
// Register window focus events // Register window focus events
//======================================================================== //========================================================================
@ -227,6 +249,53 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
} }
//========================================================================
// Register window position events
//========================================================================
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
{
if (window->positionX == x && window->positionY == y)
return;
window->positionX = x;
window->positionY = y;
}
//========================================================================
// Register window size events
//========================================================================
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
{
if (window->width == width && window->height == height)
return;
window->width = width;
window->height = height;
if (_glfwLibrary.windowSizeCallback)
_glfwLibrary.windowSizeCallback(window, width, height);
}
//========================================================================
// Register window size events
//========================================================================
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
{
if (window->iconified == iconified)
return;
window->iconified = iconified;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, iconified);
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW public API ////// ////// GLFW public API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////

View File

@ -1194,33 +1194,27 @@ static void processSingleEvent(void)
event.xmotion.y != window->X11.cursorPosY) event.xmotion.y != window->X11.cursorPosY)
{ {
// The mouse cursor was moved and we didn't do it // The mouse cursor was moved and we didn't do it
int x, y;
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (_glfwLibrary.activeWindow != window) if (_glfwLibrary.activeWindow != window)
break; break;
window->mousePosX += event.xmotion.x - x = event.xmotion.x - window->X11.cursorPosX;
window->X11.cursorPosX; y = event.xmotion.y - window->X11.cursorPosY;
window->mousePosY += event.xmotion.y -
window->X11.cursorPosY;
} }
else else
{ {
window->mousePosX = event.xmotion.x; x = event.xmotion.x;
window->mousePosY = event.xmotion.y; x = event.xmotion.y;
} }
window->X11.cursorPosX = event.xmotion.x; window->X11.cursorPosX = event.xmotion.x;
window->X11.cursorPosY = event.xmotion.y; window->X11.cursorPosY = event.xmotion.y;
window->X11.cursorCentered = GL_FALSE; window->X11.cursorCentered = GL_FALSE;
if (_glfwLibrary.mousePosCallback) _glfwInputCursorMotion(window, x, y);
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
}
} }
break; break;
@ -1236,27 +1230,13 @@ static void processSingleEvent(void)
return; return;
} }
if (event.xconfigure.width != window->width || _glfwInputWindowSize(window,
event.xconfigure.height != window->height) event.xconfigure.width,
{ event.xconfigure.height);
// The window was resized
window->width = event.xconfigure.width; _glfwInputWindowPos(window,
window->height = event.xconfigure.height; event.xconfigure.x,
if (_glfwLibrary.windowSizeCallback) event.xconfigure.y);
{
_glfwLibrary.windowSizeCallback(window,
window->width,
window->height);
}
}
if (event.xconfigure.x != window->positionX ||
event.xconfigure.y != window->positionY)
{
window->positionX = event.xconfigure.x;
window->positionY = event.xconfigure.y;
}
break; break;
} }
@ -1305,11 +1285,7 @@ static void processSingleEvent(void)
return; return;
} }
window->iconified = GL_FALSE; _glfwInputWindowIconify(window, GL_FALSE);
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
break; break;
} }
@ -1323,11 +1299,7 @@ static void processSingleEvent(void)
return; return;
} }
window->iconified = GL_TRUE; _glfwInputWindowIconify(window, GL_TRUE);
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
break; break;
} }