added console code (from SDL_console)
authorBradley Bell <btb@icculus.org>
Mon, 2 Jun 2003 01:55:03 +0000 (01:55 +0000)
committerBradley Bell <btb@icculus.org>
Mon, 2 Jun 2003 01:55:03 +0000 (01:55 +0000)
15 files changed:
ChangeLog
Makefile.am
arch/sdl/event.c
configure.ac
console/CON_console.c [new file with mode: 0644]
console/DT_drawtext.c [new file with mode: 0644]
console/Makefile.am [new file with mode: 0644]
console/internal.c [new file with mode: 0644]
include/CON_console.h [new file with mode: 0644]
include/DT_drawtext.h [new file with mode: 0644]
include/console.h
main/console.c
main/game.c
main/gamecntl.c
main/gamerend.c

index ab45b24..90edcd7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-06-01    <btb@icculus.org>
+
+       * Makefile.am, arch/sdl/event.c, configure.ac,
+       console/CON_console.c, console/DT_drawtext.c, console/Makefile.am,
+       console/internal.c, include/CON_console.h, include/DT_drawtext.h,
+       include/console.h, main/console.c, main/game.c, main/gamecntl.c,
+       main/gamerend.c: added console code (from SDL_console)
+
 0.2.4:
 
 2003-05-12  Bradley Bell  <btb@icculus.org>
index 28db43f..b5b72fc 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS = 2d 3d maths mem cfile iff texmap misc arch main libmve utilities
+SUBDIRS = 2d 3d maths mem cfile iff texmap misc arch main libmve utilities console
 
 EXTRA_SUBDIRS = include unused debian rpm
 
@@ -34,7 +34,7 @@ d2x_gl_SOURCES =
 d2x_svga_SOURCES =
 d2x_ggi_SOURCES =
 
-d2x_LDADD = ${LD_KLUDGE} main/libmain.a ${EDITOR_LIBS} 3d/lib3d.a 2d/lib2d.a ${ARCH_LIBS} libmve/libmve.a mem/libmem.a cfile/libcfile.a iff/libiff.a texmap/libtexmap.a misc/libmisc.a maths/libmaths.a
+d2x_LDADD = ${LD_KLUDGE} main/libmain.a ${EDITOR_LIBS} 3d/lib3d.a 2d/lib2d.a ${ARCH_LIBS} libmve/libmve.a mem/libmem.a cfile/libcfile.a iff/libiff.a texmap/libtexmap.a misc/libmisc.a maths/libmaths.a console/libconsole.a
 
 if MINGW32
 if USE_NETWORK
