ref: 6ecffa76f732fdc20873c1611723843464ac485a
parent: 62b5f953677addeebac38ab6774599bbbab130f0
author: Simon Howard <fraggle@gmail.com>
date: Sat May 20 13:37:57 EDT 2006
Checkbox class Subversion-branch: /trunk/chocolate-doom Subversion-revision: 491
--- a/textscreen/Makefile.am
+++ b/textscreen/Makefile.am
@@ -5,6 +5,7 @@
bin_PROGRAMS=guitest
libtextscreen_a_SOURCES = \
+ txt_checkbox.c txt_checkbox.h \
txt_desktop.c txt_desktop.h \
txt_gui.c txt_gui.h \
txt_io.c txt_io.h \
--- /dev/null
+++ b/textscreen/txt_checkbox.c
@@ -1,0 +1,101 @@
+
+#include <string.h>
+
+#include "doomkeys.h"
+
+#include "txt_checkbox.h"
+#include "txt_io.h"
+#include "txt_main.h"
+#include "txt_window.h"
+
+static int TXT_CheckBoxSizeCalc(txt_widget_t *widget)
+{
+ txt_checkbox_t *checkbox = (txt_checkbox_t *) widget;
+
+ // Minimum width is the string length + two spaces for padding
+
+ return strlen(checkbox->label) + 6;
+}
+
+static void TXT_CheckBoxDrawer(txt_widget_t *widget, int w, int selected)
+{
+ txt_checkbox_t *checkbox = (txt_checkbox_t *) widget;
+ int i;
+
+ TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
+ TXT_DrawString(" (");
+
+ TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
+
+ if (*checkbox->variable)
+ {
+ TXT_DrawString("\x07");
+ }
+ else
+ {
+ TXT_DrawString(" ");
+ }
+
+ TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
+
+ TXT_DrawString(") ");
+
+ if (selected)
+ {
+ TXT_BGColor(TXT_COLOR_GREY, 0);
+ }
+
+ TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
+
+ TXT_DrawString(checkbox->label);
+
+ for (i=strlen(checkbox->label); i < w-6; ++i)
+ {
+ TXT_DrawString(" ");
+ }
+}
+
+static void TXT_CheckBoxDestructor(txt_widget_t *widget)
+{
+ txt_checkbox_t *checkbox = (txt_checkbox_t *) widget;
+
+ free(checkbox->label);
+}
+
+static int TXT_CheckBoxKeyPress(txt_widget_t *widget, int key)
+{
+ txt_checkbox_t *checkbox = (txt_checkbox_t *) widget;
+
+ if (key == KEY_ENTER || key == ' ')
+ {
+ *checkbox->variable = !*checkbox->variable;
+ return 1;
+ }
+
+ return 0;
+}
+
+txt_widget_class_t txt_checkbox_class =
+{
+ TXT_CheckBoxSizeCalc,
+ TXT_CheckBoxDrawer,
+ TXT_CheckBoxKeyPress,
+ TXT_CheckBoxDestructor,
+};
+
+txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable)
+{
+ txt_checkbox_t *checkbox;
+
+ checkbox = malloc(sizeof(txt_checkbox_t));
+
+ checkbox->widget.widget_class = &txt_checkbox_class;
+ checkbox->widget.selectable = 1;
+ checkbox->widget.visible = 1;
+ checkbox->label = strdup(label);
+ checkbox->variable = variable;
+
+ return checkbox;
+}
+
--- /dev/null
+++ b/textscreen/txt_checkbox.h
@@ -1,0 +1,43 @@
+// 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_CHECKBOX_H
+#define TXT_CHECKBOX_H
+
+typedef struct txt_checkbox_s txt_checkbox_t;
+
+#include "txt_widget.h"
+
+struct txt_checkbox_s
+{
+ txt_widget_t widget;
+ char *label;
+ int *variable;
+};
+
+txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable);
+
+#endif /* #ifndef TXT_CHECKBOX_H */
+
+