void g2Controller::__MouseClick(g2MouseButton button, g2MouseClick state, int x, int y)
{
    // Ignore if not visible
    if(!GetVisibility())
        return;
    
    // Update mouse to localized positions
    x -= pX;
    y -= pY;
    
    // Are we in this object's volume and do we have a full left-click?
    if(InController(x, y) && button == g2MouseButton_Left && state == g2MouseClick_Down)
        ControllerState = g2ControllerState_Pressed;
    
    // Else, if there is a mouse release AND we are coming from a pressed state....
    else if(InController(x, y) && button == g2MouseButton_Left && state == g2MouseClick_Up && ControllerState == g2ControllerState_Pressed)
        ControllerState = g2ControllerState_Clicked;
    
    // Else, reset to either hover or none...
    else if(InController(x, y))
        ControllerState = g2ControllerState_Hover;
    
    // Else, no hovering, just nothing
    else
        ControllerState = g2ControllerState_None;
    
    // Update mouse click
    MouseClick(button, state, x, y);
    
    // Update all children
    int QueueSize = (int)ChildObjects.size();
    for(int i = 0; i < QueueSize; i++)
    {
        // Get child
        g2Controller* Child = ChildObjects.front();
        ChildObjects.pop();
        
        // Update child window event
        Child->__MouseClick(button, state, x, y);
        
        // Put back
        ChildObjects.push(Child);
    }
    
    // Execute callback
    if(!GetDisabled() && GetControllerState() == g2ControllerState_Clicked && PressedCallback != 0)
        PressedCallback(this);
}
Exemple #2
0
void g2Controller::__MouseClick(g2MouseButton button, g2MouseClick state, int x, int y)
{
    // Ignore if not visible
    if(!GetVisibility())
        return;
    
    // Update mouse to localized positions
    x -= pX;
    y -= pY;
    
    // Are we in this object's volume and do we have a full left-click?
    if(InController(x, y) && button == g2MouseButton_Left && state == g2MouseClick_Down)
        ControllerState |= g2ControllerState_Pressed;
    
    // Check for full click, if there is a mouse release AND we are coming from a pressed state....
    if(InController(x, y) && button == g2MouseButton_Left && state == g2MouseClick_Up && ((ControllerState & g2ControllerState_Pressed) == g2ControllerState_Pressed))
        ControllerState |= g2ControllerState_Clicked;
    
    // Are we no longer holding the mouse button down anymore?
    if((button == g2MouseButton_Left && state == g2MouseClick_Up) && ((ControllerState & g2ControllerState_Pressed) == g2ControllerState_Pressed))
        ControllerState ^= g2ControllerState_Pressed;
    
    // Update mouse click; save an older version of the controller state,
    // in case the user destroys the clicked flag by calling GetControllerState()
    g2ControllerState OldControllerState = ControllerState;
    MouseClick(button, state, x, y);
    
    // If it's anything non-key-release
    if(state != g2MouseClick_Up)
    {
        // Apply update to all non-blocked objects
        // We must go from front-to-back ordering (which is the reverse
        // of what the rendering ordering is)
        for(ChildObjectsRevIt Child = ChildObjects.rbegin(); Child != ChildObjects.rend(); Child++)
        {
            // Child position
            int cx, cy;
            (*Child)->GetPos(&cx, &cy);
            
            // Stop applying on our first collision if we are in that controller
            // and it's on-screen (regardless of it being enabled or not)
            // Note that we must localize the coordinate for each controller
            if((*Child)->GetVisibility() && (*Child)->InController(x -cx , y - cy))
            {
                (*Child)->__MouseClick(button, state, x, y);
                break;
            }
        }
    }
    // Else, apply release to everyone
    else
    {
        // Allow the recieving function to figure it's own event
        for(ChildObjectsRevIt Child = ChildObjects.rbegin(); Child != ChildObjects.rend(); Child++)
            (*Child)->__MouseClick(button, state, x, y);
    }
    
    // Execute callback (releases button-click flag)
    if(!GetDisabled() && ((OldControllerState & g2ControllerState_Clicked) == g2ControllerState_Clicked) && PressedCallback != 0)
    {
        // Callback and xor the controller state's click-event out
        PressedCallback(this);
    }
}