home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 500-599 / ff552.lzh / GNUPlot / gnuplot3.lzh / gnuplot / term / gpr.trm < prev    next >
Text File  |  1991-06-03  |  12KB  |  379 lines

  1. /* GNUPLOT - gpr.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.  *   APOLLO's GPR windowing system
  21.  *
  22.  * AUTHORS
  23.  *  Michael Aramini
  24.  *  Roque D Oliveira , oliveria@caen.engin.umich.edu
  25.  * 
  26.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  27.  * 
  28.  */
  29. #include <apollo/base.h>
  30. #include <apollo/error.h>
  31. #include <apollo/gpr.h>
  32. #include <apollo/pad.h>
  33. /* landscape window */
  34. /*
  35. #define GPR_XMAX 720
  36. #define GPR_YMAX 450
  37. */
  38. /* portrait window */
  39. #define GPR_XMAX 585
  40. #define GPR_YMAX 735
  41.  
  42. #define GPR_XLAST (GPR_XMAX - 1)
  43. #define GPR_YLAST (GPR_YMAX - 1)
  44.  
  45. #define GPR_VCHAR 19
  46. #define GPR_HCHAR 10
  47. #define GPR_VTIC (GPR_YMAX/80)
  48. #define GPR_HTIC (GPR_XMAX/80)
  49.  
  50. gpr_$direction_t  gpr_path=gpr_$right;
  51. int               gpr_ang=0;            /* text angle, 0=horizontal, 1=vertical */
  52. enum JUSTIFY      gpr_justify=LEFT;     /* text is flush left */
  53.  
  54. static status_$t  status;
  55. unsigned int      DEBUG    = 0;         /* set it to 1 when debugging program */
  56.  
  57.  
  58. static void check(messagex)
  59. char *messagex;
  60. {
  61.   if (status.all = status_$ok)
  62.   {
  63.     error_$print(status);
  64.     printf("Error occurred while %s.\n", messagex);
  65.   }
  66. }
  67.  
  68. /* return whether stdout is a DM pad . Called by term.c */
  69. gpr_isa_pad()
  70. {
  71.     pad_$isa(1, &status);
  72.     return (status.all == status_$ok);
  73. }
  74.  
  75.  
  76. GPR_init()
  77. {
  78.   gpr_$offset_t dm_bitmap_size;
  79.   gpr_$bitmap_desc_t dm_bitmap_desc;
  80.   pad_$window_desc_t window;
  81.   short font_id;
  82.   stream_$id_t stream_id;
  83.   static gpr_$rgb_plane_t  hi_plane;
  84.   static gpr_$disp_char_t  display_characteristics;
  85.   static float             screen_size_r_width,screen_size_r_height ;
  86.   static short int         disp_len = sizeof(gpr_$disp_char_t);
  87.   static short int         disp_len_returned;
  88.  
  89.  
  90.   /* open a pad to do graphics in */
  91.   window.top    = 0;
  92.   window.left   = 0;
  93.   window.width  = GPR_XMAX + 10; /* 10 accounts for width of window border */
  94.   window.height = GPR_YMAX + 35; /* 35 accounts for height of window border */
  95.   pad_$create_window("",(short)0,pad_$transcript,(short)1,window,&stream_id,&status);
  96.   check("pad_$create_window");
  97.  
  98. /*  pad_$set_full_window(stream_id,(short) 1,&window, &status); */
  99. /*  pad_$set_border (stream_id,(short) 1, true, &status); */
  100.   pad_$set_scale (stream_id,(short) 1,(short) 1, &status);
  101.   pad_$set_auto_close(stream_id, (short) 1, true, &status );
  102.  
  103.   gpr_$inq_disp_characteristics(gpr_$direct,stream_id,disp_len,&display_characteristics,&disp_len_returned,&status);
  104.   check("in gpr_$inq_display_characteristics");
  105.   screen_size_r_width    = (float) display_characteristics.x_window_size;    /*x_window_size in pixels */
  106.   screen_size_r_height   = (float) display_characteristics.y_window_size;    /*y_window_size in pixels */
  107.   hi_plane  = display_characteristics.n_planes - 1;  
  108.   if(DEBUG) printf("width=%f height=%f \n",screen_size_r_width,screen_size_r_height);
  109.  
  110.   dm_bitmap_size.x_size = 1280;
  111.   dm_bitmap_size.y_size = 1024;
  112.   gpr_$init(gpr_$direct,stream_id,dm_bitmap_size,hi_plane,&dm_bitmap_desc,&status); 
  113.   check("in gpr_$init");
  114. /*
  115.   gpr_$set_obscured_opt(gpr_$pop_if_obs, &status); 
  116.   check("in gpr_$set_obscured_opt");
  117. */
  118.   gpr_$set_auto_refresh(true, &status); 
  119.   check("in gpr_$set_auto_refresh");
  120.  
  121.   /* load a font and make it current */
  122.   gpr_$load_font_file("f7x13", 5, &font_id, &status);
  123.   check("in gpr_$load_font_file");
  124.   gpr_$set_text_font(font_id, &status);
  125.   check("in gpr_$set_text_font");
  126.  
  127.   /* set up color values */
  128.   gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  129.   check("in gpr_set_draw_value");
  130.   gpr_$set_text_background_value((gpr_$pixel_value_t)(-1), &status); /* trans */
  131.   check("in gpr_$set_text_background_value");
  132.   gpr_$set_text_value((gpr_$pixel_value_t)7, &status);  /* white */
  133.   check("in gpr_$set_text_value");
  134. }
  135.  
  136.  
  137. GPR_graphics()
  138. {
  139.   gpr_$coordinate_t locx,locy,marker_size;
  140.  
  141.   (void) gpr_$acquire_display(&status);
  142.   check("in gpr_$acquire display");
  143.   gpr_$clear((gpr_$pixel_value_t)0, &status);  /* black */
  144.   check("in gpr_$clear");
  145.  
  146.   if(DEBUG) 
  147.    {
  148.     marker_size = (short) 10;  
  149.  
  150.     locx = (short) 5;
  151.     locy = (short) 5;
  152.     gpr_$set_draw_value((gpr_$pixel_value_t)2, &status);  /* white */
  153.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  154.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  155.     gpr_$move( locx, (locy + marker_size/2),&status);
  156.     gpr_$line( locx, (locy - marker_size/2),&status);
  157.     
  158.     locx = (short) (GPR_XMAX -1 - 5);
  159.     locy = (short) 5;
  160.     gpr_$set_draw_value((gpr_$pixel_value_t)3, &status);  /* white */
  161.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  162.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  163.     gpr_$move( locx, (locy + marker_size/2),&status);
  164.     gpr_$line( locx, (locy - marker_size/2),&status);
  165.     
  166.     locx = (short) 5;
  167.     locy = (short) (GPR_YMAX -1 - 5);
  168.     gpr_$set_draw_value((gpr_$pixel_value_t)4, &status);  /* white */
  169.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  170.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  171.     gpr_$move( locx, (locy + marker_size/2),&status);
  172.     gpr_$line( locx, (locy - marker_size/2),&status);
  173.     
  174.     locx = (short) (GPR_XMAX -1 - 5);
  175.     locy = (short) (GPR_YMAX -1 - 5);
  176.     gpr_$set_draw_value((gpr_$pixel_value_t)5, &status);  /* white */
  177.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  178.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  179.     gpr_$move( locx, (locy + marker_size/2),&status);
  180.     gpr_$line( locx, (locy - marker_size/2),&status);
  181.     
  182.     gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  183.     check("in gpr_$set_draw_value");
  184.    } /* end if(DEBUG) */
  185.  
  186. }
  187.  
  188.  
  189. GPR_text()
  190. {
  191.   gpr_$release_display(&status);
  192.   check("gpr_$release_display");
  193. }
  194.  
  195.  
  196. GPRold_linetype(linetype)
  197. int linetype;
  198. {
  199.   static gpr_$line_pattern_t patterns[2+5] = {
  200.       { 0xFFFF },   /* solid              1111111111111111 */
  201.       { 0x3FFF },   /* very long dashed   0011111111111111 */
  202.       { 0xFFFF },   /* solid              1111111111111111 */
  203.       { 0x5555 },   /* dotted             0101010101010101 */
  204.       { 0x3333 },   /* short dashed       0011001100110011 */
  205.       { 0xB5AD },   /* dot short-dashed   1011010110101101 */
  206.       { 0x3FFF }    /* very long dashed   0011111111111111 */
  207.                                              };
  208.   if (linetype >= 5) linetype %= 5;
  209.   gpr_$set_line_pattern((short)1, patterns[linetype+2], (short)16, &status);
  210.   check("in gpr_$set_line_pattern");
  211. }
  212.  
  213. GPR_linetype(linetype)
  214. int linetype;
  215. {
  216.   static gpr_$line_pattern_t patterns[2+7] = {
  217.       { 0xFFFF },   /* solid              1111111111111111 */
  218.       { 0x1111 },   /* long-spaced dotted 0001000100010001 */
  219.       { 0xFFFF },   /* solid              1111111111111111 */
  220.       { 0x5555 },   /* dotted             0101010101010101 */
  221.       { 0x3333 },   /* short  dashed      0011001100110011 */
  222.       { 0x7777 },   /* medium dashed      0111011101110111 */
  223.       { 0x3F3F },   /* long   dashed      0011111100111111 */
  224.       { 0x0F0F },   /* long-spaced dashed 0000111100001111 */
  225.       { 0x5F5F }    /* dot dashed         0101111101011111 */
  226.                                              };
  227.   if (linetype >= 7) linetype %= 7;
  228.   gpr_$set_line_pattern((short)1, patterns[linetype+2], (short)16, &status);
  229.   check("in gpr_$set_line_pattern");
  230.  
  231. /*
  232.   gpr_$set_draw_value((gpr_$pixel_value_t)(linetype + 1), &status);
  233.   check("in gpr_$set_draw_value");
  234. */
  235. }
  236.  
  237.  
  238. GPR_move(x, y)
  239. unsigned int x, y;
  240. {
  241.   gpr_$move((short)x, (short)(GPR_YMAX -1 - y), &status);
  242.   check("in gpr_$move");
  243. }
  244.  
  245.  
  246. GPR_vector(x, y)
  247. unsigned int x, y;
  248. {
  249.   gpr_$line((short)x, (short)(GPR_YMAX -1 - y), &status);
  250.   check("in gpr_$line");
  251. }
  252.  
  253.  
  254. GPR_put_text(x,y,str)
  255. unsigned int x,y;        /* reference point of string */
  256. char str[];              /* the text */
  257. {
  258.   gpr_$coordinate_t xgpr,ygpr;
  259.   gpr_$offset_t     str_size_in_pixels;
  260.   short int         str_len;     
  261.  
  262.   gpr_$coordinate_t locx,locy,marker_size;
  263.  
  264.   if(DEBUG) 
  265.    {
  266.     locx = (short) x;
  267.     locy = (short) (GPR_YMAX -1 - y);
  268.     marker_size = (short) 20;  
  269.     gpr_$set_draw_value((gpr_$pixel_value_t)1, &status);  /* white */
  270.     gpr_$move( (locx - marker_size/2) ,locy,&status);
  271.     gpr_$line( (locx + marker_size/2) ,locy,&status);
  272.     gpr_$move( locx, (locy + marker_size/2),&status);
  273.     gpr_$line( locx, (locy - marker_size/2),&status);
  274.     gpr_$set_draw_value((gpr_$pixel_value_t)7, &status);  /* white */
  275.    }
  276.  
  277.   xgpr = (short) x;
  278.   ygpr = (short) (GPR_YMAX -1 - y); 
  279.   gpr_$set_text_path(gpr_path, &status); 
  280.   check("gpr_$set_text_path");
  281.  
  282.   str_len = (short) strlen(str);
  283.   gpr_$inq_text_extent(str,str_len,&str_size_in_pixels,&status); /* Calculate how much space (in pixels) the string requires */    
  284.   check("in gpr_$inq_text_extent");
  285.  
  286.   switch (gpr_justify) 
  287.    {
  288.     case LEFT :
  289.         {
  290.          switch (gpr_path) 
  291.           {
  292.            case gpr_$up :           /* vertical */
  293.                {
  294.                 if(DEBUG) printf("LEFT and up , str=%s\n",str);
  295.                 break;
  296.                }
  297.            case gpr_$right :        /* horizontal */
  298.                {
  299.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  300.                 if(DEBUG) printf("LEFT and right, str=%s \n",str);
  301.                 break;
  302.                }
  303.           }
  304.          break;
  305.         }
  306.  
  307.     case CENTRE :
  308.         {  
  309.          switch (gpr_path) 
  310.           {
  311.            case gpr_$up :           /* vertical */
  312.                {
  313.                 xgpr = xgpr + str_size_in_pixels.x_size/2;
  314.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  315.                 if(DEBUG) printf("CENTRE and up, str=%s \n",str);
  316.                 break;
  317.                }
  318.            case gpr_$right :        /* horizontal */
  319.                {
  320.                 xgpr = xgpr - str_size_in_pixels.x_size/2;
  321.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  322.                 if(DEBUG) printf("CENTRE and right, str=%s \n",str);
  323.                 break;
  324.                }
  325.           }
  326.          break;
  327.         }
  328.     case RIGHT :
  329.         {
  330.          switch (gpr_path) 
  331.           {
  332.            case gpr_$up :           /* vertical */
  333.                {
  334.                 ygpr = ygpr + str_size_in_pixels.y_size;
  335.                 if(DEBUG) printf("RIGHT and up, str=%s \n",str);
  336.                 break;
  337.                }
  338.            case gpr_$right :        /* horizontal */
  339.                {
  340.                 xgpr = xgpr - str_size_in_pixels.x_size;
  341.                 ygpr = ygpr + str_size_in_pixels.y_size/2;
  342.                 if(DEBUG) printf("RIGHT and right, str=%s \n",str);
  343.                 break;
  344.                }
  345.           }
  346.          break;
  347.         }
  348.    }
  349.  
  350.   gpr_$move(xgpr,ygpr,&status);
  351.   check("in gpr_$move");
  352.   gpr_$text(str, str_len, &status);
  353.   check("in gpr_$text");
  354. }
  355.  
  356. int GPR_text_angle(ang)
  357. int ang;
  358. {   
  359.     if (gpr_ang != ang)
  360.       {
  361.         gpr_ang  = ang;
  362.         gpr_path = (gpr_ang == 1 ? gpr_$up : gpr_$right);
  363.       }
  364.     return (TRUE);
  365. }
  366.  
  367. int GPR_justify_text(mode)
  368. enum JUSTIFY mode;
  369. {
  370.     gpr_justify = mode;
  371.     return (TRUE);
  372. }
  373.  
  374. GPR_reset()
  375. {
  376.   gpr_$terminate(false, &status);
  377.   check("in gpr_$terminate");
  378. }
  379.