1 /* $Header: /home/yav/xpx/RCS/info.c,v 1.25 1996/04/23 10:58:05 yav Exp $
2 * xpx information window
3 * written by yav (UHD98984@pcvan.or.jp)
4 */
5
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8 #include <X11/keysym.h>
9
10 #include "headers.h"
11 #include "xpx.h"
12 #include "work.h"
13 #include "infodef.h"
14 #include "icondef.h"
15 #define PUBLIC_INFO_C
16 #include "extern.h"
17
18 #define INFOWIDTH 428
19 #define INFOHEIGHT 180
20 #define INFOMNX 4
21 #define INFOMNY 4
22 #define INFOMNH 24
23
24 #define VIEWX 8
25 #define VIEWY (INFOHEIGHT-1)
26
27 char rcsid_info[] = "$Id: info.c,v 1.25 1996/04/23 10:58:05 yav Exp $";
28
29 char *infostr();
30 int infoev();
31
32 MENU infomenu[] = {
33 {
34 INFOMENU_TITLE, 0,
35 INFOMNX, INFOMNY, INFOWIDTH-INFOMNX, INFOMNH,
36 0, ExposureMask, 0,
37 NULL, infostr, 0, 64, NULL},
38 {
39 INFOMENU_MARK, 0,
40 INFOMNX, INFOMNY, 16, 16,
41 0, ExposureMask, 0,
42 infoev, NULL, 0, 0, "Rei"},
43 {
44 INFOMENU_IMGFILE, MenuModeMaskLeft,
45 INFOMNX, INFOMNY+INFOMNH*1, 400, INFOMNH,
46 0, ExposureMask, 0,
47 infoev, infostr, 0, 64, NULL},
48 {
49 INFOMENU_IMGSIZE, MenuModeMaskLeft,
50 INFOMNX, INFOMNY+INFOMNH*2, 38, INFOMNH,
51 0, ExposureMask, 0,
52 NULL, NULL, 0, 0, "size:"},
53 {
54 INFOMENU_IMGWIDTH, MenuModeMaskBorder,
55 INFOMNX+38, INFOMNY+INFOMNH*2, 40, INFOMNH,
56 0,
57 ExposureMask|EnterWindowMask|LeaveWindowMask|KeyPressMask,
58 0,
59 infoev, NULL, 0, 8, NULL},
60 {
61 INFOMENU_IMGSIZEX, 0,
62 INFOMNX+38+40+BDW*2, INFOMNY+INFOMNH*2, 16, INFOMNH,
63 0, ExposureMask, 0,
64 NULL, NULL, 0, 0, "x"},
65 {
66 INFOMENU_IMGHEIGHT, MenuModeMaskBorder,
67 INFOMNX+38+40+BDW*2+16, INFOMNY+INFOMNH*2, 40, INFOMNH,
68 0,
69 ExposureMask|EnterWindowMask|LeaveWindowMask|KeyPressMask,
70 0,
71 infoev, NULL, 0, 8, NULL},
72 {
73 INFOMENU_COLFILE, MenuModeMaskLeft,
74 INFOMNX, INFOMNY+INFOMNH*3+BDW*2, 400, INFOMNH,
75 0, ExposureMask, 0,
76 NULL, infostr, 0, 256, NULL},
77 {
78 INFOMENU_COLCOUNT, MenuModeMaskLeft,
79 INFOMNX, INFOMNY+INFOMNH*4+BDW*2, 300, INFOMNH,
80 0, ExposureMask, 0,
81 NULL, infostr, 0, 64, NULL},
82 {
83 INFOMENU_GRIDCOLOR, MenuModeMaskBorder,
84 INFOMNX, INFOMNY+INFOMNH*5+BDW*2, 100, 20,
85 0, ExposureMask|EnterWindowMask|LeaveWindowMask|ButtonPressMask, 0,
86 infoev, NULL, 0, 0, "grid color"},
87 {
88 INFOMENU_SCROLLSTOP, MenuModeMaskBorder|MenuModeMaskOn,
89 INFOMNX+100+BDW*2+4, INFOMNY+INFOMNH*5+BDW*2, 100, 20,
90 0, ExposureMask|EnterWindowMask|LeaveWindowMask|ButtonPressMask, 0,
91 infoev, NULL, 0, 0, "scroll stop"},
92 {
93 INFOMENU_GSCEL, MenuModeMaskBorder,
94 INFOMNX+100+BDW*2+4+100+BDW*2+4, INFOMNY+INFOMNH*5+BDW*2,
95 100, 20,
96 0, ExposureMask|EnterWindowMask|LeaveWindowMask|ButtonPressMask, 0,
97 infoev, NULL, 0, 0, "cel/GS"},
98 {
99 INFOMENU_GSKCF, MenuModeMaskBorder,
100 INFOMNX+100+BDW*2+4+100+BDW*2+4+100+BDW*2+4, INFOMNY+INFOMNH*5+BDW*2,
101 100, 20,
102 0, ExposureMask|EnterWindowMask|LeaveWindowMask|ButtonPressMask, 0,
103 infoev, NULL, 0, 0, "kcf/GS"},
104 {
105 INFOMENU_OK, MenuModeMaskBorder,
106 BDW*2+4, BDW*2+4, 50, 20,
107 0,
108 ExposureMask|EnterWindowMask|LeaveWindowMask|ButtonPressMask,
109 SouthEastGravity,
110 infoev, NULL, 0, 0, "OK"},
111 {
112 INFOMENU_HOTSPOT, MenuModeMaskLeft,
113 INFOMNX+156, INFOMNY+INFOMNH*2, 60, INFOMNH,
114 0, ExposureMask, 0,
115 NULL, NULL, 0, 0, "hotspot:"},
116 {
117 INFOMENU_HOTX, MenuModeMaskBorder,
118 INFOMNX+156+60, INFOMNY+INFOMNH*2, 40, INFOMNH,
119 0,
120 ExposureMask|EnterWindowMask|LeaveWindowMask|KeyPressMask,
121 0,
122 infoev, NULL, 0, 8, NULL},
123 {
124 INFOMENU_HOTSPOT2, 0,
125 INFOMNX+156+60+40+BDW*2, INFOMNY+INFOMNH*2, 12, INFOMNH,
126 0, ExposureMask, 0,
127 NULL, NULL, 0, 0, ","},
128 {
129 INFOMENU_HOTY, MenuModeMaskBorder,
130 INFOMNX+156+60+40+BDW*2+12, INFOMNY+INFOMNH*2, 40, INFOMNH,
131 0,
132 ExposureMask|EnterWindowMask|LeaveWindowMask|KeyPressMask,
133 0,
134 infoev, NULL, 0, 8, NULL},
135 {
136 INFOMENU_HOTSPOTCENTER, MenuModeMaskBorder,
137 INFOMNX, INFOMNY+INFOMNH*6+BDW*2, 100, 20,
138 0, ExposureMask|EnterWindowMask|LeaveWindowMask|ButtonPressMask, 0,
139 infoev, NULL, 0, 0, "hotspot center"},
140 {
141 INFOMENU_DEPTH, 0,
142 INFOMNX+328, INFOMNY+INFOMNH*2, 50, INFOMNH,
143 0,
144 ExposureMask,
145 0,
146 NULL, NULL, 0, 0, "depth:"},
147 {
148 INFOMENU_DEPTHN, MenuModeMaskBorder,
149 INFOMNX+328+50, INFOMNY+INFOMNH*2, 40, INFOMNH,
150 0,
151 ExposureMask|EnterWindowMask|LeaveWindowMask|KeyPressMask,
152 0,
153 infoev, NULL, 0, 8, NULL},
154 {
155 INFOMENU_IMGPOS, 0,
156 INFOMNX+450, INFOMNY+INFOMNH*2, 50, INFOMNH,
157 0,
158 ExposureMask,
159 0,
160 NULL, NULL, 0, 0, "imgpos:"},
161 {
162 INFOMENU_IMGPOSX, MenuModeMaskBorder,
163 INFOMNX+450+50, INFOMNY+INFOMNH*2, 40, INFOMNH,
164 0,
165 ExposureMask|EnterWindowMask|LeaveWindowMask|KeyPressMask,
166 0,
167 infoev, NULL, 0, 8, NULL},
168 {
169 INFOMENU_IMGPOS2, 0,
170 INFOMNX+450+50+40+BDW*2, INFOMNY+INFOMNH*2, 20, INFOMNH,
171 0,
172 ExposureMask,
173 0,
174 NULL, NULL, 0, 0, ","},
175 {
176 INFOMENU_IMGPOSY, MenuModeMaskBorder,
177 INFOMNX+450+50+40+BDW*2+20, INFOMNY+INFOMNH*2, 40, INFOMNH,
178 0,
179 ExposureMask|EnterWindowMask|LeaveWindowMask|KeyPressMask,
180 0,
181 infoev, NULL, 0, 8, NULL},
182 {
183 INFOMENU_COLPOS, 0,
184 INFOMNX+450, INFOMNY+INFOMNH*4+BDW*2, 50, INFOMNH,
185 0,
186 ExposureMask,
187 0,
188 NULL, NULL, 0, 0, "colpos:"},
189 {
190 INFOMENU_COLPOSX, MenuModeMaskBorder,
191 INFOMNX+450+50, INFOMNY+INFOMNH*4+BDW*2, 40, INFOMNH,
192 0,
193 ExposureMask|EnterWindowMask|LeaveWindowMask|KeyPressMask,
194 0,
195 infoev, NULL, 0, 8, NULL},
196 {
197 INFOMENU_COLPOS2, 0,
198 INFOMNX+450+50+40+BDW*2, INFOMNY+INFOMNH*4+BDW*2, 20, INFOMNH,
199 0,
200 ExposureMask,
201 0,
202 NULL, NULL, 0, 0, ","},
203 {
204 INFOMENU_COLPOSY, MenuModeMaskBorder,
205 INFOMNX+450+50+40+BDW*2+20, INFOMNY+INFOMNH*4+BDW*2, 40, INFOMNH,
206 0,
207 ExposureMask|EnterWindowMask|LeaveWindowMask|KeyPressMask,
208 0,
209 infoev, NULL, 0, 8, NULL},
210 {
211 -1, 0,
212 0, 0, 0, 0,
213 0, 0, 0,
214 NULL, NULL, 0, 0, NULL}
215 };
216
info_parm_set(p,n)217 void info_parm_set(p, n)
218 MENU *p;
219 int n;
220 {
221 sprintf(p->str, "%d", n);
222 p->cursor = strlen(p->str);
223 redraw_window(p->win);
224 }
225
226 /* update displaying numbers */
info_imgsize_set()227 void info_imgsize_set()
228 {
229 info_parm_set(infomenu+INFOMENU_IMGWIDTH, imgfilew);
230 info_parm_set(infomenu+INFOMENU_IMGHEIGHT, imgfileh);
231 info_parm_set(infomenu+INFOMENU_HOTX, hotspotx);
232 info_parm_set(infomenu+INFOMENU_HOTY, hotspoty);
233 info_parm_set(infomenu+INFOMENU_DEPTHN, imgfiledepth);
234 info_parm_set(infomenu+INFOMENU_IMGPOSX, imgposx);
235 info_parm_set(infomenu+INFOMENU_IMGPOSY, imgposy);
236 info_parm_set(infomenu+INFOMENU_COLPOSX, colposx);
237 info_parm_set(infomenu+INFOMENU_COLPOSY, colposy);
238 }
239
create_info_window()240 int create_info_window()
241 {
242 create_toplevel_window(&infowin, "info", str_info_geom,
243 INFOWIDTH, INFOHEIGHT);
244 XSelectInput(dsp, infowin, ExposureMask);
245
246 viewwin = XCreateSimpleWindow(dsp, infowin, VIEWX, VIEWY,
247 imgmaxw, imgmaxh, BDW, fg, bg);
248 XSelectInput(dsp, viewwin, ExposureMask|EnterWindowMask|LeaveWindowMask|
249 ButtonPressMask);
250 XMapWindow(dsp, viewwin);
251 menuwin_create(infomenu, infowin, 0, 0);
252 info_imgsize_set();
253 return 0;
254 }
255
unmap_info_window()256 void unmap_info_window()
257 {
258 infomenu[INFOMENU_OK].mode &= ~MenuModeMaskOn;
259 XUnmapWindow(dsp, infowin);
260 }
261
map_info_window()262 void map_info_window()
263 {
264 XMapRaised(dsp, infowin);
265 }
266
close_info_window()267 void close_info_window()
268 {
269 XDestroyWindow(dsp, viewwin);
270 XDestroyWindow(dsp, infowin);
271 }
272
273
infostr(p)274 char *infostr(p)
275 MENU *p;
276 {
277 switch(p->n) {
278 case INFOMENU_TITLE:
279 sprintf(p->str, "%s %s", myname, xpx_version);
280 break;
281 case INFOMENU_IMGFILE:
282 sprintf(p->str, "image file: %s", imgfilename);
283 break;
284 case INFOMENU_COLFILE:
285 sprintf(p->str, "color file: %s", colfilename);
286 break;
287 case INFOMENU_COLCOUNT:
288 sprintf(p->str, "color : %d (private %d common %d) missed: %d",
289 alloced_color,
290 alloced_private_color,
291 alloced_color - alloced_private_color,
292 missed_color
293 );
294 break;
295 }
296 return p->str;
297 }
298
alloc_vimg()299 int alloc_vimg()
300 {
301 vimg = XCreateImage(dsp, DefaultVisual(dsp, scr), DefaultDepth(dsp, scr),
302 ZPixmap, 0, None, imgfilew, imgfileh, 32, 0);
303 if (vimg == NULL)
304 return 1;
305 vimg->data = (char *)malloc(vimg->bytes_per_line * vimg->height);
306 if (vimg->data == NULL)
307 return 1;
308 return 0;
309 }
310
free_vimg()311 void free_vimg()
312 {
313 if (vimg != NULL) {
314 if (vimg->data != NULL)
315 free(vimg->data);
316 XFree((char *)vimg);
317 vimg = NULL;
318 }
319 }
320
make_view_image()321 int make_view_image()
322 {
323 if (view_sw & 1) {
324 free_vimg();
325 if (vimg == NULL) {
326 if (alloc_vimg()) {
327 message("!view image alloc error!\n");
328 return 1;
329 }
330 gen_image_subv(0, 0, imgfilew, imgfileh);
331 }
332 }
333 return 0;
334 }
335
redraw_view(ev)336 void redraw_view(ev)
337 XEvent *ev;
338 {
339 if (view_sw & 1) {
340 if (vimg == NULL && make_view_image())
341 view_sw &= ~1;
342 }
343 if (view_sw & 1) {
344 XPutImage(dsp, viewwin, gc0, vimg, ev->xexpose.x, ev->xexpose.y,
345 ev->xexpose.x, ev->xexpose.y,
346 ev->xexpose.width, ev->xexpose.height);
347 } else {
348 if (ev->xexpose.count == 0) {
349 menuwin_center(viewwin, imgmaxw, imgmaxh, "view off");
350 XDrawLine(dsp, ev->xexpose.window, gc0, 0, 0, imgmaxw-1, imgmaxh-1);
351 XDrawLine(dsp, ev->xexpose.window, gc0, imgmaxw-1, 0, 0, imgmaxh-1);
352 }
353 }
354 }
355
info_expose(ev)356 void info_expose(ev)
357 XEvent *ev;
358 {
359 if (ev->xexpose.window == viewwin)
360 redraw_view(ev);
361 }
362
363
info_press(ev)364 void info_press(ev)
365 XEvent *ev;
366 {
367 if (ev->xbutton.window == viewwin) {
368 view_sw ^= 1;
369 redraw_window(viewwin);
370 }
371 }
372
infoev(p,ev)373 int infoev(p, ev)
374 MENU *p;
375 XEvent *ev;
376 {
377 switch(ev->type) {
378 case KeyPress:
379 {
380 int i;
381 KeySym key;
382 char buf[16];
383
384 i = XLookupString((XKeyEvent *)ev, buf, sizeof(buf)-1, &key, NULL);
385 buf[i] = '\0';
386 switch(key) {
387 case XK_KP_Enter:
388 case XK_Return:
389 i = strtol(p->str, NULL, 0);
390 switch(p->n) {
391 case INFOMENU_IMGWIDTH:
392 set_image_size(i, -1);
393 break;
394 case INFOMENU_IMGHEIGHT:
395 set_image_size(-1, i);
396 break;
397 case INFOMENU_HOTX:
398 hotspotx = i;
399 set_image_size(-1, -1);
400 break;
401 case INFOMENU_HOTY:
402 hotspoty = i;
403 set_image_size(-1, -1);
404 break;
405 case INFOMENU_DEPTHN:
406 imgfiledepth = i;
407 info_imgsize_set(); /* no need to update image */
408 break;
409 case INFOMENU_IMGPOSX:
410 imgposx = i;
411 info_imgsize_set(); /* no need to update image */
412 break;
413 case INFOMENU_IMGPOSY:
414 imgposy = i;
415 info_imgsize_set(); /* no need to update image */
416 break;
417 case INFOMENU_COLPOSX:
418 colposx = i;
419 info_imgsize_set(); /* no need to update image */
420 break;
421 case INFOMENU_COLPOSY:
422 colposy = i;
423 info_imgsize_set(); /* no need to update image */
424 break;
425 }
426 }
427 }
428 return 0;
429 case ButtonPress:
430 switch(p->n) {
431 case INFOMENU_HOTSPOTCENTER:
432 p->mode ^= MenuModeMaskOn;
433 img_expose(0, 0, imgwinwidth, imgwinheight);
434 break;
435 case INFOMENU_GRIDCOLOR:
436 p->mode ^= MenuModeMaskOn;
437 XSetForeground(dsp, gridgc, (p->mode & MenuModeMaskOn)?fg:bg);
438 XSetForeground(dsp, grid0gc, (p->mode & MenuModeMaskOn)?fg:bg);
439 img_expose(0, 0, imgwinwidth, imgwinheight);
440 break;
441 case INFOMENU_OK:
442 p->mode ^= MenuModeMaskOn;
443 menu_stat_change(2, 0);
444 break;
445 default:
446 return 0;
447 }
448 redraw_window(p->win);
449 return 1;
450 case Expose:
451 switch(p->n) {
452 case INFOMENU_MARK:
453 XCopyArea(dsp, icon_pixmap(ICON_mars), p->win, gc0,
454 ev->xexpose.x, ev->xexpose.y,
455 ev->xexpose.width, ev->xexpose.height,
456 ev->xexpose.x, ev->xexpose.y);
457 return 1;
458 }
459 }
460 return 0;
461 }
462
463 /* End of file */
464