shithub: choc

Download patch

ref: 9ee3b53c8ea0b4d731cd7dbdb876a5422e144b82
parent: c4c79440c404fabc7a77e1d4561ff707e223233a
author: Simon Howard <[email protected]>
date: Mon Oct 23 03:13:16 EDT 2006

Stackable clip areas (useful for a future implementation of scrollable
panes).

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

--- a/textscreen/txt_desktop.c
+++ b/textscreen/txt_desktop.c
@@ -118,6 +118,8 @@
     int i;
     char *title;
 
+    TXT_InitClipArea();
+
     if (desktop_title == NULL)
         title = "";
     else
--- a/textscreen/txt_gui.c
+++ b/textscreen/txt_gui.c
@@ -25,6 +25,15 @@
 #include "txt_io.h"
 #include "txt_main.h"
 
+typedef struct txt_cliparea_s txt_cliparea_t;
+
+struct txt_cliparea_s
+{
+    int x1, x2;
+    int y1, y2;
+    txt_cliparea_t *next;
+};
+
 // Array of border characters for drawing windows. The array looks like this:
 //
 // +-++
@@ -32,7 +41,7 @@
 // +-++
 // +-++
 
-static int borders[4][4] = 
+static const int borders[4][4] = 
 {
     {0xda, 0xc4, 0xc2, 0xbf},
     {0xb3, ' ',  0xb3, 0xb3},
@@ -40,9 +49,11 @@
     {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)
+static txt_cliparea_t *cliparea = NULL;
 
+#define VALID_X(x) ((x) >= cliparea->x1 && (x) < cliparea->x2)
+#define VALID_Y(y) ((y) >= cliparea->y1 && (y) < cliparea->y2)
+
 void TXT_DrawDesktopBackground(char *title)
 {
     int i;
@@ -238,5 +249,63 @@
     }
 
     TXT_GotoXY(x + strlen(s), y);
+}
+
+void TXT_InitClipArea(void)
+{
+    if (cliparea == NULL)
+    {
+        cliparea = malloc(sizeof(txt_cliparea_t));
+        cliparea->x1 = 0;
+        cliparea->x2 = TXT_SCREEN_W;
+        cliparea->y1 = 1;
+        cliparea->y2 = TXT_SCREEN_H - 1;
+        cliparea->next = NULL;
+    }
+}
+
+void TXT_PushClipArea(int x1, int x2, int y1, int y2)
+{
+    txt_cliparea_t *newarea;
+
+    newarea = malloc(sizeof(txt_cliparea_t));
+
+    // Set the new clip area to the intersection of the old
+    // area and the new one.
+
+    newarea->x1 = cliparea->x1;
+    newarea->x2 = cliparea->x2;
+    newarea->y1 = cliparea->y1;
+    newarea->y2 = cliparea->y2;
+
+    if (x1 > newarea->x1)
+        newarea->x1 = x1;
+    if (x2 < newarea->x2)
+        newarea->x2 = x2;
+    if (y1 > newarea->x1)
+        newarea->y1 = y1;
+    if (y2 < newarea->y2)
+        newarea->y2 = y2;
+
+    // Hook into the list
+    
+    newarea->next = cliparea;
+    cliparea = newarea;
+}
+
+void TXT_PopClipArea(void)
+{
+    txt_cliparea_t *next_cliparea;
+
+    // Never pop the last entry
+
+    if (cliparea->next == NULL)
+        return;
+
+    // Unlink the last entry and delete
+   
+    next_cliparea = cliparea->next;
+    free(cliparea);
+    cliparea = next_cliparea;
 }
 
--- a/textscreen/txt_gui.h
+++ b/textscreen/txt_gui.h
@@ -32,5 +32,9 @@
 void TXT_DrawSeparator(int x, int y, int w);
 void TXT_DrawString(char *s);
 
+void TXT_InitClipArea(void);
+void TXT_PushClipArea(int x1, int x2, int y1, int y2);
+void TXT_PopClipArea(void);
+
 #endif /* #ifndef TXT_GUI_H */