Пример #1
0
/* Outputs text to the console (in game), up to CON_CHARS_PER_LINE chars can be entered */
void CON_Out(ConsoleInformation *console, const char *str, ...) {
    va_list marker;

    char temp[CON_CHARS_PER_LINE+1];
    char* ptemp;

    if(!console)
        return;

    va_start(marker, str);
    vsnprintf(temp, CON_CHARS_PER_LINE, str, marker);
    va_end(marker);

    ptemp = temp;

    /* temp now contains the complete string we want to output
       the only problem is that temp is maybe longer than the console
       width so we have to cut it into several pieces */

    if(console->ConsoleLines) {
        while(strlen(ptemp) > console->VChars) {
            CON_NewLineConsole(console);
            strncpy(console->ConsoleLines[0], ptemp, console->VChars);
            console->ConsoleLines[0][console->VChars] = '\0';
            ptemp = &ptemp[console->VChars];
        }
        CON_NewLineConsole(console);
        strncpy(console->ConsoleLines[0], ptemp, console->VChars);
        console->ConsoleLines[0][console->VChars] = '\0';
        CON_UpdateConsole(console);
    }

    /* And print to stdout */
    /* printf("%s\n", temp); */
}
Пример #2
0
/* Makes the console visible */
void CON_Show(ConsoleInformation *console) {
    if(console) {
        console->Visible = CON_OPENING;
        CON_UpdateConsole(console);

        //console->WasUnicode = SDL_EnableUNICODE(-1);
        //SDL_EnableUNICODE(1);
    }
}
Пример #3
0
/* Adds  background image to the console, x and y based on consoles x and y */
int CON_Background(ConsoleInformation * console, const char *image, int x,
                   int y)
{
    SDL_Surface *temp;
    SDL_Rect backgroundsrc, backgrounddest;

    if (!console)
        return 1;

    /* Free the background from the console */
    if (image == NULL) {
        if (console->BackgroundImage == NULL)
            SDL_FreeSurface(console->BackgroundImage);
        console->BackgroundImage = NULL;
        SDL_FillRect(console->InputBackground, NULL,
                     SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0,
                                 SDL_ALPHA_OPAQUE));
        return 0;
    }

    /* Load a new background */
#ifdef HAVE_SDLIMAGE
    temp = IMG_Load(image);
#else
    temp = SDL_LoadBMP(image);
#endif
    if (!temp) {
        CON_Out(console, "Cannot load background %s.", image);
        return 1;
    }

    console->BackgroundImage = SDL_DisplayFormat(temp);
    SDL_FreeSurface(temp);
    console->BackX = x;
    console->BackY = y;

    backgroundsrc.x = 0;
    backgroundsrc.y =
        console->ConsoleSurface->h - console->FontHeight - console->BackY;
    backgroundsrc.w = console->BackgroundImage->w;
    backgroundsrc.h = console->InputBackground->h;

    backgrounddest.x = console->BackX;
    backgrounddest.y = 0;
    backgrounddest.w = console->BackgroundImage->w;
    backgrounddest.h = console->FontHeight;

    SDL_FillRect(console->InputBackground, NULL,
                 SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0,
                             SDL_ALPHA_OPAQUE));
    SDL_BlitSurface(console->BackgroundImage, &backgroundsrc,
                    console->InputBackground, &backgrounddest);

    CON_UpdateConsole(console);
    return 0;
}
Пример #4
0
/* ==========================================================================
 * DRAWING
 * ==========================================================================
 */
void con_draw(void)
{
#ifdef CONSOLE
    CON_DrawConsole(Console);
    CON_UpdateConsole(Console);
#else
#if 0
    char buffer[CON_LINE_LEN+1];
    int i,j;
    for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
    {
        memcpy(buffer, con_display[i], CON_LINE_LEN);
        buffer[CON_LINE_LEN] = 0;
        GrString(1, j * 10, buffer, 1);
    }
#endif
#endif
}
Пример #5
0
/* resizes the console, has to reset alot of stuff
 * returns 1 on error */
