Beispiel #1
0
void UIDisplay::drawWindowText( ID3D11DeviceContext* device, UIWindow& window, TextManager& tm )
{
    UIWindow::Text* text;
    uint textCount;
    window.getText( &text, &textCount );

    float x = 0.0f;
    float y = 0.0f;
    float len = static_cast<float>( strlen( text->message ) ) * FONTWIDTH;

    y = window.getPosition().y + (UIWINDOW_TITLE_BAR_HEIGHT / 2.0f) - ( FONTHEIGHT / 2.0f );
    x = window.getPosition().x + ( window.getDimension().x / 2.0f ) - ( len / 2.0f );

    XMFLOAT4 colors[3] =
    {
        XMFLOAT4(1,1,1,1), //Not selected: White
        XMFLOAT4(1,1,0,1), //Highlighted: Yellow
        XMFLOAT4(0,0,1,1)  //Selected: Blue
    };

    D3DX11_TECHNIQUE_DESC techDesc;
    mTechnique->GetDesc( &techDesc );

    for(ushort p = 0; p < techDesc.Passes; ++p)
    {
        //Draw title
        mTechnique->GetPassByIndex(p)->Apply(0, device);
        tm.drawString( device, text->message, x, y );

        float len = 0.0f;

        //Draw tab names
        for(uint i = 0; i < window.getTabCount(); i++) {
            tm.drawString( device, window.getTab(i).name,
                           window.getPosition().x +(mBorderDimension * 2.0f) + len,
                           window.getPosition().y + (UIWINDOW_TITLE_BAR_HEIGHT * 2.0f) - ( FONTHEIGHT * 1.5f ),
                           i == window.getCurrentTab() ? colors[2] : window.getTab(i).highlighted ? colors[1] : colors[0]);
            len += static_cast<float>(strlen(window.getTab(i).name)) * FONTWIDTH + ( FONTWIDTH / 2.0f );
        }

        //Draw UI Text
        UIWindow::Tab& t = window.getTab( window.getCurrentTab() );

        //Loop through and build elements in the current tab
        for(int i = 0; i < t.elementCount; i++) {

            if( t.elements[i]->getElemType() == UIElement::ElemType::TextBox ) {
                UIElement::Text* text;
                uint textCount;

                t.elements[i]->getText( &text, &textCount );

                for(uint l = 0; l < textCount; l++) {
                    tm.drawString( device, text[l].message,
                                   t.elements[i]->getPosition().x + text[l].offset.x + window.getPosition().x + FONTWIDTH / 2.0f,
                                   t.elements[i]->getPosition().y + text[l].offset.y + window.getPosition().y + (FONTHEIGHT / 2.0f),
                                   colors[0] );
                }
            } else if( t.elements[i]->getElemType() == UIElement::ElemType::OptionBox ) {

                UIOptionBox* box = (UIOptionBox*)(t.elements[i]);

                for(uint o = 0; o < box->getNumOptions(); o++) {
                    char* opt = box->getOption(o);

                    uint optIndex = o + ( box->getScrollIndex() - box->getNumOptions() );

                    tm.drawString( device, opt,
                                   t.elements[i]->getPosition().x + window.getPosition().x + 0.02f,
                                   t.elements[i]->getPosition().y + window.getPosition().y + ( ( FONTHEIGHT + 0.04f ) * static_cast<float>(o) ),
                                   colors[ optIndex == box->getSelected() ? 2 : optIndex == box->getHighlighted() ? 1 : 0 ] );
                }
            } else {
                UIElement::Text* text;
                uint tCount;
                t.elements[i]->getText(&text, &tCount );

                //Center the text
                float xOffset = (t.elements[i]->getDimension().x / 2.0f) - (static_cast<float>(strlen(text->message)) * FONTWIDTH / 2.0f);
                float yOffset = (t.elements[i]->getDimension().y / 2.0f) -  FONTHEIGHT / 2.0f;

                //Draw the text bro
                tm.drawString( device, text->message,
                               t.elements[i]->getPosition().x + window.getPosition().x + xOffset + text->offset.x,
                               t.elements[i]->getPosition().y + window.getPosition().y + yOffset + text->offset.y,
                               colors[ t.elements[i]->getSelectedState() ]);
            }

            //If it is a drop menu, draw the options
            if( t.elements[i]->getElemType() == UIElement::ElemType::DropMenu ) {
                UIDropMenu* d = *(UIDropMenu**)(t.elements + i);

                float tx = t.elements[i]->getPosition().x + window.getPosition().x + (FONTWIDTH / 2.0f);
                float ty = t.elements[i]->getPosition().y + window.getPosition().y + (FONTHEIGHT / 2.0f);

                if( d->isDropped() ) {
                    for(uint o = 0; o < d->getOptionCount(); o++) {
                        tm.drawString( device, d->getOption(o),
                                       tx, ty,
                                       d->getSelectedOption() == o ? colors[2] : d->getHightlightedOption() == o ? colors[1] : colors[0] );
                        ty += 0.1f;
                    }
                } else {
                    tm.drawString( device, d->getOption(d->getSelectedOption()),
                                   tx, ty,
                                   colors[2]);
                }
            } else if( t.elements[i]->getElemType() == UIElement::ElemType::InputBox ) {
                UIInputBox* d = *(UIInputBox**)(t.elements + i);

                float tx = t.elements[i]->getPosition().x + window.getPosition().x + (FONTWIDTH / 2.0f);
                float ty = t.elements[i]->getPosition().y + window.getPosition().y + (FONTHEIGHT / 2.0f);

                tm.drawString( device, d->getInput(),
                               tx, ty,
                               colors[0]);
            }
        }
    }
}