home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / sun.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  7.7 KB  |  340 lines

  1. /*
  2.  * $Id: sun.trm,v 1.7 1995/12/20 21:48:12 drd Exp $
  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.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  35.  */
  36.  
  37. #ifndef GOT_DRIVER_H
  38. #include "driver.h"
  39. #endif
  40.  
  41. #ifdef TERM_REGISTER
  42. register_term(sun)
  43. #endif
  44.  
  45. #ifdef TERM_PROTO
  46. TERM_PUBLIC void SUN_init __P((void));
  47. TERM_PUBLIC void SUN_graphics __P((void));
  48. TERM_PUBLIC void SUN_text __P((void));
  49. TERM_PUBLIC void SUN_linetype __P((int linetype));
  50. TERM_PUBLIC void SUN_move __P((unsigned int x, unsigned int y));
  51. TERM_PUBLIC void SUN_vector __P((unsigned int x, unsigned int y));
  52. TERM_PUBLIC void SUN_put_text __P((unsigned int x, unsigned int y, char *str));
  53. TERM_PUBLIC int SUN_justify_text __P((enum JUSTIFY mode));
  54. TERM_PUBLIC void SUN_reset __P((void));
  55. #define SUN_XMAX 600
  56. #define SUN_YMAX 512
  57.  
  58. #define SUN_VCHAR (12)        /* default, will be changed */
  59. #define SUN_HCHAR (8)        /* default, will be changed */
  60. #define SUN_VTIC (SUN_YMAX/80)
  61. #define SUN_HTIC (SUN_XMAX/80)
  62. #endif /* TERM_PROTO */
  63.  
  64. #ifndef TERM_PROTO_ONLY
  65. #ifdef TERM_BODY
  66. #include <suntool/sunview.h>
  67. #include <suntool/canvas.h>
  68. #include <suntool/scrollbar.h>
  69. #include <suntool/panel.h>
  70. #include <pixrect/pixrect_hs.h>
  71.  
  72. void sun_setmaskpixel __P((unsigned int x, unsigned int y, unsigned int value));
  73. void sun_line __P((unsigned int x1, unsigned int x2, unsigned int y1, unsigned int y2));
  74. static Notify_value local_notice_destroy __P((Frame frame, Destroy_status status));
  75.  
  76. #define MARGIN 5
  77. #define MINWIN 128
  78.  
  79. static Frame frame;
  80. static Canvas canvas;
  81. static Pixwin *pw;
  82. static struct pixfont *sun_font = NULL;
  83.  
  84. static enum JUSTIFY sun_justify=LEFT;
  85.  
  86. static Notify_value local_notice_destroy();
  87.  
  88. extern Notify_error notify_dispatch();
  89.   
  90. /* dotted line generator */
  91. unsigned int sun_value = 1;    /* this can be used for colour */
  92. unsigned int sun_line_mask = 0xffff;    /* 16 bit mask for dotted lines */
  93. static unsigned int sun_pattern[] = {0xffff, 0x1111,
  94.     0xffff, 0x5555, 0x3333, 0x7777, 0x3f3f, 0x0f0f, 0x5f5f};
  95. int sun_mask_count = 0;
  96. unsigned int sun_lastx, sun_lasty;    /* last pixel set - used by sun_line */
  97.  
  98.  
  99. TERM_PUBLIC void SUN_init()
  100. {
  101.   struct termentry *t = term;
  102.   struct pr_subregion bound;
  103.  
  104.   frame = window_create(NULL, FRAME, 
  105.             FRAME_LABEL,               "Gnuplot",
  106.             0);
  107.   notify_interpose_destroy_func(frame,local_notice_destroy);
  108.   canvas = window_create(frame, CANVAS,
  109.             CANVAS_AUTO_EXPAND,        TRUE,
  110.             CANVAS_AUTO_SHRINK,        TRUE,
  111.             CANVAS_MARGIN,             MARGIN,
  112.             0);
  113.   notify_do_dispatch();
  114.   pw = canvas_pixwin(canvas);
  115.   window_set(frame, WIN_SHOW, TRUE, 0);
  116.  
  117.   /* figure out font and rough size */
  118.   sun_font = pf_default();
  119.   pf_textbound(&bound, 1, sun_font, "M");
  120.   t->v_char = bound.size.y;
  121.   t->h_char = bound.size.x;
  122.  
  123.   return;
  124. }
  125.  
  126. TERM_PUBLIC void SUN_graphics()
  127. {
  128.   term->xmax = (int) window_get(canvas,CANVAS_WIDTH);
  129.   term->ymax = (int) window_get(canvas,CANVAS_HEIGHT);
  130.   pw_writebackground(pw,0,0,term->xmax, term->ymax, PIX_SRC );
  131.   notify_dispatch();
  132.   /* do not let the user make the window too small */
  133.   if ((term->xmax)<MINWIN)
  134.   {
  135.       window_set(frame,
  136.             WIN_WIDTH,                MINWIN+2*MARGIN+24,
  137.             0);
  138.       notify_dispatch();
  139.       SUN_graphics();
  140.       }
  141.   if ((term->ymax) <MINWIN)
  142.   {
  143.       window_set(frame,
  144.             WIN_HEIGHT,               MINWIN+2*MARGIN+24,
  145.             0);
  146.       notify_dispatch();
  147.       SUN_graphics();
  148.       }
  149.   notify_dispatch();
  150.   return;
  151. }
  152.  
  153. TERM_PUBLIC void SUN_text()
  154. {
  155.   notify_dispatch();
  156.   return; /* enter text from another window!!! */
  157. }
  158.  
  159. TERM_PUBLIC void SUN_linetype(linetype)
  160. int linetype;
  161. {
  162.     if (linetype>=7)
  163.         linetype %= 7;
  164.     sun_line_mask = sun_pattern[linetype+2];
  165.     sun_mask_count=0;
  166. }
  167.  
  168.  
  169. TERM_PUBLIC void SUN_move(x, y)
  170. unsigned int x, y;
  171. {
  172.   sun_lastx = x;
  173.   sun_lasty = y;
  174.   notify_dispatch();
  175.   return;
  176. }
  177.  
  178. TERM_PUBLIC void SUN_vector(x, y)
  179. unsigned int x, y;
  180. {
  181.   if ( (x>=term->xmax) || (y>=term->ymax) )
  182.     return;
  183.   sun_line(sun_lastx,x,sun_lasty,y);
  184.   canvas_pixwin(canvas);
  185.   notify_dispatch();
  186.   return;
  187. }
  188.  
  189. TERM_PUBLIC void SUN_put_text(x,y,str)
  190. unsigned int x, y;
  191. char *str;
  192. {
  193.   struct pr_subregion bound;
  194.  
  195.   if ( (x>=term->xmax) || (y>=term->ymax) )
  196.     return;
  197.  
  198.   pf_textbound(&bound, strlen(str), sun_font, str);
  199.   y = term->ymax-1-y + bound.size.y/3; /* vertical centering */
  200.  
  201.   switch(sun_justify) {
  202.      case LEFT:   break;
  203.      case CENTRE: x -= bound.size.x/2; break;
  204.      case RIGHT:  x -= bound.size.x; break;
  205.   }
  206.   pw_text(pw, x,y, PIX_SRC | PIX_DST, 0, str); 
  207.   canvas_pixwin(canvas);
  208.   notify_dispatch();
  209.   return;
  210. }
  211.  
  212.  
  213. TERM_PUBLIC int SUN_justify_text(mode)
  214.     enum JUSTIFY mode;
  215. {
  216.     sun_justify = mode;
  217.     return (TRUE);
  218. }
  219.   
  220.   
  221.  
  222.  
  223. TERM_PUBLIC void SUN_reset()
  224. {
  225.   
  226.   term->xmax = SUN_XMAX;
  227.   term->ymax = SUN_YMAX;
  228.   window_set(frame, WIN_SHOW, FALSE, 0);
  229.   return;
  230. }
  231.  
  232.  
  233.  
  234. void sun_setmaskpixel(x,y,value)
  235. unsigned int x,y,value;
  236. {
  237.     /* dotted line generator */
  238.     if ((sun_line_mask>>sun_mask_count)&(unsigned int)(1)) {
  239.         pw_put(pw,x,term->ymax-1-y,sun_value);
  240.     }
  241.     sun_mask_count= (sun_mask_count+1) % 16;
  242.     sun_lastx= x;  /* last pixel set with mask */
  243.     sun_lasty= y;
  244. }
  245.  
  246.  
  247.  
  248.  
  249. void sun_line(x1,x2,y1,y2)
  250. unsigned int x1,x2,y1,y2;
  251. {
  252. int runcount;
  253. int dx,dy;
  254. int xinc,yinc;
  255. unsigned int xplot,yplot;
  256.  
  257.     runcount=0;
  258.     dx = abs((int)(x1)-(int)(x2));
  259.     if (x2>x1)  xinc=  1;
  260.     if (x2==x1) xinc=  0;
  261.     if (x2<x1)  xinc= -1;
  262.     dy = abs((int)(y1)-(int)(y2));
  263.     if (y2>y1)  yinc=  1;
  264.     if (y2==y1) yinc=  0;
  265.     if (y2<y1)  yinc= -1;
  266.     xplot=x1;
  267.     yplot=y1;
  268.     if (dx>dy) {
  269.         /* iterate x */
  270.         if ( (sun_line_mask==0xffff) ||
  271.             ((xplot!=sun_lastx) && (yplot!=sun_lasty)) )
  272.             sun_setmaskpixel(xplot,yplot,sun_value);
  273.         while (xplot!=x2) { 
  274.             xplot+=xinc;
  275.             runcount+=dy;
  276.             if (runcount>=(dx-runcount)) {
  277.                 yplot+=yinc;
  278.                 runcount-=dx;
  279.             }
  280.             sun_setmaskpixel(xplot,yplot,sun_value);
  281.         } 
  282.     } else {
  283.         /* iterate y */
  284.         if ( (sun_line_mask==0xffff) ||
  285.             ((xplot!=sun_lastx) && (yplot!=sun_lasty)) )
  286.             sun_setmaskpixel(xplot,yplot,sun_value);
  287.         while (yplot!=y2) {
  288.             yplot+=yinc;
  289.             runcount+=dx;
  290.             if (runcount>=(dy-runcount)) {
  291.                 xplot+=xinc;
  292.                 runcount-=dy;
  293.             }
  294.             sun_setmaskpixel(xplot,yplot,sun_value);
  295.         } 
  296.     }
  297. }
  298.  
  299.  
  300. static Notify_value local_notice_destroy(frame, status)
  301.    Frame frame;
  302.    Destroy_status status;
  303. {
  304.    if (status != DESTROY_CHECKING)
  305.    {
  306.       SUN_reset();
  307.       term_init = FALSE;
  308.    }
  309.    return(NOTIFY_DONE);
  310. }
  311.  
  312. #endif /* TERM_BODY */
  313.  
  314. #ifdef TERM_TABLE
  315.  
  316. TERM_TABLE_START(sun_driver)
  317.     "sun", "SunView window system",
  318.        SUN_XMAX, SUN_YMAX, SUN_VCHAR, SUN_HCHAR, 
  319.        SUN_VTIC, SUN_HTIC, options_null, SUN_init, SUN_reset, 
  320.        SUN_text, null_scale, SUN_graphics, SUN_move, SUN_vector,
  321.        SUN_linetype, SUN_put_text, null_text_angle, 
  322.        SUN_justify_text, line_and_point, do_arrow, set_font_null
  323. TERM_TABLE_END(sun_driver)
  324.  
  325. #undef LAST_TERM
  326. #define LAST_TERM sun_driver
  327.  
  328. #endif /* TERM_TABLE */
  329. #endif /* TERM_PROTO_ONLY */
  330.  
  331. /*
  332.  * NAME: sun
  333.  *
  334.  * OPTIONS: none
  335.  *
  336.  * SUPPORTS: SunView window system
  337.  *
  338.  * Further Info: none
  339.  *
  340.  */