Exemplo n.º 1
0
void MenuSlider::Draw(MyMatrix* pMatProj, MyMatrix* pMatView)
{
    float centerx = m_PosX;
    float top = m_PosY;
    // TODO: take more justifications and vertical/horizontal into account for top and left.
    //       should ideally be done once instead of every frame.
    //if( m_Justification & Justify_Left )
    //{
    //    centerx += m_BarThickness/2;
    //}

    float emptypos = (m_PosY - m_VisualRange);

    MyAssert( m_pSprite );
    //m_pSprite = g_pGame->m_pResources->m_pSprites[SL_WhiteSquareResizable];

    if( m_pSprite )
    {
        BufferManager* pBufferManager = m_pGameCore->GetManagers()->GetBufferManager();
        m_pSprite->Create( pBufferManager, "MenuSlider", m_BarThickness, m_VisualRange, 0, 1, 0, 1, Justify_CenterX|Justify_Top );
        MyMatrix world;
        world.SetIdentity();
        world.SetTranslation( centerx, top, 0 );
        //FIX m_pSprite->SetTint( m_Colors[MSCT_BarColor] );
        m_pSprite->Draw( pMatProj, pMatView, &world ); //&g_pGame->m_OrthoMatrix );

        m_pSprite->Create( pBufferManager, "MenuSlider", m_HandleWidth, m_HandleHeight, 0, 1, 0, 1, Justify_CenterX|Justify_Top );
        world.SetTranslation( centerx, emptypos + m_ValuePerc*m_VisualRange, 0 );
        //FIX m_pSprite->SetTint( m_Colors[MSCT_HandleColor] );
        m_pSprite->Draw( pMatProj, pMatView, &world ); //&g_pGame->m_OrthoMatrix );
    }
}
Exemplo n.º 2
0
int MyMeshText::CreateString(bool concat, float fontheight, float x, float y, float z, float rotz, unsigned char justificationflags, ColorByte color, Vector2 size, const char* text, ...)
{
    assert( m_pFont && m_pFont->m_pFont );

    if( strlen( text ) == 0 )
        return 0;

    const char* stringtodraw = text;
    if( g_pLanguageTable != 0 && text[0] == '.' )
        stringtodraw = g_pLanguageTable->LookUp( text );

    int numlines = 0;

    if( concat == false )
    {
        ClearText();
    }

    bool moretexttocome = true;
    const char* stringpos = stringtodraw;

    while( moretexttocome )
    {
        numlines++;

        char singlelinebuffer[300];
        singlelinebuffer[0] = 0;
        char* singlelinebufferpos = singlelinebuffer;

        // word wrap if width of text is not 0.
        if( size.x != 0 )
        {
            float linewidth = -1;// = GetStringSize( fontheight, Vector2(0,0), singlelinebuffer ).x;
            while( linewidth < size.x &&
                    *stringpos != 0 )
            {
                *singlelinebufferpos = *stringpos;
                singlelinebufferpos++;
                *singlelinebufferpos = 0;
                stringpos++;

                linewidth = GetStringSize( fontheight, Vector2(0,0), singlelinebuffer ).x;

                assert( singlelinebufferpos < singlelinebuffer + 300 );
            }

            int numcharswewentback = 0;
            while( ( *(singlelinebufferpos-1) != ' ' && *stringpos != 0 ) &&
                    singlelinebufferpos > singlelinebuffer )
            {
                singlelinebufferpos--;
                numcharswewentback++;
            }

            if( singlelinebufferpos != singlelinebuffer )
            {
                *singlelinebufferpos = 0;
                stringpos -= numcharswewentback;
            }

            if( *stringpos == 0 )
                moretexttocome = false;

            stringtodraw = singlelinebuffer;
        }
        else
        {
            moretexttocome = false;
        }
            
        //// don't bother drawing if fontheight is zero... still doing logic above so the currect number of lines will be returned.
        //if( g_pRTQGlobals->m_WordWrapCountLinesOnly )
        //    continue;

        Vertex_XYZUV_RGBA* pVertsToDraw = (Vertex_XYZUV_RGBA*)GetVerts( true );

        int newverts = (int)strlen( stringtodraw ) * 4;
#if _DEBUG
        m_MostLettersAttemptedToDrawThisFrame += newverts/4;
        if( m_MostLettersAttemptedToDrawThisFrame > m_MostLettersAttemptedToDrawEver )
            m_MostLettersAttemptedToDrawEver = m_MostLettersAttemptedToDrawThisFrame;
#endif

        if( m_NumVertsToDraw + newverts > GetNumVerts() )
        {
#if _DEBUG
            LOGInfo( LOGTag, "TextMesh buffer isn't big enough for string (%s) - %d of %d letters used - most letters needed (%d)\n", stringtodraw, m_NumVertsToDraw/4, GetNumVerts()/4, m_MostLettersAttemptedToDrawEver );
#endif
            //assert( false ); // drawing more than we have room for.
            return 0;
        }

        pVertsToDraw += m_NumVertsToDraw;

        unsigned int textstrlen = m_pFont->m_pFont->GenerateVerts( stringtodraw, true, pVertsToDraw, fontheight, GL_TRIANGLES, justificationflags, color );

        m_NumVertsToDraw += (unsigned short)(textstrlen * 4);
        m_NumIndicesToDraw += textstrlen * 6;

        MyMatrix position;
        position.SetIdentity();
        position.Rotate( rotz, 0, 0, 1 );
        position.SetPosition( x, y - (numlines-1)*fontheight, z );
        //position.SetPosition( x, y - (numlines-1)*g_pRTQGlobals->m_WordWrapLineIncSize, z );
        //position.SetPosition( x, y, z );

        for( unsigned int i=0; i<textstrlen*4; i++ )
        {
            Vector3 out = position.TransformVector3( *(Vector3*)&pVertsToDraw[i].x );
            pVertsToDraw[i].x = out.x;
            pVertsToDraw[i].y = out.y;
            pVertsToDraw[i].z = out.z;
        }
    }

    return numlines;
}