File: med.c

package info (click to toggle)
xbat 1.11-9
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,236 kB
  • ctags: 796
  • sloc: ansic: 6,298; makefile: 654; sh: 63
file content (298 lines) | stat: -rw-r--r-- 6,119 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#define _MAIN

#include "xev.h"
#include "back.h"

int map_y = 0;
int c_no = 0;

PRIVATE Pixmap pixmap[CHIJOU];
PRIVATE GC gc[CHIJOU];
PRIVATE char inkey = 0;

void MSetChar()
{
      int c_no;
      char img[CSIZE*CSIZE],mask[128];
      XGCValues gcv;

      gcv.graphics_exposures = True;

      for(c_no = 0 ; c_no < CHIJOU ; c_no++) {
            int x,y;



	    sprintf(tpath , "./Image/%s",fn[c_no]);

	    fprintf(stderr,"%d %s",c_no,tpath);

            LoadChar(tpath,img , sizeof(img));
	    fprintf(stderr,"lll");
	    
            pixmap[c_no] = XCreatePixmap(d,w,CSIZE,CSIZE,depth);
	    fprintf(stderr,"ppp");

            gc[c_no] = XCreateGC(d,w,GCGraphicsExposures,&gcv);
	    fprintf(stderr,"ggggg");

            DrawChar32(img , mask , gc[c_no],pixmap[c_no]);
	    fprintf(stderr,"mmmm\n");
      }
}

void Init()
{

      InitWin(1);
      MSetChar();
      fprintf(stderr,"mpa");
      memset(map , 1 , sizeof(map));
      map_y = YMAP - 18;
      XSetForeground(d,back_gc,pixel[41]);
      XDrawLine(d,w,back_gc,XSIZE+99,50,XSIZE+99,270);
}
      
void Inkey()
{
      int i, k;
      KeySym ks;
      char mask;
      
      
      while (XPending(d) > 0){
            mask = 0;
            XNextEvent(d, &e);
            switch (e.type){
		case KeyPress:
		case KeyRelease:
		  switch (XKeycodeToKeysym(d, e.xkey.keycode, 0)){
		      case XK_Up: 
		      case XK_KP_8:
		      case XK_i:
			mask = (1<<Up); break;
		      case XK_Down: 
		      case XK_KP_2:
		      case XK_KP_5:
		      case XK_k:
		      case XK_m:
			mask = (1<<Down); break;
		      case XK_Left: 
		      case XK_KP_4:
		      case XK_j:
			mask = (1<<Left); break;
		      case XK_Right: 
		      case XK_KP_6:
			mask = (1<<Right); break;
		      case XK_x: mask = (rev_key)?(1<<Kx):(1<<Kz); break;
		      case XK_z: mask = (rev_key)?(1<<Kz):(1<<Kx); break;
		      case XK_s: mask = (1<<Ks); break;
		      case XK_l: mask = (1<<Kq); break;
		  }
		  if (e.type == KeyPress) inkey |= mask;
		  else inkey &= ~mask;
		  break;
	    }
      }
}

void Save()
{
      char fn[256];
      FILE *fp;

      fprintf(stderr,"Input Save Filename ? ");
      fscanf(stdin,"%s",fn);
      
      if((fp = fopen(fn,"wb")) != NULL) {
	    if(fwrite(map ,sizeof(map),1,fp) != 1)
	      {
		    fprintf(stderr,"Write Error !!\n");
		    fclose(fp);
		    return;
	      }
	    fclose(fp);
      } else {
	    fprintf(stderr,"Error!\n");
      }
}

void Load()
{
      char fn[256];
      FILE *fp;
      
      fprintf(stderr,"Input Load Filename ? ");
      fscanf(stdin,"%s",fn);
      
      if((fp = fopen(fn,"rb")) != NULL) {
	    if(fread(map ,sizeof(map),1,fp) != 1)
	      {
		    fprintf(stderr,"Write Error !!\n");
		    fclose(fp);
		    return;
	      }
	    fclose(fp);
      }else{
	    fprintf(stderr,"Error!\n");
      }
}

