Annotation of OpenXM_contrib/gnuplot/term/gpr.trm, Revision 1.1
1.1 ! maekawa 1: /*
! 2: * $Id: gpr.trm,v 1.13 1998/04/14 00:17:46 drd Exp $
! 3: *
! 4: */
! 5:
! 6: /* GNUPLOT - gpr.trm */
! 7:
! 8: /*[
! 9: * Copyright 1990 - 1993, 1998
! 10: *
! 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.
! 16: *
! 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,
! 21: * provided you
! 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
! 29: * software.
! 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.
! 33: *
! 34: * This software is provided "as is" without express or implied warranty
! 35: * to the extent permitted by applicable law.
! 36: ]*/
! 37:
! 38: /*
! 39: * This file is included by ../term.c.
! 40: *
! 41: * This terminal driver supports:
! 42: * APOLLO's GPR windowing system
! 43: *
! 44: * AUTHORS
! 45: * Michael Aramini
! 46: * Roque D Oliveira , oliveria@caen.engin.umich.edu
! 47: *
! 48: * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
! 49: *
! 50: */
! 51:
! 52: /*
! 53: * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
! 54: */
! 55:
! 56: #include "driver.h"
! 57:
! 58: #ifdef TERM_REGISTER
! 59: register_term(gpr)
! 60: #endif
! 61:
! 62: #ifdef TERM_PROTO
! 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, 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 */
! 74: /*
! 75: #define GPR_XMAX 720
! 76: #define GPR_YMAX 450
! 77: */
! 78: /* portrait window */
! 79: #define GPR_XMAX 585
! 80: #define GPR_YMAX 735
! 81: #define GPR_VCHAR 19
! 82: #define GPR_HCHAR 10
! 83: #define GPR_VTIC (GPR_YMAX/80)
! 84: #define GPR_HTIC (GPR_XMAX/80)
! 85: #endif /* TERM_PROTO */
! 86:
! 87: #ifndef TERM_PROTO_ONLY
! 88: #ifdef TERM_BODY
! 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>
! 96:
! 97: #define GPR_XLAST (GPR_XMAX - 1)
! 98: #define GPR_YLAST (GPR_YMAX - 1)
! 99:
! 100:
! 101: gpr_$direction_t gpr_path = gpr_$right;
! 102: /* text angle, 0=horizontal, 1=vertical */
! 103: int gpr_ang = 0;
! 104: /* text is flush left */
! 105: enum JUSTIFY gpr_justify = LEFT;
! 106:
! 107: static status_$t status;
! 108: /* set it to 1 when debugging program */
! 109: unsigned int Debug = 0;
! 110:
! 111:
! 112: static void check(messagex)
! 113: char *messagex;
! 114: {
! 115: if (status.all = status_$ok) {
! 116: error_$print(status);
! 117: printf("Error occurred while %s.\n", messagex);
! 118: }
! 119: }
! 120:
! 121: /* return whether stdout is a DM pad . Called by term.c */
! 122: int gpr_isa_pad()
! 123: {
! 124: pad_$isa(1, &status);
! 125: return (status.all == status_$ok);
! 126: }
! 127:
! 128:
! 129: TERM_PUBLIC void GPR_init()
! 130: {
! 131: gpr_$offset_t dm_bitmap_size;
! 132: gpr_$bitmap_desc_t dm_bitmap_desc;
! 133: pad_$window_desc_t window;
! 134: short font_id;
! 135: stream_$id_t stream_id;
! 136: static gpr_$rgb_plane_t hi_plane;
! 137: static gpr_$disp_char_t display_characteristics;
! 138: static float screen_size_r_width, screen_size_r_height;
! 139: static short int disp_len = sizeof(gpr_$disp_char_t);
! 140: static short int disp_len_returned;
! 141:
! 142:
! 143: /* open a pad to do graphics in */
! 144: window.top = 0;
! 145: window.left = 0;
! 146: /* 10 accounts for width of window border */
! 147: window.width = GPR_XMAX + 10;
! 148: /* 35 accounts for height of window border */
! 149: window.height = GPR_YMAX + 35;
! 150: pad_$create_window("", (short) 0, pad_$transcript, (short) 1, window, &stream_id, &status);
! 151: check("pad_$create_window");
! 152:
! 153: /* pad_$set_full_window(stream_id,(short) 1,&window, &status); */
! 154: /* pad_$set_border (stream_id,(short) 1, true, &status); */
! 155: pad_$set_scale(stream_id, (short) 1, (short) 1, &status);
! 156: pad_$set_auto_close(stream_id, (short) 1, true, &status);
! 157:
! 158: gpr_$inq_disp_characteristics(gpr_$direct, stream_id, disp_len, &display_characteristics, &disp_len_returned, &status);
! 159: check("in gpr_$inq_display_characteristics");
! 160: /*x_window_size in pixels */
! 161: screen_size_r_width = (float) display_characteristics.x_window_size;
! 162: /*y_window_size in pixels */
! 163: screen_size_r_height = (float) display_characteristics.y_window_size;
! 164: hi_plane = display_characteristics.n_planes - 1;
! 165: if (Debug)
! 166: printf("width=%f height=%f \n", screen_size_r_width, screen_size_r_height);
! 167:
! 168: dm_bitmap_size.x_size = 1280;
! 169: dm_bitmap_size.y_size = 1024;
! 170: gpr_$init(gpr_$direct, stream_id, dm_bitmap_size, hi_plane, &dm_bitmap_desc, &status);
! 171: check("in gpr_$init");
! 172: /*
! 173: gpr_$set_obscured_opt(gpr_$pop_if_obs, &status);
! 174: check("in gpr_$set_obscured_opt");
! 175: */
! 176: gpr_$set_auto_refresh(true, &status);
! 177: check("in gpr_$set_auto_refresh");
! 178:
! 179: /* load a font and make it current */
! 180: gpr_$load_font_file("f7x13", 5, &font_id, &status);
! 181: check("in gpr_$load_font_file");
! 182: gpr_$set_text_font(font_id, &status);
! 183: check("in gpr_$set_text_font");
! 184:
! 185: /* set up color values */
! 186: gpr_$set_draw_value((gpr_$pixel_value_t) 7, &status); /* white */
! 187: check("in gpr_set_draw_value");
! 188: gpr_$set_text_background_value((gpr_$pixel_value_t) (-1), &status); /* trans */
! 189: check("in gpr_$set_text_background_value");
! 190: gpr_$set_text_value((gpr_$pixel_value_t) 7, &status); /* white */
! 191: check("in gpr_$set_text_value");
! 192: }
! 193:
! 194:
! 195: TERM_PUBLIC void GPR_graphics()
! 196: {
! 197: gpr_$coordinate_t locx, locy, marker_size;
! 198:
! 199: (void) gpr_$acquire_display(&status);
! 200: check("in gpr_$acquire display");
! 201: gpr_$clear((gpr_$pixel_value_t) 0, &status); /* black */
! 202: check("in gpr_$clear");
! 203:
! 204: if (Debug) {
! 205: marker_size = (short) 10;
! 206:
! 207: locx = (short) 5;
! 208: locy = (short) 5;
! 209: gpr_$set_draw_value((gpr_$pixel_value_t) 2, &status); /* white */
! 210: gpr_$move((locx - marker_size / 2), locy, &status);
! 211: gpr_$line((locx + marker_size / 2), locy, &status);
! 212: gpr_$move(locx, (locy + marker_size / 2), &status);
! 213: gpr_$line(locx, (locy - marker_size / 2), &status);
! 214:
! 215: locx = (short) (GPR_XMAX - 1 - 5);
! 216: locy = (short) 5;
! 217: gpr_$set_draw_value((gpr_$pixel_value_t) 3, &status); /* white */
! 218: gpr_$move((locx - marker_size / 2), locy, &status);
! 219: gpr_$line((locx + marker_size / 2), locy, &status);
! 220: gpr_$move(locx, (locy + marker_size / 2), &status);
! 221: gpr_$line(locx, (locy - marker_size / 2), &status);
! 222:
! 223: locx = (short) 5;
! 224: locy = (short) (GPR_YMAX - 1 - 5);
! 225: gpr_$set_draw_value((gpr_$pixel_value_t) 4, &status); /* white */
! 226: gpr_$move((locx - marker_size / 2), locy, &status);
! 227: gpr_$line((locx + marker_size / 2), locy, &status);
! 228: gpr_$move(locx, (locy + marker_size / 2), &status);
! 229: gpr_$line(locx, (locy - marker_size / 2), &status);
! 230:
! 231: locx = (short) (GPR_XMAX - 1 - 5);
! 232: locy = (short) (GPR_YMAX - 1 - 5);
! 233: gpr_$set_draw_value((gpr_$pixel_value_t) 5, &status); /* white */
! 234: gpr_$move((locx - marker_size / 2), locy, &status);
! 235: gpr_$line((locx + marker_size / 2), locy, &status);
! 236: gpr_$move(locx, (locy + marker_size / 2), &status);
! 237: gpr_$line(locx, (locy - marker_size / 2), &status);
! 238:
! 239: gpr_$set_draw_value((gpr_$pixel_value_t) 7, &status); /* white */
! 240: check("in gpr_$set_draw_value");
! 241: } /* end if(Debug) */
! 242: }
! 243:
! 244:
! 245: TERM_PUBLIC void GPR_text()
! 246: {
! 247: gpr_$release_display(&status);
! 248: check("gpr_$release_display");
! 249: }
! 250:
! 251:
! 252: void GPRold_linetype(linetype)
! 253: int linetype;
! 254: {
! 255: static gpr_$line_pattern_t patterns[2 + 5] =
! 256: {
! 257: {0xFFFF}, /* solid 1111111111111111 */
! 258: {0x3FFF}, /* very long dashed 0011111111111111 */
! 259: {0xFFFF}, /* solid 1111111111111111 */
! 260: {0x5555}, /* dotted 0101010101010101 */
! 261: {0x3333}, /* short dashed 0011001100110011 */
! 262: {0xB5AD}, /* dot short-dashed 1011010110101101 */
! 263: {0x3FFF} /* very long dashed 0011111111111111 */
! 264: };
! 265: if (linetype >= 5)
! 266: linetype %= 5;
! 267: gpr_$set_line_pattern((short) 1, patterns[linetype + 2], (short) 16, &status);
! 268: check("in gpr_$set_line_pattern");
! 269: }
! 270:
! 271: TERM_PUBLIC void GPR_linetype(linetype)
! 272: int linetype;
! 273: {
! 274: static gpr_$line_pattern_t patterns[2 + 7] =
! 275: {
! 276: {0xFFFF}, /* solid 1111111111111111 */
! 277: {0x1111}, /* long-spaced dotted 0001000100010001 */
! 278: {0xFFFF}, /* solid 1111111111111111 */
! 279: {0x5555}, /* dotted 0101010101010101 */
! 280: {0x3333}, /* short dashed 0011001100110011 */
! 281: {0x7777}, /* medium dashed 0111011101110111 */
! 282: {0x3F3F}, /* long dashed 0011111100111111 */
! 283: {0x0F0F}, /* long-spaced dashed 0000111100001111 */
! 284: {0x5F5F} /* dot dashed 0101111101011111 */
! 285: };
! 286: if (linetype >= 7)
! 287: linetype %= 7;
! 288: gpr_$set_line_pattern((short) 1, patterns[linetype + 2], (short) 16, &status);
! 289: check("in gpr_$set_line_pattern");
! 290:
! 291: /*
! 292: gpr_$set_draw_value((gpr_$pixel_value_t)(linetype + 1), &status);
! 293: check("in gpr_$set_draw_value");
! 294: */
! 295: }
! 296:
! 297:
! 298: TERM_PUBLIC void GPR_move(x, y)
! 299: unsigned int x, y;
! 300: {
! 301: gpr_$move((short) x, (short) (GPR_YMAX - 1 - y), &status);
! 302: check("in gpr_$move");
! 303: }
! 304:
! 305:
! 306: TERM_PUBLIC void GPR_vector(x, y)
! 307: unsigned int x, y;
! 308: {
! 309: gpr_$line((short) x, (short) (GPR_YMAX - 1 - y), &status);
! 310: check("in gpr_$line");
! 311: }
! 312:
! 313:
! 314: TERM_PUBLIC void GPR_put_text(x, y, str)
! 315: unsigned int x, y; /* reference point of string */
! 316: char str[]; /* the text */
! 317: {
! 318: gpr_$coordinate_t xgpr, ygpr;
! 319: gpr_$offset_t str_size_in_pixels;
! 320: short int str_len;
! 321:
! 322: gpr_$coordinate_t locx, locy, marker_size;
! 323:
! 324: if (Debug) {
! 325: locx = (short) x;
! 326: locy = (short) (GPR_YMAX - 1 - y);
! 327: marker_size = (short) 20;
! 328: gpr_$set_draw_value((gpr_$pixel_value_t) 1, &status); /* white */
! 329: gpr_$move((locx - marker_size / 2), locy, &status);
! 330: gpr_$line((locx + marker_size / 2), locy, &status);
! 331: gpr_$move(locx, (locy + marker_size / 2), &status);
! 332: gpr_$line(locx, (locy - marker_size / 2), &status);
! 333: gpr_$set_draw_value((gpr_$pixel_value_t) 7, &status); /* white */
! 334: }
! 335: xgpr = (short) x;
! 336: ygpr = (short) (GPR_YMAX - 1 - y);
! 337: gpr_$set_text_path(gpr_path, &status);
! 338: check("gpr_$set_text_path");
! 339:
! 340: str_len = (short) strlen(str);
! 341: /* Calculate how much space (in pixels) the string requires */
! 342: gpr_$inq_text_extent(str, str_len, &str_size_in_pixels, &status);
! 343: check("in gpr_$inq_text_extent");
! 344:
! 345: switch (gpr_justify) {
! 346: case LEFT:
! 347: {
! 348: switch (gpr_path) {
! 349: case gpr_$up: /* vertical */
! 350: {
! 351: if (Debug)
! 352: printf("LEFT and up , str=%s\n", str);
! 353: break;
! 354: }
! 355: case gpr_$right: /* horizontal */
! 356: {
! 357: ygpr = ygpr + str_size_in_pixels.y_size / 2;
! 358: if (Debug)
! 359: printf("LEFT and right, str=%s \n", str);
! 360: break;
! 361: }
! 362: }
! 363: break;
! 364: }
! 365:
! 366: case CENTRE:
! 367: {
! 368: switch (gpr_path) {
! 369: case gpr_$up: /* vertical */
! 370: {
! 371: xgpr = xgpr + str_size_in_pixels.x_size / 2;
! 372: ygpr = ygpr + str_size_in_pixels.y_size / 2;
! 373: if (Debug)
! 374: printf("CENTRE and up, str=%s \n", str);
! 375: break;
! 376: }
! 377: case gpr_$right: /* horizontal */
! 378: {
! 379: xgpr = xgpr - str_size_in_pixels.x_size / 2;
! 380: ygpr = ygpr + str_size_in_pixels.y_size / 2;
! 381: if (Debug)
! 382: printf("CENTRE and right, str=%s \n", str);
! 383: break;
! 384: }
! 385: }
! 386: break;
! 387: }
! 388: case RIGHT:
! 389: {
! 390: switch (gpr_path) {
! 391: case gpr_$up: /* vertical */
! 392: {
! 393: ygpr = ygpr + str_size_in_pixels.y_size;
! 394: if (Debug)
! 395: printf("RIGHT and up, str=%s \n", str);
! 396: break;
! 397: }
! 398: case gpr_$right: /* horizontal */
! 399: {
! 400: xgpr = xgpr - str_size_in_pixels.x_size;
! 401: ygpr = ygpr + str_size_in_pixels.y_size / 2;
! 402: if (Debug)
! 403: printf("RIGHT and right, str=%s \n", str);
! 404: break;
! 405: }
! 406: }
! 407: break;
! 408: }
! 409: }
! 410:
! 411: gpr_$move(xgpr, ygpr, &status);
! 412: check("in gpr_$move");
! 413: gpr_$text(str, str_len, &status);
! 414: check("in gpr_$text");
! 415: }
! 416:
! 417: TERM_PUBLIC int GPR_text_angle(ang)
! 418: int ang;
! 419: {
! 420: if (gpr_ang != ang) {
! 421: gpr_ang = ang;
! 422: gpr_path = (gpr_ang == 1 ? gpr_$up : gpr_$right);
! 423: }
! 424: return (TRUE);
! 425: }
! 426:
! 427: TERM_PUBLIC int GPR_justify_text(mode)
! 428: enum JUSTIFY mode;
! 429: {
! 430: gpr_justify = mode;
! 431: return (TRUE);
! 432: }
! 433:
! 434: TERM_PUBLIC void GPR_reset()
! 435: {
! 436: gpr_$terminate(false, &status);
! 437: check("in gpr_$terminate");
! 438: }
! 439:
! 440: #endif /* TERM_BODY */
! 441:
! 442: #ifdef TERM_TABLE
! 443:
! 444: TERM_TABLE_START(gpr_driver)
! 445: "gpr", "Apollo Graphics Primitive Resource, fixed-size window",
! 446: GPR_XMAX, GPR_YMAX, GPR_VCHAR, GPR_HCHAR,
! 447: GPR_VTIC, GPR_HTIC, options_null, GPR_init, GPR_reset,
! 448: GPR_text, null_scale, GPR_graphics, GPR_move, GPR_vector,
! 449: GPR_linetype, GPR_put_text, GPR_text_angle,
! 450: GPR_justify_text, line_and_point, do_arrow, set_font_null
! 451: TERM_TABLE_END(gpr_driver)
! 452:
! 453: #undef LAST_TERM
! 454: #define LAST_TERM gpr_driver
! 455:
! 456: #endif /* TERM_TABLE */
! 457: #endif /* TERM_PROTO_ONLY */
! 458:
! 459: #ifdef TERM_HELP
! 460: START_HELP(gpr)
! 461: "1 gpr",
! 462: "?commands set terminal gpr",
! 463: "?set terminal gpr",
! 464: "?set term gpr",
! 465: "?terminal gpr",
! 466: "?term gpr",
! 467: "?gpr",
! 468: " The `gpr` terminal driver supports the Apollo Graphics Primitive Resource",
! 469: " for a fixed-size window. It has no options.",
! 470: "",
! 471: " If a variable window size is desired, use the `apollo` terminal instead."
! 472: END_HELP(gpr)
! 473: #endif /* TERM_HELP */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>