home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / maths / plplot / plplot_2 / drivers / mgr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-19  |  9.2 KB  |  373 lines

  1. /* $Id: mgr.c,v 1.4 1994/07/19 22:30:22 mjl Exp $
  2.  * $Log: mgr.c,v $
  3.  * Revision 1.4  1994/07/19  22:30:22  mjl
  4.  * All device drivers: enabling macro renamed to PLD_<driver>, where <driver>
  5.  * is xwin, ps, etc.  See plDevs.h for more detail.
  6.  *
  7.  * Revision 1.3  1994/04/08  11:35:59  mjl
  8.  * Put nopause support back into the drivers where it is better off.
  9.  * I don't know WHAT I was thinking.
  10.  *
  11.  * Revision 1.2  1994/03/23  06:34:29  mjl
  12.  * All drivers: cleaned up by eliminating extraneous includes (stdio.h and
  13.  * stdlib.h now included automatically by plplotP.h), extraneous clears
  14.  * of pls->fileset, pls->page, and pls->OutFile = NULL (now handled in
  15.  * driver interface or driver initialization as appropriate).  Special
  16.  * handling for malloc includes eliminated (no longer needed) and malloc
  17.  * prototypes fixed as necessary.
  18.  *
  19.  * Revision 1.1  1993/08/03  03:21:55  mjl
  20.  * Added contributions from Sergio Fanchiotti for use under Linux.
  21. */
  22.  
  23. /*
  24.     mgr.c
  25.     S. Fanchiotti (Using gnusvga.c by Geoffrey Furnish)
  26.     4 May 1993
  27.     
  28.     This file constitutes the driver for an MGR window under Linux
  29.     using the GNU CC compiler.
  30.  
  31.     Things to note:
  32.          The idea of an event handler as done for xterm.c should be used
  33.      as it is more elegant and also it can be used to set the event
  34.      codes. In this way no recompilation would be ncessary if other
  35.      routines set up messages for the same event.
  36. */
  37. #include "plDevs.h"
  38.  
  39. #ifdef PLD_mgr            /* Only compile if MGR support is needed */
  40.  
  41. #include "plplotP.h"
  42. #include "drivers.h"
  43. #include <string.h>
  44. /* The next one is highly dependant on the MGR installation!!! */
  45. #include "/usr/mgr/include/term.h"
  46.  
  47. /* Function prototypes */
  48. /* INDENT OFF */
  49.  
  50. static void SetEvent    (void);
  51. static void GetKey    (PLStream *);
  52. static void mgr_text    (PLStream *pls);
  53. static void mgr_graph    (PLStream *pls);
  54.  
  55. /* INDENT ON */
  56.  
  57. static PLINT mgrx = 639;
  58. static PLINT mgry = 479;
  59.  
  60. /* A flag to tell us whether we are in text or graphics mode */
  61.  
  62. #define TEXT_MODE 0
  63. #define GRAPHICS_MODE 1
  64.  
  65. /* gmf; should probably query this on start up... Maybe later. */
  66.  
  67. static int col = 1;
  68. static int totcol = 16;
  69.  
  70. #define CLEAN 0
  71. #define DIRTY 1
  72.  
  73. static page_state;
  74.  
  75. /*----------------------------------------------------------------------*\
  76. * plD_init_mgr()
  77. *
  78. * Initialize device.
  79. \*----------------------------------------------------------------------*/
  80.  
  81. void
  82. plD_init_mgr(PLStream *pls)
  83. {
  84.     PLDev *dev;
  85.     int Xw, Yw;            /* Dummy vars */
  86.  
  87. /* Check if we are running in a MGR window */
  88.     if (strcmp(getenv("TERM"), "mgr"))
  89.     plexit("plD_init_mgr: TERM enviroment var not set to \"mgr\".");
  90.  
  91. /* Ok, now set up the device parameters */
  92.     pls->termin = 1;        /* is an interactive terminal */
  93.     pls->icol0 = 1;
  94.     pls->color = 0;        /* No color implemented in Linux MGR (Yet!) */
  95.     pls->width = 1;
  96.     pls->bytecnt = 0;
  97.     pls->page = 0;
  98.     pls->graphx = TEXT_MODE;
  99.  
  100.     if (!pls->colorset)
  101.     pls->color = BLACK;    /* As defined in window.h */
  102.  
  103. /* Allocate and initialize device-specific data */
  104.  
  105.     dev = plAllocDev(pls);
  106.  
  107.     m_setup(M_FLUSH | M_MODEOK);/* Initialize function library */
  108.     m_push(P_ALL);        /* Store terminal state in a stack */
  109.  
  110.     /* Now we get the dimensions of the window */
  111.     m_setnoecho();        /* MGR not echoing to screen */
  112.     get_size(&Xw, &Yw, &mgrx, &mgry);
  113.     mgrx -= 1;
  114.     mgry -= 1;
  115.  
  116.     dev->xold = UNDEFINED;
  117.     dev->yold = UNDEFINED;
  118.     dev->xmin = 0;
  119.     dev->xmax = mgrx;
  120.     dev->ymin = 0;
  121.     dev->ymax = mgry;
  122.  
  123.     dev->xlen = dev->xmax - dev->xmin;
  124.     dev->ylen = dev->ymax - dev->ymin;
  125.  
  126.     setpxl(2.5, 2.5);        /* My best guess.  Seems to work okay. */
  127.  
  128.     setphy(0, mgrx, 0, mgry);
  129.  
  130.     SetEvent();            /* Tell MGR to inform us of changes */
  131.     m_setecho();        /* In case there is some text interaction */
  132. }
  133.  
  134. /*----------------------------------------------------------------------*\
  135. * plD_line_mgr()
  136. *
  137. * Draw a line in the current color from (x1,y1) to (x2,y2).
  138. \*----------------------------------------------------------------------*/
  139.  
  140. void
  141. plD_line_mgr(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
  142. {
  143.     int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
  144.  
  145.     y1 = mgry - y1;
  146.     y2 = mgry - y2;
  147.  
  148.     m_line(x1, y1, x2, y2);
  149.  
  150.     page_state = DIRTY;
  151. }
  152.  
  153. /*----------------------------------------------------------------------*\
  154. * plD_polyline_mgr()
  155. *
  156. * Draw a polyline in the current color.
  157. \*----------------------------------------------------------------------*/
  158.  
  159. void
  160. plD_polyline_mgr(PLStream *pls, short *xa, short *ya, PLINT npts)
  161. {
  162.     PLINT i;
  163.  
  164.     for (i = 0; i < npts - 1; i++)
  165.     plD_line_mgr(pls, xa[i], ya[i], xa[i + 1], ya[i + 1]);
  166. }
  167.  
  168. /*----------------------------------------------------------------------*\
  169. * plD_eop_mgr()
  170. *
  171. * End of page.
  172. \*----------------------------------------------------------------------*/
  173.  
  174. void
  175. plD_eop_mgr(PLStream *pls)
  176. {
  177.     if (page_state == DIRTY)
  178.     GetKey(pls);
  179.  
  180.     m_clear();            /* just clean it */
  181.  
  182.     page_state = CLEAN;
  183. }
  184.  
  185. /*----------------------------------------------------------------------*\
  186. * plD_bop_mgr()
  187. *
  188. * Set up for the next page.
  189. * Advance to next family file if necessary (file output).
  190. \*----------------------------------------------------------------------*/
  191.  
  192. void
  193. plD_bop_mgr(PLStream *pls)
  194. {
  195.     pls->page++;
  196.     plD_eop_mgr(pls);
  197. }
  198.  
  199. /*----------------------------------------------------------------------*\
  200. * plD_tidy_mgr()
  201. *
  202. * Close graphics file or otherwise clean up.
  203. \*----------------------------------------------------------------------*/
  204.  
  205. void
  206. plD_tidy_mgr(PLStream *pls)
  207. {
  208.     m_ttyreset();        /* Reset tty mode */
  209.     m_popall();            /* Restores original state of window (see
  210.                    plD_init_mgr) */
  211. }
  212.  
  213. /*----------------------------------------------------------------------*\
  214. * plD_state_mgr()
  215. *
  216. * Handle change in PLStream state (color, pen width, fill attribute, etc).
  217. \*----------------------------------------------------------------------*/
  218.  
  219. void
  220. plD_state_mgr(PLStream *pls, PLINT op)
  221. {
  222.     switch (op) {
  223.  
  224.       case PLSTATE_WIDTH:
  225.     break;
  226.  
  227.       case PLSTATE_COLOR0:
  228.     if (pls->color) {
  229.         col = (pls->icol0) % totcol;    /* Color modulo # of colors
  230.                            available */
  231.         m_fcolor(col);    /* Useless in monochrome MGR */
  232.     }
  233.     break;
  234.  
  235.       case PLSTATE_COLOR1:
  236.     break;
  237.     }
  238. }
  239.  
  240. /*----------------------------------------------------------------------*\
  241. * plD_esc_mgr()
  242. *
  243. * Escape function.
  244. \*----------------------------------------------------------------------*/
  245.  
  246. void
  247. plD_esc_mgr(PLStream *pls, PLINT op, void *ptr)
  248. {
  249.     switch (op) {
  250.  
  251.       case PLESC_TEXT:
  252.     mgr_text(pls);
  253.     break;
  254.  
  255.       case PLESC_GRAPH:
  256.     mgr_graph(pls);
  257.     break;
  258.     }
  259. }
  260.  
  261. /*----------------------------------------------------------------------*\
  262. * mgr_text()
  263. *
  264. * Switch to text mode.
  265. \*----------------------------------------------------------------------*/
  266.  
  267. static void
  268. mgr_text(PLStream *pls)
  269. {
  270.     if (pls->graphx == GRAPHICS_MODE) {
  271.  
  272.     m_setecho();        /* Echo characters again  */
  273.     m_ttyreset();        /* Reset tty mode */
  274.  
  275.     pls->graphx = TEXT_MODE;
  276.     }
  277. }
  278.  
  279. /*----------------------------------------------------------------------*\
  280. * mgr_graph()
  281. *
  282. * Switch to graphics mode.
  283. \*----------------------------------------------------------------------*/
  284.  
  285. static void
  286. mgr_graph(PLStream *pls)
  287. {
  288.     if (pls->graphx == TEXT_MODE) {
  289.  
  290.     m_ttyset();        /* Enable MGR commands */
  291.     m_setcursor(CS_INVIS);    /* make cursor invisible */
  292.     m_setnoecho();        /* Don't write to terminal MGR's messages */
  293.     m_setmode(M_ABS);    /* We will use absolute window coordinates. */
  294.  
  295.     pls->graphx = GRAPHICS_MODE;
  296.     page_state = CLEAN;
  297.     }
  298. }
  299.  
  300. /*----------------------------------------------------------------------*\
  301. * SetEvent(void)
  302. *
  303. * Setup MGR event messages format and load menus.
  304. \*----------------------------------------------------------------------*/
  305.  
  306. static void
  307. SetEvent(void)
  308. {
  309.     /* Load menu in Middle and Right buttons */
  310.     m_loadmenu(0, "|Next page|Non-stop|Quit|N||Q|");
  311.     m_loadmenu(1, "|Next page|Non-stop|Quit|N||Q|");
  312.     m_selectmenu(0);        /* Middle button */
  313.     m_selectmenu2(1);        /* Right button */
  314.  
  315.     m_setevent(RESHAPE, "");    /* If a window reshape occurs an Ctrl-R char is
  316.                    passed to the client */
  317. }
  318.  
  319. /*----------------------------------------------------------------------*\
  320. * GetKey(PLStream *)
  321. *
  322. * Check if MGR did something to the window and act accordingly. It needs
  323. * to wait for a key to be pressed though.
  324. \*----------------------------------------------------------------------*/
  325.  
  326. static void
  327. GetKey(PLStream *pls)
  328. {
  329.     PLDev *dev = (PLDev *) pls->dev;
  330.     static char ch;
  331.     static int again, Xw, Yw;    /* Dummy vars */
  332.  
  333.     if (pls->nopause) 
  334.     return;
  335.  
  336.     do {
  337.     again = FALSE;
  338.     ch = m_getchar();    /* Ignore ESC character */
  339.     switch (ch) {
  340.       case '':        /* Checkout window dimensions again */
  341.         get_size(&Xw, &Yw, &mgrx, &mgry);
  342.         mgrx -= 1;
  343.         mgry -= 1;
  344.         /* Inform of the change to the plplot routines */
  345.         dev->xmax = mgrx;
  346.         dev->ymax = mgry;
  347.         dev->xlen = dev->xmax - dev->xmin;
  348.         dev->ylen = dev->ymax - dev->ymin;
  349.         setphy(0, mgrx, 0, mgry);    /* A hack */
  350.         again = TRUE;
  351.         break;
  352.       case '':        /* Run non stop */
  353.         pls->nopause = TRUE;
  354.         break;
  355.       case 'q':        /* Sort of ``cut it off now!'' */
  356.       case 'Q':
  357.       case 'x':
  358.         pls->nopause = TRUE;
  359.         plexit("");        /* Abort the thing */
  360.         break;
  361.     }
  362.     } while (again);
  363. }
  364.  
  365. #else
  366. int
  367. pldummy_mgr()
  368. {
  369.     return 0;
  370. }
  371.  
  372. #endif                /* PLD_mgr */
  373.