1 /* XDigger Copyright (C) 1988-99 Alexander Lang.
2
3 XDigger is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 XDigger is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
16
17 #include <stdio.h>
18 #include <X11/Xlib.h>
19 #include <X11/Xutil.h>
20
21 #include "typedef.h"
22 #include "xdigger.h"
23 #include "drawpixmaps.h"
24
25 CharEntry charfield[40][32];
26 GC gc_text;
27 XGCValues gc_text_values;
28 unsigned long gc_text_mask;
29
ClearCharField(int bg,Bool todraw)30 void ClearCharField(int bg, Bool todraw)
31 {
32 int x, y;
33 for (y=0; y<32; y++) for (x=0; x<40; x++)
34 {
35 charfield[x][y].c = '\0';
36 charfield[x][y].bg = bg;
37 charfield[x][y].todraw = todraw;
38 }
39 } /* ClearCharField(int bg, Bool todraw) */
40
DrawBitmapChar(GC gc,unsigned char c,int x,int y)41 void DrawBitmapChar(GC gc, unsigned char c, int x, int y)
42 {
43 if (c<0x20) c=0x20;
44 /* XCopyPlane(display, xbm_charset, mainwindow, gc, 0, */
45 /* (c-0x20)*8*xpmmag, 8*xpmmag, 8*xpmmag, x*8*xpmmag, y*8*xpmmag, 1); */
46 XCopyPlane(display, xbm_charset[c-0x20], mainwindow, gc,
47 0, 0, 8*xpmmag, 8*xpmmag, x*8*xpmmag, y*8*xpmmag, 1);
48 } /* DrawBitmapChar(GC gc, unsigned char c, int x, int y) */
49
DrawOneCharEntry(int x,int y)50 void DrawOneCharEntry(int x, int y)
51 {
52 if ((gc_text_values.foreground != charfield[x][y].fg) ||
53 (gc_text_values.background != charfield[x][y].bg))
54 {
55 gc_text_values.foreground = charfield[x][y].fg;
56 gc_text_values.background = charfield[x][y].bg;
57 gc_text_mask = GCForeground | GCBackground;
58 XChangeGC(display, gc_text, gc_text_mask, &gc_text_values);
59 }
60 DrawBitmapChar(gc_text, charfield[x][y].c, x, y);
61 } /* DrawOneCharEntry(int x, int y) */
62
DrawTextField()63 void DrawTextField()
64 {
65 int x, y;
66
67 for (y=0; y<32; y++) for (x=0; x<40; x++)
68 if (charfield[x][y].todraw)
69 {
70 DrawOneCharEntry(x, y);
71 charfield[x][y].todraw = False;
72 }
73 /* XFlush(display); */
74 } /* DrawTextField() */
75
WriteTextStr(const unsigned char * str,int x,int y,int fg,int bg)76 void WriteTextStr(const unsigned char *str, int x, int y, int fg, int bg)
77 {
78 int i, len;
79
80 len = strlen(str);
81 for (i=0; i<len; i++)
82 {
83 charfield[x+i][y].c = str[i];
84 charfield[x+i][y].fg = fg;
85 charfield[x+i][y].bg = bg;
86 charfield[x+i][y].todraw = True;
87 }
88 } /* WriteTextStr(const unsigned char *str, int x, int y, int fg, int bg) */
89
Mark_CharField(XExposeEvent * xexpose,int max_y)90 void Mark_CharField(XExposeEvent *xexpose, int max_y)
91 {
92 int x, xa, xe, y, ya, ye;
93
94 /*fprintf(stderr, "Mark %d \n", xpmmag);
95 fflush(stderr);*/
96 xa = (xexpose->x / (8*xpmmag));
97 xe = ((xexpose->x + xexpose->width - 1) / (8*xpmmag));
98 if (xa > 39) return;
99 if (xe > 39) xe = 39;
100 ya = (xexpose->y / (8*xpmmag));
101 ye = ((xexpose->y + xexpose->height - 1) / (8*xpmmag));
102 if (ya > max_y) return;
103 if (ye > max_y) ye = max_y;
104 for (y=ya; y<=ye; y++) for (x=xa; x<=xe; x++)
105 charfield[x][y].todraw = True;
106 } /* Mark_CharField(XExposeEvent *xexpose, int max_y) */
107