home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_03 / sun.trm < prev    next >
Text File  |  1991-02-05  |  6KB  |  279 lines

  1. /* GNUPLOT - sun.trm */
  2. /*
  3.  * Copyright (C) 1990   
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  * This file is included by ../term.c.
  18.  *
  19.  * This terminal driver supports:
  20.  *   SUNview windowing system
  21.  *
  22.  * AUTHORS
  23.  *  Maurice Castro
  24.  * 
  25.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  26.  * 
  27.  */
  28.  
  29. #include <suntool/sunview.h>
  30. #include <suntool/canvas.h>
  31. #include <suntool/scrollbar.h>
  32. #include <suntool/panel.h>
  33. #include <pixrect/pixrect_hs.h>
  34.  
  35. #define SUN_XMAX 600
  36. #define SUN_YMAX 512
  37.  
  38. #define SUN_VCHAR (12)        /* default, will be changed */
  39. #define SUN_HCHAR (8)        /* default, will be changed */
  40. #define SUN_VTIC (SUN_YMAX/80)
  41. #define SUN_HTIC (SUN_XMAX/80)
  42. #define MARGIN 5
  43. #define MINWIN 128
  44.  
  45. static Frame frame;
  46. static Canvas canvas;
  47. static Pixwin *pw;
  48. static struct pixfont *sun_font = NULL;
  49.  
  50. static enum JUSTIFY sun_justify=LEFT;
  51.  
  52. static Notify_value local_notice_destroy();
  53.  
  54. extern Notify_error notify_dispatch();
  55.   
  56. /* dotted line generator */
  57. unsigned int sun_value = 1;    /* this can be used for colour */
  58. unsigned int sun_line_mask = 0xffff;    /* 16 bit mask for dotted lines */
  59. static unsigned int sun_pattern[] = {0xffff, 0x1111,
  60.     0xffff, 0x5555, 0x3333, 0x7777, 0x3f3f, 0x0f0f, 0x5f5f};
  61. int sun_mask_count = 0;
  62. unsigned int sun_lastx, sun_lasty;    /* last pixel set - used by sun_line */
  63.  
  64.  
  65. SUN_init()
  66. {
  67.   struct termentry *t = &term_tbl[term];
  68.   struct pr_subregion bound;
  69.  
  70.   frame = window_create(NULL, FRAME, 
  71.             FRAME_LABEL,               "Gnuplot",
  72.             0);
  73.   notify_interpose_destroy_func(frame,local_notice_destroy);
  74.   canvas = window_create(frame, CANVAS,
  75.             CANVAS_AUTO_EXPAND,        TRUE,
  76.             CANVAS_AUTO_SHRINK,        TRUE,
  77.             CANVAS_MARGIN,             MARGIN,
  78.             0);
  79.   notify_do_dispatch();
  80.   pw = canvas_pixwin(canvas);
  81.   window_set(frame, WIN_SHOW, TRUE, 0);
  82.  
  83.   /* figure out font and rough size */
  84.   sun_font = pf_default();
  85.   pf_textbound(&bound, 1, sun_font, "M");
  86.   t->v_char = bound.size.y;
  87.   t->h_char = bound.size.x;
  88.  
  89.   return;
  90. }
  91.  
  92. SUN_graphics()
  93. {
  94.   term_tbl[term].xmax = (int) window_get(canvas,CANVAS_WIDTH);
  95.   term_tbl[term].ymax = (int) window_get(canvas,CANVAS_HEIGHT);
  96.   pw_writebackground(pw,0,0,term_tbl[term].xmax, term_tbl[term].ymax, PIX_SRC );
  97.   notify_dispatch();
  98.   /* do not let the user make the window too small */
  99.   if ((term_tbl[term].xmax)<MINWIN)
  100.   {
  101.       window_set(frame,
  102.             WIN_WIDTH,                MINWIN+2*MARGIN+24,
  103.             0);
  104.       notify_dispatch();
  105.       SUN_graphics();
  106.       }
  107.   if ((term_tbl[term].ymax) <MINWIN)
  108.   {
  109.       window_set(frame,
  110.             WIN_HEIGHT,               MINWIN+2*MARGIN+24,
  111.             0);
  112.       notify_dispatch();
  113.       SUN_graphics();
  114.       }
  115.   notify_dispatch();
  116.   return;
  117. }
  118.  
  119. SUN_text()
  120. {
  121.   notify_dispatch();
  122.   return; /* enter text from another window!!! */
  123. }
  124.  
  125. SUN_linetype(linetype)
  126. int linetype;
  127. {
  128.     if (linetype>=7)
  129.         linetype %= 7;
  130.     sun_line_mask = sun_pattern[linetype+2];
  131.     sun_mask_count=0;
  132. }
  133.  
  134.  
  135. SUN_move(x, y)
  136. unsigned int x, y;
  137. {
  138.   sun_lastx = x;
  139.   sun_lasty = y;
  140.   notify_dispatch();
  141.   return;
  142. }
  143.  
  144. SUN_vector(x, y)
  145. unsigned int x, y;
  146. {
  147.   if ( (x>=term_tbl[term].xmax) || (y>=term_tbl[term].ymax) )
  148.     return;
  149.   sun_line(sun_lastx,x,sun_lasty,y);
  150.   canvas_pixwin(canvas);
  151.   notify_dispatch();
  152.   return;
  153. }
  154.  
  155.  
  156. SUN_put_text(x,y,str)
  157. unsigned int x, y;
  158. char *str;
  159. {
  160.   struct pr_subregion bound;
  161.  
  162.   if ( (x>=term_tbl[term].xmax) || (y>=term_tbl[term].ymax) )
  163.     return;
  164.  
  165.   pf_textbound(&bound, strlen(str), sun_font, str);
  166.   y = term_tbl[term].ymax-1-y + bound.size.y/3; /* vertical centering */
  167.  
  168.   switch(sun_justify) {
  169.      case LEFT:   break;
  170.      case CENTRE: x -= bound.size.x/2; break;
  171.      case RIGHT:  x -= bound.size.x; break;
  172.   }
  173.   pw_text(pw, x,y, PIX_SRC | PIX_DST, 0, str); 
  174.   canvas_pixwin(canvas);
  175.   notify_dispatch();
  176.   return;
  177. }
  178.  
  179.  
  180. int SUN_justify_text(mode)
  181.     enum JUSTIFY mode;
  182. {
  183.     sun_justify = mode;
  184.     return (TRUE);
  185. }
  186.   
  187.   
  188.  
  189.  
  190. SUN_reset()
  191. {
  192.   
  193.   term_tbl[term].xmax = SUN_XMAX;
  194.   term_tbl[term].ymax = SUN_YMAX;
  195.   window_set(frame, WIN_SHOW, FALSE, 0);
  196.   return;
  197. }
  198.  
  199.  
  200.  
  201. sun_setmaskpixel(x,y,value)
  202. unsigned int x,y,value;
  203. {
  204.     /* dotted line generator */
  205.     if ((sun_line_mask>>sun_mask_count)&(unsigned int)(1)) {
  206.         pw_put(pw,x,term_tbl[term].ymax-1-y,sun_value);
  207.     }
  208.     sun_mask_count= (sun_mask_count+1) % 16;
  209.     sun_lastx= x;  /* last pixel set with mask */
  210.     sun_lasty= y;
  211. }
  212.  
  213.  
  214.  
  215.  
  216. sun_line(x1,x2,y1,y2)
  217. unsigned int x1,x2,y1,y2;
  218. {
  219. int runcount;
  220. int dx,dy;
  221. int xinc,yinc;
  222. unsigned int xplot,yplot;
  223.  
  224.     runcount=0;
  225.     dx = abs((int)(x1)-(int)(x2));
  226.     if (x2>x1)  xinc=  1;
  227.     if (x2==x1) xinc=  0;
  228.     if (x2<x1)  xinc= -1;
  229.     dy = abs((int)(y1)-(int)(y2));
  230.     if (y2>y1)  yinc=  1;
  231.     if (y2==y1) yinc=  0;
  232.     if (y2<y1)  yinc= -1;
  233.     xplot=x1;
  234.     yplot=y1;
  235.     if (dx>dy) {
  236.         /* iterate x */
  237.         if ( (sun_line_mask==0xffff) ||
  238.             ((xplot!=sun_lastx) && (yplot!=sun_lasty)) )
  239.             sun_setmaskpixel(xplot,yplot,sun_value);
  240.         while (xplot!=x2) { 
  241.             xplot+=xinc;
  242.             runcount+=dy;
  243.             if (runcount>=(dx-runcount)) {
  244.                 yplot+=yinc;
  245.                 runcount-=dx;
  246.             }
  247.             sun_setmaskpixel(xplot,yplot,sun_value);
  248.         } 
  249.     } else {
  250.         /* iterate y */
  251.         if ( (sun_line_mask==0xffff) ||
  252.             ((xplot!=sun_lastx) && (yplot!=sun_lasty)) )
  253.             sun_setmaskpixel(xplot,yplot,sun_value);
  254.         while (yplot!=y2) {
  255.             yplot+=yinc;
  256.             runcount+=dx;
  257.             if (runcount>=(dy-runcount)) {
  258.                 xplot+=xinc;
  259.                 runcount-=dy;
  260.             }
  261.             sun_setmaskpixel(xplot,yplot,sun_value);
  262.         } 
  263.     }
  264. }
  265.  
  266.  
  267. static Notify_value local_notice_destroy(frame, status)
  268.    Frame frame;
  269.    Destroy_status status;
  270. {
  271.    if (status != DESTROY_CHECKING)
  272.    {
  273.       SUN_reset();
  274.       term_init = FALSE;
  275.       }
  276.    return(NOTIFY_DONE);
  277.    }
  278.  
  279.