コード例 #1
0
ファイル: console.cpp プロジェクト: bcrowell/planetfinder_ios
	void Console::Draw() {
		if ( font == NULL ) {
			font = r3::CreateStbFont( con_font.GetVal(), con_fontSize.GetVal() ); 			
		}
		if ( ! IsActive() ) {
			return;
		}
		
		int border = 10;
		
		int w = r_windowWidth.GetVal();
		int h = r_windowHeight.GetVal();
		int conW = w - 2 * border;
		int conH = ( h - ( h >> 2 ) ) - border;
		float s = con_fontScale.GetVal();

		static Bounds2f bO;
		static float yAdvance = 0;
		static float sCache = 0;
		if ( s != sCache ) {
			bO = font->GetStringDimensions( "O", s );
			Bounds2f bb = font->GetStringDimensions( "|", s );
			sCache = s;
			yAdvance = std::max( bO.Height(), bb.Height() );
		}
		
		int x0 = border;
		int y = ( h >> 2) + border;
		
		ImColor( 16, 16, 16, con_opacity.GetVal() * 255 );
		BlendFunc( BlendFunc_SrcAlpha, BlendFunc_OneMinusSrcAlpha );
		BlendEnable();

		DrawQuad( x0, y, x0 + conW, y + conH );
		
		string cl = "> " + commandLine;
		int cp = cursorPos + 2;

		Bounds2f b = font->GetStringDimensions( cl, s );
		Bounds2f b2 = font->GetStringDimensions( cl.substr(0, cp ), s );
		
		ImColor( 255, 255, 255, 192 );
		font->Print( cl, x0, y, s );
		
		ImColor( 255, 255, 255, 64 );
		DrawQuad( x0 + b2.Width(), y, x0 + b2.Width() + bO.Width(), y + bO.Height() );
		
		y += yAdvance;

		ImColor( 255, 255, 255, 128 );
		for ( int i = outputBuffer.size() - 1; i >= 0 && y < h; i-- ) {
			string & line = outputBuffer[ i ];
			font->Print( line, x0, y, s );
			y += yAdvance;
		}

		BlendDisable();
	}
コード例 #2
0
ファイル: console.cpp プロジェクト: nyotis/r3
void Console::Draw() {
    if ( font == NULL ) {
        font = r3::CreateStbFont( con_font.GetVal(), "", con_fontSize.GetVal() );
    }

    ScopedMutex scm( conMutex, R3_LOC );

    if ( ! IsActive() ) {
        return;
    }

    int border = 10;

    int w = r_windowWidth.GetVal();
    int h = r_windowHeight.GetVal();
    int conW = w - 2 * border;
    int conH = ( h - ( h >> 2 ) ) - border;
    float s = con_fontScale.GetVal();

    static Bounds2f bO;
    static float yAdvance = 0;
    static float sCache = 0;
    if ( s != sCache ) {
        bO = font->GetStringDimensions( "O", s );
        Bounds2f bb = font->GetStringDimensions( "|", s );
        sCache = s;
        yAdvance = std::max<int>( bO.Height(), bb.Height() );
    }

    int x0 = border;
    int y = ( h >> 2) + border;

    glColor4ub( 16, 16, 16, con_opacity.GetVal() * 255 );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    glEnable( GL_BLEND );

    DrawQuad( x0, y, x0 + conW, y + conH );

    string cl = "> " + commandLine;
    int cp = cursorPos + 2;

    //Bounds2f b = font->GetStringDimensions( cl, s );
    Bounds2f b2 = font->GetStringDimensions( cl.substr(0, cp ), s );

    glColor4ub( 255, 255, 255, 192 );
    font->Print( cl, x0, y, s );


    glColor4ub( 255, 255, 255, 64 );
    DrawQuad( x0 + b2.Width(), y, x0 + b2.Width() + bO.Width(), y + bO.Height() );

    y += yAdvance;

    glColor4ub( 255, 255, 255, 128 );
    for ( int i = (int)outputBuffer.size() - 1 - outputBufferPos; i >= 0 && y < h; i-- ) {
        string & line = outputBuffer[ i ];
        font->Print( line, x0, y, s );
        y += yAdvance;
    }
    glDisable( GL_BLEND );
}