int CON_Resize(ConsoleInformation *console, SDL_Rect rect, SDL_Surface* displayScreen) {
    SDL_Surface *Temp;
    SDL_Rect backgroundsrc, backgrounddest;

    if(!console)
        return 1;

    /* make sure that the size of the console is valid */
    if(rect.w > console->OutputScreen->w || rect.w < console->FontWidth * 32)
        rect.w = console->OutputScreen->w;
    if(rect.h > console->OutputScreen->h || rect.h < console->FontHeight)
        rect.h = console->OutputScreen->h;
    if(rect.x < 0 || rect.x > console->OutputScreen->w - rect.w)
        console->DispX = 0;
    else
        console->DispX = rect.x;
    if(rect.y < 0 || rect.y > console->OutputScreen->h - rect.h)
        console->DispY = 0;
    else
        console->DispY = rect.y;

    /* load the console surface */
    SDL_FreeSurface(console->ConsoleSurface);
    Temp = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, console->OutputScreen->format->BitsPerPixel, 0, 0, 0, 0);
    if(Temp == NULL) {
        PRINT_ERROR("Couldn't create the console->ConsoleSurface\n");
        return 1;
    }
    //console->ConsoleSurface = SDL_DisplayFormat(Temp);
    console->ConsoleSurface = SDL_ConvertSurfaceFormat(Temp, displayScreen->format->format, displayScreen->flags);
    SDL_FreeSurface(Temp);

    /* Load the dirty rectangle for user input */
    SDL_FreeSurface(console->InputBackground);
    Temp = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, console->FontHeight, console->OutputScreen->format->BitsPerPixel, 0, 0, 0, 0);
    if(Temp == NULL) {
        PRINT_ERROR("Couldn't create the input background\n");
        return 1;
    }
    //console->InputBackground = SDL_DisplayFormat(Temp);
    console->InputBackground = SDL_ConvertSurfaceFormat(Temp, displayScreen->format->format, displayScreen->flags);
    SDL_FreeSurface(Temp);

    /* Now reset some stuff dependent on the previous size */
    console->ConsoleScrollBack = 0;

    /* Reload the background image (for the input text area) in the console */
    if(console->BackgroundImage) {
        backgroundsrc.x = 0;
        backgroundsrc.y = console->ConsoleSurface->h - console->FontHeight - console->BackY;
        backgroundsrc.w = console->BackgroundImage->w;
        backgroundsrc.h = console->InputBackground->h;

        backgrounddest.x = console->BackX;
        backgrounddest.y = 0;
        backgrounddest.w = console->BackgroundImage->w;
        backgrounddest.h = console->FontHeight;

        SDL_FillRect(console->InputBackground, NULL, SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
        SDL_BlitSurface(console->BackgroundImage, &backgroundsrc, console->InputBackground, &backgrounddest);
    }

    /* restore the alpha level */
    CON_Alpha(console, console->ConsoleAlpha);

    /* re-calculate the number of visible characters in the command line */
    console->VChars = (rect.w - CON_CHAR_BORDER) / console->FontWidth;
    if(console->VChars > CON_CHARS_PER_LINE)
        console->VChars = CON_CHARS_PER_LINE;

    CON_UpdateConsole(console);
    return 0;
}
Пример #6
0
/*  Takes keys from the keyboard and inputs them to the console
    If the event was not handled (i.e. WM events or unknown ctrl-shift
    sequences) the function returns the event for further processing. */
