예제 #1
0
파일: console.cpp 프로젝트: nyotis/r3
void Console::OnKeyEvent( KeyEvent &keyEvent ) {
    //Output( "Got console key event! key = %d, keyState = %s\n", key, keyState == KeyState_Up ? "up" : "down" );
    keyEvent.handled = true;
    if ( keyEvent.state == KeyState_Up ) {
        return;
    }

    if ( keyEvent.key == '`' ) {
        ExecuteCommand( "deactivateconsole" );
        return;
    } else if ( keyEvent.key == XK_BackSpace ) {
        if ( cursorPos > 0 ) {
            cursorPos--;
            commandLine.erase( cursorPos, 1 );
        }
    } else if ( keyEvent.key == XK_Delete ) {
        if ( cursorPos > 0 && cursorPos < commandLine.size() ) {
            commandLine.erase( cursorPos, 1 );
        }
    } else if ( keyEvent.key == XK_Return ) {
        AppendOutput( "> " + commandLine );
        ExecuteCommand( commandLine.c_str() );
        history.pop_back();
        history.push_back( commandLine );
        history.push_back( "" );
        while( con_historySize.GetVal() > 0 && history.size() > con_historySize.GetVal() ) {
            history.pop_front();
        }
        commandLine.clear();
        cursorPos = 0;
        historyPos = (int)history.size() - 1;
    } else if ( keyEvent.key == XK_Up || keyEvent.key == XK_Down ) {
        historyPos -= keyEvent.key == XK_Up ? 1 : -1;
        historyPos = std::max<int>( 0, std::min<int>( (int)historyPos, (int)history.size() - 1 ) );
        if ( history.size() > 0 ) {
            commandLine = history[ historyPos ];
            cursorPos = (int)commandLine.size();
        }
    } else if ( keyEvent.key == XK_Left ) {
        cursorPos--;
        cursorPos = std::max<int>( cursorPos, 0 );
    } else if ( keyEvent.key == XK_Right ) {
        cursorPos++;
        cursorPos = std::min<int>( cursorPos, (int)commandLine.size() );
    } else if ( keyEvent.key == XK_Page_Up ) {
        outputBufferPos = min( (int)outputBuffer.size(), outputBufferPos + 1 );
    } else if ( keyEvent.key == XK_Page_Down ) {
        outputBufferPos = max( 0, outputBufferPos - 1 );
    } else if ( keyEvent.key == XK_Tab ) {
        AttemptCompletion( commandLine, cursorPos );
    } else if ( keyEvent.key >= 0x20 && keyEvent.key <= 0x7f ) { // printable characters
        char c[2] = { keyEvent.key, 0 };
        commandLine.insert( cursorPos, c );
        cursorPos++;
        outputBufferPos = 0;
    }

    //Output( "> %s_%s\n", commandLine.substr(0, cursorPos ).c_str(), commandLine.substr( cursorPos, string::npos ).c_str() );
    // else actually process the keyboard input
}
예제 #2
0
파일: console.cpp 프로젝트: nyotis/r3
void Console::AppendOutput( const string & str ) {
    ScopedMutex scm( conMutex, R3_LOC );
    outputBuffer.push_back( str );
    if ( outputBuffer.size() > con_scrollBuffer.GetVal() ) {
        outputBuffer.pop_front();
    }
}
예제 #3
0
	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();
	}
예제 #4
0
	void Console::AppendOutput( const string & str ) {
		outputBuffer.push_back( str );
		if ( outputBuffer.size() > con_scrollBuffer.GetVal() ) {
			outputBuffer.pop_front();
		}		
	}
예제 #5
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 );
}