shithub: choc

Download patch

ref: 3a5668eeb63a3deae8861dd9a7f176bb773df898
parent: e40b14026828e11fb229c614bc0247edcdd90afb
author: Simon Howard <[email protected]>
date: Mon May 29 15:22:51 EDT 2006

Add strut class to allow table column width to be forced.

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

--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_gui.c 534 2006-05-26 19:15:33Z fraggle $
+// $Id: net_gui.c 539 2006-05-29 19:22:51Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -94,6 +94,7 @@
 
 #include "txt_desktop.h"
 #include "txt_label.h"
+#include "txt_strut.h"
 #include "txt_table.h"
 #include "txt_window.h"
 
@@ -130,8 +131,8 @@
     // Add spacers
 
     TXT_AddWidget(table, NULL);
-    TXT_AddWidget(table, TXT_NewLabel("                         "));
-    TXT_AddWidget(table, TXT_NewLabel("                 "));
+    TXT_AddWidget(table, TXT_NewStrut(25));
+    TXT_AddWidget(table, TXT_NewStrut(17));
 
     // Player labels
     
--- a/textscreen/Makefile.am
+++ b/textscreen/Makefile.am
@@ -18,6 +18,7 @@
 	txt_label.c              txt_label.h              \
 	txt_radiobutton.c        txt_radiobutton.h        \
 	txt_separator.c          txt_separator.h          \
+	txt_strut.c              txt_strut.h              \
 	txt_table.c              txt_table.h              \
 	txt_widget.c             txt_widget.h             \
 	txt_window.c             txt_window.h             \
--- /dev/null
+++ b/textscreen/txt_strut.c
@@ -1,0 +1,55 @@
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "doomkeys.h"
+
+#include "txt_strut.h"
+#include "txt_io.h"
+#include "txt_main.h"
+#include "txt_window.h"
+
+static void TXT_StrutSizeCalc(TXT_UNCAST_ARG(strut), int *w, int *h)
+{
+    TXT_CAST_ARG(txt_strut_t, strut);
+
+    // Minimum width is the string length + two spaces for padding
+
+    *w = strut->width;
+    *h = 0;
+}
+
+static void TXT_StrutDrawer(TXT_UNCAST_ARG(strut), int w, int selected)
+{
+    // Nothing is drawn for a strut.
+}
+
+static void TXT_StrutDestructor(TXT_UNCAST_ARG(strut))
+{
+}
+
+static int TXT_StrutKeyPress(TXT_UNCAST_ARG(strut), int key)
+{
+}
+
+txt_widget_class_t txt_strut_class =
+{
+    TXT_StrutSizeCalc,
+    TXT_StrutDrawer,
+    TXT_StrutKeyPress,
+    TXT_StrutDestructor,
+};
+
+txt_strut_t *TXT_NewStrut(int width)
+{
+    txt_strut_t *strut;
+
+    strut = malloc(sizeof(txt_strut_t));
+
+    TXT_InitWidget(strut, &txt_strut_class);
+    strut->widget.selectable = 0;
+    strut->width = width;
+
+    return strut;
+}
+
--- /dev/null
+++ b/textscreen/txt_strut.h
@@ -1,0 +1,47 @@
+// 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_STRUT_H
+#define TXT_STRUT_H
+
+typedef struct txt_strut_s txt_strut_t;
+
+#include "txt_widget.h"
+
+//
+// A strut is used to force a table to a minimum width.  It is not
+// visible but it takes up space.
+// 
+
+struct txt_strut_s
+{
+    txt_widget_t widget;
+    int width;
+};
+
+txt_strut_t *TXT_NewStrut(int width);
+
+#endif /* #ifndef TXT_STRUT_H */
+
+