index a83a7b7..5424362 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: event.c,v 1.9 2003-03-27 02:26:02 btb Exp $ */
+/* $Id: event.c,v 1.10 2003-06-02 01:55:03 btb Exp $ */
 /*
  *
  * SDL Event related stuff
@@ -14,6 +14,7 @@
 #include <stdlib.h>
 
 #include <SDL.h>
+#include "CON_console.h"
 
 extern void key_handler(SDL_KeyboardEvent *event);
 extern void mouse_button_handler(SDL_MouseButtonEvent *mbe);
@@ -31,6 +32,8 @@ void event_poll()
        SDL_Event event;
 
        while (SDL_PollEvent(&event)) {
+               if(!CON_Events(&event))
+                       continue;
                switch(event.type) {
                case SDL_KEYDOWN:
                case SDL_KEYUP:
index 8cc5f1a..1f5d6b9 100644 (file)
@@ -154,14 +154,6 @@ if test x$enable_fastfileio != xno; then
     D2X_FEATURES="fastfileio ${D2X_FEATURES}"
 fi
 
-dnl Build with CONSOLE?
-AC_ARG_ENABLE(console,
-    [  --enable-console         Enable console (very experimental) ],,)
-if test x$enable_console = xyes; then
-    AC_DEFINE(CONSOLE,,[Define to enable console])
-    D2X_FEATURES="console ${D2X_FEATURES}"
-fi
-
 AC_ARG_WITH(sharepath,
     [[  --with-sharepath=DIR    Use DIR for shared game data (unix only) [DATADIR/games/d2x]]],
     sharepath=$withval, sharepath="auto")
@@ -379,6 +371,7 @@ AC_OUTPUT(
     arch/svgalib/Makefile
     arch/win32/Makefile
     cfile/Makefile
+    console/Makefile
     iff/Makefile
     libmve/Makefile
     main/Makefile
diff --git a/console/CON_console.c b/console/CON_console.c
new file mode 100644 (file)
index 0000000..19613f9
--- /dev/null
@@ -0,0 +1,1052 @@
+/*  CON_console.c
+ *  Written By: Garrett Banuk <mongoose@mongeese.org>
+ *  Code Cleanup and heavily extended by: Clemens Wacha <reflex-2000@gmx.net>
+ *
+ *  This is free, just be sure to give us credit when using it
+ *  in any of your programs.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include "SDL.h"
+#include "SDL_image.h"
+#include "CON_console.h"
+#include "DT_drawtext.h"
+#include "internal.h"
+
+
+/* This contains a pointer to the "topmost" console. The console that
+ * is currently taking keyboard input. */
+static ConsoleInformation *Topmost;
+
+/*  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_UpdateConsole(Topmost);
+
+                                       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;
+}
+
+/* CON_AlphaGL() -- sets the alpha channel of an SDL_Surface to the
+ * specified value.  Preconditions: the surface in question is RGBA.
+ * 0 <= a <= 255, where 0 is transparent and 255 is opaque. */
+void CON_AlphaGL(SDL_Surface *s, int alpha) {
+       Uint8 val;
+       int x, y, w, h;
+       Uint32 pixel;
+       Uint8 r, g, b, a;
+       SDL_PixelFormat *format;
+       static char errorPrinted = 0;
+
+
+       /* debugging assertions -- these slow you down, but hey, crashing sucks */
+       if(!s) {
+               PRINT_ERROR("NULL Surface passed to CON_AlphaGL\n");
+               return;
+       }
+
+       /* clamp alpha value to 0...255 */
+       if(alpha < SDL_ALPHA_TRANSPARENT)
+               val = SDL_ALPHA_TRANSPARENT;
+       else if(alpha > SDL_ALPHA_OPAQUE)
+               val = SDL_ALPHA_OPAQUE;
+       else
+               val = alpha;
+
+       /* loop over alpha channels of each pixel, setting them appropriately. */
+       w = s->w;
+       h = s->h;
+       format = s->format;
+       switch (format->BytesPerPixel) {
+       case 2:
+               /* 16-bit surfaces don't seem to support alpha channels. */
+               if(!errorPrinted) {
+                       errorPrinted = 1;
+                       PRINT_ERROR("16-bit SDL surfaces do not support alpha-blending under OpenGL.\n");
+               }
+               break;
+       case 4: {
+                       /* we can do this very quickly in 32-bit mode.  24-bit is more
+                        * difficult.  And since 24-bit mode is reall the same as 32-bit,
+                        * so it usually ends up taking this route too.  Win!  Unroll loop
+                        * and use pointer arithmetic for extra speed. */
+                       int numpixels = h * (w << 2);
+                       Uint8 *pix = (Uint8 *) (s->pixels);
+                       Uint8 *last = pix + numpixels;
+                       Uint8 *pixel;
+                       if((numpixels & 0x7) == 0)
+                               for(pixel = pix + 3; pixel < last; pixel += 32)
+                                       *pixel = *(pixel + 4) = *(pixel + 8) = *(pixel + 12) = *(pixel + 16) = *(pixel + 20) = *(pixel + 24) = *(pixel + 28) = val;
+                       else
+                               for(pixel = pix + 3; pixel < last; pixel += 4)
+                                       *pixel = val;
+                       break;
+               }
+       default:
+               /* we have no choice but to do this slowly.  <sigh> */
+               for(y = 0; y < h; ++y)
+                       for(x = 0; x < w; ++x) {
+                               char print = 0;
+                               /* Lock the surface for direct access to the pixels */
+                               if(SDL_MUSTLOCK(s) && SDL_LockSurface(s) < 0) {
+                                       PRINT_ERROR("Can't lock surface: ");
+                                       fprintf(stderr, "%s\n", SDL_GetError());
+                                       return;
+                               }
+                               pixel = DT_GetPixel(s, x, y);
+                               if(x == 0 && y == 0)
+                                       print = 1;
+                               SDL_GetRGBA(pixel, format, &r, &g, &b, &a);
+                               pixel = SDL_MapRGBA(format, r, g, b, val);
+                               SDL_GetRGBA(pixel, format, &r, &g, &b, &a);
+                               DT_PutPixel(s, x, y, pixel);
+
+                               /* unlock surface again */
+                               if(SDL_MUSTLOCK(s))
+                                       SDL_UnlockSurface(s);
+                       }
+               break;
+       }
+}
+
+
+/* Updates the console buffer */
+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));
+
+       if(console->OutputScreen->flags & SDL_OPENGLBLIT)
+               SDL_SetAlpha(console->ConsoleSurface, 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);
+       }
+
+       /* 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.
+        */
+       if((console->OutputScreen->flags & SDL_OPENGLBLIT) && (console->OutputScreen->format->BytesPerPixel > 2)) {
+               Uint32 *pix = (Uint32 *) (CurrentFont->FontSurface->pixels);
+               SDL_SetColorKey(CurrentFont->FontSurface, SDL_SRCCOLORKEY, *pix);
+       }
+
+
+       //now draw text from last but second line to top
+       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);
+       }
+
+       if(console->OutputScreen->flags & SDL_OPENGLBLIT)
+               SDL_SetColorKey(CurrentFont->FontSurface, 0, 0);
+}
+
+void CON_UpdateOffset(ConsoleInformation* console) {
+       if(!console)
+               return;
+
+       switch(console->Visible) {
+       case CON_CLOSING:
+               console->RaiseOffset -= CON_OPENCLOSE_SPEED;
+               if(console->RaiseOffset <= 0) {
+                       console->RaiseOffset = 0;
+                       console->Visible = CON_CLOSED;
+               }
+               break;
+       case CON_OPENING:
+               console->RaiseOffset += CON_OPENCLOSE_SPEED;
+               if(console->RaiseOffset >= console->ConsoleSurface->h) {
+                       console->RaiseOffset = console->ConsoleSurface->h;
+                       console->Visible = CON_OPEN;
+               }
+               break;
+       case CON_OPEN:
+       case CON_CLOSED:
+               break;
+       }
+}
+
+/* Draws the console buffer to the screen if the console is "visible" */
+void CON_DrawConsole(ConsoleInformation *console) {
+       SDL_Rect DestRect;
+       SDL_Rect SrcRect;
+
+       if(!console)
+               return;
+
+       /* only draw if console is visible: here this means, that the console is not CON_CLOSED */
+       if(console->Visible == CON_CLOSED)
+               return;
+
+       /* Update the scrolling offset */
+       CON_UpdateOffset(console);
+
+       /* Update the command line since it has a blinking cursor */
+       DrawCommandLine();
+
+       /* before drawing, make sure the alpha channel of the console surface is set
+        * properly.  (sigh) I wish we didn't have to do this every frame... */
+       if(console->OutputScreen->flags & SDL_OPENGLBLIT)
+               CON_AlphaGL(console->ConsoleSurface, console->ConsoleAlpha);
+
+       SrcRect.x = 0;
+       SrcRect.y = console->ConsoleSurface->h - console->RaiseOffset;
+       SrcRect.w = console->ConsoleSurface->w;
+       SrcRect.h = console->RaiseOffset;
+
+       /* Setup the rect the console is being blitted into based on the output screen */
+       DestRect.x = console->DispX;
+       DestRect.y = console->DispY;
+       DestRect.w = console->ConsoleSurface->w;
+       DestRect.h = console->ConsoleSurface->h;
+
+       SDL_BlitSurface(console->ConsoleSurface, &SrcRect, console->OutputScreen, &DestRect);
+
+       if(console->OutputScreen->flags & SDL_OPENGLBLIT)
+               SDL_UpdateRects(console->OutputScreen, 1, &DestRect);
+}
+
+
+/* Initializes the console */
+ConsoleInformation *CON_Init(const char *FontName, SDL_Surface *DisplayScreen, int lines, SDL_Rect rect) {
+       int loop;
+       SDL_Surface *Temp;
+       ConsoleInformation *newinfo;
+
+
+       /* Create a new console struct and init it. */
+       if((newinfo = (ConsoleInformation *) malloc(sizeof(ConsoleInformation))) == NULL) {
+               PRINT_ERROR("Could not allocate the space for a new console info struct.\n");
+               return NULL;
+       }
+       newinfo->Visible = CON_CLOSED;
+       newinfo->WasUnicode = 0;
+       newinfo->RaiseOffset = 0;
+       newinfo->ConsoleLines = NULL;
+       newinfo->CommandLines = NULL;
+       newinfo->TotalConsoleLines = 0;
+       newinfo->ConsoleScrollBack = 0;
+       newinfo->TotalCommands = 0;
+       newinfo->BackgroundImage = NULL;
+       newinfo->ConsoleAlpha = SDL_ALPHA_OPAQUE;
+       newinfo->Offset = 0;
+       newinfo->InsMode = 1;
+       newinfo->CursorPos = 0;
+       newinfo->CommandScrollBack = 0;
+       newinfo->OutputScreen = DisplayScreen;
+       newinfo->Prompt = CON_DEFAULT_PROMPT;
+       newinfo->HideKey = CON_DEFAULT_HIDEKEY;
+
+       CON_SetExecuteFunction(newinfo, Default_CmdFunction);
+       CON_SetTabCompletion(newinfo, Default_TabFunction);
+
+       /* Load the consoles font */
+       if(-1 == (newinfo->FontNumber = DT_LoadFont(FontName, TRANS_FONT))) {
+               PRINT_ERROR("Could not load the font ");
+               fprintf(stderr, "\"%s\" for the console!\n", FontName);
+               return NULL;
+       }
+
+       newinfo->FontHeight = DT_FontHeight(newinfo->FontNumber);
+       newinfo->FontWidth = DT_FontWidth(newinfo->FontNumber);
+
+       /* make sure that the size of the console is valid */
+       if(rect.w > newinfo->OutputScreen->w || rect.w < newinfo->FontWidth * 32)
+               rect.w = newinfo->OutputScreen->w;
+       if(rect.h > newinfo->OutputScreen->h || rect.h < newinfo->FontHeight)
+               rect.h = newinfo->OutputScreen->h;
+       if(rect.x < 0 || rect.x > newinfo->OutputScreen->w - rect.w)
+               newinfo->DispX = 0;
+       else
+               newinfo->DispX = rect.x;
+       if(rect.y < 0 || rect.y > newinfo->OutputScreen->h - rect.h)
+               newinfo->DispY = 0;
+       else
+               newinfo->DispY = rect.y;
+
+       /* load the console surface */
+       Temp = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, newinfo->OutputScreen->format->BitsPerPixel, 0, 0, 0, 0);
+       if(Temp == NULL) {
+               PRINT_ERROR("Couldn't create the ConsoleSurface\n");
+               return NULL;
+       }
+       newinfo->ConsoleSurface = SDL_DisplayFormat(Temp);
+       SDL_FreeSurface(Temp);
+       SDL_FillRect(newinfo->ConsoleSurface, NULL, SDL_MapRGBA(newinfo->ConsoleSurface->format, 0, 0, 0, newinfo->ConsoleAlpha));
+
+       /* Load the dirty rectangle for user input */
+       Temp = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, newinfo->FontHeight, newinfo->OutputScreen->format->BitsPerPixel, 0, 0, 0, SDL_ALPHA_OPAQUE);
+       if(Temp == NULL) {
+               PRINT_ERROR("Couldn't create the InputBackground\n");
+               return NULL;
+       }
+       newinfo->InputBackground = SDL_DisplayFormat(Temp);
+       SDL_FreeSurface(Temp);
+       SDL_FillRect(newinfo->InputBackground, NULL, SDL_MapRGBA(newinfo->ConsoleSurface->format, 0, 0, 0, SDL_ALPHA_OPAQUE));
+
+       /* calculate the number of visible characters in the command line */
+       newinfo->VChars = (rect.w - CON_CHAR_BORDER) / newinfo->FontWidth;
+       if(newinfo->VChars > CON_CHARS_PER_LINE)
+               newinfo->VChars = CON_CHARS_PER_LINE;
+
+       /* We would like to have a minumum # of lines to guarentee we don't create a memory error */
+       if(rect.h / newinfo->FontHeight > lines)
+               newinfo->LineBuffer = rect.h / newinfo->FontHeight;
+       else
+               newinfo->LineBuffer = lines;
+
+
+       newinfo->ConsoleLines = (char **)malloc(sizeof(char *) * newinfo->LineBuffer);
+       newinfo->CommandLines = (char **)malloc(sizeof(char *) * newinfo->LineBuffer);
+       for(loop = 0; loop <= newinfo->LineBuffer - 1; loop++) {
+               newinfo->ConsoleLines[loop] = (char *)calloc(CON_CHARS_PER_LINE, sizeof(char));
+               newinfo->CommandLines[loop] = (char *)calloc(CON_CHARS_PER_LINE, sizeof(char));
+       }
+       memset(newinfo->Command, 0, CON_CHARS_PER_LINE);
+       memset(newinfo->LCommand, 0, CON_CHARS_PER_LINE);
+       memset(newinfo->RCommand, 0, CON_CHARS_PER_LINE);
+       memset(newinfo->VCommand, 0, CON_CHARS_PER_LINE);
+
+
+       CON_Out(newinfo, "Console initialised.");
+       CON_NewLineConsole(newinfo);
+       //CON_ListCommands(newinfo);
+
+       return newinfo;
+}
+
+/* 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);
+       }
+}
+
+/* Hides the console (make it invisible) */
+void CON_Hide(ConsoleInformation *console) {
+       if(console) {
+               console->Visible = CON_CLOSING;
+               SDL_EnableUNICODE(console->WasUnicode);
+       }
+}
+
+/* tells wether the console is visible or not */
+int CON_isVisible(ConsoleInformation *console) {
+       if(!console)
+               return CON_CLOSED;
+       return((console->Visible == CON_OPEN) || (console->Visible == CON_OPENING));
+}
+
+/* Frees all the memory loaded by the console */
+void CON_Destroy(ConsoleInformation *console) {
+       DT_DestroyDrawText();
+       CON_Free(console);
+}
+
+/* Frees all the memory loaded by the console */
+void CON_Free(ConsoleInformation *console) {
+       int i;
+
+       if(!console)
+               return;
+
+       //CON_DestroyCommands();
+       for(i = 0; i <= console->LineBuffer - 1; i++) {
+               free(console->ConsoleLines[i]);
+               free(console->CommandLines[i]);
+       }
+       free(console->ConsoleLines);
+       free(console->CommandLines);
+
+       console->ConsoleLines = NULL;
+       console->CommandLines = NULL;
+       free(console);
+}
+
+
+/* Increments the console lines */
+void CON_NewLineConsole(ConsoleInformation *console) {
+       int loop;
+       char* temp;
+
+       if(!console)
+               return;
+
+       temp = console->ConsoleLines[console->LineBuffer - 1];
+
+       for(loop = console->LineBuffer - 1; loop > 0; loop--)
+               console->ConsoleLines[loop] = console->ConsoleLines[loop - 1];
+
+       console->ConsoleLines[0] = temp;
+
+       memset(console->ConsoleLines[0], 0, CON_CHARS_PER_LINE);
+       if(console->TotalConsoleLines < console->LineBuffer - 1)
+               console->TotalConsoleLines++;
+
+       //Now adjust the ConsoleScrollBack
+       //dont scroll if not at bottom
+       if(console->ConsoleScrollBack != 0)
+               console->ConsoleScrollBack++;
+       //boundaries
+       if(console->ConsoleScrollBack > console->LineBuffer-1)
+               console->ConsoleScrollBack = console->LineBuffer-1;
+
+}
+
+
+/* Increments the command lines */
+void CON_NewLineCommand(ConsoleInformation *console) {
+       int loop;
+       char *temp;
+
+       if(!console)
+               return;
+
+       temp  = console->CommandLines[console->LineBuffer - 1];
+
+
+       for(loop = console->LineBuffer - 1; loop > 0; loop--)
+               console->CommandLines[loop] = console->CommandLines[loop - 1];
+
+       console->CommandLines[0] = temp;
+
+       memset(console->CommandLines[0], 0, CON_CHARS_PER_LINE);
+       if(console->TotalCommands < console->LineBuffer - 1)
+               console->TotalCommands++;
+}
+
+/* Draws the command line the user is typing in to the screen */
+/* completely rewritten by C.Wacha */
+void DrawCommandLine() {
+       SDL_Rect rect;
+       int x;
+       int commandbuffer;
+       BitFont* CurrentFont;
+       static Uint32 LastBlinkTime = 0;        /* Last time the consoles cursor blinked */
+       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);
+
+       //Concatenate the left and right side to command
+       strcpy(Topmost->Command, Topmost->LCommand);
+       strncat(Topmost->Command, Topmost->RCommand, strlen(Topmost->RCommand));
+
+       //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.
+       if(Topmost->OutputScreen->flags & SDL_OPENGLBLIT) {
+               Uint32 *pix = (Uint32 *) (CurrentFont->FontSurface->pixels);
+               SDL_SetColorKey(CurrentFont->FontSurface, SDL_SRCCOLORKEY, *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() > LastBlinkTime) {
+               LastBlinkTime = SDL_GetTicks() + CON_BLINK_RATE;
+               if(Blink)
+                       Blink = 0;
+               else
+                       Blink = 1;
+       }
+
+       //check if cursor has moved - if yes display cursor anyway
+       if(Topmost->CursorPos != LastCursorPos) {
+               LastCursorPos = Topmost->CursorPos;
+               LastBlinkTime = 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);
+       }
+
+
+       if(Topmost->OutputScreen->flags & SDL_OPENGLBLIT) {
+               SDL_SetColorKey(CurrentFont->FontSurface, 0, 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;
+       //keep some space free for stuff like CON_Out(console, "blablabla %s", console->Command);
+       char temp[CON_CHARS_PER_LINE + 128];
+       char* ptemp;
+
+       if(!console)
+               return;
+
+       va_start(marker, str);
+       vsnprintf(temp, CON_CHARS_PER_LINE + 127, 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);
+}
+
+
+/* Sets the alpha level of the console, 0 turns off alpha blending */
+void CON_Alpha(ConsoleInformation *console, unsigned char alpha) {
+       if(!console)
+               return;
+
+       /* store alpha as state! */
+       console->ConsoleAlpha = alpha;
+
+       if((console->OutputScreen->flags & SDL_OPENGLBLIT) == 0) {
+               if(alpha == 0)
+                       SDL_SetAlpha(console->ConsoleSurface, 0, alpha);
+               else
+                       SDL_SetAlpha(console->ConsoleSurface, SDL_SRCALPHA, alpha);
+       }
+
+       //      CON_UpdateConsole(console);
+}
+
+
+/* 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 */
+       temp = IMG_Load(image);
+       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);
+
+       return 0;
+}
+
+/* takes a new x and y of the top left of the console window */
+void CON_Position(ConsoleInformation *console, int x, int y) {
+       if(!console)
+               return;
+
+       if(x < 0 || x > console->OutputScreen->w - console->ConsoleSurface->w)
+               console->DispX = 0;
+       else
+               console->DispX = x;
+
+       if(y < 0 || y > console->OutputScreen->h - console->ConsoleSurface->h)
+               console->DispY = 0;
+       else
+               console->DispY = y;
+}
+
+/* resizes the console, has to reset alot of stuff
+ * returns 1 on error */
+int CON_Resize(ConsoleInformation *console, SDL_Rect rect) {
+       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);
+       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);
+       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);
+       return 0;
+}
+
+/* Transfers the console to another screen surface, and adjusts size */
+int CON_Transfer(ConsoleInformation* console, SDL_Surface* new_outputscreen, SDL_Rect rect) {
+       if(!console)
+               return 1;
+
+       console->OutputScreen = new_outputscreen;
+
+       return( CON_Resize(console, rect) );
+}
+
+/* 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;
+}
+
+/* Sets the Prompt for console */
+void CON_SetPrompt(ConsoleInformation *console, char* newprompt) {
+       if(!console)
+               return;
+
+       //check length so we can still see at least 1 char :-)
+       if(strlen(newprompt) < console->VChars)
+               console->Prompt = strdup(newprompt);
+       else
+               CON_Out(console, "prompt too long. (max. %i chars)", console->VChars - 1);
+}
+
+/* Sets the key that deactivates (hides) the console. */
+void CON_SetHideKey(ConsoleInformation *console, int key) {
+       if(console)
+               console->HideKey = key;
+}
+
+/* Executes the command entered */
+void CON_Execute(ConsoleInformation *console, char* command) {
+       if(console)
+               console->CmdFunction(console, command);
+}
+
+void CON_SetExecuteFunction(ConsoleInformation *console, void(*CmdFunction)(ConsoleInformation *console2, char* command)) {
+       if(console)
+               console->CmdFunction = CmdFunction;
+}
+
+void Default_CmdFunction(ConsoleInformation *console, char* command) {
+       CON_Out(console, "     No CommandFunction registered");
+       CON_Out(console, "     use 'CON_SetExecuteFunction' to register one");
+       CON_Out(console, " ");
+       CON_Out(console, "Unknown Command \"%s\"", command);
+}
+
+void CON_SetTabCompletion(ConsoleInformation *console, char*(*TabFunction)(char* command)) {
+       if(console)
+               console->TabFunction = TabFunction;
+}
+
+void CON_TabCompletion(ConsoleInformation *console) {
+       int i,j;
+       char* command;
+
+       if(!console)
+               return;
+
+       command = strdup(console->LCommand);
+       command = console->TabFunction(command);
+
+       if(!command)
+               return; //no tab completion took place so return silently
+
+       j = strlen(command);
+       if(j > CON_CHARS_PER_LINE - 2)
+               j = CON_CHARS_PER_LINE-1;
+
+       memset(console->LCommand, 0, CON_CHARS_PER_LINE);
+       console->CursorPos = 0;
+
+       for(i = 0; i < j; i++) {
+               console->CursorPos++;
+               console->LCommand[i] = command[i];
+       }
+       //add a trailing space
+       console->CursorPos++;
+       console->LCommand[j] = ' ';
+       console->LCommand[j+1] = '\0';
+}
+
+char* Default_TabFunction(char* command) {
+       CON_Out(Topmost, "     No TabFunction registered");
+       CON_Out(Topmost, "     use 'CON_SetTabCompletion' to register one");
+       CON_Out(Topmost, " ");
+       return NULL;
+}
+
+void Cursor_Left(ConsoleInformation *console) {
+       char temp[CON_CHARS_PER_LINE];
+
+       if(Topmost->CursorPos > 0) {
+               Topmost->CursorPos--;
+               strcpy(temp, Topmost->RCommand);
+               strcpy(Topmost->RCommand, &Topmost->LCommand[strlen(Topmost->LCommand)-1]);
+               strcat(Topmost->RCommand, temp);
+               Topmost->LCommand[strlen(Topmost->LCommand)-1] = '\0';
+               //CON_Out(Topmost, "L:%s, R:%s", Topmost->LCommand, Topmost->RCommand);
+       }
+}
+
+void Cursor_Right(ConsoleInformation *console) {
+       char temp[CON_CHARS_PER_LINE];
+
+       if(Topmost->CursorPos < strlen(Topmost->Command)) {
+               Topmost->CursorPos++;
+               strncat(Topmost->LCommand, Topmost->RCommand, 1);
+               strcpy(temp, Topmost->RCommand);
+               strcpy(Topmost->RCommand, &temp[1]);
+               //CON_Out(Topmost, "L:%s, R:%s", Topmost->LCommand, Topmost->RCommand);
+       }
+}
+
+void Cursor_Home(ConsoleInformation *console) {
+       char temp[CON_CHARS_PER_LINE];
+
+       Topmost->CursorPos = 0;
+       strcpy(temp, Topmost->RCommand);
+       strcpy(Topmost->RCommand, Topmost->LCommand);
+       strncat(Topmost->RCommand, temp, strlen(temp));
+       memset(Topmost->LCommand, 0, CON_CHARS_PER_LINE);
+}
+
+void Cursor_End(ConsoleInformation *console) {
+       Topmost->CursorPos = strlen(Topmost->Command);
+       strncat(Topmost->LCommand, Topmost->RCommand, strlen(Topmost->RCommand));
+       memset(Topmost->RCommand, 0, CON_CHARS_PER_LINE);
+}
+
+void Cursor_Del(ConsoleInformation *console) {
+       char temp[CON_CHARS_PER_LINE];
+
+       if(strlen(Topmost->RCommand) > 0) {
+               strcpy(temp, Topmost->RCommand);
+               strcpy(Topmost->RCommand, &temp[1]);
+       }
+}
+
+void Cursor_BSpace(ConsoleInformation *console) {
+       if(Topmost->CursorPos > 0) {
+               Topmost->CursorPos--;
+               Topmost->Offset--;
+               if(Topmost->Offset < 0)
+                       Topmost->Offset = 0;
+               Topmost->LCommand[strlen(Topmost->LCommand)-1] = '\0';
+       }
+}
+
+void Cursor_Add(ConsoleInformation *console, SDL_Event *event) {
+       if(strlen(Topmost->Command) < CON_CHARS_PER_LINE - 1 && event->key.keysym.unicode) {
+               Topmost->CursorPos++;
+               Topmost->LCommand[strlen(Topmost->LCommand)] = (char)event->key.keysym.unicode;
+               Topmost->LCommand[strlen(Topmost->LCommand)] = '\0';
+       }
+}
+
+void Clear_Command(ConsoleInformation *console) {
+       Topmost->CursorPos = 0;
+       memset(Topmost->VCommand, 0, CON_CHARS_PER_LINE);
+       memset(Topmost->Command, 0, CON_CHARS_PER_LINE);
+       memset(Topmost->LCommand, 0, CON_CHARS_PER_LINE);
+       memset(Topmost->RCommand, 0, CON_CHARS_PER_LINE);
+}
+
+void Clear_History(ConsoleInformation *console) {
+       int loop;
+
+       for(loop = 0; loop <= console->LineBuffer - 1; loop++)
+               memset(console->ConsoleLines[loop], 0, CON_CHARS_PER_LINE);
+}
+
+void Command_Up(ConsoleInformation *console) {
+       if(console->CommandScrollBack < console->TotalCommands - 1) {
+               /* move back a line in the command strings and copy the command to the current input string */
+               console->CommandScrollBack++;
+               memset(console->RCommand, 0, CON_CHARS_PER_LINE);
+               console->Offset = 0;
+               strcpy(console->LCommand, console->CommandLines[console->CommandScrollBack]);
+               console->CursorPos = strlen(console->CommandLines[console->CommandScrollBack]);
+               CON_UpdateConsole(console);
+       }
+}
+
+void Command_Down(ConsoleInformation *console) {
+       if(console->CommandScrollBack > -1) {
+               /* move forward a line in the command strings and copy the command to the current input string */
+               console->CommandScrollBack--;
+               memset(console->RCommand, 0, CON_CHARS_PER_LINE);
+               memset(console->LCommand, 0, CON_CHARS_PER_LINE);
+               console->Offset = 0;
+               if(console->CommandScrollBack > -1)
+                       strcpy(console->LCommand, console->CommandLines[console->CommandScrollBack]);
+               console->CursorPos = strlen(console->LCommand);
+               CON_UpdateConsole(console);
+       }
+}
+
diff --git a/console/DT_drawtext.c b/console/DT_drawtext.c
new file mode 100644 (file)
index 0000000..872fbb0
--- /dev/null
@@ -0,0 +1,215 @@
+/*  DT_drawtext.c
+ *  Written By: Garrett Banuk <mongoose@mongeese.org>
+ *  This is free, just be sure to give me credit when using it
+ *  in any of your programs.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "SDL.h"
+#include "SDL_image.h"
+#include "DT_drawtext.h"
+#include "internal.h"
+
+
+static BitFont *BitFonts = NULL;       /* Linked list of fonts */
+
+
+/* sets the transparency value for the font in question.  assumes that
+ * we're in an OpenGL context.  */
+void DT_SetFontAlphaGL(int FontNumber, int a) {
+       unsigned char val;
+       BitFont *CurrentFont;
+       unsigned char r_targ, g_targ, b_targ;
+       int i, imax;
+       unsigned char *pix;
+
+       /* get pointer to font */
+       CurrentFont = DT_FontPointer(FontNumber);
+       if(CurrentFont == NULL) {
+               PRINT_ERROR("Setting font alpha for non-existent font!\n");
+               return;
+       }
+       if(CurrentFont->FontSurface->format->BytesPerPixel == 2) {
+               PRINT_ERROR("16-bit SDL surfaces do not support alpha-blending under OpenGL\n");
+               return;
+       }
+       if(a < SDL_ALPHA_TRANSPARENT)
+               val = SDL_ALPHA_TRANSPARENT;
+       else if(a > SDL_ALPHA_OPAQUE)
+               val = SDL_ALPHA_OPAQUE;
+       else
+               val = a;
+
+       /* iterate over all pixels in the font surface.  For each
+        * pixel that is (255,0,255), set its alpha channel
+        * appropriately.  */
+       imax = CurrentFont->FontSurface->h * (CurrentFont->FontSurface->w << 2);
+       pix = (unsigned char *)(CurrentFont->FontSurface->pixels);
+       r_targ = 255;           /*pix[0]; */
+       g_targ = 0;             /*pix[1]; */
+       b_targ = 255;           /*pix[2]; */
+       for(i = 3; i < imax; i += 4)
+               if(pix[i - 3] == r_targ && pix[i - 2] == g_targ && pix[i - 1] == b_targ)
+                       pix[i] = val;
+       /* also make sure that alpha blending is disabled for the font
+          surface. */
+       SDL_SetAlpha(CurrentFont->FontSurface, 0, SDL_ALPHA_OPAQUE);
+}
+
+/* Loads the font into a new struct
+ * returns -1 as an error else it returns the number
+ * of the font for the user to use
+ */
+int DT_LoadFont(const char *BitmapName, int flags) {
+       int FontNumber = 0;
+       BitFont **CurrentFont = &BitFonts;
+       SDL_Surface *Temp;
+
+
+       while(*CurrentFont) {
+               CurrentFont = &((*CurrentFont)->NextFont);
+               FontNumber++;
+       }
+
+       /* load the font bitmap */
+       if(NULL == (Temp = IMG_Load(BitmapName))) {
+               PRINT_ERROR("Cannot load file ");
+               printf("%s\n", BitmapName);
+               return -1;
+       }
+
+       /* Add a font to the list */
+       *CurrentFont = (BitFont *) malloc(sizeof(BitFont));
+
+       (*CurrentFont)->FontSurface = SDL_DisplayFormat(Temp);
+       SDL_FreeSurface(Temp);
+
+       (*CurrentFont)->CharWidth = (*CurrentFont)->FontSurface->w / 256;
+       (*CurrentFont)->CharHeight = (*CurrentFont)->FontSurface->h;
+       (*CurrentFont)->FontNumber = FontNumber;
+       (*CurrentFont)->NextFont = NULL;
+
+
+       /* Set font as transparent if the flag is set.  The assumption we'll go on
+        * is that the first pixel of the font image will be the color we should treat
+        * as transparent.
+        */
+       if(flags & TRANS_FONT) {
+               if(SDL_GetVideoSurface()->flags & SDL_OPENGLBLIT)
+                       DT_SetFontAlphaGL(FontNumber, SDL_ALPHA_TRANSPARENT);
+               else
+                       SDL_SetColorKey((*CurrentFont)->FontSurface, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB((*CurrentFont)->FontSurface->format, 255, 0, 255));
+       } else if(SDL_GetVideoSurface()->flags & SDL_OPENGLBLIT)
+               DT_SetFontAlphaGL(FontNumber, SDL_ALPHA_OPAQUE);
+
+       return FontNumber;
+}
+
+/* Takes the font type, coords, and text to draw to the surface*/
+void DT_DrawText(const char *string, SDL_Surface *surface, int FontType, int x, int y) {
+       int loop;
+       int characters;
+       int current;
+       SDL_Rect SourceRect, DestRect;
+       BitFont *CurrentFont;
+
+       CurrentFont = DT_FontPointer(FontType);
+
+       /* see how many characters can fit on the screen */
+       if(x > surface->w || y > surface->h)
+               return;
+
+       if(strlen(string) < (surface->w - x) / CurrentFont->CharWidth)
+               characters = strlen(string);
+       else
+               characters = (surface->w - x) / CurrentFont->CharWidth;
+
+       DestRect.x = x;
+       DestRect.y = y;
+       DestRect.w = CurrentFont->CharWidth;
+       DestRect.h = CurrentFont->CharHeight;
+
+       SourceRect.y = 0;
+       SourceRect.w = CurrentFont->CharWidth;
+       SourceRect.h = CurrentFont->CharHeight;
+
+       /* Now draw it */
+       for(loop = 0; loop < characters; loop++) {
+               current = string[loop];
+               if (current<0 || current > 255)
+                       current = 0;
+               //SourceRect.x = string[loop] * CurrentFont->CharWidth;
+               SourceRect.x = current * CurrentFont->CharWidth;
+               SDL_BlitSurface(CurrentFont->FontSurface, &SourceRect, surface, &DestRect);
+               DestRect.x += CurrentFont->CharWidth;
+       }
+       /* if we're in OpenGL-mode, we need to manually update after blitting. */
+       if(surface->flags & SDL_OPENGLBLIT) {
+               DestRect.x = x;
+               DestRect.w = characters * CurrentFont->CharWidth;
+               SDL_UpdateRects(surface, 1, &DestRect);
+       }
+}
+
+
+/* Returns the height of the font numbers character
+ * returns 0 if the fontnumber was invalid */
+int DT_FontHeight(int FontNumber) {
+       BitFont *CurrentFont;
+
+       CurrentFont = DT_FontPointer(FontNumber);
+       if(CurrentFont)
+               return CurrentFont->CharHeight;
+       else
+               return 0;
+}
+
+/* Returns the width of the font numbers charcter */
+int DT_FontWidth(int FontNumber) {
+       BitFont *CurrentFont;
+
+       CurrentFont = DT_FontPointer(FontNumber);
+       if(CurrentFont)
+               return CurrentFont->CharWidth;
+       else
+               return 0;
+}
+
+/* Returns a pointer to the font struct of the number
+ * returns NULL if theres an error
+ */
+BitFont *DT_FontPointer(int FontNumber) {
+       BitFont *CurrentFont = BitFonts;
+       BitFont *temp;
+
+       while(CurrentFont)
+               if(CurrentFont->FontNumber == FontNumber)
+                       return CurrentFont;
+               else {
+                       temp = CurrentFont;
+                       CurrentFont = CurrentFont->NextFont;
+               }
+
+       return NULL;
+
+}
+
+/* removes all the fonts currently loaded */
+void DT_DestroyDrawText() {
+       BitFont *CurrentFont = BitFonts;
+       BitFont *temp;
+
+       while(CurrentFont) {
+               temp = CurrentFont;
+               CurrentFont = CurrentFont->NextFont;
+
+               SDL_FreeSurface(temp->FontSurface);
+               free(temp);
+       }
+
+       BitFonts = NULL;
+}
+
+
diff --git a/console/Makefile.am b/console/Makefile.am
new file mode 100644 (file)
index 0000000..347d55b
--- /dev/null
@@ -0,0 +1,4 @@
+noinst_LIBRARIES = libconsole.a
+INCLUDES = -I $(top_srcdir)/include
+
+libconsole_a_SOURCES = CON_console.c DT_drawtext.c internal.c
diff --git a/console/internal.c b/console/internal.c
new file mode 100644 (file)
index 0000000..f32fe76
--- /dev/null
@@ -0,0 +1,75 @@
+/*  internal.c
+ *  Written By: Garrett Banuk <mongoose@mongeese.org>
+ *  This is free, just be sure to give me credit when using it
+ *  in any of your programs.
+ */
+
+/* internal.[c,h] are various routines used internally
+ * by SDL_console and DrawText. */
+
+#include "SDL.h"
+
+
+/*
+ * Return the pixel value at (x, y)
+ * NOTE: The surface must be locked before calling this!
+ */
+Uint32 DT_GetPixel(SDL_Surface *surface, int x, int y) {
+       int bpp = surface->format->BytesPerPixel;
+       /* Here p is the address to the pixel we want to retrieve */
+       Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
+
+       switch (bpp) {
+       case 1:
+               return *p;
+       case 2:
+               return *(Uint16 *) p;
+       case 3:
+               if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
+                       return p[0] << 16 | p[1] << 8 | p[2];
+               else
+                       return p[0] | p[1] << 8 | p[2] << 16;
+       case 4:
+               return *(Uint32 *) p;
+       default:
+               return 0;       /* shouldn't happen, but avoids warnings */
+       }
+}
+
+/*
+ * Set the pixel at (x, y) to the given value
+ * NOTE: The surface must be locked before calling this!
+ */
+void DT_PutPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
+       int bpp = surface->format->BytesPerPixel;
+       /* Here p is the address to the pixel we want to set */
+       Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
+
+       switch (bpp) {
+       case 1:
+               *p = pixel;
+               break;
+       case 2:
+               *(Uint16 *) p = pixel;
+               break;
+       case 3:
+               if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
+                       p[0] = (pixel >> 16) & 0xff;
+                       p[1] = (pixel >> 8) & 0xff;
+                       p[2] = pixel & 0xff;
+               } else {
+                       p[0] = pixel & 0xff;
+                       p[1] = (pixel >> 8) & 0xff;
+                       p[2] = (pixel >> 16) & 0xff;
+               }
+               break;
+       case 4:
+               *(Uint32 *) p = pixel;
+               break;
+       default:
+               break;
+       }
+}
+
+
+
diff --git a/include/CON_console.h b/include/CON_console.h
new file mode 100644 (file)
index 0000000..814d64f
--- /dev/null
@@ -0,0 +1,202 @@
+#ifndef CON_console_H
+#define CON_console_H
+
+/*! \mainpage
+\section intro Introduction
+SDL_Console is a console that can be added to any SDL application. It is similar to Quake and other games consoles.
+A console is meant to be a very simple way of interacting with a program and executing commands. You can also have 
+more than one console at a time. 
+\section docs Documentation
+For a detailed description of all functions see \ref CON_console.h. Remark that functions that have the mark "Internal" 
+are only used internally. There's not much use of calling these functions.
+Have Fun!
+\author Garett Banuk <mongoose@mongeese.org> (Original Version)
+\author Clemens Wacha <reflex-2000@gmx.net> (Version 2.x, Documentation)
+\author Boris Lesner <talanthyr@tuxfamily.org> (Package Maintainer)
+*/
+
+
+
+#include "SDL.h"
+
+//! Cut the buffer line if it becomes longer than this
+#define CON_CHARS_PER_LINE   128
+//! Cursor blink frequency in ms
+#define CON_BLINK_RATE       500
+//! Border in pixels from the most left to the first letter
+#define CON_CHAR_BORDER      4
+//! Default prompt used at the commandline
+#define CON_DEFAULT_PROMPT     "]"
+//! Scroll this many lines at a time (when pressing PGUP or PGDOWN)
+#define CON_LINE_SCROLL        2
+//! Indicator showing that you scrolled up the history
+#define CON_SCROLL_INDICATOR "^"
+//! Cursor shown if we are in insert mode
+#define CON_INS_CURSOR "_"
+//! Cursor shown if we are in overwrite mode
+#define CON_OVR_CURSOR "|"
+//! Defines the default hide key (Hide() the console if pressed)
+#define CON_DEFAULT_HIDEKEY    SDLK_ESCAPE
+//! Defines the opening/closing speed
+#define CON_OPENCLOSE_SPEED 25
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+       enum {
+           CON_CLOSED, //! The console is closed (and not shown)
+           CON_CLOSING,        //! The console is still open and visible but closing
+           CON_OPENING,        //! The console is visible and opening but not yet fully open
+           CON_OPEN    //! The console is open and visible
+       };
+
+       /*! This is a struct for each consoles data */
+       typedef struct console_information_td {
+               int Visible;                    //! enum that tells which visible state we are in CON_HIDE, CON_SHOW, CON_RAISE, CON_LOWER
+               int WasUnicode;                 //! stores the UNICODE value before the console was shown. On Hide() the UNICODE value is restored.
+               int RaiseOffset;                        //! Offset used when scrolling in the console
+               int HideKey;                    //! the key that can hide the console
+               char **ConsoleLines;            //! List of all the past lines
+               char **CommandLines;            //! List of all the past commands
+               int TotalConsoleLines;          //! Total number of lines in the console
+               int ConsoleScrollBack;          //! How much the user scrolled back in the console
+               int TotalCommands;              //! Number of commands in the Back Commands
+               int FontNumber;                 //! This is the number of the font for the console
+               int LineBuffer;                 //! The number of visible lines in the console (autocalculated)
+               int VChars;                     //! The number of visible characters in one console line (autocalculated)
+               int BackX, BackY;               //! Background images x and y coords
+               char* Prompt;                   //! Prompt displayed in command line
+               char Command[CON_CHARS_PER_LINE];       //! current command in command line = lcommand + rcommand
+               char RCommand[CON_CHARS_PER_LINE];      //! left hand side of cursor
+               char LCommand[CON_CHARS_PER_LINE];      //! right hand side of cursor
+               char VCommand[CON_CHARS_PER_LINE];      //! current visible command line
+               int CursorPos;                  //! Current cursor position in CurrentCommand
+               int Offset;                     //! CommandOffset (first visible char of command) - if command is too long to fit into console
+               int InsMode;                    //! Insert or Overwrite characters?
+               SDL_Surface *ConsoleSurface;    //! Surface of the console
+               SDL_Surface *OutputScreen;      //! This is the screen to draw the console to
+               SDL_Surface *BackgroundImage;   //! Background image for the console
+               SDL_Surface *InputBackground;   //! Dirty rectangle to draw over behind the users background
+               int DispX, DispY;               //! The top left x and y coords of the console on the display screen
+               unsigned char ConsoleAlpha;     //! The consoles alpha level
+               int CommandScrollBack;          //! How much the users scrolled back in the command lines
+               void(*CmdFunction)(struct console_information_td *console, char* command);      //! The Function that is executed if you press <Return> in the console
+               char*(*TabFunction)(char* command);     //! The Function that is executed if you press <Tab> in the console
+
+               int FontHeight;
+               int FontWidth;
+       }
+       ConsoleInformation;
+
+       /*! Takes keys from the keyboard and inputs them to the console if the console isVisible().
+               If the event was not handled (i.e. WM events or unknown ctrl- or alt-sequences) 
+               the function returns the event for further processing. */
+       SDL_Event* CON_Events(SDL_Event *event);
+       /*! Makes the console visible */
+       void CON_Show(ConsoleInformation *console);
+       /*! Hides the console */
+       void CON_Hide(ConsoleInformation *console);
+       /*! Returns 1 if the console is visible, 0 else */
+       int CON_isVisible(ConsoleInformation *console);
+       /*! Internal: Updates visible state. Used in CON_DrawConsole() */
+       void CON_UpdateOffset(ConsoleInformation* console);
+       /*! Draws the console to the screen if it isVisible()*/
+       void CON_DrawConsole(ConsoleInformation *console);
+       /*! Initializes a new console */
+       ConsoleInformation *CON_Init(const char *FontName, SDL_Surface *DisplayScreen, int lines, SDL_Rect rect);
+       /*! Frees DT_DrawText and calls CON_Free */
+       void CON_Destroy(ConsoleInformation *console);
+       /*! Frees all the memory loaded by the console */
+       void CON_Free(ConsoleInformation *console);
+       /*! printf for the console */
+       void CON_Out(ConsoleInformation *console, const char *str, ...);
+       /*! Sets the alpha channel of an SDL_Surface to the specified value (0 - transparend,
+               255 - opaque). Use this function also for OpenGL. */
+       void CON_Alpha(ConsoleInformation *console, unsigned char alpha);
+       /*! Internal: Sets the alpha channel of an SDL_Surface to the specified value.
+               Preconditions: the surface in question is RGBA. 0 <= a <= 255, where 0 is transparent and 255 opaque */
+       void CON_AlphaGL(SDL_Surface *s, int alpha);
+       /*! Sets a background image for the console */
+       int CON_Background(ConsoleInformation *console, const char *image, int x, int y);
+       /*! Changes current position of the console */
+       void CON_Position(ConsoleInformation *console, int x, int y);
+       /*! Changes the size of the console */
+       int CON_Resize(ConsoleInformation *console, SDL_Rect rect);
+       /*! Beams a console to another screen surface. Needed if you want to make a Video restart in your program. This
+               function first changes the OutputScreen Pointer then calls CON_Resize to adjust the new size. */
+       int CON_Transfer(ConsoleInformation* console, SDL_Surface* new_outputscreen, SDL_Rect rect);
+       /*! Give focus to a console. Make it the "topmost" console. This console will receive events
+               sent with CON_Events() */
+       void CON_Topmost(ConsoleInformation *console);
+       /*! Modify the prompt of the console */
+       void CON_SetPrompt(ConsoleInformation *console, char* newprompt);
+       /*! Set the key, that invokes a CON_Hide() after press. default is ESCAPE and you can always hide using
+               ESCAPE and the HideKey. compared against event->key.keysym.sym !! */
+       void CON_SetHideKey(ConsoleInformation *console, int key);
+       /*! Internal: executes the command typed in at the console (called if you press ENTER)*/
+       void CON_Execute(ConsoleInformation *console, char* command);
+       /*! Sets the callback function that is called if a command was typed in. The function could look like this:
+               void my_command_handler(ConsoleInformation* console, char* command). @param console: the console the command
+               came from. @param command: the command string that was typed in. */
+       void CON_SetExecuteFunction(ConsoleInformation *console, void(*CmdFunction)(ConsoleInformation *console2, char* command));
+       /*! Sets the callback tabulator completion function. char* my_tabcompletion(char* command). If Tab is
+               pressed, the function gets called with the already typed in command. my_tabcompletion then checks if if can
+               complete the command or if it should display a list of all matching commands (with CON_Out()). Returns the 
+               completed command or NULL if no completion was made. */
+       void CON_SetTabCompletion(ConsoleInformation *console, char*(*TabFunction)(char* command));
+       /*! Internal: Gets called when TAB was pressed */
+       void CON_TabCompletion(ConsoleInformation *console);
+       /*! Internal: makes newline (same as printf("\n") or CON_Out(console, "\n") ) */
+       void CON_NewLineConsole(ConsoleInformation *console);
+       /*! Internal: shift command history (the one you can switch with the up/down keys) */
+       void CON_NewLineCommand(ConsoleInformation *console);
+       /*! Internal: updates console after resize etc. */
+       void CON_UpdateConsole(ConsoleInformation *console);
+
+
+       /*! Internal: Default Execute callback */
+       void Default_CmdFunction(ConsoleInformation *console, char* command);
+       /*! Internal: Default TabCompletion callback */
+       char* Default_TabFunction(char* command);
+
+       /*! Internal: draws the commandline the user is typing in to the screen. called by update? */
+       void DrawCommandLine();
+
+       /*! Internal: Gets called if you press the LEFT key (move cursor left) */
+       void Cursor_Left(ConsoleInformation *console);
+       /*! Internal: Gets called if you press the RIGHT key (move cursor right) */
+       void Cursor_Right(ConsoleInformation *console);
+       /*! Internal: Gets called if you press the HOME key (move cursor to the beginning
+       of the line */
+       void Cursor_Home(ConsoleInformation *console);
+       /*! Internal: Gets called if you press the END key (move cursor to the end of the line*/
+       void Cursor_End(ConsoleInformation *console);
+       /*! Internal: Called if you press DELETE (deletes character under the cursor) */
+       void Cursor_Del(ConsoleInformation *console);
+       /*! Internal: Called if you press BACKSPACE (deletes character left of cursor) */
+       void Cursor_BSpace(ConsoleInformation *console);
+       /*! Internal: Called if you type in a character (add the char to the command) */
+       void Cursor_Add(ConsoleInformation *console, SDL_Event *event);
+
+       /*! Internal: Called if you press Ctrl-C (deletes the commandline) */
+       void Clear_Command(ConsoleInformation *console);
+       /*! Internal: Called if you press Ctrl-L (deletes the History) */
+       void Clear_History(ConsoleInformation *console);
+
+       /*! Internal: Called if you press UP key (switches through recent typed in commands */
+       void Command_Up(ConsoleInformation *console);
+       /*! Internal: Called if you press DOWN key (switches through recent typed in commands */
+       void Command_Down(ConsoleInformation *console);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif
+
+
diff --git a/include/DT_drawtext.h b/include/DT_drawtext.h
new file mode 100644 (file)
index 0000000..142a0db
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef Drawtext_h
+#define Drawtext_h
+
+
+#define TRANS_FONT 1
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+       typedef struct BitFont_td {
+               SDL_Surface             *FontSurface;
+               int                     CharWidth;
+               int                     CharHeight;
+               int                     FontNumber;
+               struct BitFont_td       *NextFont;
+       }
+       BitFont;
+
+
+       void    DT_DrawText(const char *string, SDL_Surface *surface, int FontType, int x, int y );
+       int     DT_LoadFont(const char *BitmapName, int flags );
+       int     DT_FontHeight( int FontNumber );
+       int     DT_FontWidth( int FontNumber );
+       BitFont*        DT_FontPointer(int FontNumber );
+       void    DT_DestroyDrawText();
+
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif
+
+
+
index 57279cb..d4de7a8 100644 (file)
@@ -15,6 +15,7 @@
 int  con_init(void);
 void con_printf(int level, char *fmt, ...);
 
