1 #ifndef WINDOWS
2 #include <X11/Xlib.h>
3 #endif
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include "../../../config.h"
7 
8 #undef DUMP_IMAGE
9 
10 //#define DEBUG_MODE
11 
12 #ifdef HAVE_GTK_H
13   #include <gtk/gtk.h>
14   #include <gdk/gdkkeysyms.h>
15 #ifdef WINDOWS
16   #include <gdk/gdkwindow.h>
17 #else
18   #include <gdk/gdkx.h>
19 #endif
20 #ifdef HAVE_GDK_IMLIB_H
21   #include <gdk_imlib.h>
22   #define DUMP_IMAGE 1
23 #endif
24 
25 #ifdef HAVE_GDK_PIXBUF_H
26   #include <gdk-pixbuf/gdk-pixbuf.h>
27   #define DUMP_IMAGE 1
28 #endif
29 
30 static DCL_REAL rwxold, rwyold;
31 
32 #define FACTZ  0.03          /* scaling factor */
33 
34 #ifndef TRUE
35 #define TRUE   1             /* numeric value for true  */
36 #endif
37 #ifndef FALSE
38 #define FALSE  0             /* numeric value for false */
39 #endif
40 
41 #define PAD    2.0           /* padding for workstation window */
42 #define LWDATR TRUE          /* line width  capability */
43 #define LCLATR TRUE          /* line color  capability */
44 #define LTNATR TRUE          /* hard fill   capability */
45 #define LIMATR TRUE          /* bit image   capability */
46 #define LPTATR FALSE         /* mouse point capability */
47 
48 #define MAXWDI 9             /* maximum number of line index */
49 #define MAXCLI 255           /* maximum number of line color */
50 #define MAXBMP 300           /* maximum number of bitmaps */
51 
52 #define DOPN   1
53 #define DCLS   2
54 #define PCLS   3
55 
56 static int linewidth[MAXWDI] = { 1, 2, 2, 3, 3, 4, 4, 5, 5 };
57 
58 static int iwdidz;           /* pen width */
59 static int iclidz;           /* pen color index */
60 static int iwtroz;           /* direction of frame */
61 static int lclatrz;          /* type of screen */
62 static int wsxwd, wsywd, wsxmnz, wsxmxz, wsymnz, wsymxz;
63 static int ixz, iyz, iwz, ihz, ixxz, iyyz, page; /* for image */
64 static int irxt,iryt,irxb,iryb,irwidth; /* for Invalidate */
65 static int posx, posy, wait_np, wait_op, wait_cl, key, dump, fgbg;
66 static int nbmap, nn1[MAXBMP], nn2[MAXBMP], nx[MAXBMP], ny[MAXBMP];
67 static char dmpfile[80], xtitle[80];
68 static char bmline[MAXBMP][260];
69 static int lfcmod = FALSE;
70 
71 static int lfirst = TRUE;
72 static int ltfrst = TRUE;
73 
74 static int laltz = FALSE;
75 
76 static GdkGC *gc;
77 static GdkGC *gct;
78 static GtkWidget *window = NULL;
79 static GtkWidget *drawing_area = NULL;
80 static GdkPixmap *pixmap = NULL;
81 
82 static int ldclonly = FALSE;
83 
84 static int wnd;
85 
86 #ifdef DUMP_IMAGE
87 static char imgfmt[8];
88 static DCL_REAL imgcmp;
89 #endif
90 
91 static GdkColor cx[MAXCLI];
92 
93 static int ifunc, next;
94 static int dumpz = FALSE;
95 
96 void zguprect(int,int);
97 
98 /*------------------------- GDK 設定 ------------------------*/
99 
zgupdate(int flag)100 void zgupdate(int flag)
101 {
102 
103     GdkRectangle update_rect;
104 // GdkRegion *region;
105 
106     update_rect.x = irxb-1;
107     update_rect.y = iryb-1;
108     update_rect.width = irxt-irxb+1;
109     update_rect.height = iryt-iryb+1;
110 
111     if( irxb == 0 && irxt == 0 && iryb == 0 && iryt == 0 && flag == 0){
112     update_rect.x = 0;
113     update_rect.y = 0;
114     update_rect.width = drawing_area->allocation.width;
115     update_rect.height = drawing_area->allocation.height;
116 	}
117 
118 #ifdef DEBUG_MODE
119 	printf("zgupdate %d\n");
120 #endif
121     while (gtk_events_pending())
122         gtk_main_iteration();
123     gtk_widget_draw(drawing_area, &update_rect);
124    //     if (GTK_WIDGET_VISIBLE(window) && GTK_WIDGET_DRAWABLE(drawing_area))
125    // gdk_window_process_updates(drawing_area->window, FALSE);
126 
127 //    if (flag == 1){
128 //    gtk_widget_draw(drawing_area, &update_rect);
129 //    }
130      irxt = 0;
131      irxb = 0;
132      iryt = 0;
133      iryb = 0;
134 
135 }
136 
zgsdrw_(GtkWidget * d)137 void zgsdrw_(GtkWidget *d)
138 {
139 
140   /* set/reset drawing_area */
141 #ifdef DEBUG_MODE
142 	printf("zgsdrw\n");
143 #endif
144 
145   drawing_area = d;
146 }
147 
148 /*-----------------------------------------------*/
zg_expose_event(GtkWidget * widget,GdkEventExpose * event)149 gint zg_expose_event(GtkWidget *widget, GdkEventExpose *event)
150 {
151 
152   gdk_draw_pixmap(widget->window,
153 		  widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
154 		  pixmap,
155 		  event->area.x, event->area.y,
156 		  event->area.x, event->area.y,
157 		  event->area.width, event->area.height);
158 #ifdef DEBUG_MODE
159 	printf("zg_expose_event\n");
160 #endif
161 
162   return FALSE;
163 }
164 
zg_key_press_event(GtkWidget * widget,GdkEventKey * event)165 gint zg_key_press_event(GtkWidget *widget, GdkEventKey *event)
166 {
167 #ifdef DEBUG_MODE
168 	printf("zg_key_press_event\n");
169 #endif
170 
171   switch (ifunc){
172   case DOPN:
173     next = TRUE;
174     break;
175 
176   case DCLS:
177     switch (event->keyval) {
178     case GDK_space:
179     case GDK_Return:
180       next = TRUE;
181       break;
182     default:
183       next = FALSE;
184     }
185     break;
186 
187   case PCLS:
188     switch (event->keyval) {
189     case GDK_Return:
190     case GDK_space:
191       next = TRUE;
192       break;
193     case GDK_d:
194       next = TRUE;
195       dumpz = TRUE;
196       break;
197     case GDK_s:
198       next = TRUE;
199       wait_np = FALSE;
200       break;
201     case GDK_q:
202       gtk_exit(0);
203       exit(0);
204     default:
205       next = FALSE;
206     }
207     break;
208 
209   default:
210     next = FALSE;
211   }
212 
213   return TRUE;
214 }
215 
zg_button_press_event(GtkWidget * widget,GdkEventButton * event)216 gint zg_button_press_event(GtkWidget *widget, GdkEventButton *event)
217 {
218 #ifdef DEBUG_MODE
219 	printf("zg_button_press_event\n");
220 #endif
221 
222   switch (ifunc){
223   case DOPN:
224   case DCLS:
225   case PCLS:
226     next = TRUE;
227     break;
228 
229   default:
230     next = FALSE;
231   }
232 
233   return TRUE;
234 }
235 
zg_destroy_event(GtkWidget * widget,GdkEventButton * event)236 gint zg_destroy_event(GtkWidget *widget, GdkEventButton *event)
237 {
238       gtk_exit(0);
239       exit(0);
240 
241   return TRUE;
242 }
243 /*-----------------------------------------------*/
zggdrw_(DCL_INT * width,DCL_INT * height)244 static GtkWidget *zggdrw_(DCL_INT *width, DCL_INT *height)
245 {
246   GtkWidget * drw;
247   GtkWidget *vbox;
248 #ifdef DEBUG_MODE
249 	printf("zggdrw\n");
250 #endif
251 
252   wsxwd  = *width  + 2 * PAD;  /* window width */
253   wsywd  = *height + 2 * PAD;  /* window height */
254   wsxmnz = PAD;                /* lower-left  corner */
255   wsymnz = PAD;                /* lower-left  corner */
256   wsxmxz = PAD + *width  - 1;  /* upper-right corner */
257   wsymxz = PAD + *height - 1;  /* upper-right corner */
258   page   = 0;
259 
260   gtk_init(0,NULL);
261 
262   drw = gtk_drawing_area_new();
263   gtk_drawing_area_size(GTK_DRAWING_AREA (drw), wsxwd, wsywd);
264   gtk_widget_show(drw);
265 
266   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
267   gtk_window_set_title (GTK_WINDOW (window), xtitle);
268   gtk_container_add(GTK_CONTAINER (window), drw);
269 
270   if (!wnd)
271     gtk_widget_realize(drw);
272   else {
273     if (key){
274       gtk_widget_set_events(window, GDK_BUTTON_PRESS_MASK|GDK_KEY_PRESS_MASK);
275       gtk_signal_connect(GTK_OBJECT (window), "key_press_event",
276 			 (GtkSignalFunc) zg_key_press_event, NULL);
277     } else
278       gtk_widget_set_events(window, GDK_BUTTON_PRESS_MASK);
279 
280     gtk_signal_connect(GTK_OBJECT (window), "button_press_event",
281 		       (GtkSignalFunc) zg_button_press_event, NULL);
282 
283     gtk_widget_set_events(drw, GDK_EXPOSURE_MASK);
284     gtk_signal_connect(GTK_OBJECT (drw), "expose_event",
285 		       (GtkSignalFunc) zg_expose_event, NULL);
286 
287     gtk_signal_connect(GTK_OBJECT (window), "destroy",
288 		       (GtkSignalFunc) zg_destroy_event, NULL);
289 
290     gtk_widget_show(window);
291   }
292 
293   return drw;
294 }
295 
zgqdrw_(void)296 GtkWidget *zgqdrw_(void)
297 {
298 #ifdef DEBUG_MODE
299 	printf("zgqdrw\n");
300 #endif
301   return drawing_area;
302 }
303 
zgspmp_(GdkPixmap * pmap)304 void zgspmp_(GdkPixmap *pmap)
305 {
306 
307   /* set/reset pixmap */
308 #ifdef DEBUG_MODE
309 	printf("zgspmp\n");
310 #endif
311 
312   pixmap = pmap;
313 }
314 
zggpmp(void)315 static GdkPixmap *zggpmp(void)
316 {
317   GdkPixmap *pmap;
318 #ifdef DEBUG_MODE
319 	printf("zggpmp\n");
320 #endif
321 
322   pmap = gdk_pixmap_new(drawing_area->window,
323 			drawing_area->allocation.width,
324 			drawing_area->allocation.height,
325 			-1);
326 
327   gdk_draw_rectangle(pmap,
328 		     gc,
329 		     TRUE,
330 		     0, 0,
331 		     drawing_area->allocation.width,
332 		     drawing_area->allocation.height);
333 
334   return pmap;
335 }
336 
zgqpmp_(void)337 GdkPixmap *zgqpmp_(void)
338 {
339 #ifdef DEBUG_MODE
340 	printf("zgqpmp\n");
341 #endif
342   return pixmap;
343 }
344 
345 /*-----------------------------------------------*/
zgbmcv(int * nx,int * ny,char bmline[],char bitmap[])346 static void zgbmcv(int *nx, int *ny, char bmline[], char bitmap[])
347 {
348   static int n8 = 8;
349   int n, nb;
350   unsigned bx;
351 #ifdef DEBUG_MODE
352 	printf("zgbmcv\n");
353 #endif
354 
355   nb = *nx * *ny / n8;
356   for (n = 0; n < nb; n++){
357     sscanf(&bmline[2*n], "%2x", &bx);
358     bitmap[n] = bx;
359   }
360   bitmap[nb] = '\0';
361 }
362 #endif
363 
364 
365 /*------------------------- device ------------------------*/
zgdopn_(DCL_INT * width,DCL_INT * height,DCL_INT * iposx,DCL_INT * iposy,DCL_INT * lwait,DCL_INT * lwait0,DCL_INT * lwait1,DCL_INT * lalt,DCL_INT * lkey,DCL_INT * ldump,DCL_INT * lwnd,DCL_INT * lfgbg,char cimgfmt[],DCL_REAL * rimgcmp,char clrmap[],char cbmmap[],char file[],char title[])366 void zgdopn_(DCL_INT *width, DCL_INT *height, DCL_INT *iposx, DCL_INT *iposy,
367              DCL_INT *lwait, DCL_INT *lwait0, DCL_INT *lwait1, DCL_INT *lalt,
368              DCL_INT *lkey, DCL_INT *ldump, DCL_INT *lwnd, DCL_INT *lfgbg,
369 	     char cimgfmt[], DCL_REAL *rimgcmp, char clrmap[], char cbmmap[], char file[], char title[])
370 {
371   void cfnchr();
372 
373 #ifdef HAVE_GTK_H
374   int ncolor, n, m ,fscanret;
375 
376   guint16 rx[MAXCLI], gx[MAXCLI], bx[MAXCLI], rx1, gx1, bx1;
377   char c[80], cmapz[80], bmapz[80];
378 
379   FILE *stream;
380 
381   GdkVisual *vis;
382   GdkColormap *cmap;
383 
384   GdkRectangle update_rect;
385   GdkEvent *ev;
386 
387 #ifdef DEBUG_MODE
388 	printf("zgdopn\n");
389 #endif
390 
391   posx      = *iposx;
392   posy      = *iposy;
393   wait_np   = *lwait;
394   wait_op   = *lwait0;
395   wait_cl   = *lwait1;
396   key       = *lkey;
397   dump      = *ldump;
398   fgbg      = *lfgbg;
399   laltz     = *lalt;
400 
401 #ifdef DUMP_IMAGE
402   wnd       = *lwnd;
403   cfnchr(imgfmt, cimgfmt, 7);
404   imgcmp = *rimgcmp;
405 
406   if (!wnd) {
407     wait_np = FALSE;
408     wait_op = FALSE;
409     wait_cl = FALSE;
410     dump    = TRUE;
411   }
412 #else
413   wnd       = TRUE;
414 #endif
415 
416   cfnchr(dmpfile, file, 79);
417   cfnchr(xtitle, title, 79);
418 
419   /* check drawing_area, if not set, stop */
420 
421   if (drawing_area == NULL) {
422 
423     ldclonly = TRUE;
424 
425     drawing_area = zggdrw_(width,height);
426   }
427 
428   /* read colormap file */
429 
430   cfnchr(cmapz, clrmap, 79);
431 
432   if ((stream = fopen(cmapz, "r")) == NULL) {
433     fprintf(stderr, "*** Error in zgdopn : ");
434     fprintf(stderr,
435 	    "Allocation failed for colormap (%s).\n", cmapz);
436     exit (1);
437   }
438 
439   fscanret=fscanf(stream, "%d : %s", &ncolor, c);
440   for (n = 0; n < ncolor; n++)
441     fscanret=fscanf(stream, "%6hd%6hd%6hd : %s", &rx[n], &gx[n], &bx[n], c);
442   fclose(stream);
443 
444   if (fgbg) {
445     rx1 = rx[0];
446     gx1 = gx[0];
447     bx1 = bx[0];
448     rx[0] = rx[1];
449     gx[0] = gx[1];
450     bx[0] = bx[1];
451     rx[1] = rx1;
452     gx[1] = gx1;
453     bx[1] = bx1;
454   }
455 
456   /* read bitmap file */
457 
458   cfnchr (bmapz, cbmmap, 79);
459 
460   if ((stream = fopen(bmapz, "r")) == NULL) {
461     fprintf(stderr, "*** Error in zgdopn : ");
462     fprintf(stderr,
463 	     "Allocation failed for bitmap (%s).\n", bmapz);
464     exit (1);
465   }
466 
467   fscanret=fscanf(stream, "%d", &nbmap);
468   for (n = 0; n < nbmap; n++)
469     fscanret=fscanf(stream, "%4d%4d%3d%3d%s",
470 	   &nn1[n], &nn2[n], &nx[n], &ny[n], bmline[n]);
471   fclose(stream);
472 
473   /* set colormap */
474 
475   vis = gtk_widget_get_visual(drawing_area);
476 
477   lclatrz = (vis->type != GDK_VISUAL_STATIC_GRAY);
478 
479   if (lclatrz) {
480 
481     cmap = gtk_widget_get_colormap(drawing_area);
482 
483     for (n = 0; n < MAXCLI; n++) {
484 
485       m = n % ncolor;
486 
487       cx[n].red   = rx[m];
488       cx[n].green = gx[m];
489       cx[n].blue  = bx[m];
490 
491       if (!gdk_colormap_alloc_color(cmap, &cx[n], FALSE, FALSE))
492 	break;
493 
494     }
495 
496     if (n < MAXCLI) {
497 
498       fprintf (stderr, "*** Warning in zgdopn : ");
499       fprintf (stderr, "Only %d colors are allocated.\n", n);
500 
501       for ( ; n < MAXCLI; n++)
502 	cx[n].pixel = drawing_area->style->black.pixel;
503 
504     }
505 
506   } else {
507     cx[0].pixel = drawing_area->style->white.pixel;
508     for (n = 1; n < MAXCLI; n++)
509       cx[n].pixel = drawing_area->style->black.pixel;
510   }
511 
512   gc = gdk_gc_new(drawing_area->window);
513   gdk_gc_set_foreground(gc, &cx[0]);
514 
515   if (ldclonly) {
516 
517     if (pixmap)
518       gdk_pixmap_unref(pixmap);
519 
520     pixmap = zggpmp();
521 
522     zgupdate(0);
523 
524     if (wait_op) {
525       next = FALSE;
526       ifunc = DOPN;
527       while (1) {
528 	gtk_main_iteration();
529 	if (next)
530 	  break;
531       }
532     }
533 
534   } else
535     if (!pixmap)
536       pixmap = zggpmp();
537 #endif
538 }
539 
zgdcls_(void)540 void zgdcls_(void)
541 {
542 #ifdef HAVE_GTK_H
543   /* device closing proc. */
544 
545   GdkEvent *ev;
546 
547 #ifdef DEBUG_MODE
548 	printf("zgdcls\n");
549 #endif
550 
551   if (ldclonly) {
552     zgupdate(0);
553   }
554     if (!wait_np && wait_cl) {
555       next = FALSE;
556       ifunc = DCLS;
557       while (1) {
558 	gtk_main_iteration();
559 	if (next)
560 	  break;
561       }
562     }
563     gtk_widget_destroy(drawing_area);
564     drawing_area = NULL;
565     gtk_widget_destroy(window);
566     window = NULL;
567 #endif
568 }
569 
570 /*------------------------- page --------------------------*/
571 
zgpopn_(void)572 void zgpopn_(void)
573 {
574 #ifdef HAVE_GTK_H
575 
576   /* background drawing proc. */
577   ++page;
578 
579 #ifdef DEBUG_MODE
580 	printf("zgpopn\n");
581 #endif
582 
583   iwdidz = 1;
584   iclidz = 1;
585 
586   gdk_gc_set_foreground(gc, &cx[0]);
587   gdk_draw_rectangle(pixmap,
588 		     gc,
589 		     TRUE,
590 		     0, 0,
591 		     drawing_area->allocation.width,
592 		     drawing_area->allocation.height);
593 #endif
594 }
595 
zgpcls_(void)596 void zgpcls_(void)
597 {
598 #ifdef HAVE_GTK_H
599 
600   /* event loop */
601 
602   char cout[64];
603 
604   char* opt_key[2];
605   char* opt_val[2];
606 
607   char cnum[4];
608 
609 #ifdef DEBUG_MODE
610 	printf("zgpcls\n");
611 #endif
612 
613   if (ldclonly) {
614 
615     zgupdate(0);
616 
617     if (wait_np) {
618       dumpz = FALSE;
619       next = FALSE;
620       ifunc = PCLS;
621       while (1) {
622 	gtk_main_iteration();
623 	if (next)
624 	  break;
625       }
626     }
627     if (dump || dumpz) {
628 
629 #ifdef HAVE_GDK_PIXBUF_H
630       sprintf (cout, "%s_%03d.%s", dmpfile, page, imgfmt);
631       opt_key[0] = NULL;
632       opt_key[1] = NULL;
633       if (imgcmp>=0.0 && imgcmp<=1.0) {
634 	if (strcmp(imgfmt, "png")==0) {
635 	  opt_key[0] = "compression";
636           sprintf(cnum, "%d", (int)(imgcmp*9));
637 	  opt_val[0] = cnum;
638 	} else if (strcmp(imgfmt, "jpeg")==0) {
639 	  opt_key[0] = "quality";
640 	  sprintf(cnum, "%d", (int)((1-imgcmp)*100));
641 	  opt_val[0] = cnum;
642 	}
643       } else if (imgcmp>1.0) {
644 	fprintf(stderr, " *** Error in zgdopn : ");
645 	fprintf(stderr,
646 		"Image compression must be 0-1.\n");
647       }
648       if (!gdk_pixbuf_savev(gdk_pixbuf_get_from_drawable(
649 							NULL,
650 							pixmap,
651 							NULL,
652 							0, 0,
653 							0, 0,
654 							wsxwd, wsywd),
655 			   cout, imgfmt, opt_key, opt_val, NULL) ) {
656 	fprintf(stderr, " *** Error in zgdopn : ");
657 	fprintf(stderr,
658 		"Image format (\"%s\") is not supported.\n", imgfmt);
659       }
660 
661 #elif defined(HAVE_GDK_IMLIB_H)
662       sprintf (cout, "%s_%03d.%s", dmpfile, page, imgfmt);
663       gdk_imlib_save_image(gdk_imlib_create_image_from_drawable(
664 								pixmap,
665 								NULL,
666 								0, 0,
667 								wsxwd,wsywd),
668 			   cout, NULL);
669 #else
670       sprintf (cout, "xwd -name %s -out %s_%03d.xwd", xtitle, dmpfile, page);
671       system (cout);
672 #endif
673 
674     }
675   }
676 #endif
677 }
678 
679 
680 /*------------------------- object ------------------------*/
681 
zgoopn_(char * objname,char * comment)682 void zgoopn_(char *objname, char *comment)
683 {
684 #ifdef HAVE_GTK_H
685 
686 #ifdef DEBUG_MODE
687 	printf("zgoopn\n");
688 #endif
689 
690   /* for long-type message? */
691 #endif
692 }
693 
zgocls_(char * objname)694 void zgocls_(char *objname)
695 {
696 #ifdef HAVE_GTK_H
697 #ifdef DEBUG_MODE
698 	printf("zgocls\n");
699 #endif
700 
701   if(!laltz){
702     zgupdate(1);
703  }
704   /* for long-type message? */
705 #endif
706 }
707 
708 /*------------------------- line --------------------------*/
709 
zgswdi_(DCL_INT * iwdidx)710 void zgswdi_(DCL_INT *iwdidx)
711 {
712 #ifdef HAVE_GTK_H
713 
714   /* set line width index */
715 
716   iwdidz = *iwdidx % 10;
717   irwidth = iwdidz;
718 
719 #ifdef DEBUG_MODE
720 	printf("zgswdi\n");
721 #endif
722 
723   if (iwdidz == 0)
724     iwdidz = 1;
725 #endif
726 }
727 
zgscli_(DCL_INT * iclidx)728 void zgscli_(DCL_INT *iclidx)
729 {
730 #ifdef HAVE_GTK_H
731 
732 #ifdef DEBUG_MODE
733 	printf("zgscli\n");
734 #endif
735 
736   /* set line color index */
737 
738   iclidz = *iclidx % MAXCLI;
739 
740 /*if (iclidz == 0)
741     iclidz = 1; */
742 #endif
743 }
744 
zggopn_(void)745 void zggopn_(void)
746 {
747 #ifdef HAVE_GTK_H
748 
749   /* open graphic segment */
750 
751 #ifdef DEBUG_MODE
752 	printf("zggopn\n");
753 #endif
754 
755   if (lfcmod == FALSE){
756     gdk_gc_set_foreground(gc,&cx[iclidz]);
757   }
758 
759   gdk_gc_set_line_attributes(gc,
760 			     linewidth[iwdidz-1],
761 			     GDK_LINE_SOLID,
762 			     GDK_CAP_ROUND,
763 			     GDK_JOIN_BEVEL);
764 #endif
765 }
766 
zggmov_(DCL_REAL * wx,DCL_REAL * wy)767 void zggmov_(DCL_REAL *wx, DCL_REAL *wy)
768 {
769 #ifdef HAVE_GTK_H
770   void zgfint_();
771   DCL_INT iwxold, iwyold;
772 
773   /* pen-up move */
774 
775 #ifdef DEBUG_MODE
776 	printf("zggmov\n");
777 #endif
778 
779   rwxold = *wx;
780   rwyold = *wy;
781   zgfint_(&rwxold, &rwyold, &iwxold, &iwyold);
782   zguprect(iwxold,iwyold);
783 #endif
784 }
785 
zggplt_(DCL_REAL * wx,DCL_REAL * wy)786 void zggplt_(DCL_REAL *wx, DCL_REAL *wy)
787 {
788 #ifdef HAVE_GTK_H
789   DCL_INT iwxold, iwyold, iwx, iwy;
790   void zgfint_();
791 
792   /* pen-down move */
793 
794 #ifdef DEBUG_MODE
795 	printf("zggplt\n");
796 #endif
797 
798   zgfint_(&rwxold, &rwyold, &iwxold, &iwyold);
799   zgfint_( wx,      wy,     &iwx,    &iwy   );
800 
801   if (iwxold == iwx && iwyold == iwy){
802     gdk_draw_point(pixmap, gc, (int) iwx, (int) iwy);
803   }else{
804     gdk_draw_line(pixmap, gc, (int) iwxold, (int) iwyold, (int) iwx, (int) iwy);
805   }
806   zguprect(iwx,iwy);
807   rwxold = *wx;
808   rwyold = *wy;
809 #endif
810 }
811 
zggcls_(void)812 void zggcls_(void)
813 {
814 #ifdef HAVE_GTK_H
815 
816 #ifdef DEBUG_MODE
817 	printf("zggcls\n");
818 #endif
819 
820   /* close graphic segment */
821 #endif
822 }
823 
824 /*------------------------- tone --------------------------*/
825 
zggton_(DCL_INT * np,DCL_REAL wpx[],DCL_REAL wpy[],DCL_INT * itpat)826 void zggton_(DCL_INT *np, DCL_REAL wpx[], DCL_REAL wpy[], DCL_INT *itpat)
827 {
828 #ifdef HAVE_GTK_H
829   static int ltfrst = TRUE, ibitold = -1;
830   static GdkPoint p[16384];
831   DCL_INT ipx, ipy, iclr, ibit;
832   int i, nb;
833   char bitmap[16384];
834 
835   GdkPixmap *pattern;
836 
837   void zgfint_();
838 
839   /* hard fill */
840 
841 #ifdef DEBUG_MODE
842 	printf("zggton\n");
843 #endif
844 
845   if (ltfrst) {
846     gct = gdk_gc_new (drawing_area->window);
847 
848     ltfrst = FALSE;
849   }
850 
851   if (lfcmod == FALSE){
852     ibit = *itpat % 1000;
853     iclr = (*itpat / 1000) % MAXCLI;
854 /*if (iclr == 0)
855     iclr = 1; */
856 
857     gdk_gc_set_foreground (gct, &cx[iclr]);
858   }
859 
860   if (ibit != ibitold) {
861     ibitold = ibit;
862     nb = -1;
863     if (iwtroz == 1) {
864       for (i = 0; i < nbmap; i++)
865 	if (ibit == nn1[i]) {
866 	  nb = i;
867 	  break;
868 	}
869     }
870     else {
871       for (i = 0; i < nbmap; i++)
872 	if (ibit == nn2[i]) {
873 	  nb = i;
874 	  break;
875 	}
876     }
877     if (nb >= 0) {
878       zgbmcv(&nx[nb], &ny[nb], bmline[nb], bitmap);
879       pattern = gdk_bitmap_create_from_data(NULL, bitmap, nx[nb], ny[nb]);
880       gdk_gc_set_fill(gct, GDK_STIPPLED);
881       gdk_gc_set_stipple(gct, pattern);
882     }
883     else
884       return;
885   }
886 
887   for (i = 0; i < *np; i++) {
888     zgfint_(&wpx[i],&wpy[i], &ipx, &ipy);
889     p[i].x = ipx;
890     p[i].y = ipy;
891     zguprect(ipx,ipy);
892   }
893 
894   gdk_draw_polygon(pixmap, gct, TRUE, p, *np);
895 #endif
896 }
897 
898 /*------------------------- image -------------------------*/
899 
zgiopn_(DCL_INT * iwx,DCL_INT * iwy,DCL_INT * iwidth,DCL_INT * iheight)900 void zgiopn_(DCL_INT *iwx, DCL_INT *iwy, DCL_INT *iwidth, DCL_INT *iheight)
901 {
902 #ifdef HAVE_GTK_H
903 
904 #ifdef DEBUG_MODE
905 	printf("zgiopn\n");
906 #endif
907 
908   ixz = *iwx;
909   iyz = *iwy;
910   iwz = *iwidth;
911   ihz = *iheight;
912   ixxz = ixz;
913   iyyz = iyz;
914   printf (" *** image ");
915 #endif
916 }
917 
zgidat_(DCL_INT image[],DCL_INT * nlen)918 void zgidat_(DCL_INT image[], DCL_INT *nlen)
919 {
920 #ifdef HAVE_GTK_H
921   int i;
922 
923 #ifdef DEBUG_MODE
924 	printf("zgidat\n");
925 #endif
926 
927   for (i = 0; i < *nlen; i++) {
928     if (image[i] != 0) {
929       gdk_gc_set_foreground(gc, &cx[image[i]]);
930       gdk_draw_point(pixmap, gc, ixxz, iyyz);
931       zguprect(ixxz,iyyz);
932     }
933     ixxz = ixxz + 1;
934     if (ixxz >= ixz+iwz) {
935       ixxz = ixz;
936       iyyz = iyyz + 1;
937       if (iyyz % 16 == 0) {
938 	printf (".");
939 	fflush (stdout);
940       }
941     }
942   }
943   zgupdate(1);
944 #endif
945 }
946 
zgicls_(void)947 void zgicls_(void)
948 {
949 #ifdef HAVE_GTK_H
950 
951 #ifdef DEBUG_MODE
952 	printf("zgicls\n");
953 #endif
954 
955   printf (" end\n");
956 #endif
957 }
958 
959 /*------------------------- mouse -------------------------*/
960 
zgqpnt_(DCL_REAL * wx,DCL_REAL * wy,DCL_INT * mb)961 void zgqpnt_(DCL_REAL *wx, DCL_REAL *wy, DCL_INT *mb)
962 {
963 #ifdef HAVE_GTK_H
964 
965 #ifdef DEBUG_MODE
966 	printf("zgqpnt\n");
967 #endif
968 
969   /* mouse pointer position info. */
970 #endif
971 }
972 
973 /*---------------------- transformation -------------------*/
974 
zgfint_(DCL_REAL * wx,DCL_REAL * wy,DCL_INT * iwx,DCL_INT * iwy)975 void zgfint_(DCL_REAL *wx, DCL_REAL *wy, DCL_INT *iwx, DCL_INT *iwy)
976 {
977 #ifdef HAVE_GTK_H
978   int dheight;
979   int dwidth;
980 
981 #ifdef DEBUG_MODE
982 	printf("zgfint\n");
983 #endif
984 
985   *iwx = *wx + 0.5;
986   *iwy = drawing_area->allocation.height - *wy + 0.5;
987 #endif
988 }
989 
zgiint_(DCL_INT * iwx,DCL_INT * iwy,DCL_REAL * wx,DCL_REAL * wy)990 void zgiint_(DCL_INT *iwx, DCL_INT *iwy, DCL_REAL *wx, DCL_REAL *wy)
991 {
992 #ifdef HAVE_GTK_H
993 #ifdef DEBUG_MODE
994 	printf("zgiint\n");
995 #endif
996   *wx = *iwx;
997   *wy = drawing_area->allocation.height - *iwy;
998 #endif
999 }
1000 
1001 /*------------------------- inquiry -----------------------*/
1002 
zgqwdc_(DCL_INT * lwdatr)1003 void zgqwdc_(DCL_INT *lwdatr)
1004 {
1005 #ifdef HAVE_GTK_H
1006 
1007 #ifdef DEBUG_MODE
1008 	printf("zgwqdc\n");
1009 #endif
1010 
1011   /* inquire line width capability */
1012 
1013   *lwdatr = LWDATR;
1014 #endif
1015 }
1016 
zgqclc_(DCL_INT * lclatr)1017 void zgqclc_(DCL_INT *lclatr)
1018 {
1019 #ifdef HAVE_GTK_H
1020 
1021 #ifdef DEBUG_MODE
1022 	printf("zgqclc\n");
1023 #endif
1024 
1025   /* inquire line color capability */
1026 
1027   *lclatr = lclatrz;
1028 #endif
1029 }
1030 
zgqtnc_(DCL_INT * ltnatr)1031 void zgqtnc_(DCL_INT *ltnatr)
1032 {
1033 #ifdef HAVE_GTK_H
1034 
1035 #ifdef DEBUG_MODE
1036 	printf("zgqtnc\n");
1037 #endif
1038 
1039   /* inquire hard fill capability */
1040 
1041   *ltnatr = LTNATR;
1042 #endif
1043 }
1044 
zgqimc_(DCL_INT * limatr)1045 void zgqimc_(DCL_INT *limatr)
1046 {
1047 #ifdef HAVE_GTK_H
1048 
1049 #ifdef DEBUG_MODE
1050 	printf("zgqimc\n");
1051 #endif
1052 
1053   /* inquire bit image capability */
1054 
1055   *limatr = LIMATR;
1056 #endif
1057 }
1058 
zgqptc_(DCL_INT * lptatr)1059 void zgqptc_(DCL_INT *lptatr)
1060 {
1061 #ifdef HAVE_GTK_H
1062 
1063 #ifdef DEBUG_MODE
1064 	printf("zgqptc\n");
1065 #endif
1066 
1067   /* inquire mouse point capability */
1068 
1069   *lptatr = LPTATR;
1070 #endif
1071 }
1072 
zgqrct_(DCL_REAL * wsxmn,DCL_REAL * wsxmx,DCL_REAL * wsymn,DCL_REAL * wsymx,DCL_REAL * fact)1073 void zgqrct_(DCL_REAL *wsxmn, DCL_REAL *wsxmx, DCL_REAL *wsymn, DCL_REAL *wsymx, DCL_REAL *fact)
1074 {
1075 #ifdef HAVE_GTK_H
1076 
1077 #ifdef DEBUG_MODE
1078 	printf("zgqrct\n");
1079 #endif
1080 
1081   /* inquire workstation rectangle */
1082 
1083   *wsxmn = 0.;
1084   *wsxmx = drawing_area->allocation.width;
1085   *wsymn = 0.;
1086   *wsymx = drawing_area->allocation.height;
1087   *fact  = FACTZ;
1088 #endif
1089 }
1090 
zgsrot_(DCL_INT * iwtrot)1091 void zgsrot_(DCL_INT *iwtrot)
1092 {
1093 #ifdef HAVE_GTK_H
1094 
1095 #ifdef DEBUG_MODE
1096 	printf("zgsrot\n");
1097 #endif
1098 
1099   /* set frame rotation flag */
1100 
1101   iwtroz = *iwtrot;
1102 #endif
1103 }
1104 
1105 
1106 // New function for Fullcolor
zgsfcm_(DCL_INT * lfc)1107 void zgsfcm_(DCL_INT *lfc)
1108 {
1109 #ifdef DEBUG_MODE
1110 	printf("zgsfcm\n");
1111 #endif
1112 
1113   lfcmod = *lfc;
1114 }
zgslcl_(DCL_INT * icolor)1115 void zgslcl_(DCL_INT *icolor)
1116 {
1117   GdkColor loccx;
1118   GdkColormap *cmap;
1119 
1120 #ifdef DEBUG_MODE
1121 	printf("zgslcl\n");
1122 #endif
1123 
1124   loccx.red   = ((*icolor >> 16) & 255) * 256;
1125   loccx.green = ((*icolor >> 8)  & 255) * 256;
1126   loccx.blue  = ((*icolor >> 0)  & 255) * 256;
1127 
1128 
1129   cmap = gtk_widget_get_colormap(drawing_area);
1130   gdk_colormap_alloc_color(cmap, &loccx, FALSE, TRUE);
1131   gdk_gc_set_foreground(gc,&loccx);
1132 
1133 }
zgstcl_(DCL_INT * icolor)1134 void zgstcl_(DCL_INT *icolor)
1135 {
1136   /*This Function is not used in uipk samples
1137      So, it is not tested.*/
1138   /* set tone color in 24 bit RGB */
1139   GdkColor  loccx;
1140   GdkColormap *cmap;
1141 
1142 #ifdef DEBUG_MODE
1143 	printf("zgstcl\n");
1144 #endif
1145 
1146   if (ltfrst) {
1147     gct = gdk_gc_new (drawing_area->window);
1148 
1149     ltfrst = FALSE;
1150   }
1151 
1152   loccx.red   = ((*icolor >> 16) & 255) * 256;
1153   loccx.green = ((*icolor >> 8)  & 255) * 256;
1154   loccx.blue  = ((*icolor >> 0)  & 255) * 256;
1155 
1156     cmap = gtk_widget_get_colormap(drawing_area);
1157     gdk_colormap_alloc_color(cmap, &loccx, FALSE, TRUE);
1158     gdk_gc_set_foreground(gct,&loccx);
1159 
1160 }
zgiclr_(DCL_INT * image,DCL_INT * nlen)1161 void zgiclr_(DCL_INT *image,DCL_INT *nlen)
1162 {
1163   GdkColor  loccx;
1164   GdkColormap *cmap;
1165   int i;
1166 
1167 #ifdef DEBUG_MODE
1168 	printf("zgiclr\n");
1169 #endif
1170 
1171   for (i = 0; i < *nlen; i++) {
1172 
1173     loccx.red   = ((image[i] >> 16) & 255) * 256;
1174     loccx.green = ((image[i] >> 8)  & 255) * 256;
1175     loccx.blue  = ((image[i] >> 0)  & 255) * 256;
1176 
1177     cmap = gtk_widget_get_colormap(drawing_area);
1178     gdk_colormap_alloc_color(cmap, &loccx, FALSE, TRUE);
1179     gdk_gc_set_foreground(gc,&loccx);
1180 
1181     gdk_draw_point(pixmap,gc,(int) ixxz,(int) iyyz);
1182     zguprect(ixxz,iyyz);
1183 
1184     ixxz = ixxz + 1;
1185 
1186     if (ixxz >= ixz+iwz) {
1187       ixxz = ixz;
1188       iyyz = iyyz + 1;
1189       if (iyyz % 16 == 0) {
1190 	printf (".");
1191 	fflush (stdout);
1192       }
1193     }
1194   }
1195   zgupdate(1);
1196 }
1197 
1198 
1199 
zgclini_(char clrmap[],DCL_INT * lfgbg)1200 void zgclini_(char clrmap[], DCL_INT *lfgbg)
1201 {
1202 
1203   void cfnchr();
1204 
1205   char c[80],cmapz[80];
1206   FILE *stream;
1207   int ncolor,n,m,fscanret;
1208   guint16 rx[MAXCLI], gx[MAXCLI], bx[MAXCLI], rx1, gx1, bx1;
1209 
1210   GdkVisual *vis;
1211   GdkColormap *cmap;
1212 
1213   /* read colormap file */
1214 
1215 #ifdef DEBUG_MODE
1216 	printf("zgclini\n");
1217 #endif
1218 
1219   cfnchr(cmapz, clrmap, 79);
1220 
1221   if ((stream = fopen(cmapz, "r")) == NULL) {
1222     fprintf(stderr, "*** Error in zgdopn : ");
1223     fprintf(stderr,
1224 	    "Allocation failed for colormap (%s).\n", cmapz);
1225     exit (1);
1226   }
1227 
1228   fscanret=fscanf(stream, "%d : %s", &ncolor, c);
1229   for (n = 0; n < ncolor; n++)
1230     fscanret=fscanf(stream, "%6hd%6hd%6hd : %s", &rx[n], &gx[n], &bx[n], c);
1231   fclose(stream);
1232 
1233   if (fgbg) {
1234     rx1 = rx[0];
1235     gx1 = gx[0];
1236     bx1 = bx[0];
1237     rx[0] = rx[1];
1238     gx[0] = gx[1];
1239     bx[0] = bx[1];
1240     rx[1] = rx1;
1241     gx[1] = gx1;
1242     bx[1] = bx1;
1243 	}
1244 
1245   /* set colormap */
1246 
1247   vis = gtk_widget_get_visual(drawing_area);
1248 
1249   lclatrz = (vis->type != GDK_VISUAL_STATIC_GRAY);
1250 
1251   if (lclatrz) {
1252 
1253     cmap = gtk_widget_get_colormap(drawing_area);
1254 
1255     for (n = 0; n < MAXCLI; n++) {
1256 
1257       m = n % ncolor;
1258 
1259       cx[n].red   = rx[m];
1260       cx[n].green = gx[m];
1261       cx[n].blue  = bx[m];
1262 
1263       if (!gdk_colormap_alloc_color(cmap, &cx[n], FALSE, FALSE))
1264 	break;
1265     }
1266    }
1267 
1268 }
1269 
zguprect(int ix,int iy)1270 void zguprect(int ix,int iy){
1271 	if ((ix-irwidth) < irxb || irxb == 0) irxb =ix-irwidth;
1272 	if ((ix+irwidth) > irxt ) irxt =ix+irwidth;
1273 	if ((iy-irwidth) < iryb || iryb == 0) iryb =iy-irwidth;
1274 	if ((iy+irwidth) > iryt ) iryt =iy+irwidth;
1275 }
1276