ref: 1ba69c88d26b33fbec2af21172bb52ad214b0f2a
parent: f761f821f95a3fbf8af1eb645d8ae9412abdc541
author: Simon Howard <[email protected]>
date: Sat May 20 11:45:36 EDT 2006
Clip windows against the workspace boundaries. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 487
--- a/textscreen/txt_button.c
+++ b/textscreen/txt_button.c
@@ -23,7 +23,7 @@
TXT_BGColor(TXT_COLOR_BLUE, 0);
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
- TXT_PutChar(' ');
+ TXT_DrawString(" ");
if (selected)
{
@@ -30,14 +30,11 @@
TXT_BGColor(TXT_COLOR_GREY, 0);
}
- for (i=0; i<strlen(button->label); ++i)
- {
- TXT_PutChar(button->label[i]);
- }
+ TXT_DrawString(button->label);
for (i=strlen(button->label); i < w-2; ++i)
{
- TXT_PutChar(' ');
+ TXT_DrawString(" ");
}
}
--- a/textscreen/txt_gui.c
+++ b/textscreen/txt_gui.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: txt_gui.c 486 2006-05-20 15:15:17Z fraggle $
+// $Id: txt_gui.c 487 2006-05-20 15:45:36Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -30,6 +30,7 @@
#include <string.h>
+#include "txt_gui.h"
#include "txt_io.h"
#include "txt_main.h"
@@ -48,6 +49,9 @@
{0xc0, 0xc4, 0xc1, 0xd9},
};
+#define VALID_X(y) ((y) >= 0 && (y) < TXT_SCREEN_W)
+#define VALID_Y(y) ((y) >= 1 && (y) < TXT_SCREEN_H - 1)
+
void TXT_DrawDesktopBackground(char *title)
{
int i;
@@ -90,8 +94,8 @@
TXT_FGColor(TXT_COLOR_BLACK);
TXT_BGColor(TXT_COLOR_GREY, 0);
- TXT_PutChar(' ');
- TXT_Puts(title);
+ TXT_DrawString(" ");
+ TXT_DrawString(title);
}
void TXT_DrawShadow(int x, int y, int w, int h)
@@ -108,8 +112,7 @@
for (x1=x; x1<x+w; ++x1)
{
- if (x1 >= 0 && x1 < TXT_SCREEN_W
- && y1 >= 0 && y1 < TXT_SCREEN_H)
+ if (VALID_X(x1) && VALID_Y(y1))
{
p[1] = TXT_COLOR_DARK_GREY;
}
@@ -129,8 +132,6 @@
for (y1=y; y1<y+h; ++y1)
{
- TXT_GotoXY(x, y1);
-
// Select the appropriate row and column in the borders
// array to pick the appropriate character to draw at
// this location.
@@ -147,7 +148,11 @@
bx = x1 == x ? 0 :
x1 == x + w - 1 ? 3 : 1;
- TXT_PutChar(borders[by][bx]);
+ if (VALID_X(x1) && VALID_Y(y1))
+ {
+ TXT_GotoXY(x1, y1);
+ TXT_PutChar(borders[by][bx]);
+ }
}
}
@@ -159,11 +164,11 @@
for (x1=0; x1<w-2; ++x1)
{
- TXT_PutChar(' ');
+ TXT_DrawString(" ");
}
TXT_GotoXY(x + (w - strlen(title)) / 2, y + 1);
- TXT_Puts(title);
+ TXT_DrawString(title);
// Draw the window's shadow.
@@ -179,6 +184,11 @@
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_BGColor(TXT_COLOR_BLUE, 0);
+ if (!VALID_Y(y))
+ {
+ return;
+ }
+
for (x1=x; x1<x+w; ++x1)
{
TXT_GotoXY(x1, y);
@@ -187,7 +197,38 @@
x1 == x + w - 1 ? borders[2][3] :
borders[2][1];
- TXT_PutChar(c);
+ if (VALID_X(x1))
+ {
+ TXT_PutChar(c);
+ }
}
+}
+
+void TXT_DrawString(char *s)
+{
+ int x, y;
+ int x1;
+ char *p;
+
+ TXT_GetXY(&x, &y);
+
+ if (VALID_Y(y))
+ {
+ p = s;
+ x1 = x;
+
+ for (p = s; *p != '\0'; ++p)
+ {
+ if (VALID_X(x1))
+ {
+ TXT_GotoXY(x1, y);
+ TXT_PutChar(*p);
+ }
+
+ x1 += 1;
+ }
+ }
+
+ TXT_GotoXY(x + strlen(s), y);
}
--- a/textscreen/txt_gui.h
+++ b/textscreen/txt_gui.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: txt_gui.h 483 2006-05-19 19:57:59Z fraggle $
+// $Id: txt_gui.h 487 2006-05-20 15:45:36Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -45,6 +45,7 @@
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);
+void TXT_DrawString(char *s);
#endif /* #ifndef TXT_GUI_H */
--- a/textscreen/txt_separator.c
+++ b/textscreen/txt_separator.c
@@ -42,14 +42,9 @@
TXT_BGColor(TXT_COLOR_BLUE, 0);
TXT_FGColor(TXT_COLOR_BRIGHT_GREEN);
- TXT_PutChar(' ');
-
- for (i=0; i<strlen(separator->label); ++i)
- {
- TXT_PutChar(separator->label[i]);
- }
-
- TXT_PutChar(' ');
+ TXT_DrawString(" ");
+ TXT_DrawString(separator->label);
+ TXT_DrawString(" ");
}
}