From d78780cfc3f4c5c601bc19ae7976c2ae26ac9495 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 13 Jan 2006 23:56:00 +0000 Subject: Add text-mode I/O functions. Use text-mode screen for the waiting screen. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 291 --- textscreen/Makefile.am | 6 +- textscreen/txt_gui.c | 188 +++++++++++++++++++++++++++++++++++ textscreen/txt_gui.h | 50 ++++++++++ textscreen/txt_io.c | 260 +++++++++++++++++++++++++++++++++++++++++++++++++ textscreen/txt_io.h | 55 +++++++++++ textscreen/txt_main.c | 7 +- 6 files changed, 564 insertions(+), 2 deletions(-) create mode 100644 textscreen/txt_gui.c create mode 100644 textscreen/txt_gui.h create mode 100644 textscreen/txt_io.c create mode 100644 textscreen/txt_io.h (limited to 'textscreen') diff --git a/textscreen/Makefile.am b/textscreen/Makefile.am index 2aaec244..8894f0f4 100644 --- a/textscreen/Makefile.am +++ b/textscreen/Makefile.am @@ -3,6 +3,10 @@ AM_CFLAGS = @SDL_CFLAGS@ noinst_LIBRARIES=libtextscreen.a -libtextscreen_a_SOURCES = txt_main.c txt_main.h txt_font.h +libtextscreen_a_SOURCES = \ + txt_gui.c txt_gui.h \ + txt_io.c txt_io.h \ + txt_main.c txt_main.h \ + txt_font.h diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c new file mode 100644 index 00000000..ee581fee --- /dev/null +++ b/textscreen/txt_gui.c @@ -0,0 +1,188 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: txt_gui.c 291 2006-01-13 23:56:00Z fraggle $ +// +// Copyright(C) 1993-1996 Id Software, Inc. +// Copyright(C) 2005 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// $Log$ +// Revision 1.1 2006/01/13 23:56:00 fraggle +// Add text-mode I/O functions. +// Use text-mode screen for the waiting screen. +// +// + +#include + +#include "txt_io.h" +#include "txt_main.h" + +// Array of border characters for drawing windows. The array looks like this: +// +// +-++ +// | || +// +-++ +// +-++ + +static int borders[4][4] = +{ + {0xda, 0xc4, 0xc2, 0xbf}, + {0xb3, ' ', 0xb3, 0xb3}, + {0xc3, 0xc4, 0xc5, 0xb4}, + {0xc0, 0xc4, 0xc1, 0xd9}, +}; + +void TXT_DrawDesktop(char *title) +{ + int i; + unsigned char *screendata; + unsigned char *p; + + screendata = TXT_GetScreenData(); + + // Fill the screen with gradient characters + + p = screendata; + + for (i=0; i +#include + +#include "txt_io.h" +#include "txt_main.h" + +static struct +{ + txt_color_t color; + char *name; +} colors[] = { + {TXT_COLOR_BLACK, "black"}, + {TXT_COLOR_BLUE, "blue"}, + {TXT_COLOR_GREEN, "green"}, + {TXT_COLOR_CYAN, "cyan"}, + {TXT_COLOR_RED, "red"}, + {TXT_COLOR_MAGENTA, "magenta"}, + {TXT_COLOR_BROWN, "brown"}, + {TXT_COLOR_GREY, "grey"}, + {TXT_COLOR_DARK_GREY, "darkgrey"}, + {TXT_COLOR_BRIGHT_BLUE, "brightblue"}, + {TXT_COLOR_BRIGHT_GREEN, "brightgreen"}, + {TXT_COLOR_BRIGHT_CYAN, "brightcyan"}, + {TXT_COLOR_BRIGHT_RED, "brightred"}, + {TXT_COLOR_BRIGHT_MAGENTA, "brightmagenta"}, + {TXT_COLOR_YELLOW, "yellow"}, + {TXT_COLOR_BRIGHT_WHITE, "brightwhite"}, +}; + +static int cur_x = 0, cur_y = 0; +static txt_color_t fgcolor = TXT_COLOR_GREY; +static txt_color_t bgcolor = TXT_COLOR_BLACK; + +static int GetColorForName(char *s) +{ + int i; + + for (i=0; i= TXT_SCREEN_H) + { + // Scroll the screen up + + cur_y = TXT_SCREEN_H - 1; + + memcpy(screendata, screendata + TXT_SCREEN_W * 2, + TXT_SCREEN_W * 2 * (TXT_SCREEN_H -1)); + + // Clear the bottom line + + p = screendata + (TXT_SCREEN_H - 1) * 2 * TXT_SCREEN_W; + + for (i=0; i= TXT_SCREEN_W) + { + NewLine(screendata); + } + + break; + } +} + +void TXT_PutChar(int c) +{ + unsigned char *screen; + + screen = TXT_GetScreenData(); + + PutChar(screen, c); +} + +void TXT_Puts(char *s) +{ + int previous_color = TXT_COLOR_BLACK; + unsigned char *screen; + char *p; + char colorname_buf[20]; + char *ending; + int col; + + screen = TXT_GetScreenData(); + + for (p=s; *p != '\0'; ++p) + { + if (*p == '%') + { + ++p; + + if (*p == '%') + { + PutChar(screen, '%'); + } + else + { + ending = strchr(p, '%'); + + if (ending == NULL) + { + return; + } + + strncpy(colorname_buf, p, 19); + colorname_buf[ending-p] = '\0'; + + if (!strcmp(colorname_buf, "/")) + { + // End of color block + + col = previous_color; + } + else + { + col = GetColorForName(colorname_buf); + + if (col < 0) + { + return; + } + + // Save the color for the ending marker + + previous_color = fgcolor; + } + + TXT_FGColor(col); + + p = ending; + } + } + else + { + PutChar(screen, *p); + } + } + + PutChar(screen, '\n'); +} + +void TXT_GotoXY(int x, int y) +{ + cur_x = x; + cur_y = y; +} + +void TXT_FGColor(txt_color_t color) +{ + fgcolor = color; +} + +void TXT_BGColor(int color, int blinking) +{ + bgcolor = color; + if (blinking) + bgcolor |= TXT_COLOR_BLINKING; +} + +void TXT_ClearScreen(void) +{ + unsigned char *screen; + int i; + + screen = TXT_GetScreenData(); + + for (i=0; i