1 /* Hello, Emacs, this is -*-C-*-
2 * $Id: gpr.trm,v 1.13 2006/07/21 02:35:46 sfeam Exp $
6 /* GNUPLOT - gpr.trm */
9 * Copyright 1990 - 1993, 1998, 2004
11 * Permission to use, copy, and distribute this software and its
12 * documentation for any purpose with or without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and
14 * that both that copyright notice and this permission notice appear
15 * in supporting documentation.
17 * Permission to modify the software is granted, but not the right to
18 * distribute the complete modified source code. Modifications are to
19 * be distributed as patches to the released version. Permission to
20 * distribute binaries produced by compiling modified sources is granted,
22 * 1. distribute the corresponding source modifications from the
23 * released version in the form of a patch file along with the binaries,
24 * 2. add special version identification to distinguish your version
25 * in addition to the base release version number,
26 * 3. provide your name and address as the primary contact for the
27 * support of your modified version, and
28 * 4. retain our contact information in regard to use of the base
30 * Permission to distribute the released version of the source code along
31 * with corresponding source modifications in the form of a patch file is
32 * granted with same provisions 2 through 4 for binary distributions.
34 * This software is provided "as is" without express or implied warranty
35 * to the extent permitted by applicable law.
39 * This file is included by ../term.c.
41 * This terminal driver supports:
42 * APOLLO's GPR windowing system
46 * Roque D Oliveira , oliveria@caen.engin.umich.edu
48 * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
53 * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
63 TERM_PUBLIC void GPR_init __PROTO((void));
64 TERM_PUBLIC void GPR_graphics __PROTO((void));
65 TERM_PUBLIC void GPR_text __PROTO((void));
66 TERM_PUBLIC void GPR_linetype __PROTO((int linetype));
67 TERM_PUBLIC void GPR_move __PROTO((unsigned int x, unsigned int y));
68 TERM_PUBLIC void GPR_vector __PROTO((unsigned int x, unsigned int y));
69 TERM_PUBLIC void GPR_put_text __PROTO((unsigned int x, unsigned int y, const char str[]));
70 TERM_PUBLIC int GPR_text_angle __PROTO((int ang));
71 TERM_PUBLIC int GPR_justify_text __PROTO((enum JUSTIFY mode));
72 TERM_PUBLIC void GPR_reset __PROTO((void));
73 /* landscape window */
83 #define GPR_VTIC (GPR_YMAX/80)
84 #define GPR_HTIC (GPR_XMAX/80)
85 #endif /* TERM_PROTO */
87 #ifndef TERM_PROTO_ONLY
89 void GPRold_linetype __PROTO((int linetype));
90 static void check __PROTO((char *messagex));
91 int gpr_isa_pad __PROTO((void));
92 #include <apollo/base.h>
93 #include <apollo/error.h>
94 #include <apollo/gpr.h>
95 #include <apollo/pad.h>
97 #define GPR_XLAST (GPR_XMAX - 1)
98 #define GPR_YLAST (GPR_YMAX - 1)
101 gpr_$direction_t gpr_path = gpr_$right;
102 /* text angle, 0=horizontal, 1=vertical */
104 /* text is flush left */
105 enum JUSTIFY gpr_justify = LEFT;
107 static status_$t status;
108 /* set it to 1 when debugging program */
109 unsigned int Debug = 0;
113 check(char *messagex)
115 if (status.all = status_$ok) {
116 error_$print(status);
117 printf("Error occurred while %s.\n", messagex);
121 /* return whether stdout is a DM pad . Called by term.c */
125 pad_$isa(1, &status);
126 return (status.all == status_$ok);
133 gpr_$offset_t dm_bitmap_size;
134 gpr_$bitmap_desc_t dm_bitmap_desc;
135 pad_$window_desc_t window;
137 stream_$id_t stream_id;
138 static gpr_$rgb_plane_t hi_plane;
139 static gpr_$disp_char_t display_characteristics;
140 static float screen_size_r_width, screen_size_r_height;
141 static short int disp_len = sizeof(gpr_$disp_char_t);
142 static short int disp_len_returned;
145 /* open a pad to do graphics in */
148 /* 10 accounts for width of window border */
149 window.width = GPR_XMAX + 10;
150 /* 35 accounts for height of window border */
151 window.height = GPR_YMAX + 35;
152 pad_$create_window("", (short) 0, pad_$transcript, (short) 1, window, &stream_id, &status);
153 check("pad_$create_window");
155 /* pad_$set_full_window(stream_id,(short) 1,&window, &status); */
156 /* pad_$set_border (stream_id,(short) 1, true, &status); */
157 pad_$set_scale(stream_id, (short) 1, (short) 1, &status);
158 pad_$set_auto_close(stream_id, (short) 1, true, &status);
160 gpr_$inq_disp_characteristics(gpr_$direct, stream_id, disp_len, &display_characteristics, &disp_len_returned, &status);
161 check("in gpr_$inq_display_characteristics");
162 /*x_window_size in pixels */
163 screen_size_r_width = (float) display_characteristics.x_window_size;
164 /*y_window_size in pixels */
165 screen_size_r_height = (float) display_characteristics.y_window_size;
166 hi_plane = display_characteristics.n_planes - 1;
168 printf("width=%f height=%f \n", screen_size_r_width, screen_size_r_height);
170 dm_bitmap_size.x_size = 1280;
171 dm_bitmap_size.y_size = 1024;
172 gpr_$init(gpr_$direct, stream_id, dm_bitmap_size, hi_plane, &dm_bitmap_desc, &status);
173 check("in gpr_$init");
175 gpr_$set_obscured_opt(gpr_$pop_if_obs, &status);
176 check("in gpr_$set_obscured_opt");
178 gpr_$set_auto_refresh(true, &status);
179 check("in gpr_$set_auto_refresh");
181 /* load a font and make it current */
182 gpr_$load_font_file("f7x13", 5, &font_id, &status);
183 check("in gpr_$load_font_file");
184 gpr_$set_text_font(font_id, &status);
185 check("in gpr_$set_text_font");
187 /* set up color values */
188 gpr_$set_draw_value((gpr_$pixel_value_t) 7, &status); /* white */
189 check("in gpr_set_draw_value");
190 gpr_$set_text_background_value((gpr_$pixel_value_t) (-1), &status); /* trans */
191 check("in gpr_$set_text_background_value");
192 gpr_$set_text_value((gpr_$pixel_value_t) 7, &status); /* white */
193 check("in gpr_$set_text_value");
200 gpr_$coordinate_t locx, locy, marker_size;
202 (void) gpr_$acquire_display(&status);
203 check("in gpr_$acquire display");
204 gpr_$clear((gpr_$pixel_value_t) 0, &status); /* black */
205 check("in gpr_$clear");
208 marker_size = (short) 10;
212 gpr_$set_draw_value((gpr_$pixel_value_t) 2, &status); /* white */
213 gpr_$move((locx - marker_size / 2), locy, &status);
214 gpr_$line((locx + marker_size / 2), locy, &status);
215 gpr_$move(locx, (locy + marker_size / 2), &status);
216 gpr_$line(locx, (locy - marker_size / 2), &status);
218 locx = (short) (GPR_XMAX - 1 - 5);
220 gpr_$set_draw_value((gpr_$pixel_value_t) 3, &status); /* white */
221 gpr_$move((locx - marker_size / 2), locy, &status);
222 gpr_$line((locx + marker_size / 2), locy, &status);
223 gpr_$move(locx, (locy + marker_size / 2), &status);
224 gpr_$line(locx, (locy - marker_size / 2), &status);
227 locy = (short) (GPR_YMAX - 1 - 5);
228 gpr_$set_draw_value((gpr_$pixel_value_t) 4, &status); /* white */
229 gpr_$move((locx - marker_size / 2), locy, &status);
230 gpr_$line((locx + marker_size / 2), locy, &status);
231 gpr_$move(locx, (locy + marker_size / 2), &status);
232 gpr_$line(locx, (locy - marker_size / 2), &status);
234 locx = (short) (GPR_XMAX - 1 - 5);
235 locy = (short) (GPR_YMAX - 1 - 5);
236 gpr_$set_draw_value((gpr_$pixel_value_t) 5, &status); /* white */
237 gpr_$move((locx - marker_size / 2), locy, &status);
238 gpr_$line((locx + marker_size / 2), locy, &status);
239 gpr_$move(locx, (locy + marker_size / 2), &status);
240 gpr_$line(locx, (locy - marker_size / 2), &status);
242 gpr_$set_draw_value((gpr_$pixel_value_t) 7, &status); /* white */
243 check("in gpr_$set_draw_value");
244 } /* end if(Debug) */
251 gpr_$release_display(&status);
252 check("gpr_$release_display");
257 GPRold_linetype(int linetype)
259 static gpr_$line_pattern_t patterns[2 + 5] =
261 {0xFFFF}, /* solid 1111111111111111 */
262 {0x3FFF}, /* very long dashed 0011111111111111 */
263 {0xFFFF}, /* solid 1111111111111111 */
264 {0x5555}, /* dotted 0101010101010101 */
265 {0x3333}, /* short dashed 0011001100110011 */
266 {0xB5AD}, /* dot short-dashed 1011010110101101 */
267 {0x3FFF} /* very long dashed 0011111111111111 */
271 gpr_$set_line_pattern((short) 1, patterns[linetype + 2], (short) 16, &status);
272 check("in gpr_$set_line_pattern");
276 GPR_linetype(int linetype)
278 static gpr_$line_pattern_t patterns[2 + 7] =
280 {0xFFFF}, /* solid 1111111111111111 */
281 {0x1111}, /* long-spaced dotted 0001000100010001 */
282 {0xFFFF}, /* solid 1111111111111111 */
283 {0x5555}, /* dotted 0101010101010101 */
284 {0x3333}, /* short dashed 0011001100110011 */
285 {0x7777}, /* medium dashed 0111011101110111 */
286 {0x3F3F}, /* long dashed 0011111100111111 */
287 {0x0F0F}, /* long-spaced dashed 0000111100001111 */
288 {0x5F5F} /* dot dashed 0101111101011111 */
292 gpr_$set_line_pattern((short) 1, patterns[linetype + 2], (short) 16, &status);
293 check("in gpr_$set_line_pattern");
296 gpr_$set_draw_value((gpr_$pixel_value_t)(linetype + 1), &status);
297 check("in gpr_$set_draw_value");
303 GPR_move(unsigned int x, unsigned int y)
305 gpr_$move((short) x, (short) (GPR_YMAX - 1 - y), &status);
306 check("in gpr_$move");
311 GPR_vector(unsigned int x, unsigned int y)
313 gpr_$line((short) x, (short) (GPR_YMAX - 1 - y), &status);
314 check("in gpr_$line");
319 GPR_put_text(unsigned int x, unsigned int y, const char str[])
321 gpr_$coordinate_t xgpr, ygpr;
322 gpr_$offset_t str_size_in_pixels;
325 gpr_$coordinate_t locx, locy, marker_size;
329 locy = (short) (GPR_YMAX - 1 - y);
330 marker_size = (short) 20;
331 gpr_$set_draw_value((gpr_$pixel_value_t) 1, &status); /* white */
332 gpr_$move((locx - marker_size / 2), locy, &status);
333 gpr_$line((locx + marker_size / 2), locy, &status);
334 gpr_$move(locx, (locy + marker_size / 2), &status);
335 gpr_$line(locx, (locy - marker_size / 2), &status);
336 gpr_$set_draw_value((gpr_$pixel_value_t) 7, &status); /* white */
339 ygpr = (short) (GPR_YMAX - 1 - y);
340 gpr_$set_text_path(gpr_path, &status);
341 check("gpr_$set_text_path");
343 str_len = (short) strlen(str);
344 /* Calculate how much space (in pixels) the string requires */
345 gpr_$inq_text_extent(str, str_len, &str_size_in_pixels, &status);
346 check("in gpr_$inq_text_extent");
348 switch (gpr_justify) {
352 case gpr_$up: /* vertical */
355 printf("LEFT and up , str=%s\n", str);
358 case gpr_$right: /* horizontal */
360 ygpr = ygpr + str_size_in_pixels.y_size / 2;
362 printf("LEFT and right, str=%s \n", str);
372 case gpr_$up: /* vertical */
374 xgpr = xgpr + str_size_in_pixels.x_size / 2;
375 ygpr = ygpr + str_size_in_pixels.y_size / 2;
377 printf("CENTRE and up, str=%s \n", str);
380 case gpr_$right: /* horizontal */
382 xgpr = xgpr - str_size_in_pixels.x_size / 2;
383 ygpr = ygpr + str_size_in_pixels.y_size / 2;
385 printf("CENTRE and right, str=%s \n", str);
394 case gpr_$up: /* vertical */
396 ygpr = ygpr + str_size_in_pixels.y_size;
398 printf("RIGHT and up, str=%s \n", str);
401 case gpr_$right: /* horizontal */
403 xgpr = xgpr - str_size_in_pixels.x_size;
404 ygpr = ygpr + str_size_in_pixels.y_size / 2;
406 printf("RIGHT and right, str=%s \n", str);
414 gpr_$move(xgpr, ygpr, &status);
415 check("in gpr_$move");
416 gpr_$text(str, str_len, &status);
417 check("in gpr_$text");
421 GPR_text_angle(int ang)
423 if (gpr_ang != ang) {
425 gpr_path = (gpr_ang ? gpr_$up : gpr_$right);
431 GPR_justify_text(enum JUSTIFY mode)
440 gpr_$terminate(false, &status);
441 check("in gpr_$terminate");
444 #endif /* TERM_BODY */
448 TERM_TABLE_START(gpr_driver)
449 "gpr", "Apollo Graphics Primitive Resource, fixed-size window",
450 GPR_XMAX, GPR_YMAX, GPR_VCHAR, GPR_HCHAR,
451 GPR_VTIC, GPR_HTIC, options_null, GPR_init, GPR_reset,
452 GPR_text, null_scale, GPR_graphics, GPR_move, GPR_vector,
453 GPR_linetype, GPR_put_text, GPR_text_angle,
454 GPR_justify_text, line_and_point, do_arrow, set_font_null
455 TERM_TABLE_END(gpr_driver)
458 #define LAST_TERM gpr_driver
460 #endif /* TERM_TABLE */
461 #endif /* TERM_PROTO_ONLY */
466 "?commands set terminal gpr",
472 " The `gpr` terminal driver supports the Apollo Graphics Primitive Resource",
473 " for a fixed-size window. It has no options.",
475 " If a variable window size is desired, use the `apollo` terminal instead."
477 #endif /* TERM_HELP */