void PutChar(x,y,s)
     int x,y,s;
{
      int px,py,wx,wy;

      wx = (x/32)*32;
      wy = (y/32)*32;

      for(py = wy ; py < wy+s*32 ; py+=32)
	for(px = wx ; px < wx+s*32 ; px+=32) {
	      if(px <  XSIZE && py < YSIZE) {
		    map[py/32+map_y][px/32] = c_no;
      
		    XCopyArea(d,pixmap[c_no],w,back_gc,0,0,CSIZE,CSIZE,px,py);
	      }
	}
      XFlush(d);
      u_sleep(30000);
}

void MPutChar(x,y)
     int x,y;
{
      int wx,wy;

      wx = (x/32)*32;
      wy = (y/32)*32;

      XCopyArea(d,pixmap[c_no],w,back_gc,0,0,CSIZE,CSIZE,wx,wy);
      XFlush(d);
      u_sleep(30000);
}


void DrawMap()
{
      int x,y;
      char msg[10];
      for(y = 0 ; y < 19 ; y++) 
	for(x = 0 ; x < XMAP ; x++) 
	  XCopyArea(d,pixmap[map[map_y+y][x]],w,back_gc,0,0,CSIZE,CSIZE,x*32,y*32);
      XSetForeground(d,back_gc,pixel[0]);
      XFillRectangle(d,w,back_gc,XSIZE+100,50,20,220);
      XFillRectangle(d,w,back_gc,XSIZE+20,450,200,50);
      
      XSetForeground(d,back_gc,pixel[41]);
      XDrawLine(d,w,back_gc,XSIZE+100,50+map_y,XSIZE+115,50+map_y);
      XSetForeground(d,font_gc,pixel[20]);
      sprintf(msg,"%d",map_y+1);
      XDrawString(d,w,font_gc,XSIZE+20,500,msg,10);
      for(x = 1 ; x < 15 ; x++)
	XDrawLine(d,w,font_gc,x*CSIZE,0,x*CSIZE,YSIZE);
      
      for(x = 0 ; x < 30 ; x++) {
	    char c[3];

	    sprintf(c,"%d",x);
	    XDrawString(d,w,font_gc,x*CSIZE/2,20,c , 2);
      }

      XFlush(d);
}

	  
main()
{
      Window r,child;
      int rx,ry;
      unsigned int mask;
      int mx,my;

      Init();
      fprintf(stderr,"jkjj");
      while(1)
        {
              u_sleep(30000);

              XQueryPointer(d,w,&r,&child,&rx,&ry,&mx,&my,&mask);
	      

	      Inkey();

	      switch(inkey&15) {
		  case 1:
		    if(map_y > 0) {
			  map_y--;
			  DrawMap();
			  u_sleep(10000);
		    }
		    break;
		  case 2:
		    if(map_y < YMAP - 18) {
			  map_y++;
			  DrawMap();
			  u_sleep(10000);
                    }
		    break;
	      }
	      
	      if(inkey & (1<<Right)) {
		    if(c_no < CHIJOU-1)
		      c_no++;
		    MPutChar(XSIZE,0);
		    fprintf(stderr,"%s ",fn[c_no]);
		    u_sleep(30000);
	      }
	      
	      if(inkey & (1<<Left)) {
                    if(c_no > 0)
		      c_no--;
		    fprintf(stderr,"%s ",fn[c_no]);

		    MPutChar(XSIZE,0);
		    u_sleep(30000);
              }

	      if(inkey & (1<<Kx)) {
                    if(c_no > 10)
		      c_no-=10;
		    fprintf(stderr,"%s ",fn[c_no]);

		    MPutChar(XSIZE,0);
		    u_sleep(30000);
	      }
	      
	      if(inkey & (1<<Kz)) {
                    if(c_no < CHIJOU-10)
                      c_no+=10;
                    fprintf(stderr,"%s ",fn[c_no]);

                    MPutChar(XSIZE,0);
                    u_sleep(30000);
              }


	      if(inkey & (1<<Ks)) {
		    Save();
              }
	      
	      if(inkey & (1<<Kq)) {
		    Load();
              }

	      if(mask == Button1Mask && mx < XSIZE && my < YSIZE)
		PutChar(mx,my,1);

	      /*if(inkey & (1<< Kx) && mx < XSIZE && my < YSIZE)
                PutChar(mx,my,1);*/

	      if(mask == Button2Mask && mx < XSIZE && my < YSIZE)
                PutChar(mx,my,2);

	      if(mask == Button3Mask && mx < XSIZE && my < YSIZE)
                PutChar(mx,my,4);

	}
}