Пример #1
0
LRESULT CALLBACK _glfwWindowCallback( HWND hWnd, UINT uMsg,
     WPARAM wParam, LPARAM lParam )
{
    int WheelDelta, Iconified;


	// ZBS added this code to look for the correct _glfwWin given the hWnd
	// Changed all the references from _glfwWin. to winPtr->
	_GLFWwin *winPtr = 0;
	int i;
	for( i=0; i<MAX_ALIASES; i++ ) {
		if( aliases[i].Wnd == hWnd ) {
			winPtr = &aliases[i];
			break;
		}
	}
	if( winPtr == 0 ) {
		winPtr = &_glfwWin;
	}


    // Handle certain window messages
    switch( uMsg )
    {
        // Window activate message? (iconification?)
        case WM_ACTIVATE:
            winPtr->Active = LOWORD(wParam) != WA_INACTIVE ? GL_TRUE :
                                                              GL_FALSE;
            Iconified = HIWORD(wParam) ? GL_TRUE : GL_FALSE;

            // Were we deactivated/iconified?
            if( (!winPtr->Active || Iconified) && !winPtr->Iconified )
            {
                // If we are in fullscreen mode we need to iconify
                if( winPtr->Fullscreen )
                {
                    // Do we need to manually iconify?
                    if( !Iconified )
                    {
                        // Minimize window
                        CloseWindow( winPtr->Wnd );

                        // The window is now iconified
                        Iconified = GL_TRUE;
                    }

                    // Change display settings to the desktop resolution
                    ChangeDisplaySettings( NULL, CDS_FULLSCREEN );
                }

                // Unlock mouse
                if( !winPtr->OldMouseLockValid )
                {
                    winPtr->OldMouseLock = winPtr->MouseLock;
                    winPtr->OldMouseLockValid = GL_TRUE;
                    glfwEnable( GLFW_MOUSE_CURSOR );
                }
            }
            else if( winPtr->Active || !Iconified )
            {
                // If we are in fullscreen mode we need to maximize
                if( winPtr->Fullscreen && winPtr->Iconified )
                {
                    // Change display settings to the user selected mode
                    _glfwSetVideoModeMODE( winPtr->ModeID );

                    // Do we need to manually restore window?
                    if( Iconified )
                    {
                        // Restore window
                        OpenIcon( winPtr->Wnd );

                        // The window is no longer iconified
                        Iconified = GL_FALSE;

                        // Activate window
                        ShowWindow( hWnd, SW_SHOW );
                        _glfwSetForegroundWindow( winPtr->Wnd );
                        SetFocus( winPtr->Wnd );
                    }
                }

                // Lock mouse, if necessary
                if( winPtr->OldMouseLockValid && winPtr->OldMouseLock )
                {
                    glfwDisable( GLFW_MOUSE_CURSOR );
                }
                winPtr->OldMouseLockValid = GL_FALSE;
            }

            winPtr->Iconified = Iconified;
            return 0;

        // Intercept system commands (forbid certain actions/events)
        case WM_SYSCOMMAND:
            switch( wParam )
            {
                // Screensaver trying to start or monitor trying to enter
                // powersave?
                case SC_SCREENSAVE:
                case SC_MONITORPOWER:
                    if( winPtr->Fullscreen )
                    {
                        return 0;
                    }
                    else
                    {
                        break;
                    }

                // User trying to access application menu using ALT?
                case SC_KEYMENU:
                    return 0;
            }
            break;

        // Did we receive a close message?
        case WM_CLOSE:
            PostQuitMessage( 0 );
            return 0;

        // Is a key being pressed?
        case WM_KEYDOWN:
        case WM_SYSKEYDOWN:
            // Translate and report key press
            _glfwInputKey( _glfwTranslateKey( wParam, lParam ),
                           GLFW_PRESS );

            // Translate and report character input
            if( winPtr->CharCallback )
            {
                _glfwTranslateChar( wParam, lParam, GLFW_PRESS );
            }
            return 0;

        // Is a key being released?
        case WM_KEYUP:
        case WM_SYSKEYUP:
            // Special trick: release both shift keys on SHIFT up event
            if( wParam == VK_SHIFT )
            {
                _glfwInputKey( GLFW_KEY_LSHIFT, GLFW_RELEASE );
                _glfwInputKey( GLFW_KEY_RSHIFT, GLFW_RELEASE );
            }
            else
            {
                // Translate and report key release
                _glfwInputKey( _glfwTranslateKey( wParam, lParam ),
                               GLFW_RELEASE );
            }

            // Translate and report character input
            if( winPtr->CharCallback )
            {
                _glfwTranslateChar( wParam, lParam, GLFW_RELEASE );
            }
            return 0;

        // Were any of the mouse-buttons pressed?
        case WM_LBUTTONDOWN:
            SetCapture(hWnd);
            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS );
            return 0;
        case WM_RBUTTONDOWN:
            SetCapture(hWnd);
            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS );
            return 0;
        case WM_MBUTTONDOWN:
            SetCapture(hWnd);
            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_MIDDLE, GLFW_PRESS );
            return 0;
        case WM_XBUTTONDOWN:
            if( HIWORD(wParam) == XBUTTON1 )
            {
                SetCapture(hWnd);
                _glfwInputMouseClick( GLFW_MOUSE_BUTTON_4, GLFW_PRESS );
            }
            else if( HIWORD(wParam) == XBUTTON2 )
            {
                SetCapture(hWnd);
                _glfwInputMouseClick( GLFW_MOUSE_BUTTON_5, GLFW_PRESS );
            }
            return 1;

        // Were any of the mouse-buttons released?
        case WM_LBUTTONUP:
            ReleaseCapture();
            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_LEFT, GLFW_RELEASE );
            return 0;
        case WM_RBUTTONUP:
            ReleaseCapture();
            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_RIGHT, GLFW_RELEASE );
            return 0;
        case WM_MBUTTONUP:
            ReleaseCapture();
            _glfwInputMouseClick( GLFW_MOUSE_BUTTON_MIDDLE, GLFW_RELEASE );
            return 0;
        case WM_XBUTTONUP:
            if( HIWORD(wParam) == XBUTTON1 )
            {
                ReleaseCapture();
                _glfwInputMouseClick( GLFW_MOUSE_BUTTON_4, GLFW_RELEASE );
            }
            else if( HIWORD(wParam) == XBUTTON2 )
            {
                ReleaseCapture();
                _glfwInputMouseClick( GLFW_MOUSE_BUTTON_5, GLFW_RELEASE );
            }
            return 1;

        // Did the mouse move?
        case WM_MOUSEMOVE:
            {
                int NewMouseX, NewMouseY;

                // Get signed (!) mouse position
                NewMouseX = (int)((short)LOWORD(lParam));
                NewMouseY = (int)((short)HIWORD(lParam));

                if( NewMouseX != _glfwInput.OldMouseX ||
                    NewMouseY != _glfwInput.OldMouseY )
                {
                    if( winPtr->MouseLock )
                    {
                        _glfwInput.MousePosX += NewMouseX -
                                                _glfwInput.OldMouseX;
                        _glfwInput.MousePosY += NewMouseY -
                                                _glfwInput.OldMouseY;
                    }
                    else
                    {
                        _glfwInput.MousePosX = NewMouseX;
                        _glfwInput.MousePosY = NewMouseY;
                    }
                    _glfwInput.OldMouseX = NewMouseX;
                    _glfwInput.OldMouseY = NewMouseY;
                    _glfwInput.MouseMoved = GL_TRUE;
    
                    // Call user callback function
                    if( winPtr->MousePosCallback )
                    {
                        winPtr->MousePosCallback( _glfwInput.MousePosX,
                                                   _glfwInput.MousePosY );
                    }
                }
            }
            return 0;

        // Mouse wheel action?
        case WM_MOUSEWHEEL:
            // WM_MOUSEWHEEL is not supported under Windows 95
            if( _glfwSys.WinVer != _GLFW_WIN_95 )
            {
                WheelDelta = (((int)wParam) >> 16) / WHEEL_DELTA;
                _glfwInput.WheelPos += WheelDelta;
                if( winPtr->MouseWheelCallback )
                {
                    winPtr->MouseWheelCallback( _glfwInput.WheelPos );
                }
                return 0;
            }
            break;

        // Resize the window?
        case WM_SIZE:
            winPtr->Width  = LOWORD(lParam);
            winPtr->Height = HIWORD(lParam);
            if( winPtr->WindowSizeCallback )
            {
                winPtr->WindowSizeCallback( LOWORD(lParam),
                                             HIWORD(lParam) );
            }
            return 0;

        // Was the window contents damaged?
        case WM_PAINT:
            // Call user callback function
            if( winPtr->WindowRefreshCallback )
            {
                winPtr->WindowRefreshCallback();
            }
            break;

        default:
            break;
    }
Пример #2
0
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 );
}