OSStatus _glfwWindowEventHandler( EventHandlerCallRef handlerCallRef, EventRef event, void *userData ) { switch( GetEventKind(event) ) { case kEventWindowBoundsChanged: { WindowRef window; GetEventParameter( event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window ); Rect rect; GetWindowPortBounds( window, &rect ); if( _glfwWin.Width != rect.right || _glfwWin.Height != rect.bottom ) { aglUpdateContext(_glfwWin.AGLContext); _glfwWin.Width = rect.right; _glfwWin.Height = rect.bottom; if( _glfwWin.WindowSizeCallback ) { _glfwWin.WindowSizeCallback( _glfwWin.Width, _glfwWin.Height ); } // Emulate (force) content invalidation if( _glfwWin.WindowRefreshCallback ) { _glfwWin.WindowRefreshCallback(); } } break; } case kEventWindowClose: { // Check if the program wants us to close the window if( _glfwWin.WindowCloseCallback ) { if( _glfwWin.WindowCloseCallback() ) { glfwCloseWindow(); } } else { glfwCloseWindow(); } return noErr; } case kEventWindowDrawContent: { // Call user callback function if( _glfwWin.WindowRefreshCallback ) { _glfwWin.WindowRefreshCallback(); } break; } case kEventWindowActivated: { _glfwWin.Active = GL_TRUE; break; } case kEventWindowDeactivated: { _glfwWin.Active = GL_FALSE; _glfwInputDeactivation(); break; } } return eventNotHandledErr; }
static int _glfwProcessEvents( void ) { struct IntuiMessage message, *tmp_message = NULL; struct MsgPort *msg_port; int win_closed = GL_FALSE, action; int x, y; // Examine pending messages msg_port = _glfwWin.Window->UserPort; while( (tmp_message = (struct IntuiMessage *) GetMsg( msg_port )) ) { // Copy contents of message structure message = *tmp_message; // Now reply to the message (we don't need it anymore) ReplyMsg( (struct Message *) tmp_message ); // Handle different messages switch( message.Class ) { // Was the window activated? case IDCMP_ACTIVEWINDOW: _glfwWin.Active = GL_TRUE; break; // Was the window deactivated? case IDCMP_INACTIVEWINDOW: _glfwWin.Active = GL_FALSE; _glfwInputDeactivation(); break; // Did we get a keyboard press or release? case IDCMP_RAWKEY: action = (message.Code & 0x80) ? GLFW_RELEASE : GLFW_PRESS; message.Code &= 0x7F; _glfwInputKey( _glfwTranslateKey( &message ), action ); _glfwInputChar( _glfwTranslateChar( &message ), action ); break; // Was the mouse moved? case IDCMP_MOUSEMOVE: x = message.MouseX; y = message.MouseY; if( _glfwWin.PointerHidden ) { // When pointer is hidden, we get delta moves x += _glfwInput.MousePosX; y += _glfwInput.MousePosY; } else if( x < 0 || x >= _glfwWin.Width || y < 0 || y >= _glfwWin.Height ) { // Only report mouse moves that are INSIDE client area break; } if( x != _glfwInput.MousePosX || y != _glfwInput.MousePosY ) { _glfwInput.MousePosX = x; _glfwInput.MousePosY = y; if( _glfwWin.MousePosCallback ) { _glfwWin.MousePosCallback( x, y ); } } break; // Did we get a mouse button event? case IDCMP_MOUSEBUTTONS: switch( message.Code ) { case SELECTUP: _glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE ); break; case SELECTDOWN: _glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS ); break; case MENUUP: _glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE ); break; case MENUDOWN: _glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS ); break; default: break; } break; // Was the window size changed? case IDCMP_NEWSIZE: _glfwWin.Width = message.IDCMPWindow->GZZWidth; _glfwWin.Height = message.IDCMPWindow->GZZHeight; if( _glfwWin.WindowSizeCallback ) { _glfwWin.WindowSizeCallback( _glfwWin.Width, _glfwWin.Height ); } break; // Was the window contents damaged? case IDCMP_REFRESHWINDOW: // Intuition wants us to do this... BeginRefresh( _glfwWin.Window ); EndRefresh( _glfwWin.Window, TRUE ); // Call user callback function if( _glfwWin.WindowRefreshCallback ) { _glfwWin.WindowRefreshCallback(); } break; // Was the window closed? case IDCMP_CLOSEWINDOW: win_closed = GL_TRUE; break; default: break; } } // Return GL_TRUE if window was closed return( win_closed ); }