Exemplo n.º 1
0
/* Updates the console, draws the background and the history lines. Does not draw the Commandline */
void CON_UpdateConsole(ConsoleInformation *console) {
    int loop;
    int loop2;
    int Screenlines;
    SDL_Rect DestRect;
    BitFont *CurrentFont = DT_FontPointer(console->FontNumber);

    if(!console)
        return;

    /* Due to the Blits, the update is not very fast: So only update if it's worth it */
    if(!CON_isVisible(console))
        return;

    Screenlines = console->ConsoleSurface->h / console->FontHeight;


    SDL_FillRect(console->ConsoleSurface, NULL, SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0, console->ConsoleAlpha));

// TR2
//	if(console->OutputScreen->flags & SDL_OPENGLBLIT)
//        SDL_SetSurfaceAlphaMod(console->ConsoleSurface, SDL_ALPHA_OPAQUE);

    /* draw the background image if there is one */
    if(console->BackgroundImage) {
        DestRect.x = console->BackX;
        DestRect.y = console->BackY;
        DestRect.w = console->BackgroundImage->w;
        DestRect.h = console->BackgroundImage->h;
        SDL_BlitSurface(console->BackgroundImage, NULL, console->ConsoleSurface, &DestRect);
    }

    /* Draw the text from the back buffers, calculate in the scrollback from the user
     * this is a normal SDL software-mode blit, so we need to temporarily set the ColorKey
     * for the font, and then clear it when we're done.
     */
    /*TR2 if((console->OutputScreen->flags & SDL_OPENGLBLIT) && (console->OutputScreen->format->BytesPerPixel > 2)) {
    	Uint32 *pix = (Uint32 *) (CurrentFont->FontSurface->pixels);
    	SDL_SetColorKey(CurrentFont->FontSurface, SDL_TRUE, *pix);
    }*/

    /*	now draw text from last but second line to top
    	loop: for every line in the history
    	loop2: draws the scroll indicators to the line above the Commandline
    */
    for(loop = 0; loop < Screenlines-1 && loop < console->LineBuffer - console->ConsoleScrollBack; loop++) {
        if(console->ConsoleScrollBack != 0 && loop == 0)
            for(loop2 = 0; loop2 < (console->VChars / 5) + 1; loop2++)
                DT_DrawText(CON_SCROLL_INDICATOR, console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER + (loop2*5*console->FontWidth), (Screenlines - loop - 2) * console->FontHeight);
        else
            DT_DrawText(console->ConsoleLines[console->ConsoleScrollBack + loop], console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER, (Screenlines - loop - 2) * console->FontHeight);
    }

    // TR2
    //if(console->OutputScreen->flags & SDL_OPENGLBLIT)
    //	SDL_SetColorKey(CurrentFont->FontSurface, 0, 0);
}
Exemplo n.º 2
0
/* Updates the console, draws the background and the history lines. Does not draw the Commandline */
void CON_UpdateConsole(ConsoleInformation * console)
{
    int loop;
    int loop2;
    int Screenlines;
    SDL_Rect DestRect;
    /*BitFont *CurrentFont = DT_FontPointer(console->FontNumber);*/

    if (!console)
        return;

    /* Due to the Blits, the update is not very fast: So only update if it's worth it */
    if (!CON_isVisible(console))
        return;

    Screenlines = console->ConsoleSurface->h / console->FontHeight;


    SDL_FillRect(console->ConsoleSurface, NULL,
                 SDL_MapRGBA(console->ConsoleSurface->format, 0, 20, 0,
                             SDL_ALPHA_OPAQUE));

    /* draw the background image if there is one */
    if (console->BackgroundImage) {
        DestRect.x = console->BackX;
        DestRect.y = console->BackY;
        DestRect.w = console->BackgroundImage->w;
        DestRect.h = console->BackgroundImage->h;
        SDL_BlitSurface(console->BackgroundImage, NULL,
                        console->ConsoleSurface, &DestRect);
    }

    /*      now draw text from last but second line to top
       loop: for every line in the history
       loop2: draws the scroll indicators to the line above the Commandline
     */
    for (loop = 0;
            loop < Screenlines - 1
            && loop < console->LineBuffer - console->ConsoleScrollBack;
            loop++) {
        if (console->ConsoleScrollBack != 0 && loop == 0)
            for (loop2 = 0; loop2 < (console->VChars / 5) + 1; loop2++)
                DT_DrawText(CON_SCROLL_INDICATOR, console->ConsoleSurface,
                            console->FontNumber,
                            CON_CHAR_BORDER +
                            (loop2 * 5 * console->FontWidth),
                            (Screenlines - loop -
                             2) * console->FontHeight);
        else
            DT_DrawText(console->
                        ConsoleLines[console->ConsoleScrollBack + loop],
                        console->ConsoleSurface, console->FontNumber,
                        CON_CHAR_BORDER,
                        (Screenlines - loop - 2) * console->FontHeight);
    }
}
Exemplo n.º 3
0
/* Sets the topmost console for input */
void CON_Topmost(ConsoleInformation *console) {
    SDL_Rect rect;

    if(!console)
        return;

    /* Make sure the blinking cursor is gone */
    if(Topmost) {
        rect.x = 0;
        rect.y = Topmost->ConsoleSurface->h - Topmost->FontHeight;
        rect.w = Topmost->InputBackground->w;
        rect.h = Topmost->InputBackground->h;
        SDL_BlitSurface(Topmost->InputBackground, NULL, Topmost->ConsoleSurface, &rect);
        DT_DrawText(Topmost->VCommand, Topmost->ConsoleSurface, Topmost->FontNumber, CON_CHAR_BORDER, Topmost->ConsoleSurface->h - Topmost->FontHeight);
    }
    Topmost = console;
}
Exemplo n.º 4
0
/* completely rewritten by C.Wacha */
void DrawCommandLine() {
    SDL_Rect rect;
    int x;
    int commandbuffer;
    BitFont* CurrentFont;
    static Uint32 NextBlinkTime = 0;	/* time the consoles cursor blinks again */
    static int LastCursorPos = 0;		/* Last Cursor Position */
    static int Blink = 0;			/* Is the cursor currently blinking */

    if(!Topmost)
        return;

    commandbuffer = Topmost->VChars - strlen(Topmost->Prompt) - 1; /*  -1 to make cursor visible */

    CurrentFont = DT_FontPointer(Topmost->FontNumber);

    /* calculate display offset from current cursor position */
    if(Topmost->Offset < Topmost->CursorPos - commandbuffer)
        Topmost->Offset = Topmost->CursorPos - commandbuffer;
    if(Topmost->Offset > Topmost->CursorPos)
        Topmost->Offset = Topmost->CursorPos;

    /* first add prompt to visible part */
    strcpy(Topmost->VCommand, Topmost->Prompt);

    /* then add the visible part of the command */
    strncat(Topmost->VCommand, &Topmost->Command[Topmost->Offset], strlen(&Topmost->Command[Topmost->Offset]));

    /* now display the result */

    /* once again we're drawing text, so in OpenGL context we need to temporarily set up
       software-mode transparency. */
    /*TR2 if(Topmost->OutputScreen->flags & SDL_OPENGLBLIT) {
    	Uint32 *pix = (Uint32 *) (CurrentFont->FontSurface->pixels);
    	SDL_SetColorKey(CurrentFont->FontSurface, SDL_TRUE, *pix);
    }*/

    /* first of all restore InputBackground */
    rect.x = 0;
    rect.y = Topmost->ConsoleSurface->h - Topmost->FontHeight;
    rect.w = Topmost->InputBackground->w;
    rect.h = Topmost->InputBackground->h;
    SDL_BlitSurface(Topmost->InputBackground, NULL, Topmost->ConsoleSurface, &rect);

    /* now add the text */
    DT_DrawText(Topmost->VCommand, Topmost->ConsoleSurface, Topmost->FontNumber, CON_CHAR_BORDER, Topmost->ConsoleSurface->h - Topmost->FontHeight);

    /* at last add the cursor
       check if the blink period is over */
    if(SDL_GetTicks() > NextBlinkTime) {
        NextBlinkTime = SDL_GetTicks() + CON_BLINK_RATE;
        Blink = 1 - Blink;
    }

    /* check if cursor has moved - if yes display cursor anyway */
    if(Topmost->CursorPos != LastCursorPos) {
        LastCursorPos = Topmost->CursorPos;
        NextBlinkTime = SDL_GetTicks() + CON_BLINK_RATE;
        Blink = 1;
    }

    if(Blink) {
        x = CON_CHAR_BORDER + Topmost->FontWidth * (Topmost->CursorPos - Topmost->Offset + strlen(Topmost->Prompt));
        if(Topmost->InsMode)
            DT_DrawText(CON_INS_CURSOR, Topmost->ConsoleSurface, Topmost->FontNumber, x, Topmost->ConsoleSurface->h - Topmost->FontHeight);
        else
            DT_DrawText(CON_OVR_CURSOR, Topmost->ConsoleSurface, Topmost->FontNumber, x, Topmost->ConsoleSurface->h - Topmost->FontHeight);
    }


    /* TR2 if(Topmost->OutputScreen->flags & SDL_OPENGLBLIT) {
    	SDL_SetColorKey(CurrentFont->FontSurface, 0, 0);
    }*/
}
Exemplo n.º 5
0
/* completely rewritten by C.Wacha */
void DrawCommandLine()
{
    SDL_Rect rect;
    int x;
    int commandbuffer;
    BitFont *CurrentFont;
    static Uint32 NextBlinkTime = 0;	/* time the consoles cursor blinks again */
    static int LastCursorPos = 0;	/* Last Cursor Position */
    static int Blink = 0;	/* Is the cursor currently blinking */

    if (!Topmost)
        return;

    commandbuffer = Topmost->VChars - strlen(Topmost->Prompt) - 1;	/*  -1 to make cursor visible */

    CurrentFont = DT_FontPointer(Topmost->FontNumber);

    /* calculate display offset from current cursor position */
    if (Topmost->Offset < Topmost->CursorPos - commandbuffer)
        Topmost->Offset = Topmost->CursorPos - commandbuffer;
    if (Topmost->Offset > Topmost->CursorPos)
        Topmost->Offset = Topmost->CursorPos;

    /* first add prompt to visible part */
    strcpy(Topmost->VCommand, Topmost->Prompt);

    /* then add the visible part of the command */
    strncat(Topmost->VCommand, &Topmost->Command[Topmost->Offset],
            strlen(&Topmost->Command[Topmost->Offset]));


    /* first of all restore InputBackground */
    rect.x = 0;
    rect.y = Topmost->ConsoleSurface->h - Topmost->FontHeight;
    rect.w = Topmost->InputBackground->w;
    rect.h = Topmost->InputBackground->h;
    SDL_BlitSurface(Topmost->InputBackground, NULL,
                    Topmost->ConsoleSurface, &rect);

    /* now add the text */
    DT_DrawText(Topmost->VCommand, Topmost->ConsoleSurface,
                Topmost->FontNumber, CON_CHAR_BORDER,
                Topmost->ConsoleSurface->h - Topmost->FontHeight);

    /* at last add the cursor
       check if the blink period is over */
    if (SDL_GetTicks() > NextBlinkTime) {
        NextBlinkTime = SDL_GetTicks() + CON_BLINK_RATE;
        Blink = 1 - Blink;
    }

    /* check if cursor has moved - if yes display cursor anyway */
    if (Topmost->CursorPos != LastCursorPos) {
        LastCursorPos = Topmost->CursorPos;
        NextBlinkTime = SDL_GetTicks() + CON_BLINK_RATE;
        Blink = 1;
    }

    if (Blink) {
        x = CON_CHAR_BORDER + Topmost->FontWidth * (Topmost->CursorPos -
                Topmost->Offset +
                strlen(Topmost->
                       Prompt));
        if (Topmost->InsMode)
            DT_DrawText(CON_INS_CURSOR, Topmost->ConsoleSurface,
                        Topmost->FontNumber, x,
                        Topmost->ConsoleSurface->h - Topmost->FontHeight);
        else
            DT_DrawText(CON_OVR_CURSOR, Topmost->ConsoleSurface,
                        Topmost->FontNumber, x,
                        Topmost->ConsoleSurface->h - Topmost->FontHeight);
    }

}