SDL_Event* CON_Events(SDL_Event *event) {
    if(Topmost == NULL)
        return event;
    if(!CON_isVisible(Topmost))
        return event;

    if(event->type == SDL_KEYDOWN) {
        if(event->key.keysym.mod & KMOD_CTRL) {
            /* CTRL pressed */
            switch(event->key.keysym.sym) {
            case SDLK_a:
                Cursor_Home(Topmost);
                break;
            case SDLK_e:
                Cursor_End(Topmost);
                break;
            case SDLK_c:
                Clear_Command(Topmost);
                break;
            case SDLK_l:
                Clear_History(Topmost);
                CON_UpdateConsole(Topmost);
                break;
            default:
                return event;
            }
        } else if(event->key.keysym.mod & KMOD_ALT) {
            /* the console does not handle ALT combinations! */
            return event;
        } else {
            /* first of all, check if the console hide key was pressed */
            if(event->key.keysym.sym == Topmost->HideKey) {
                CON_Hide(Topmost);
                return NULL;
            }
            switch (event->key.keysym.sym) {
            case SDLK_HOME:
                if(event->key.keysym.mod & KMOD_SHIFT) {
                    Topmost->ConsoleScrollBack = Topmost->LineBuffer-1;
                    CON_UpdateConsole(Topmost);
                } else {
                    Cursor_Home(Topmost);
                }
                break;
            case SDLK_END:
                if(event->key.keysym.mod & KMOD_SHIFT) {
                    Topmost->ConsoleScrollBack = 0;
                    CON_UpdateConsole(Topmost);
                } else {
                    Cursor_End(Topmost);
                }
                break;
            case SDLK_PAGEUP:
                Topmost->ConsoleScrollBack += CON_LINE_SCROLL;
                if(Topmost->ConsoleScrollBack > Topmost->LineBuffer-1)
                    Topmost->ConsoleScrollBack = Topmost->LineBuffer-1;

                CON_UpdateConsole(Topmost);
                break;
            case SDLK_PAGEDOWN:
                Topmost->ConsoleScrollBack -= CON_LINE_SCROLL;
                if(Topmost->ConsoleScrollBack < 0)
                    Topmost->ConsoleScrollBack = 0;
                CON_UpdateConsole(Topmost);
                break;
            case SDLK_UP:
                Command_Up(Topmost);
                break;
            case SDLK_DOWN:
                Command_Down(Topmost);
                break;
            case SDLK_LEFT:
                Cursor_Left(Topmost);
                break;
            case SDLK_RIGHT:
                Cursor_Right(Topmost);
                break;
            case SDLK_BACKSPACE:
                Cursor_BSpace(Topmost);
                break;
            case SDLK_DELETE:
                Cursor_Del(Topmost);
                break;
            case SDLK_INSERT:
                Topmost->InsMode = 1-Topmost->InsMode;
                break;
            case SDLK_TAB:
                CON_TabCompletion(Topmost);
                break;
            case SDLK_RETURN:
                if(strlen(Topmost->Command) > 0) {
                    CON_NewLineCommand(Topmost);

                    /* copy the input into the past commands strings */
                    strcpy(Topmost->CommandLines[0], Topmost->Command);

                    /* display the command including the prompt */
                    CON_Out(Topmost, "%s%s", Topmost->Prompt, Topmost->Command);

                    CON_Execute(Topmost, Topmost->Command);
                    /* printf("Command: %s\n", Topmost->Command); */

                    Clear_Command(Topmost);
                    Topmost->CommandScrollBack = -1;
                }
                break;
            case SDLK_ESCAPE:
                /* deactivate Console */
                CON_Hide(Topmost);
                return NULL;
            default:
                if(Topmost->InsMode)
                    Cursor_Add(Topmost, event);
                else {
                    Cursor_Add(Topmost, event);
                    Cursor_Del(Topmost);
                }
            }
        }
        return NULL;
    }
    return event;
}
Пример #7
0
/*  Takes keys from the keyboard and inputs them to the console
    If the event was not handled (i.e. WM events or unknown ctrl-shift
    sequences) the function returns the event for further processing. */
