C:/Users/Dennis/src/lang/bertrand/BERTRAND/bertrand/graphics.c

Go to the documentation of this file.
00001 /*********************************************************
00002  *
00003  * Graphics routines for the NeWS window system.
00004  *
00005  * The routines snews_setup, snews_line, and snews_string are defined
00006  * in graphics.cps, which gets converted into graphics.h by cps.
00007  * The routines ps_open_PostScript, ps_flush_PostScript,
00008  * ps_close_PostScript, and PostScriptInput are defined by NeWS.
00009  *
00010  *********************************************************/
00011 
00012 #include "def.h"
00013 #include "graphics.h"
00014 
00015 /* this variable is set to true when the graphics device has been opened */
00016 int graphics = FALSE;
00017 
00018 /* open graphics device */
00019 void
00020 graphics_init()
00021 {
00022 ps_open_PostScript();
00023 snews_setup();
00024 ps_flush_PostScript();
00025 graphics = TRUE;
00026 }
00027 
00028 /* Assume numbers in Bertrand are in inches */
00029 /* If other units are desired, simply use a different constant */
00030 #define INCHES 100      /* resolution of the screen, in pixels per inch */
00031 
00032 /* draw a line between two points */
00033 void
00034 draw_line(x1,y1,x2,y2)
00035 double x1, y1, x2, y2;
00036 {
00037 int x1i = (int) (INCHES * x1);
00038 int y1i = (int) (INCHES * y1);
00039 int x2i = (int) (INCHES * x2);
00040 int y2i = (int) (INCHES * y2);
00041 
00042 if (!graphics) graphics_init();
00043 snews_line(x1i, y1i, x2i, y2i);
00044 ps_flush_PostScript();
00045 }
00046 
00047 /* paint a string, centered at a certain location */
00048 void
00049 draw_string(str,x,y)
00050 char *str;
00051 double x,y;
00052 {
00053 int xi = (int) (INCHES * x);
00054 int yi = (int) (INCHES * y);
00055 if (!graphics) graphics_init();
00056 snews_string(str, xi, yi);
00057 ps_flush_PostScript();
00058 }
00059 
00060 /* close the graphics device, only called if graphics == TRUE */
00061 void
00062 graphics_close()
00063 {
00064 while ('X' != getc(PostScriptInput))            ;
00065 while ('\n' != getc(PostScriptInput))           ;
00066 ps_close_PostScript();
00067 graphics = FALSE;
00068 }

Generated on Fri Jan 25 09:58:43 2008 for Bertrand by  doxygen 1.5.4