示例#1
0
void EclUpdateMouse ( int _mouseX, int _mouseY, bool _lmb, bool _rmb )
{

    int oldMouseX = mouseX;
    int oldMouseY = mouseY;

    mouseX = _mouseX;
    mouseY = _mouseY;

    EclWindow *currentWindow = EclGetWindow( mouseX, mouseY );

    if ( !_lmb && !lmb && !_rmb && !rmb )                        // No buttons changed, mouse move only
    {
        if ( currentWindow )
        {
            EclButton *button = currentWindow->GetButton ( mouseX - currentWindow->m_x, mouseY - currentWindow->m_y );
            if ( button )
            {
                if ( strcmp ( currentButton, button->m_name ) != 0 ) 
                {
                    strcpy ( currentButton, button->m_name );
                    tooltipTimer = GetHighResTime();
                }
            }
            else
            {
                if ( strcmp ( currentButton, "None" ) != 0 )
                {
                    strcpy ( currentButton, "None" );
                    tooltipTimer = 0.0f;
                }
            }
        }
        else
        {
            if ( strcmp ( currentButton, "None" ) != 0 )
            {
                strcpy ( currentButton, "None" );
                tooltipTimer = 0.0f;
            }
        }
    }
    else if ( _lmb && !lmb )                                     // Left button down
    {
        EclWindow *currentWindow = EclGetWindow( mouseX, mouseY );
        if ( currentWindow )
        {            
            strcpy ( windowFocus, currentWindow->m_name );
            EclBringWindowToFront( currentWindow->m_name );
            strcpy ( mouseDownWindow, currentWindow->m_name );
           
            EclButton *button = currentWindow->GetButton ( mouseX - currentWindow->m_x, mouseY - currentWindow->m_y );
            if ( button )
            {
                strcpy ( currentButton, button->m_name );
                button->MouseDown();
            }
            else
            {
                strcpy( currentButton, "None" );
                currentWindow->MouseEvent( true, false, false, true );
                if( currentWindow->m_movable ) 
                {
                    mouseDownWindowX = mouseX - currentWindow->m_x;
                    mouseDownWindowY = mouseY - currentWindow->m_y;

                    if( mouseY > currentWindow->m_y + currentWindow->m_h - 6 )
                    {
                        mouseDownBottom = true;
                    }

                    if( mouseX > currentWindow->m_x + currentWindow->m_w - 6 )
                    {
                        mouseDownRight = true;
                    }
                }
            }
        
        }
        else
        {
            if ( strcmp ( windowFocus, "None" ) != 0 ) 
            {
                strcpy ( windowFocus, "None" );
            }
        }

        lmb = true;
    }
    else if ( _lmb && lmb )                                 // Left button dragged
    {
        if ( strcmp ( mouseDownWindow, "None" ) != 0 ) {

            EclWindow *window = EclGetWindow( mouseDownWindow );
            EclButton *button;
			
			if (grabbedButton) 
				button = window->GetButton( EclGetCurrentButton() );
			else
				button = window->GetButton( mouseX - window->m_x, mouseY - window->m_y );			
            
            if( button && mouseDownWindowX < 0.0f )
            {
                button->MouseDown();
            }
            else
            {
                if( strcmp( currentButton, "None" ) == 0 ||
                    mouseDownWindowX >= 0.0f )
                {
                    int newWidth = window->m_w;
                    int newHeight = window->m_h;
                    bool sizeChanged = false;

                    if( mouseDownBottom )
                    {                
                        newHeight = mouseY - window->m_y;
                        sizeChanged = true;
                    }
            
                    if( mouseDownRight )
                    {
                        newWidth = mouseX - window->m_x;
                        sizeChanged = true;
                    }

                    if( sizeChanged )
                    {
                        if( newWidth < window->m_minW ) newWidth = window->m_minW;
                        if( newHeight < window->m_minH ) newHeight = window->m_minH;  
                        EclSetWindowSize( mouseDownWindow, newWidth, newHeight );
                    }
                    else 
                    {
                        EclSetWindowPosition ( mouseDownWindow, 
                                               mouseX - mouseDownWindowX, 
                                               mouseY - mouseDownWindowY );
                    }
                }
            }
        }
    }
    else if ( !_lmb && lmb )                                // Left button up
    {
        strcpy ( mouseDownWindow, "None" );
        mouseDownWindowX = -1;
        mouseDownWindowY = -1;
        mouseDownBottom = false;
        mouseDownRight = false;
		grabbedButton = false;
        
        lmb = false;

        EclWindow *currentWindow = EclGetWindow( mouseX, mouseY );
        if ( currentWindow )
        {
            EclButton *button = currentWindow->GetButton( mouseX - currentWindow->m_x, mouseY - currentWindow->m_y );
            if ( button ) {
                button->MouseUp ();
            }
            else
            {
                currentWindow->MouseEvent( true, false, true, false );
            }
        }
    }

    if ( _rmb && !rmb )
    {
        // Right button down
    }
    else if ( _rmb && rmb )
    {
        // Right button dragged
    }
    else if ( !_rmb && rmb )
    {
        // Right button up
    }

}
void EclUpdateMouse ( int _mouseX, int _mouseY, bool _lmb, bool _rmb )
{

    int oldMouseX = mouseX;
    int oldMouseY = mouseY;

    mouseX = _mouseX;
    mouseY = _mouseY;

    EclWindow *currentHighlightedWindow = EclGetWindow( mouseX, mouseY );
    if( currentHighlightedWindow )
    {
        EclDirtyWindow( currentHighlightedWindow );
    }

    if ( !_lmb && !lmb && !_rmb && !rmb )                        // No buttons changed, mouse move only
    {
        EclWindow *currentWindow = EclGetWindow( windowFocus );
        if ( currentWindow )
        {
            EclButton *button = currentWindow->GetButton ( mouseX - currentWindow->m_x, mouseY - currentWindow->m_y );
            if ( button )
            {
                if ( strcmp ( currentButton, button->m_name ) != 0 ) 
                {
                    strcpy ( currentButton, button->m_name );
                    EclDirtyWindow ( currentWindow );
                    tooltipTimer = EclGetAccurateTime() + 1000;
                }
                else
                {
                    if( EclGetAccurateTime() > tooltipTimer )
                    {
                        if( tooltipCallback ) tooltipCallback( currentWindow, button );                    
                    }
                }
            }
            else
            {
                if ( strcmp ( currentButton, "None" ) != 0 )
                {
                    strcpy ( currentButton, "None" );
                    EclDirtyWindow ( currentWindow );
                    if( tooltipCallback ) tooltipCallback( NULL, NULL );
                }
            }
        }
        else
        {
            if ( strcmp ( currentButton, "None" ) != 0 )
            {
                strcpy ( currentButton, "None" );
                if( tooltipCallback ) tooltipCallback( NULL, NULL );
            }
        }
    }
    else if ( _lmb && !lmb )                                     // Left button down
    {
		buttonDownMouseX = mouseX;
		buttonDownMouseY = mouseY;

        EclWindow *currentWindow = EclGetWindow( mouseX, mouseY );
        if ( currentWindow )
        {            
            if ( strcmp ( windowFocus, "None" ) != 0 ) EclDirtyWindow ( windowFocus );
            strcpy ( windowFocus, currentWindow->m_name );
            EclBringWindowToFront( currentWindow->m_name );
            strcpy ( mouseDownWindow, currentWindow->m_name );
           
            EclButton *button = currentWindow->GetButton ( mouseX - currentWindow->m_x, mouseY - currentWindow->m_y );
            if ( button )
            {
                strcpy ( currentButton, button->m_name );
                button->MouseDown();
            }
            else
            {
                strcpy( currentButton, "None" );
                currentWindow->MouseEvent( true, false, false, true );
                if( currentWindow->m_movable ) 
                {
                    mouseDownWindowX = mouseX - currentWindow->m_x;
                    mouseDownWindowY = mouseY - currentWindow->m_y;
                }
            }
        
        }
        else
        {
            if ( strcmp ( windowFocus, "None" ) != 0 ) 
            {
                EclDirtyWindow ( windowFocus );
                strcpy ( windowFocus, "None" );
            }
        }

        lmb = true;
    }
    else if ( _lmb && lmb )                                 // Left button dragged
    {
		buttonDownMouseX = mouseX;
		buttonDownMouseY = mouseY;

        if ( strcmp ( mouseDownWindow, "None" ) != 0 ) {

            EclWindow *window = EclGetWindow( mouseDownWindow );
            if( window )
            {
                EclButton *button = window->GetButton( mouseX - window->m_x, mouseY - window->m_y );
            
                if( button )
                {
                    button->MouseDown();
                }
                else
                {
                    if( strcmp( currentButton, "None" ) == 0 )
                    {
                        int newWidth = window->m_w;
                        int newHeight = window->m_h;
                        bool sizeChanged = false;

                        if( oldMouseY > window->m_y + window->m_h - 4 &&
                            oldMouseY < window->m_y + window->m_h + 4 )
                        {                
                            newHeight = mouseY - window->m_y;
                            sizeChanged = true;
                        }
                
                        if( oldMouseX > window->m_x + window->m_w - 4 &&
                            oldMouseX < window->m_x + window->m_w + 4 )
                        {
                            newWidth = mouseX - window->m_x;
                            sizeChanged = true;
                        }

                        if( sizeChanged )
                        {
                            if( window->m_resizable )
                            {
                                if( newWidth < 60 ) newWidth = 60;
                                if( newHeight < 40 ) newHeight = 40;  
                                EclSetWindowSize( mouseDownWindow, newWidth, newHeight );
                            }
                        }
                        else 
                        {
                            if( window->m_movable )
                            {
                                EclSetWindowPosition ( mouseDownWindow, 
                                                       mouseX - mouseDownWindowX, 
                                                       mouseY - mouseDownWindowY );
                            }
                        }
                    }
                }
            }
        }
    }
    else if ( !_lmb && lmb )                                // Left button up
    {
        strcpy ( mouseDownWindow, "None" );
        lmb = false;

        EclWindow *currentWindow = EclGetWindow( buttonDownMouseX, buttonDownMouseY );
        if ( currentWindow )
        {
            EclButton *button = currentWindow->GetButton( buttonDownMouseX - currentWindow->m_x, buttonDownMouseY - currentWindow->m_y );
            if ( button ) {
                EclDirtyWindow ( currentWindow );
                button->MouseUp ();
            }
            else
            {
                currentWindow->MouseEvent( true, false, true, false );
                EclRemovePopup();
            }
        }
        else
        {
            EclRemovePopup();
        }
    }

    if ( _rmb && !rmb )
    {
        // Right button down
    }
    else if ( _rmb && rmb )
    {
        // Right button dragged
    }
    else if ( !_rmb && rmb )
    {
        // Right button up
    }

}