Exemplo n.º 1
0
void pawsTree::Select(pawsTreeNode* node)
{
    selected = node;

    //we have to check if the selected element is outside sight. If so move the scrollbar
    //correctly in order to have it on screen.

    if(selected->GetScreenFrame().ymin < GetScreenFrame().ymin) //the element is hidden in the top
    {
        //get the current position and move it relatively of the part which is hidden
        if(vertScrollBar) //just to be safe
            vertScrollBar->SetCurrentValue(vertScrollBar->GetCurrentValue()-(GetScreenFrame().ymin-selected->GetScreenFrame().ymin));
    }
    else if(selected->GetScreenFrame().ymax > GetScreenFrame().ymax) //the element is hidden in the bottom
    {
        //get the current position and move it relatively of the part which is hidden
        if(vertScrollBar) //just to be safe
            vertScrollBar->SetCurrentValue(vertScrollBar->GetCurrentValue()+(selected->GetScreenFrame().ymax-GetScreenFrame().ymax));
    }

    if(notificationTarget != NULL)
    {
        notificationTarget->OnSelected(node);
    }
}
void pawsActiveMagicWindow::OnResize()
{
    if(GetScreenFrame().Width() > GetScreenFrame().Height())
    {
        Orientation = ScrollMenuOptionHORIZONTAL;
    }
    else
    {
        Orientation = ScrollMenuOptionVERTICAL;
    }
    if(buffList!=NULL)
    {
        buffList->SetOrientation(Orientation);
    }
}
void psMainWidget::PrintOnScreen( const char* text, int color, float ymod )
{
    if (strlen(text) < 2)
    {
        Error2("Tried to print text with less than 2 chars in a Fading way (%s)",text);
        return;
    }

    // Create a fading textbox widget
    pawsFadingTextBox* txtBox = new pawsFadingTextBox;
    txtBox->SetParent(this);
    txtBox->SetText(text,mesgFirstFont,mesgFont,color); // Set options and enable
    txtBox->Show();

    onscreen.Push(txtBox); // Do like this to have full controll on the controlls :P

    // Set the right size
    int h=0,w=0;
    txtBox->GetSize(w,h);
    txtBox->Resize(w,h,0);

    int x,y;
    x = (GetScreenFrame().Width() / 2) - (w / 2);

    y = (int)(GetScreenFrame().Height() * ymod) - (h / 2);
    y = y - GetScreenFrame().Height() / 8;

    txtBox->MoveTo(x,y);


    // Move the others down
    if (onscreen.GetSize() < 2)
        return;

    int j = 0;
    for (int i = (int)onscreen.GetSize()-2; i >= 0; i--)
    {
        j++;
        pawsFadingTextBox* widget = (pawsFadingTextBox*)onscreen[i];
        widget->MoveDelta(0,h);
        
        if (j > 2) // force fading if there is more than 2 elements
            widget->Fade();
    }
}
Exemplo n.º 4
0
bool pawsComboBox::OnButtonPressed(int /*mouseButton*/, int /*keyModifier*/, pawsWidget* widget)
{
    switch ( widget->GetID() )
    {
        case SHOW_LIST:
        {
            if ( closed )
            {
                arrow->SetUpImage(upButton);
                arrow->SetDownImage(upButtonPressed);
                oldHeight = GetScreenFrame().Height();    
                oldWidth  = GetScreenFrame().Width();    
                SetSize( GetScreenFrame().Width(), defaultFrame.Height()+rows*GetActualHeight(rowHeight)+15 );
                if (fliptotop)
                {
                    MoveDelta(0,-1*(rows*GetActualHeight(rowHeight)+15));
                    itemChoice->MoveDelta(0,rows*GetActualHeight(rowHeight)+15);
                    arrow->MoveDelta(0,rows*GetActualHeight(rowHeight)+15);
                }
                                
                listChoice->Show();
                closed = false;
            }
            else
            {
                arrow->SetUpImage(downButton);
                arrow->SetDownImage(downButtonPressed);
                SetSize( oldWidth, oldHeight );
                if (fliptotop)
                {
                    MoveDelta(0,rows*GetActualHeight(rowHeight)+15);
                    itemChoice->MoveDelta(0,-1*(rows*GetActualHeight(rowHeight)+15));
                    arrow->MoveDelta(0,-1*(rows*GetActualHeight(rowHeight)+15));
                }
                listChoice->Hide();
                closed = true;
            }
            return true;
        }
    }    
    
    return false;
}
void pawsActiveMagicWindow::AutoResize()
{
    if(!buffList)
    {
        return;
    }

    //what is the starting position ?
    int leftEdge   = GetScreenFrame().xmin,
        rightEdge  = GetScreenFrame().xmax,
        topEdge    = GetScreenFrame().ymin,
        bottomEdge = GetScreenFrame().ymax;

    int newLeftEdge   = 0,
        newRightEdge  = 0,
        newTopEdge    = 0,
        newBottomEdge = 0,
        newHeight     = 0,
        newWidth      = 0,
        tOrientation  = Orientation;


    if(Orientation == ScrollMenuOptionHORIZONTAL)
    {
        int rows = int( buffList->GetTotalButtonWidth()/(psengine->GetG2D()->GetWidth()-16) )+1; //how many rows will we need to show all the entries
	
        if( leftEdge<=0 ) //left anchored, takes precedence over right anchored.
        {
            newLeftEdge=0;
            if( rows==1 )
            {
                newRightEdge=(newLeftEdge+buffList->GetTotalButtonWidth()+16);
            }
            else //rows>1
            {
                newRightEdge=psengine->GetG2D()->GetWidth();
            }
        }
        else if( rightEdge>=psengine->GetG2D()->GetWidth() ) //right anchored
        {
            newRightEdge=psengine->GetG2D()->GetWidth();
            if( rows==1 )
            {
                newLeftEdge=rightEdge-buffList->GetTotalButtonWidth()-16;
            }
            else //rows>1
            {
                newLeftEdge=0;
            }
        }
        else //not anchored at all, expand and contract on right
        {
            if( leftEdge+buffList->GetTotalButtonWidth()+16 < psengine->GetG2D()->GetWidth() )
            {
                newLeftEdge  =leftEdge;
                newRightEdge =leftEdge+buffList->GetTotalButtonWidth()+16;
                if( newRightEdge>psengine->GetG2D()->GetWidth() )
                {
                    newRightEdge=psengine->GetG2D()->GetWidth();
                }
            }
            else //this will push it over the right edge of the screen, adjust
            {
                newRightEdge=psengine->GetG2D()->GetWidth();
                newLeftEdge=newRightEdge-buffList->GetTotalButtonWidth()-16;
                if( newLeftEdge<0 )
                {
                    newLeftEdge=0;
                }
            }
        }

        if( topEdge<=0 ) //anchored at top, takes precendence over bottom anchor
        {
            newTopEdge=0;
            newBottomEdge=(rows*buffList->GetButtonHeight())+16;
        }
        else if( bottomEdge>=psengine->GetG2D()->GetHeight() )  //anchored to bottom
        {
            newTopEdge=psengine->GetG2D()->GetHeight()-(rows*buffList->GetButtonHeight());
            newBottomEdge=bottomEdge;
        }
        else //not anchored
        {
            newTopEdge    =topEdge;
            newBottomEdge =topEdge+(rows*buffList->GetButtonHeight())+16;
        }
    }
    else
    {
        int cols  = int( (buffList->GetSize()*buffList->GetButtonHeight())/(psengine->GetG2D()->GetHeight()-16) )+1, //how many columns will we need to sho all the entries
            tSize = 0;

        tSize = buffList->GetSize()<1?1:buffList->GetSize();

        if( topEdge<=0 )  //top anchored, takes precedence over bottom anchor
        {
            newTopEdge = 0;
            if( cols==1 )
            {
                newBottomEdge = (tSize*buffList->GetButtonHeight())+16;
            }
            else 
            {
                newBottomEdge=psengine->GetG2D()->GetHeight();
            }
        }
        else if( bottomEdge>=psengine->GetG2D()->GetHeight() )
        {
            newBottomEdge=psengine->GetG2D()->GetHeight();
            if( cols==1 )
            {
                newTopEdge=newBottomEdge-(tSize*buffList->GetButtonHeight())-16;
            }
            else
            {
                newTopEdge=0;
            }
        }
        else //no anchor, expand and contract on bottom
        {
           if( topEdge+(tSize*buffList->GetButtonHeight())+16 < psengine->GetG2D()->GetHeight() )
           {
               newTopEdge=topEdge;
               newBottomEdge=topEdge+(tSize*buffList->GetButtonHeight())+16;
           }
           else
           {
               newBottomEdge=psengine->GetG2D()->GetHeight();
               newTopEdge=newBottomEdge-(tSize*buffList->GetButtonHeight())-16;
           }
        }

        if( leftEdge<=0 ) //anchored at left, takes precendence over right anchor
        {
            newLeftEdge=0;
            newRightEdge=((cols*buffList->GetWidestWidth())<buffList->GetButtonHeight()?buffList->GetButtonHeight():cols*buffList->GetWidestWidth())+16;
        }
        else if( rightEdge>=psengine->GetG2D()->GetWidth() )  //anchored to right
        {
            newLeftEdge=psengine->GetG2D()->GetWidth()-((cols*buffList->GetWidestWidth())<buffList->GetButtonHeight()?buffList->GetButtonHeight():cols*buffList->GetWidestWidth())-16;
            newRightEdge=psengine->GetG2D()->GetWidth();
        }
        else //not anchored
        {
            newLeftEdge    =leftEdge;
            newRightEdge =leftEdge+((cols*buffList->GetWidestWidth())<buffList->GetButtonHeight()?buffList->GetButtonHeight():cols*buffList->GetWidestWidth() )+16;
        }
    }

    if( newRightEdge-newLeftEdge < buffList->GetButtonWidth() )
    {
        newWidth=buffList->GetButtonWidth()+BUTTON_PADDING;
    }
    else
    {
        newWidth=newRightEdge-newLeftEdge;
    }
    if( newBottomEdge-newTopEdge < buffList->GetButtonWidth() )
    {
        newHeight = buffList->GetButtonWidth()+BUTTON_PADDING;
    }
    else
    {
        newHeight = newBottomEdge-newTopEdge;
    }
    SetRelativeFrame( newLeftEdge, newTopEdge, newWidth, newHeight ); 

    //SetRelativeFrame calls OnResize which will recalculate Orientation, but we don't want
    //autoResize to change orientation. Restore it here.
    Orientation=tOrientation; 
    buffList->SetOrientation(Orientation);

    buffList->SetRelativeFrame( 0, 0, newRightEdge-newLeftEdge-16, newBottomEdge-newTopEdge-16 ); 

}