SDL_Event *CON_Events(SDL_Event * event)
{
    if (Topmost == NULL)
        return event;
    if (!CON_isVisible(Topmost))
        return event;

    if (event->type == SDL_KEYDOWN) {
        if (event->key.keysym.mod & KMOD_CTRL) {
            /* CTRL pressed */
            /* kps - please modify this to work like in talk.c */
            switch (event->key.keysym.sym) {
            case SDLK_a:
                Cursor_Home(Topmost);
                break;
            case SDLK_b:
                Cursor_Left(Topmost);
                break;
            case SDLK_f:
                Cursor_Right(Topmost);
                break;
            case SDLK_e:
                Cursor_End(Topmost);
                break;
            /*
             * kps - Ctrl-k should really just clear from current
             * cursor position to end of line.
             */
            case SDLK_k:
            case SDLK_u:
                Clear_Command(Topmost);
                break;
            case SDLK_l:
                Clear_History(Topmost);
                CON_UpdateConsole(Topmost);
                break;
            default:
                return event;
            }
#if 0
        } else if (event->key.keysym.mod & KMOD_ALT) {
            /* the console does not handle ALT combinations! */
            return event;
#endif
        } else {
            switch (event->key.keysym.sym) {
            case SDLK_HOME:
                if (event->key.keysym.mod & KMOD_SHIFT) {
                    Topmost->ConsoleScrollBack = Topmost->LineBuffer - 1;
                    CON_UpdateConsole(Topmost);
                } else {
                    Cursor_Home(Topmost);
                }
                break;
            case SDLK_END:
                if (event->key.keysym.mod & KMOD_SHIFT) {
                    Topmost->ConsoleScrollBack = 0;
                    CON_UpdateConsole(Topmost);
                } else {
                    Cursor_End(Topmost);
                }
                break;
            case SDLK_PAGEUP:
                Topmost->ConsoleScrollBack += CON_LINE_SCROLL;
                if (Topmost->ConsoleScrollBack > Topmost->LineBuffer - 1)
                    Topmost->ConsoleScrollBack = Topmost->LineBuffer - 1;

                CON_UpdateConsole(Topmost);
                break;
            case SDLK_PAGEDOWN:
                Topmost->ConsoleScrollBack -= CON_LINE_SCROLL;
                if (Topmost->ConsoleScrollBack < 0)
                    Topmost->ConsoleScrollBack = 0;
                CON_UpdateConsole(Topmost);
                break;
            case SDLK_UP:
                Command_Up(Topmost);
                break;
            case SDLK_DOWN:
                Command_Down(Topmost);
                break;
            case SDLK_LEFT:
                Cursor_Left(Topmost);
                break;
            case SDLK_RIGHT:
                Cursor_Right(Topmost);
                break;
            case SDLK_BACKSPACE:
                Cursor_BSpace(Topmost);
                break;
            case SDLK_DELETE:
                Cursor_Del(Topmost);
                break;
            case SDLK_INSERT:
                Topmost->InsMode = 1 - Topmost->InsMode;
                break;
            case SDLK_TAB:
                CON_TabCompletion(Topmost);
                break;
            case SDLK_RETURN:
                if (strlen(Topmost->Command) > 0) {
                    CON_NewLineCommand(Topmost);

                    /* copy the input into the past commands strings */
                    strcpy(Topmost->CommandLines[0], Topmost->Command);

                    /* display the command including the prompt */
                    CON_Out(Topmost, "%s%s", Topmost->Prompt,
                            Topmost->Command);

                    CON_Execute(Topmost, Topmost->Command);
                    /* printf("Command: %s\n", Topmost->Command); */

                    Clear_Command(Topmost);
                    Topmost->CommandScrollBack = -1;
                }
                else
                    /* deactivate Console if return is pressed on empty line */

                    /* was: CON_Hide(Topmost); */
                    Talk_set_state(false);
                break;
            case SDLK_ESCAPE:
                if (strlen(Topmost->Command) > 0) {
                    CON_NewLineCommand(Topmost);

                    /* copy the input into the past commands strings */
                    strcpy(Topmost->CommandLines[0], Topmost->Command);

                    Clear_Command(Topmost);
                    Topmost->CommandScrollBack = -1;
                }
                /* deactivate Console */

                /*was: CON_Hide(Topmost);*/
                Talk_set_state(false);

                return NULL;
            default:
                if (Topmost->InsMode)
                    Cursor_Add(Topmost, event);
                else {
                    Cursor_Add(Topmost, event);
                    Cursor_Del(Topmost);
                }
            }
        }
        return NULL;
    }
    return event;
}
Пример #8
0
/*  Takes keys from the keyboard and inputs them to the console
    If the event was not handled (i.e. WM events or unknown ctrl-shift 
    sequences) the function returns the event for further processing. */
