[BACK]Return to djsvga.trm CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/djsvga.trm, Revision 1.1

1.1     ! maekawa     1: /*
        !             2:  * $Id: djsvga.trm,v 1.17 1998/04/14 00:17:36 drd Exp $
        !             3:  */
        !             4:
        !             5: /* GNUPLOT - djsvga.trm */
        !             6:
        !             7: /*[
        !             8:  * Copyright 1992 - 1993, 1998
        !             9:  *
        !            10:  * Permission to use, copy, and distribute this software and its
        !            11:  * documentation for any purpose with or without fee is hereby granted,
        !            12:  * provided that the above copyright notice appear in all copies and
        !            13:  * that both that copyright notice and this permission notice appear
        !            14:  * in supporting documentation.
        !            15:  *
        !            16:  * Permission to modify the software is granted, but not the right to
        !            17:  * distribute the complete modified source code.  Modifications are to
        !            18:  * be distributed as patches to the released version.  Permission to
        !            19:  * distribute binaries produced by compiling modified sources is granted,
        !            20:  * provided you
        !            21:  *   1. distribute the corresponding source modifications from the
        !            22:  *    released version in the form of a patch file along with the binaries,
        !            23:  *   2. add special version identification to distinguish your version
        !            24:  *    in addition to the base release version number,
        !            25:  *   3. provide your name and address as the primary contact for the
        !            26:  *    support of your modified version, and
        !            27:  *   4. retain our contact information in regard to use of the base
        !            28:  *    software.
        !            29:  * Permission to distribute the released version of the source code along
        !            30:  * with corresponding source modifications in the form of a patch file is
        !            31:  * granted with same provisions 2 through 4 for binary distributions.
        !            32:  *
        !            33:  * This software is provided "as is" without express or implied warranty
        !            34:  * to the extent permitted by applicable law.
        !            35: ]*/
        !            36:
        !            37: /*
        !            38:  * This file is included by ../term.c.
        !            39:  *
        !            40:  * This terminal driver supports:
        !            41:  *  svga
        !            42:  *
        !            43:  * AUTHORS
        !            44:  *  Russell Lang
        !            45:  *  Edzer Pebesma (gnuplot 3.6: new terminal layout, fonts, grx20)
        !            46:  *  Hans-Bernhard Broeker (several improvements)
        !            47:  *
        !            48:  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
        !            49:  *
        !            50:  */
        !            51:
        !            52: /* HBB: A new version, called grx21a was released recently. To
        !            53:  * tell gnuplot you have it, add '-DGRX21' to your compilation flags.
        !            54:  * Currently, that only enables the drawing of wide lines. Maybe more
        !            55:  *  to come.
        !            56:  */
        !            57:
        !            58: #include "driver.h"
        !            59:
        !            60: #ifdef TERM_REGISTER
        !            61: register_term(djsvga)          /* no ; */
        !            62: #endif
        !            63:
        !            64: #ifdef TERM_PROTO
        !            65: #define DJSVGA_XMAX 640
        !            66: #define DJSVGA_YMAX 480
        !            67:
        !            68: #define DJSVGA_XLAST (DJSVGA_XMAX - 1)
        !            69: #define DJSVGA_YLAST (DJSVGA_YMAX - 1)
        !            70:
        !            71: #define DJSVGA_VCHAR 16
        !            72: #define DJSVGA_HCHAR 8
        !            73: #define DJSVGA_VTIC 4
        !            74: #define DJSVGA_HTIC 4
        !            75:
        !            76: TERM_PUBLIC void DJSVGA_init __PROTO((void));
        !            77: TERM_PUBLIC void DJSVGA_graphics __PROTO((void));
        !            78: TERM_PUBLIC void DJSVGA_text __PROTO((void));
        !            79: TERM_PUBLIC void DJSVGA_reset __PROTO((void));
        !            80: TERM_PUBLIC void DJSVGA_options __PROTO((void));
        !            81: TERM_PUBLIC void DJSVGA_linetype __PROTO((int linetype));
        !            82: TERM_PUBLIC void DJSVGA_move __PROTO((unsigned int x, unsigned int y));
        !            83: TERM_PUBLIC void DJSVGA_vector __PROTO((unsigned int x, unsigned int y));
        !            84: TERM_PUBLIC int DJSVGA_angle __PROTO((int ang));
        !            85: TERM_PUBLIC int DJSVGA_justify_text __PROTO((enum JUSTIFY mode));
        !            86: TERM_PUBLIC void DJSVGA_put_text __PROTO((unsigned int x, unsigned int y,
        !            87:                                          char *str));
        !            88: TERM_PUBLIC int DJSVGA_set_font __PROTO((char *fontname));
        !            89: TERM_PUBLIC void DJSVGA_suspend __PROTO((void));
        !            90: TERM_PUBLIC void DJSVGA_resume __PROTO((void));
        !            91: /* clear part of multiplot */
        !            92: TERM_PUBLIC void DJSVGA_fillbox __PROTO((int style, unsigned int x1,
        !            93:                                         unsigned int y1, unsigned int width,
        !            94:                                         unsigned int height));
        !            95: TERM_PUBLIC void DJSVGA_linewidth __PROTO((double linewidth));
        !            96:
        !            97: #define GOT_DJSVGA_PROTO
        !            98: #endif /* TERM_PROTO */
        !            99:
        !           100: #ifndef TERM_PROTO_ONLY
        !           101: #ifdef TERM_BODY
        !           102:
        !           103: /* SVGA driver using DJGPP */
        !           104: #if (DJGPP==2)
        !           105: # define GRX20
        !           106: #endif
        !           107: #ifdef GRX20
        !           108: /* use grx20.h for DJGPP V1 / GRX V2 combo as well */
        !           109: # include <grx20.h>
        !           110: #else
        !           111: # include <grx.h>
        !           112: #endif
        !           113: #include <pc.h>
        !           114:
        !           115: static int dj_startx, dj_starty;
        !           116: static int dj_xlast, dj_ylast;
        !           117: #define DJNUMCOLOR 15
        !           118: /* HBB: Let's just use long for GRX1 as well */
        !           119: static long dj_color;
        !           120: static long svga256color[DJNUMCOLOR] =
        !           121: {7, 8, 2, 3, 4, 5, 9, 14, 12, 15, 13, 10, 11, 1, 6};
        !           122: static long dj_colors[DJNUMCOLOR];
        !           123: #ifdef GRX20
        !           124: /* Save, Restore: for 16 color mode! */
        !           125: static void *DJSVGA_colorbuf = NULL;
        !           126: #endif
        !           127: static GrTextOption DJSVGA_TextOption;
        !           128: /* HBB: I think we should use GR_NAMEWIDTH (=16), instead of MAX_ID_LEN,
        !           129:  *   which has nothing to do with GRX at all */
        !           130: #ifdef GRX20
        !           131: char DJSVGA_fontname[MAX_ID_LEN + 1] = "";
        !           132: #else
        !           133: char DJSVGA_fontname[MAX_ID_LEN + 1] = "@:pc8x14.fnt"; /* EGA bios font */
        !           134: #endif
        !           135: static GrContext *DJSVGA_context = 0;  /* save screen for suspend/resume */
        !           136: static char *dj_textsave = 0;  /* for text-screen-saving */
        !           137: static int dj_cursorx, dj_cursory;
        !           138: static int dj_width, dj_height;
        !           139: #ifdef GRX21
        !           140: static double dj_linewidth;    /* store linewidth assignments here */
        !           141: #endif
        !           142:
        !           143: TERM_PUBLIC void DJSVGA_init()
        !           144: {
        !           145:     int i, on, r, g, b, medium = 170, low = 85;
        !           146:     GrFont *font = NULL;
        !           147:
        !           148: #ifdef GRX20
        !           149:     font = &GrDefaultFont;
        !           150: #endif
        !           151:     /* HBB: save textscreen contents and cursor-position */
        !           152:     dj_textsave = gp_alloc(ScreenRows() * ScreenCols() * 2, "djsvga term scrbuf");
        !           153:     ScreenRetrieve(dj_textsave);
        !           154:     dj_width = ScreenCols();
        !           155:     dj_height = ScreenRows();
        !           156:     ScreenGetCursor(&dj_cursory, &dj_cursorx);
        !           157:     GrSetMode(GR_default_graphics);
        !           158:     GrSetRGBcolorMode();
        !           159:     GrResetColors();
        !           160:     /* Allocate colors */
        !           161:     for (i = 0; i < DJNUMCOLOR; i++) {
        !           162:        on = (svga256color[i] & 8) ? 255 : medium;
        !           163:        r = (svga256color[i] & 4) ? on : 0;
        !           164:        g = (svga256color[i] & 2) ? on : 0;
        !           165:        b = (svga256color[i] & 1) ? on : 0;
        !           166:        if (svga256color[i] == 8)
        !           167:            r = g = b = low;
        !           168:        dj_colors[i] = GrAllocColor(r, g, b);
        !           169:     }
        !           170:     /* Get the screen size: */
        !           171:     dj_xlast = GrMaxX();
        !           172:     term->xmax = dj_xlast + 1;
        !           173:     dj_ylast = GrMaxY();
        !           174:     term->ymax = dj_ylast + 1;
        !           175:     /* if GRX 1.x loads an GRX 2.x save'd file: */
        !           176:     if (font == NULL && DJSVGA_fontname[0] == '\0')
        !           177:        sprintf(DJSVGA_fontname, "@:pc8x14.fnt");
        !           178:
        !           179:     if (DJSVGA_fontname[0] != '\0')
        !           180:        font = GrLoadFont(DJSVGA_fontname);
        !           181:     if (font == NULL)
        !           182:        font = GrLoadFont("@:pc8x14.fnt");      /* try EGA bios font */
        !           183:     if (font == NULL)
        !           184:        font = GrLoadFont("@:pc8x16.fnt");      /* try VGA bios font */
        !           185:     /*
        !           186:      * HBB: There are cases when we reach this point with font still NULL,
        !           187:      *   eg. when the GRXFONT env.variable points to the GRX V1 fonts, but
        !           188:      *   GRX V2 is used for this program: some fonts will *fail* to load in
        !           189:      *   that setup (e.g. cour20b)! So IMHO, there should be some error
        !           190:      *   treatment here..., like int_error("Couldn't load font!");
        !           191:      */
        !           192:     DJSVGA_TextOption.txo_font = font;
        !           193:     DJSVGA_TextOption.txo_direct = GR_TEXT_RIGHT;
        !           194:     DJSVGA_TextOption.txo_xalign = GR_ALIGN_LEFT;
        !           195:     DJSVGA_TextOption.txo_yalign = GR_ALIGN_CENTER;
        !           196:     DJSVGA_TextOption.txo_chrtype = GR_BYTE_TEXT;
        !           197:     DJSVGA_TextOption.txo_bgcolor.v = GrNOCOLOR;
        !           198: #ifndef GRX20
        !           199:     DJSVGA_TextOption.txo_xmag = 1;
        !           200:     DJSVGA_TextOption.txo_ymag = 1;
        !           201: #endif
        !           202:     /* HBB: this version should work in all configurations */
        !           203:     term->v_char = font->h.height;
        !           204:     term->h_char = font->h.width;
        !           205:
        !           206: #ifdef GRX20
        !           207:     if (DJSVGA_colorbuf == NULL)
        !           208:        DJSVGA_colorbuf = (void *) gp_alloc(GrColorSaveBufferSize(), "djsvga term colorbuf");
        !           209:     GrSaveColors(DJSVGA_colorbuf);
        !           210: #endif
        !           211:     GrSetMode(GR_default_text);
        !           212:     ScreenUpdate(dj_textsave);
        !           213:     ScreenSetCursor(dj_cursory, dj_cursorx);
        !           214: }
        !           215:
        !           216: /*
        !           217:  * HBB: make these two inline, as they're called by other routines
        !           218:  * inside this module, and -finline-functions (normally switched
        !           219:  * on by 'gcc -O3') doesn't work for compiling term.c
        !           220:  */
        !           221: __inline__
        !           222: TERM_PUBLIC void DJSVGA_graphics()
        !           223: {
        !           224:     ScreenRetrieve(dj_textsave);       /* HBB: save text screen contents */
        !           225:     ScreenGetCursor(&dj_cursory, &dj_cursorx);
        !           226:     GrSetMode(GR_default_graphics);
        !           227: #ifdef GRX20
        !           228:     GrRestoreColors(DJSVGA_colorbuf);
        !           229: #endif
        !           230: }
        !           231:
        !           232: __inline__
        !           233: TERM_PUBLIC void DJSVGA_text()
        !           234: {
        !           235:     (void) getkey();
        !           236:     GrSetMode(GR_width_height_text, dj_width, dj_height);
        !           237:     ScreenUpdate(dj_textsave); /* HBB: restore text screen */
        !           238:     ScreenSetCursor(dj_cursory, dj_cursorx);
        !           239: }
        !           240:
        !           241: TERM_PUBLIC void DJSVGA_reset()
        !           242: {
        !           243:     GrResetColors();
        !           244:     free(dj_textsave);
        !           245: }
        !           246:
        !           247: TERM_PUBLIC void DJSVGA_options()
        !           248: {
        !           249:     if (!END_OF_COMMAND && isstring(c_token)) {
        !           250:        quote_str(DJSVGA_fontname, c_token, MAX_ID_LEN);
        !           251:        c_token++;
        !           252:     }
        !           253:     sprintf(term_options, "\"%s\"", DJSVGA_fontname);
        !           254: }
        !           255:
        !           256: TERM_PUBLIC void DJSVGA_linetype(linetype)
        !           257: int linetype;
        !           258: {
        !           259:     if (linetype >= 13)
        !           260:        linetype %= 13;
        !           261:     /* HBB: set the TextOption color variable right here (faster) */
        !           262:     DJSVGA_TextOption.txo_fgcolor.v = dj_color = dj_colors[linetype + 2];
        !           263: }
        !           264:
        !           265: TERM_PUBLIC void DJSVGA_move(x, y)
        !           266: unsigned int x, y;
        !           267: {
        !           268:     dj_startx = x;
        !           269:     dj_starty = y;
        !           270: }
        !           271:
        !           272:
        !           273: TERM_PUBLIC void DJSVGA_vector(x, y)
        !           274: unsigned int x, y;
        !           275: {
        !           276: #ifdef GRX21
        !           277:     GrLineOption dj_lineoption =
        !           278:     {dj_color, dj_linewidth, 0, ""};
        !           279:
        !           280:     GrCustomLine(dj_startx, dj_ylast - dj_starty, x, dj_ylast - y, &dj_lineoption);
        !           281: #else
        !           282:     GrLine(dj_startx, dj_ylast - dj_starty, x, dj_ylast - y, dj_color);
        !           283: #endif
        !           284:     dj_startx = x;
        !           285:     dj_starty = y;
        !           286: }
        !           287:
        !           288: /*
        !           289:  * HBB: IMHO, the previous version was seriously flawed. E.g.
        !           290:  *   in the termentry, _justify_text was pointing to the
        !           291:  *   null_justify_text dummy routine, so DJSVGA_justify wasn't
        !           292:  *   ever called at all. I copied the routines from my (now
        !           293:  *   otherwise pointless) own private driver, djgrx.trm, to
        !           294:  *   cure that.
        !           295:  */
        !           296: TERM_PUBLIC int DJSVGA_angle(ang)
        !           297: int ang;
        !           298: {
        !           299:     if (ang) {
        !           300:        DJSVGA_TextOption.txo_direct = GR_TEXT_UP;
        !           301:     } else {
        !           302:        DJSVGA_TextOption.txo_direct = GR_TEXT_RIGHT;
        !           303:     }
        !           304:     return TRUE;
        !           305: }
        !           306:
        !           307: TERM_PUBLIC int DJSVGA_justify_text(mode)
        !           308: enum JUSTIFY mode;
        !           309: {
        !           310:     if (DJSVGA_TextOption.txo_direct == GR_TEXT_RIGHT) {
        !           311:        DJSVGA_TextOption.txo_yalign = GR_ALIGN_CENTER;
        !           312:        switch (mode) {
        !           313:        case LEFT:
        !           314:            DJSVGA_TextOption.txo_xalign = GR_ALIGN_LEFT;
        !           315:            break;
        !           316:        case CENTRE:
        !           317:            DJSVGA_TextOption.txo_xalign = GR_ALIGN_CENTER;
        !           318:            break;
        !           319:        case RIGHT:
        !           320:            DJSVGA_TextOption.txo_xalign = GR_ALIGN_RIGHT;
        !           321:            break;
        !           322:        }
        !           323:     } else {
        !           324:        DJSVGA_TextOption.txo_xalign = GR_ALIGN_CENTER;
        !           325:        switch (mode) {
        !           326:        case LEFT:
        !           327:            DJSVGA_TextOption.txo_yalign = GR_ALIGN_BOTTOM;
        !           328:            break;
        !           329:        case CENTRE:
        !           330:            DJSVGA_TextOption.txo_yalign = GR_ALIGN_CENTER;
        !           331:            break;
        !           332:        case RIGHT:
        !           333:            DJSVGA_TextOption.txo_yalign = GR_ALIGN_TOP;
        !           334:            break;
        !           335:        }
        !           336:     }
        !           337:     return TRUE;
        !           338: }
        !           339:
        !           340: TERM_PUBLIC int DJSVGA_set_font(fontname)
        !           341: char *fontname;
        !           342: {
        !           343:     char *cp;
        !           344:     GrFont *font;
        !           345:
        !           346:     safe_strncpy(DJSVGA_fontname, fontname, sizeof(DJSVGA_fontname));
        !           347:     cp = strstr(DJSVGA_fontname, ",");
        !           348:     if (cp != NULL)
        !           349:        *cp = NUL;
        !           350:     font = GrLoadFont(DJSVGA_fontname);
        !           351:     /*HBB: if no font found, do *not* report success! */
        !           352:     if (font != NULL) {
        !           353:        GrUnloadFont(DJSVGA_TextOption.txo_font);
        !           354:        DJSVGA_TextOption.txo_font = font;
        !           355:        return TRUE;
        !           356:     } else {
        !           357:        graph_error("Font not found");
        !           358:        return FALSE;
        !           359:     }
        !           360: }
        !           361:
        !           362: TERM_PUBLIC void DJSVGA_put_text(x, y, str)
        !           363: unsigned int x, y;
        !           364: char *str;
        !           365: {
        !           366:     /* HBB: why isn't font!=NULL ensured elsewhere? Testing it at
        !           367:      * this point doesn't really make much sense (we're in graphics
        !           368:      * mode, so we can't even print out a useful error message!) */
        !           369:     /*if (DJSVGA_TextOption.txo_font != NULL) */
        !           370:     GrDrawString(str, strlen(str), x, dj_ylast - y, &DJSVGA_TextOption);
        !           371: }
        !           372:
        !           373: TERM_PUBLIC void DJSVGA_suspend()
        !           374: {
        !           375:     DJSVGA_context = GrCreateContext(GrSizeX(), GrSizeY(), 0, 0);
        !           376:     GrBitBltNC(DJSVGA_context, 0, 0, 0, 0, 0, GrMaxX(), GrMaxY(), GrWRITE);
        !           377:     DJSVGA_text();
        !           378: }
        !           379:
        !           380: TERM_PUBLIC void DJSVGA_resume()
        !           381: {
        !           382:     DJSVGA_graphics();
        !           383:     GrBitBltNC(0, 0, 0, DJSVGA_context, 0, 0, GrMaxX(), GrMaxY(), GrWRITE);
        !           384:     GrDestroyContext(DJSVGA_context);
        !           385: }
        !           386:
        !           387: TERM_PUBLIC void DJSVGA_fillbox(style, left, bottom, width, height)
        !           388: int style;
        !           389: unsigned int left, bottom, width, height;
        !           390: {
        !           391:     if (style >= 13)
        !           392:        style %= 13;
        !           393:     /* HBB: prize question: should it be 'width-1' instead? */
        !           394:     /* HBB: fill with GRX Color '0', which *should* be black : */
        !           395:     GrFilledBox(left, dj_ylast - bottom, left + width, dj_ylast - bottom - height, 0);
        !           396: }
        !           397:
        !           398: TERM_PUBLIC void DJSVGA_linewidth(double linewidth)
        !           399: {
        !           400: #ifdef GRX21
        !           401:     dj_linewidth = linewidth;
        !           402: #endif
        !           403: }
        !           404:
        !           405: #endif /* TERM_BODY */
        !           406:
        !           407: #ifdef TERM_TABLE
        !           408:
        !           409: /* HBB: I think \" is more readable than \042. BTW: why is this
        !           410:  *   option 'documented' here, but not in the Help node? */
        !           411: TERM_TABLE_START(djsvga_driver)
        !           412:     "svga", "IBM PC/Clone with Super VGA graphics board [\"fontname\"]",
        !           413:     DJSVGA_XMAX, DJSVGA_YMAX, DJSVGA_VCHAR, DJSVGA_HCHAR,
        !           414:     DJSVGA_VTIC, DJSVGA_HTIC,
        !           415:     DJSVGA_options,
        !           416:     DJSVGA_init, DJSVGA_reset, DJSVGA_text,
        !           417:     null_scale, DJSVGA_graphics, DJSVGA_move, DJSVGA_vector,
        !           418:     DJSVGA_linetype, DJSVGA_put_text,
        !           419:     DJSVGA_angle, DJSVGA_justify_text,
        !           420:     do_point, do_arrow, DJSVGA_set_font,
        !           421:     0,                         /* no pointsize() */
        !           422:     TERM_CAN_MULTIPLOT,
        !           423:     DJSVGA_suspend, DJSVGA_resume,
        !           424:     DJSVGA_fillbox, DJSVGA_linewidth
        !           425: TERM_TABLE_END(djsvga_driver)
        !           426:
        !           427: #undef LAST_TERM
        !           428: #define LAST_TERM djsvga_driver
        !           429:
        !           430: #endif /* TERM_TABLE */
        !           431: #endif /* TERM_PROTO_ONLY */
        !           432:
        !           433: /*
        !           434:  * HBB: I think this documentation should be at least a *bit* longer
        !           435:  *   (E.g., the "fontname" parameter is claimed to be non-existent!)
        !           436:  */
        !           437: /* RCC: Not any more...
        !           438:  *      If you have other ideas about what could be in the help section,
        !           439:  *      please let me know (rccrawford@lanl.gov) --- particularly info
        !           440:  *      about what fonts are permitted, if there is such a list.
        !           441: */
        !           442: #ifdef TERM_HELP
        !           443: START_HELP(svga)
        !           444: "1 svga",
        !           445: "?commands set terminal svga",
        !           446: "?set terminal svga",
        !           447: "?set term svga",
        !           448: "?terminal svga",
        !           449: "?term svga",
        !           450: "?svga",
        !           451: " The `svga` terminal driver supports PCs with SVGA graphics.  It can only be",
        !           452: " be used if it is compiled with DJGPP.  Its only option is the font.",
        !           453: "",
        !           454: " Syntax:",
        !           455: "       set terminal svga {\"<fontname>\"}"
        !           456: END_HELP(svga)
        !           457: #endif /* TERM_HELP */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>