shithub: choc

Download patch

ref: 344823214b77a076351e1101a89e8c2a407dca48
parent: aaf96ab501f948df13f78fdf072379884d2d3f2e
author: Simon Howard <[email protected]>
date: Fri May 19 15:57:59 EDT 2006

Split off text mode gui desktop code into a separate file. Rename some
of the functions in txt_gui.c.

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

--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_gui.c 455 2006-03-30 19:08:37Z fraggle $
+// $Id: net_gui.c 483 2006-05-19 19:57:59Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -123,10 +123,10 @@
     char buf[40];
     int i;
 
-    TXT_DrawDesktop(PACKAGE_STRING);
-    TXT_DrawWindow("Waiting for game start...", 
-                    WINDOW_X, WINDOW_Y, 
-                    WINDOW_W, WINDOW_H);
+    TXT_DrawDesktopBackground(PACKAGE_STRING);
+    TXT_DrawWindowFrame("Waiting for game start...", 
+                        WINDOW_X, WINDOW_Y, 
+                        WINDOW_W, WINDOW_H);
 
     TXT_BGColor(TXT_COLOR_BLUE, 0);
 
--- a/textscreen/Makefile.am
+++ b/textscreen/Makefile.am
@@ -5,6 +5,7 @@
 bin_PROGRAMS=guitest
 
 libtextscreen_a_SOURCES =              \
+	txt_desktop.c txt_desktop.h    \
 	txt_gui.c     txt_gui.h        \
 	txt_io.c      txt_io.h         \
 	txt_main.c    txt_main.h       \
--- a/textscreen/guitest.c
+++ b/textscreen/guitest.c
@@ -4,6 +4,7 @@
 #include "txt_main.h"
 
 #include "txt_button.h"
+#include "txt_desktop.h"
 #include "txt_separator.h"
 #include "txt_window.h"
 
@@ -45,7 +46,7 @@
     txt_window_t *window;
     int i;
     
-    window = TXT_NewWindow("Another test", 30, 7);
+    window = TXT_NewWindow("Another test", 50, 7);
 
     for (i=0; i<5; ++i)
     {
@@ -65,8 +66,7 @@
     {
         firstwin->selected = (firstwin->selected + 1) % firstwin->num_widgets;
 
-        TXT_DrawAllWindows();
-
+        TXT_DrawDesktop();
     }
 }
 
--- /dev/null
+++ b/textscreen/txt_desktop.c
@@ -1,0 +1,133 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id$
+//
+// Copyright(C) 1993-1996 Id Software, Inc.
+// Copyright(C) 2006 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.
+//
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "txt_desktop.h"
+#include "txt_gui.h"
+#include "txt_main.h"
+#include "txt_separator.h"
+#include "txt_window.h"
+
+#define MAXWINDOWS 128
+
+static char *desktop_title;
+static txt_window_t *all_windows[MAXWINDOWS];
+static int num_windows = 0;
+
+void TXT_AddDesktopWindow(txt_window_t *win)
+{
+    all_windows[num_windows] = win;
+    ++num_windows;
+}
+
+void TXT_RemoveDesktopWindow(txt_window_t *win)
+{
+    int from, to;
+
+    for (from=0, to=0; from<num_windows; ++from)
+    {
+        if (all_windows[from] != win)
+        {
+            all_windows[to] = all_windows[from];
+            ++to;
+        }
+    }
+    
+    num_windows = to;
+}
+
+static void DrawDesktopBackground(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<TXT_SCREEN_W * TXT_SCREEN_H; ++i)
+    {
+        *p++ = 0xb1;
+        *p++ = TXT_COLOR_GREY | (TXT_COLOR_BLUE << 4);
+    }
+
+    // Draw the top and bottom banners
+
+    p = screendata;
+
+    for (i=0; i<TXT_SCREEN_W; ++i)
+    {
+        *p++ = ' ';
+        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
+    }
+
+    p = screendata + (TXT_SCREEN_H - 1) * TXT_SCREEN_W * 2;
+
+    for (i=0; i<TXT_SCREEN_W; ++i)
+    {
+        *p++ = ' ';
+        *p++ = TXT_COLOR_BLACK | (TXT_COLOR_GREY << 4);
+    }
+
+    // Print the title
+
+    TXT_GotoXY(0, 0);
+    TXT_FGColor(TXT_COLOR_BLACK);
+    TXT_BGColor(TXT_COLOR_GREY, 0);
+
+    TXT_PutChar(' ');
+    TXT_Puts(title);
+}
+
+void TXT_SetDesktopTitle(char *title)
+{
+    free(desktop_title);
+    desktop_title = strdup(title);
+}
+
+void TXT_DrawDesktop(void)
+{
+    int i;
+    char *title;
+
+    if (desktop_title == NULL)
+        title = "";
+    else
+        title = desktop_title;
+
+    DrawDesktopBackground(title);
+
+    for (i=0; i<num_windows; ++i)
+    {
+        TXT_DrawWindow(all_windows[i]);
+    }
+
+    TXT_UpdateScreen();
+}
+
--- /dev/null
+++ b/textscreen/txt_desktop.h
@@ -1,0 +1,37 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id$
+//
+// Copyright(C) 1993-1996 Id Software, Inc.
+// Copyright(C) 2006 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.
+//
+
+#ifndef TXT_DESKTOP_H
+#define TXT_DESKTOP_H
+
+#include "txt_window.h"
+
+void TXT_AddDesktopWindow(txt_window_t *win);
+void TXT_RemoveDesktopWindow(txt_window_t *win);
+void TXT_SetDesktopTitle(char *title);
+void TXT_DrawDesktop(void);
+
+#endif /* #ifndef TXT_DESKTOP_T */
+
+
--- a/textscreen/txt_gui.c
+++ b/textscreen/txt_gui.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: txt_gui.c 291 2006-01-13 23:56:00Z fraggle $
+// $Id: txt_gui.c 483 2006-05-19 19:57:59Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -48,7 +48,7 @@
     {0xc0, 0xc4, 0xc1, 0xd9},
 };
 
