shithub: choc

Download patch

ref: 01a403802ecc6465a0dec05b52b3d179732bb7c7
parent: cc2a17430fa1e6c95b24de881c68f06265214b88
author: Simon Howard <[email protected]>
date: Fri Jan 13 13:23:28 EST 2006

Textscreen getchar() function; remove SDL code from I_Endoom.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 289

--- a/src/i_system.c
+++ b/src/i_system.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: i_system.c 274 2006-01-08 18:13:33Z fraggle $
+// $Id: i_system.c 289 2006-01-13 18:23:28Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.17  2006/01/13 18:23:27  fraggle
+// Textscreen getchar() function; remove SDL code from I_Endoom.
+//
 // Revision 1.16  2006/01/08 18:13:32  fraggle
 // show_endoom config file option to disable the endoom screen
 //
@@ -78,7 +81,7 @@
 //-----------------------------------------------------------------------------
 
 static const char
-rcsid[] = "$Id: i_system.c 274 2006-01-08 18:13:33Z fraggle $";
+rcsid[] = "$Id: i_system.c 289 2006-01-13 18:23:28Z fraggle $";
 
 
 #include <stdlib.h>
@@ -203,10 +206,9 @@
     unsigned char *screendata;
     unsigned int start_ms;
     boolean waiting;
-    SDL_Event ev;
 
     endoom_data = W_CacheLumpName("ENDOOM", PU_STATIC);
-    
+
     // Set up text mode screen
 
     TXT_Init();
@@ -230,23 +232,12 @@
     {
         TXT_UpdateScreen();
 
-        if (!SDL_PollEvent(&ev))
+        if (TXT_GetChar() >= 0)
         {
-            I_Sleep(50);
-            continue;
+            break;
         }
-
-        switch (ev.type)
-        {
-            case SDL_QUIT:
-            case SDL_MOUSEBUTTONDOWN:
-            case SDL_KEYDOWN:
-                waiting = false;
-                break;
-
-            default:
-                break;
-        }
+        
+        I_Sleep(50);
     }
     
     // Shut down text mode screen
--- a/textscreen/txt_main.c
+++ b/textscreen/txt_main.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: txt_main.c 183 2005-10-09 20:19:21Z fraggle $
+// $Id: txt_main.c 289 2006-01-13 18:23:28Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.4  2006/01/13 18:23:28  fraggle
+// Textscreen getchar() function; remove SDL code from I_Endoom.
+//
 // Revision 1.3  2005/10/09 20:19:21  fraggle
 // Handle blinking text in ENDOOM lumps properly.
 //
@@ -45,8 +48,6 @@
 #include "txt_main.h"
 #include "txt_font.h"
 
-#define SCREEN_W 80
-#define SCREEN_H 25
 #define CHAR_W 8
 #define CHAR_H 16
 
@@ -83,7 +84,7 @@
 {
     SDL_InitSubSystem(SDL_INIT_VIDEO);
     
-    screen = SDL_SetVideoMode(SCREEN_W * CHAR_W, SCREEN_H * CHAR_H, 8, 0);
+    screen = SDL_SetVideoMode(TXT_SCREEN_W * CHAR_W, TXT_SCREEN_H * CHAR_H, 8, 0);
 
     if (screen == NULL)
         return 0;
@@ -90,8 +91,8 @@
 
     SDL_SetColors(screen, ega_colors, 0, 16);
 
-    screendata = malloc(SCREEN_W * SCREEN_H * 2);
-    memset(screendata, 0, SCREEN_W * SCREEN_H * 2);
+    screendata = malloc(TXT_SCREEN_W * TXT_SCREEN_H * 2);
+    memset(screendata, 0, TXT_SCREEN_W * TXT_SCREEN_H * 2);
 
     return 1;
 }
@@ -115,7 +116,7 @@
     int bg, fg;
     int x1, y1;
 
-    p = &screendata[(y * SCREEN_W + x) * 2];
+    p = &screendata[(y * TXT_SCREEN_W + x) * 2];
     character = p[0];
 
     fg = p[1] & 0xf;
@@ -174,6 +175,38 @@
 
 void TXT_UpdateScreen(void)
 {
-    TXT_UpdateScreenArea(0, 0, SCREEN_W, SCREEN_H);
+    TXT_UpdateScreenArea(0, 0, TXT_SCREEN_W, TXT_SCREEN_H);
+}
+
+signed int TXT_GetChar(void)
+{
+    SDL_Event ev;
+
+    while (SDL_PollEvent(&ev))
+    {
+        switch (ev.type)
+        {
+            case SDL_MOUSEBUTTONDOWN:
+                if (ev.button.button == SDL_BUTTON_LEFT)
+                    return TXT_MOUSE_LEFT;
+                else if (ev.button.button == SDL_BUTTON_RIGHT)
+                    return TXT_MOUSE_RIGHT;
+                else if (ev.button.button == SDL_BUTTON_MIDDLE)
+                    return TXT_MOUSE_MIDDLE;
+                break;
+
+            case SDL_KEYDOWN:
+                return ev.key.keysym.unicode;
+
+            case SDL_QUIT:
+                // Quit = escape
+                return 27;
+
+            default:
+                break;
+        }
+    }
+
+    return -1;
 }
 
--- a/textscreen/txt_main.h
+++ b/textscreen/txt_main.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: txt_main.h 146 2005-10-02 03:16:03Z fraggle $
+// $Id: txt_main.h 289 2006-01-13 18:23:28Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.2  2006/01/13 18:23:28  fraggle
+// Textscreen getchar() function; remove SDL code from I_Endoom.
+//
 // Revision 1.1  2005/10/02 03:16:03  fraggle
 // Text mode emulation code
 //
@@ -35,6 +38,39 @@
 #ifndef TXT_MAIN_H
 #define TXT_MAIN_H
 
+// Special keypress values that correspond to mouse button clicks
+//
+#define TXT_MOUSE_LEFT   1
+#define TXT_MOUSE_RIGHT  2
+#define TXT_MOUSE_MIDDLE 3
+
+// Screen size
+
+#define TXT_SCREEN_W 80
+#define TXT_SCREEN_H 25
+
+#define TXT_COLOR_BLINKING (1 << 3)
+
+typedef enum
+{
+    TXT_COLOR_BLACK,
+    TXT_COLOR_BLUE,
+    TXT_COLOR_GREEN,
+    TXT_COLOR_CYAN,
+    TXT_COLOR_RED,
+    TXT_COLOR_MAGENTA,
+    TXT_COLOR_BROWN,
+    TXT_COLOR_GREY,
+    TXT_COLOR_DARK_GREY,
+    TXT_COLOR_BRIGHT_BLUE,
+    TXT_COLOR_BRIGHT_GREEN,
+    TXT_COLOR_BRIGHT_CYAN,
+    TXT_COLOR_BRIGHT_RED,
+    TXT_COLOR_BRIGHT_MAGENTA,
+    TXT_COLOR_YELLOW,
+    TXT_COLOR_BRIGHT_WHITE,
+} txt_color_t;
+
 // Initialise the screen
 // Returns 1 if successful, 0 if failed.
 
@@ -55,6 +91,10 @@
 // Update the whole screen
 
 void TXT_UpdateScreen(void);
+
+// Read a character from the keyboard
+
+int TXT_GetChar(void);
 
 #endif /* #ifndef TXT_MAIN_H */