home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 May / cica_0595_4.zip / cica_0595_4 / UTIL / GPT34SRC / TERM / SUN.TRM < prev    next >
Text File  |  1993-05-11  |  7KB  |  284 lines

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