+void con_show(void);
 void con_draw(void);
 void con_update(void);
 
index 1eaa0c6..af146fc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: console.c,v 1.9 2003-03-17 09:33:49 btb Exp $ */
+/* $Id: console.c,v 1.10 2003-06-02 01:55:03 btb Exp $ */
 /*
  *
  * FIXME: put description here
 #include <stdarg.h>
 #include <string.h>
 #include <fcntl.h>
+
+#include <SDL.h>
+#include "CON_console.h"
+
 #include "pstypes.h"
 #include "u_mem.h"
 #include "error.h"
@@ -38,8 +42,18 @@ cvar_t con_threshold = {"con_threshold", "0",};
 /* Private console stuff */
 #define CON_NUM_LINES 40
 #define CON_LINE_LEN 40
+#if 0
 static char con_display[40][40];
 static int  con_line; /* Current display line */
+#endif
+
+static int con_initialized;
+
+ConsoleInformation *Console;
+extern SDL_Surface *screen;
+
+void con_parse(ConsoleInformation *console, char *command);
+
 
 /* ======
  * con_init - Initialise the console.
@@ -47,20 +61,27 @@ static int  con_line; /* Current display line */
  */
 int con_init(void)
 {
-       /* Make sure the output is unbuffered */
-       if (text_console_enabled) {
-               setbuf (stdout, NULL);
-               setbuf (stderr, NULL);
-       }
-
-       memset(con_display, ' ', sizeof(con_display));
-       con_line = 0;
-
        /* Initialise the cvars */
        cvar_registervariable (&con_threshold);
        return 0;
 }
 
