GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


GUI button code by baldurk
void GLButton::Update(InputCode *Input)
{
    int mx, my;
    Input->GetCoord(mx, my);

    mpos = Vector((2.0f*float(mx)/float(winx))-1.0f,
          (-2.0f*float(my)/float(winy))+1.0f,
          0.0f);

    if(mpos.x > topleft.x && mpos.x < bottomright.x &&
       mpos.y > bottomright.y && mpos.y < topleft.y &&
       state == BUT_UP && ignore == false && !hidden)
    {
    if(Input->GetLeft())
    {
        state = BUT_L_DOWN;
        if(parent) parent->GotFocus();GotFocus();
        focus = true;
    }
    else if(Input->GetMiddle())
    {
        state = BUT_M_DOWN;
        if(parent) parent->GotFocus();GotFocus();
        focus = true;
    }
    else if(Input->GetRight())
    {
        state = BUT_R_DOWN;
        if(parent) parent->GotFocus();GotFocus();
        focus = true;
    }
    }
    else
    {
    if(Input->GetLeft() || Input->GetMiddle() || Input->GetRight())
        ignore = true;
    if(!Input->GetLeft() && !Input->GetMiddle() && !Input->GetRight())
        ignore = false;
    }
    
    if(state != DISABLED && state != BUT_UP &&
       !Input->GetLeft() && !Input->GetMiddle() && !Input->GetRight())
    {
    state = BUT_UP;
    if(mpos.x > topleft.x && mpos.x < bottomright.x &&
       mpos.y > bottomright.y && mpos.y < topleft.y)
    {
        buttonpressed = true;
    }
    }

    UpdatePos();

    Draw();
}