示例#1
0
float CGUILabel_Impl::GetTextExtent ( void )
{
    const CEGUI::Font* pFont = m_pWindow->getFont ();
    if ( pFont )
    {
        try
        {
            // Retrieve the longest line's extent
            std::stringstream ssText ( m_pWindow->getText ().c_str () );
            std::string sLineText;
            float fMax = 0.0f, fLineExtent = 0.0f;

            while( std::getline ( ssText, sLineText ) )
            {
                fLineExtent = pFont->getTextExtent ( sLineText );
                if ( fLineExtent > fMax )
                    fMax = fLineExtent;
            }
            return fMax;
        }
        catch ( CEGUI::Exception e )
        {}
    }

    return 0.0f;
}
示例#2
0
    void CoreMesh_XMLHandler::textElement(const std::string& element, const XMLAttributes& attributes, const std::string& text)
    {
        if(element == "POS") {

            std::stringstream ssText(text);
            Vector v;
            ssText >> v[0] >> v[1] >> v[2];
            m_currVert.pos(v);

        } else if(element == "ATTRIB") {
示例#3
0
    void CoreSkeleton_Cal3dXHandler::textElement(const std::string& element, const XMLAttributes& attributes, const std::string& text)
    {
        std::stringstream ssText(text);

        if(element == "TRANSLATION") {

            ssText >> m_vCurrBoneRelativePosition[0]
                   >> m_vCurrBoneRelativePosition[1]
                   >> m_vCurrBoneRelativePosition[2];

        } else if(element == "ROTATION") {
示例#4
0
文件: Util.cpp 项目: arkana-fts/bouge
    std::vector<float> to< std::vector<float> >(std::string s)
    {
        std::stringstream ssText(s);
        std::vector<float> ret;

        float f;
        for(ssText >> f ; ssText ; ssText >> f) {
            ret.push_back(f);
        }
        return ret;
    }
    void CoreAnimation_Cal3dXHandler::textElement(const std::string& element, const bouge::XMLAttributes& attributes, const std::string& text)
    {
        std::stringstream ssText(text);

        if(element == "TRANSLATION") {
            ssText >> m_lastTranslation;

            // Cal3D stores the animation data in "absolute", that is not
            // relative to the rest pose. Convert it to relative.
            m_lastTranslation -= m_skelToUse->bone(m_currTrackName)->relativeRootPosition();

            m_currKeyframe->translation(m_lastTranslation);
        } else if(element == "ROTATION") {
示例#6
0
int CLuaFunctionDefs::dxGetTextWidth ( lua_State* luaVM )
{
    // dxGetTextWidth ( string text, [float scale=1,string font="default"] )

    if ( lua_type ( luaVM, 1 ) == LUA_TSTRING )
    {
        const char * szText = lua_tostring ( luaVM, 1 );
        float fScale = 1.0f;
        eFontType fontType = FONT_DEFAULT;

        int iArgument2 = lua_type ( luaVM, 2 );
        if ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING )
        {
            fScale = static_cast < float > ( lua_tonumber ( luaVM, 2 ) );

            if ( lua_type ( luaVM, 3 ) == LUA_TSTRING )
            {
                const char * szFontName = lua_tostring ( luaVM, 3 );
                fontType = g_pCore->GetGraphics ()->GetFontType ( const_cast < char * > ( szFontName ) );
            }
        }

        ID3DXFont * pFont = g_pCore->GetGraphics ()->GetFont ( fontType );

        // Retrieve the longest line's extent
        std::stringstream ssText ( szText );
        std::string sLineText;
        float fWidth = 0.0f, fLineExtent = 0.0f;

        while( std::getline ( ssText, sLineText ) )
        {
            fLineExtent = g_pCore->GetGraphics ()->GetDXTextExtent ( sLineText.c_str ( ), fScale, pFont );
            if ( fLineExtent > fWidth )
                fWidth = fLineExtent;
        }
        // Success
        lua_pushnumber ( luaVM, fWidth );
        return 1;
    }
    else
        m_pScriptDebugging->LogBadType ( luaVM, "dxGetTextWidth" );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}
int CLuaOOPDefs::DxGetTextWidth ( lua_State* luaVM )
{
    //  float dxGetTextWidth ( string text, [float scale=1, mixed font="default", bool colorCoded=false] )
    SString strText; float fScale; CClientDxFont* pDxFontElement; bool bColorCoded;

    CScriptArgReader argStream ( luaVM );
    argStream.ReadUserData ( pDxFontElement );
    argStream.ReadString ( strText );
    argStream.ReadNumber ( fScale, 1 );
    argStream.ReadBool ( bColorCoded, false );

    if ( !argStream.HasErrors () )
    {
        ID3DXFont* pD3DXFont = CStaticFunctionDefinitions::ResolveD3DXFont ( FONT_DEFAULT, pDxFontElement );

        // Retrieve the longest line's extent
        std::stringstream ssText ( strText );
        std::string sLineText;
        float fWidth = 0.0f, fLineExtent = 0.0f;

        while ( std::getline ( ssText, sLineText ) )
        {
            fLineExtent = g_pCore->GetGraphics ()->GetDXTextExtent ( sLineText.c_str (), fScale, pD3DXFont, bColorCoded );
            if ( fLineExtent > fWidth )
                fWidth = fLineExtent;
        }

        // Success
        lua_pushnumber ( luaVM, fWidth );
        return 1;
    }
    else
        m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () );

    // Failed
    lua_pushboolean ( luaVM, false );
    return 1;
}