+void real_con_init(void)
+{
+       SDL_Rect Con_rect;
+
+       Con_rect.x = Con_rect.y = 0;
+       Con_rect.w = Con_rect.h = 300;
+
+       Console = CON_Init("ConsoleFont.png", screen, CON_NUM_LINES, Con_rect);
+
+       Assert(Console);
+
+       CON_SetExecuteFunction(Console, con_parse);
+
+       con_initialized = 1;
+}
+
 /* ======
  * con_printf - Print a message to the console.
  * ======
@@ -81,6 +102,8 @@ void con_printf(int priority, char *fmt, ...)
                        va_end (arglist);
                }
 
+               CON_Out(Console, buffer);
+
 /*             for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
                {
                        memcpy(con_display, &buffer[i], min(80, l-i));
@@ -94,6 +117,7 @@ void con_printf(int priority, char *fmt, ...)
  */
 void con_update(void)
 {
+#if 0
        char buffer[CMD_MAX_LENGTH], *t;
 
        /* Check for new input */
@@ -101,6 +125,7 @@ void con_update(void)
        if (t == NULL) return;
 
        cmd_parse(buffer);
+#endif
        con_draw();
 }
 
@@ -166,6 +191,9 @@ float cvar (char *cvar_name)
  */
 void con_draw(void)
 {
+#if 1
+       CON_DrawConsole(Console);
+#else
        char buffer[CON_LINE_LEN+1];
        int i,j;
        for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
@@ -174,4 +202,19 @@ void con_draw(void)
                buffer[CON_LINE_LEN] = 0;
                gr_string(1,j*10,buffer);
        }
