1 
2 #ifndef __global_h
3 #	include "global.H"
4 #endif
5 #ifndef __tile_h
6 #	include "tile.H"
7 #endif
8 #ifndef __port_h
9 #	include "port.H"
10 #endif
11 #ifndef __font_h
12 #	include "font.H"
13 #endif
14 
15 #ifndef __smiletab_H
16 #	include "smiletab.H"
17 #endif
18 
19 #ifndef __mem_image_h
20 #	include "mem_image.H"
21 #endif
22 
23 #ifdef HUBSYM
24 /*
25  * to use special ContronicS cyrillic font of Hartmann&Braun
26  */
27 static unsigned char cyr_lock_flag[] = {
28 	1,1,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* 00 - 0f */
29 	1,1,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* 10 - 1f */
30 	1,1,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* 20 - 2f */
31 	0,0,0,0,  0,0,0,0,  0,0,1,1,  1,1,1,1,		/* 30 - 3f */
32 
33 	1,1,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* 40 - 4f */
34 	1,1,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* 50 - 5f */
35 	1,1,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* 60 - 6f */
36 	1,1,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* 70 - 7f */
37 
38 	1,1,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* 80 - 8f */
39 	1,1,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* 90 - 9f */
40 	1,0,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1,		/* a0 - af */
41 	0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,		/* b0 - bf */
42 
43 	0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,		/* c0 - cf */
44 	0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,		/* d0 - df */
45 	0,0,0,0,  0,0,0,0,  0,0,0,0,  0,0,0,0,		/* e0 - ef */
46 	1,0,1,1,  1,1,1,1,  1,1,1,1,  1,1,1,1		/* f0 - ff */
47 };
48 
49 /*
50  * to use special ContronicS symbol font of Hartmann&Braun
51  */
52 static unsigned char symb_lock_flag[] = {
53    1, 0, 0, 0, 0, 0, 0, 0,   0, 1, 0, 0, 0, 0, 0, 0,
54    0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 1, 1, 0,
55    1, 0, 0, 1, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
56    0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
57    0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
58    0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
59    0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 1, 1,
60    1, 1, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
61    0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 0, 0, 0, 0,
62    0, 0, 0, 0, 0, 0, 0, 0,   0, 0, 0, 0, 1, 0, 1, 1,
63    1
64 };
65 #endif
66 
67 int Tile::used_syms[128];
68 
init_used_syms(int n)69 void Tile::init_used_syms(int n) {
70 char help[256];
71 int i,j;
72 
73 	memset(help,0,sizeof(help));
74 	switch( Port::def_mode ) {
75 #ifdef HUBSYM
76 	case Cyrillic:
77 		memcpy(help,cyr_lock_flag,sizeof(cyr_lock_flag));
78 		for (i=0;i<n;i++) {
79 			do {
80 				j=rand()%sizeof(cyr_lock_flag);
81 			}
82 			while(help[j]);
83 			help[j]=1;
84 			used_syms[i] = j;
85 		}
86 		break;
87 	case Symbol:
88 		memcpy(help,symb_lock_flag,sizeof(symb_lock_flag));
89 		for (i=0;i<n;i++) {
90 			do {
91 				j=rand()%sizeof(symb_lock_flag);
92 			}
93 			while(help[j]);
94 			help[j]=1;
95 			used_syms[i] = j;
96 		}
97 		break;
98 #endif
99 	case Photo:
100 		if ( !Port::gif ) {
101 			fprintf( stderr, "gif-file not yet loaded\n" );
102 			exit(0);
103 		}
104 		if (n>Port::gif->PicNum()) {
105 			fprintf( stderr, "sorry - no enough tiles in picture file\n" );
106 			exit(0);
107 		}
108 		for (i=0;i<n;i++) {
109 			do {
110 				if (rand()%1==0)	j=rand()%Port::gif->PicNum();
111 				else					j=rand()%(Port::gif->PicNum()/2);
112 			}
113 			while(help[j]);
114 			help[j]=1;
115 			used_syms[i] = j;
116 		}
117 		break;
118 
119 	default:
120 		for (i=0;i<((n<7)?n:7);i++)
121 			used_syms[i]=i;		// always used the standard smileys
122 
123 		for (   ;i<n;i++) {
124 			used_syms[i]=rand()%(sizeof(smiletab)/sizeof(char*));
125 			for (j=0;j<i;j++) {
126 				if (used_syms[i]==used_syms[j]) {
127 					i--;
128 					break;
129 				}
130 			}
131 		}
132 		break;
133 	}
134 }
135 
136 /*----------------------------------------------------------------------------*/
137 #define	DATA_TYPE	unsigned long
138 #define	DATA_PAD		32
CopyImage32(Port * p,int id)139 void Tile::CopyImage32( Port *p, int id ) {
140 #	include "reset_image.h"
141 }
142 #undef DATA_TYPE
143 #undef DATA_PAD
144 /*----------------------------------------------------------------------------*/
145 #define	DATA_TYPE	unsigned short
146 #define	DATA_PAD		16
CopyImage16(Port * p,int id)147 void Tile::CopyImage16( Port *p, int id ) {
148 #	include "reset_image.h"
149 }
150 #undef DATA_TYPE
151 #undef DATA_PAD
152 /*----------------------------------------------------------------------------*/
153 #define	DATA_TYPE	unsigned char
154 #define	DATA_PAD		8
CopyImage8(Port * p,int id)155 void Tile::CopyImage8( Port *p, int id ) {
156 #	include "reset_image.h"
157 }
158 #undef DATA_TYPE
159 #undef DATA_PAD
160 /*----------------------------------------------------------------------------*/
161 
162 
163 
Tile(Port * p,ScalableFont * font,int id)164 Tile::Tile( Port *p, ScalableFont *font, int id )
165 {
166 char buffer[40];
167 
168 #ifdef HUBSYM
169 	if (p->mode==Cyrillic||p->mode==Symbol) {
170 		buffer[0] = (id>=0)?used_syms[id]:32;
171 		buffer[1] = 0;
172 	}
173 	else
174 #endif
175 	if (p->mode==Smiley) {
176 		if (id>=0)	strcpy(buffer,smiletab[used_syms[id]]);
177 		else			strcpy(buffer,"");
178 	}
179 	else {
180 // check justification of sign
181 		if ((id>=0)&&(id<=9))	buffer[0] = id+48;
182 		if ((id>=10)&&(id<=35))	buffer[0] = id-10+65;
183 		if ((id>=36)&&(id<=61))	buffer[0] = id-36+97;
184 		if (id>61)					buffer[0] = id-62+60;
185 		if (id>67)					buffer[0] = id-67+33;
186 		buffer[1] = 0;
187 	}
188 
189 // create Pixmap
190 	display = p->display;	// for automatic destruction
191 
192 	pixmap = XCreatePixmap( display, RootWindowOfScreen(p->screen),
193 							p->sizex, p->sizey, DefaultDepthOfScreen(p->screen) );
194 
195 // Background
196 	if (Port::def_mode==Photo && id>=0) {
197 		if (DefaultDepthOfScreen(p->screen)==8)			CopyImage8(p,used_syms[id]);
198 		else if (DefaultDepthOfScreen(p->screen)==16)	CopyImage16(p,used_syms[id]);
199 		else if (DefaultDepthOfScreen(p->screen)==32)	CopyImage32(p,used_syms[id]);
200 		else if (DefaultDepthOfScreen(p->screen)==24)	CopyImage32(p,used_syms[id]);
201 		else {
202 			fprintf(stderr,"Depth %d currently not supported\n", DefaultDepthOfScreen(p->screen) );
203 			exit(0);
204 		}
205 	}
206 	else {
207 		XSetForeground( display, p->gc_all, (id!=-1)?p->bg:p->fg );
208 		XFillRectangle( display, pixmap, p->gc_all, 0, 0, p->sizex, p->sizey );
209 	}
210 
211 // TopLeft highlight
212 	XSetForeground( display, p->gc_all, (id>=-1)?p->dark:p->light);
213 	XDrawLine( display, pixmap, p->gc_all, 0, 0, p->sizex-1, 0 );
214 	XDrawLine( display, pixmap, p->gc_all, 0, 0, 0, p->sizey-1 );
215 	if (p->stipple_pmap) {
216 		if (id==-2) {
217 			XDrawLine( display, pixmap, p->gc_all, 1, 1, p->sizex-2, 1 );
218 			XDrawLine( display, pixmap, p->gc_all, 1, 1, 1, p->sizey-2 );
219 		}
220 	}
221 
222 	if (Port::def_mode!=Photo) {
223 		if (id>=0) {
224 #ifdef DoubleString
225 			font->DrawCentered(pixmap,p->gc_all,
226 									p->sizex/2+2,p->sizey/2+2, buffer);
227 #endif
228 			font->DrawCentered(pixmap,p->gc_all,
229 									p->sizex/2+1,p->sizey/2+1, buffer);
230 		}
231 	}
232 
233 // BottomRight shade
234 	XSetForeground( display, p->gc_all, (id>=-1)?p->light:p->dark);
235 	XDrawLine( display, pixmap, p->gc_all, 0, p->sizey-1, p->sizex-1, p->sizey-1);
236 	XDrawLine( display, pixmap, p->gc_all, p->sizex-1, 0, p->sizex-1, p->sizey-1);
237 	if (p->stipple_pmap) {
238 		if (id==-2) {
239 	 	XDrawLine( display, pixmap, p->gc_all, 1, p->sizey-2, p->sizex-2, p->sizey-2);
240 	 	XDrawLine( display, pixmap, p->gc_all, p->sizex-2, 1, p->sizex-2, p->sizey-2);
241 		}
242 	}
243 
244 	if (Port::def_mode!=Photo) {
245 		if (id>=0) {
246 #ifdef DoubleString
247 			font->DrawCentered(pixmap,p->gc_all,
248 									p->sizex/2-2,p->sizey/2-2, buffer);
249 #endif
250 			font->DrawCentered(pixmap,p->gc_all,
251 									p->sizex/2-1,p->sizey/2-1, buffer);
252 		}
253 	// Foreground
254 		XSetForeground( display, p->gc_all, p->fg );
255 		if (id>=0)
256 			font->DrawCentered(pixmap,p->gc_all,
257 									p->sizex/2,p->sizey/2, buffer);
258 	}
259 }
260 
261 
~Tile()262 Tile::~Tile() {
263 	XFreePixmap( display, pixmap );
264 }
265 
266