int CON_Events(int event)
{
	if(Topmost == NULL)
		return event;
	if(!CON_isVisible(Topmost))
		return event;

	if(event & KEY_CTRLED)
	{
		//CTRL pressed
		switch(event & ~KEY_CTRLED)
		{
		case KEY_A:
			Cursor_Home(Topmost);
			break;
		case KEY_E:
			Cursor_End(Topmost);
			break;
		case KEY_C:
			Clear_Command(Topmost);
			break;
		case KEY_L:
			Clear_History(Topmost);
			CON_UpdateConsole(Topmost);
			break;
		default:
			return event;
		}
	}
	else if(event & KEY_ALTED)
	{
		//the console does not handle ALT combinations!
		return event;
	}
	else
	{
		//first of all, check if the console hide key was pressed
		if(event == Topmost->HideKey)
		{
			CON_Hide(Topmost);
			return 0;
		}
		switch (event & 0xff)
		{
		case KEY_LSHIFT:
		case KEY_RSHIFT:
			return event;
		case KEY_HOME:
			if(event & KEY_SHIFTED)
			{
				Topmost->ConsoleScrollBack = Topmost->LineBuffer-1;
				CON_UpdateConsole(Topmost);
			} else {
				Cursor_Home(Topmost);
			}
			break;
		case KEY_END:
			if(event & KEY_SHIFTED)
			{
				Topmost->ConsoleScrollBack = 0;
				CON_UpdateConsole(Topmost);
			} else {
				Cursor_End(Topmost);
			}
			break;
		case KEY_PAGEUP:
			Topmost->ConsoleScrollBack += CON_LINE_SCROLL;
			if(Topmost->ConsoleScrollBack > Topmost->LineBuffer-1)
				Topmost->ConsoleScrollBack = Topmost->LineBuffer-1;

			CON_UpdateConsole(Topmost);
			break;
		case KEY_PAGEDOWN:
			Topmost->ConsoleScrollBack -= CON_LINE_SCROLL;
			if(Topmost->ConsoleScrollBack < 0)
				Topmost->ConsoleScrollBack = 0;
			CON_UpdateConsole(Topmost);
			break;
		case KEY_UP:
			Command_Up(Topmost);
			break;
		case KEY_DOWN:
			Command_Down(Topmost);
			break;
		case KEY_LEFT:
			Cursor_Left(Topmost);
			break;
		case KEY_RIGHT:
			Cursor_Right(Topmost);
			break;
		case KEY_BACKSP:
			Cursor_BSpace(Topmost);
			break;
		case KEY_DELETE:
			Cursor_Del(Topmost);
			break;
		case KEY_INSERT:
			Topmost->InsMode = 1-Topmost->InsMode;
			break;
		case KEY_TAB:
			CON_TabCompletion(Topmost);
			break;
		case KEY_ENTER:
			if(strlen(Topmost->Command) > 0) {
				CON_NewLineCommand(Topmost);

				// copy the input into the past commands strings
				strcpy(Topmost->CommandLines[0], Topmost->Command);

				// display the command including the prompt
				CON_Out(Topmost, "%s%s", Topmost->Prompt, Topmost->Command);
				CON_UpdateConsole(Topmost);

				CON_Execute(Topmost, Topmost->Command);
				//printf("Command: %s\n", Topmost->Command);

				Clear_Command(Topmost);
				Topmost->CommandScrollBack = -1;
			}
			break;
		case KEY_ESC:
			//deactivate Console
			if (event & KEY_SHIFTED) {
				CON_Hide(Topmost);
				return 0;
				}
			break;
		default:
			if(Topmost->InsMode)
				Cursor_Add(Topmost, event);
			else {
				Cursor_Add(Topmost, event);
				Cursor_Del(Topmost);
			}
		}
	}
	return 0;
}