+#endif
+}
+
+void con_show(void)
+{
+       if (!con_initialized)
+               real_con_init();
+
+       CON_Show(Console);
+       CON_Topmost(Console);
+}
+
+void con_parse(ConsoleInformation *console, char *command)
+{
+       cmd_parse(command);
 }
index 850d75d..437b844 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: game.c,v 1.20 2003-03-17 09:33:49 btb Exp $ */
+/* $Id: game.c,v 1.21 2003-06-02 01:55:03 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -17,7 +17,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-char game_rcsid[] = "$Id: game.c,v 1.20 2003-03-17 09:33:49 btb Exp $";
+char game_rcsid[] = "$Id: game.c,v 1.21 2003-06-02 01:55:03 btb Exp $";
 #endif
 
 #ifdef WINDOWS
@@ -2605,9 +2605,6 @@ void flicker_lights();
 
 void GameLoop(int RenderFlag, int ReadControlsFlag )
 {
-#ifdef CONSOLE
-       con_update();
-#endif
        #ifndef NDEBUG
        //      Used to slow down frame rate for testing things.
        //      RenderFlag = 1; // DEBUG
index 1dbdda5..b0f89b9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: gamecntl.c,v 1.17 2003-03-27 01:25:41 btb Exp $ */
+/* $Id: gamecntl.c,v 1.18 2003-06-02 01:55:03 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -23,6 +23,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include <string.h>
 #include <stdarg.h>
 
+#include "CON_console.h"
+
 #include "pstypes.h"
 #include "console.h"
 #include "inferno.h"
@@ -1105,6 +1107,11 @@ int HandleSystemKey(int key)
 
        switch (key) {
 
+               case KEY_SHIFTED + KEY_ESC:
+                       con_show();
+                       break;
+
+#if 0
                case KEY_SHIFTED + KEY_ESC:     //quick exit
                        #ifdef EDITOR
                                if (! SafetyCheck()) break;
@@ -1114,6 +1121,7 @@ int HandleSystemKey(int key)
                        Game_aborted=1;
                        Function_mode=FMODE_EXIT;
                        break;
+#endif
 
                MAC( case KEY_COMMAND+KEY_P: )
                case KEY_PAUSE: 
index b82dbb3..e25ba54 100644 (file)
@@ -16,7 +16,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: gamerend.c,v 1.8 2003-03-17 09:07:57 btb Exp $";
+static char rcsid[] = "$Id: gamerend.c,v 1.9 2003-06-02 01:55:03 btb Exp $";
 #endif
 
 #ifdef WINDOWS
@@ -1425,6 +1425,8 @@ void game_render_frame_mono(void)
 
 #endif
 
+       con_update();
+
        gr_update();
 }