-void TXT_DrawDesktop(char *title)
+void TXT_DrawDesktopBackground(char *title)
 {
     int i;
     unsigned char *screendata;
@@ -114,7 +114,7 @@
     }
 }
 
-void TXT_DrawWindow(char *title, int x, int y, int w, int h)
+void TXT_DrawWindowFrame(char *title, int x, int y, int w, int h)
 {
     int x1, y1;
     int bx, by;
--- a/textscreen/txt_gui.h
+++ b/textscreen/txt_gui.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: txt_gui.h 291 2006-01-13 23:56:00Z fraggle $
+// $Id: txt_gui.h 483 2006-05-19 19:57:59Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -42,8 +42,8 @@
 #ifndef TXT_GUI_H
 #define TXT_GUI_H
 
-void TXT_DrawDesktop(char *title);
-void TXT_DrawWindow(char *title, int x, int y, int w, int h);
+void TXT_DrawDesktopBackground(char *title);
+void TXT_DrawWindowFrame(char *title, int x, int y, int w, int h);
 void TXT_DrawSeparator(int x, int y, int w);
 
 #endif /* #ifndef TXT_GUI_H */
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -25,38 +25,12 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "txt_desktop.h"
 #include "txt_gui.h"
+#include "txt_main.h"
 #include "txt_separator.h"
 #include "txt_window.h"
 
-#define MAXWINDOWS 128
-
-static char *desktop_title;
-static txt_window_t *all_windows[MAXWINDOWS];
-static int num_windows = 0;
-
-static void AddWindow(txt_window_t *win)
-{
-    all_windows[num_windows] = win;
-    ++num_windows;
-}
-
-static void RemoveWindow(txt_window_t *win)
-{
-    int from, to;
-
-    for (from=0, to=0; from<num_windows; ++from)
-    {
-        if (all_windows[from] != win)
-        {
-            all_windows[to] = all_windows[from];
-            ++to;
-        }
-    }
-    
-    num_windows = to;
-}
-
 txt_window_t *TXT_NewWindow(char *title, int x, int y)
 {
     txt_window_t *win;
@@ -70,7 +44,7 @@
     win->num_widgets = 0;
     win->selected = 0;
 
-    AddWindow(win);
+    TXT_AddDesktopWindow(win);
 
     return win;
 }
@@ -92,7 +66,7 @@
     free(window->title);
     free(window);
 
-    RemoveWindow(window);
+    TXT_RemoveDesktopWindow(window);
 }
 
 static void TXT_WindowSize(txt_window_t *window, int *w, int *h)
@@ -115,7 +89,7 @@
     *h = window->num_widgets;
 }
 
-static void DrawWindow(txt_window_t *window)
+void TXT_DrawWindow(txt_window_t *window)
 {
     int widgets_w, widgets_h;
     int window_w, window_h;
@@ -138,7 +112,7 @@
 
     // Draw the window
 
-    TXT_DrawWindow(window->title, window_x, window_y, window_w, window_h);
+    TXT_DrawWindowFrame(window->title, window_x, window_y, window_w, window_h);
 
     // Draw all widgets
 
@@ -151,32 +125,6 @@
     // Separator for action area
 
     TXT_DrawSeparator(window_x, window_y + 2 + window->num_widgets, window_w);
-}
-
-void TXT_SetDesktopTitle(char *title)
-{
-    free(desktop_title);
-    desktop_title = strdup(title);
-}
-
-void TXT_DrawAllWindows(void)
-{
-    int i;
-    char *title;
-
-    if (desktop_title == NULL)
-        title = "";
-    else
-        title = desktop_title;
-
-    TXT_DrawDesktop(title);
-
-    for (i=0; i<num_windows; ++i)
-    {
-        DrawWindow(all_windows[i]);
-    }
-
-    TXT_UpdateScreen();
 }
 
 void TXT_AddWidget(txt_window_t *window, void *uncast_widget)
--- a/textscreen/txt_window.h
+++ b/textscreen/txt_window.h
@@ -52,8 +52,6 @@
 txt_window_t *TXT_NewWindow(char *title, int x, int y);
 void TXT_CloseWindow(txt_window_t *window);
 void TXT_AddWidget(txt_window_t *window, void *widget);
-void TXT_SetDesktopTitle(char *title);
-void TXT_DrawAllWindows(void);
 
 #endif /* #ifndef TXT_WINDOW_T */