spellcast (1.0-21) xtext.c

Summary

 xtext.c |   56 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 45 insertions(+), 11 deletions(-)

    
download this patch

Patch contents

--- spellcast-1.0.orig/xtext.c
+++ spellcast-1.0/xtext.c
@@ -1,19 +1,11 @@
 #include <string.h>
+#include <stdlib.h>
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include "handwave.h"
 #include "spelllist.h"
 #include "xspell.h"
 
-#define TEXT_WID (400)
-#define TEXT_HGT (512)
-#define TEXT_X (32)
-#define TEXT_Y (32)
-
-#define MAXLINESIZE (512) /* maximum number of chars that could possibly fit
-			     in a line. If the player uses bits1, this will
-			     probably crash. Tough. */
-
 static void redraw_text_only();
 void redraw_scrollbar();
 
@@ -57,6 +49,34 @@
     py->sitext.h = TEXT_HGT;
     py->sitext.redraw = redraw_text_only;
 }
+#ifdef COLOUR
+ 
+static long check_name(struct player *py, char *str)
+{
+  char *temp;
+  int i;
+ 
+  for (i = 0; i < MAXPLAYERS; i++){
+    temp = str;
+ 
+    /* is there a name in this entry */
+ 
+    if (namelist[i]){
+ 
+      /* does it match the start of the string we were passed? */
+ 
+      if (strncmp(namelist[i], temp, strlen(namelist[i])) == 0){
+ 
+        return (col_list[i]);
+      }
+    }
+  }
+ 
+  /* return default colour */ 
+  return (BlackPixel(py->dpy, py->scn));
+}
+ 
+#endif 
 
 static void redraw_text_only(py, baronly)
 struct player *py;
@@ -65,6 +85,10 @@
     int ix, sline;
     int len, width;
 
+#ifdef COLOUR
+    long col;
+#endif 
+
     if (!baronly) {
 	/* draw text */
 	for (ix=py->sitext.top; ix<=py->sitext.nlines; ix++) {
@@ -78,6 +102,11 @@
 		len = py->lineindex[ix].len;
 	    }
 	    width = py->lineindex[ix].width;
+#ifdef COLOUR
+           /* F.Hendrikx */
+           col = check_name(py, py->linebuf+py->lineindex[ix].start);
+           XSetForeground(py->dpy, py->blackgc, col);
+#endif                                                
 	    XDrawImageString(py->dpy, py->win, py->blackgc, py->textx,
 			py->texty + py->lineheight*sline,
 			py->linebuf+py->lineindex[ix].start, len);
@@ -195,6 +224,11 @@
 
 	cx = cy;
     }
+#ifdef COLOUR
+    /* F.Hendrikx */
+    /* call redraw so that colours are correct */
+    redraw_text (py);
+#endif                                                
 }
 
 int in_scrollbar_box(si, xpos, ypos)
@@ -267,7 +301,7 @@
     return ms_Scroll;
 }
 
-int scrollbar_motion(si, xpos, ypos, button)
+void scrollbar_motion(si, xpos, ypos, button)
 struct scroll_interface *si;
 int xpos, ypos;
 int button;
@@ -290,7 +324,7 @@
     }
 }
 
-int scrollbar_release(si, xpos, ypos, button)
+void scrollbar_release(si, xpos, ypos, button)
 struct scroll_interface *si;
 int xpos, ypos;
 int button;