home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************/
- /* Copyright (C) 1989, California Institute of Technology */
- /* U. S. Government Sponsorship under NASA Contract */
- /* NAS7-918 is acknowledged. */
- /*************************************************************/
-
- /*** Module: DISPUTIL
- Device Independent General Purpose Graphics Routines
-
- Includes line drawing, text display, and cursor routines.
- ***/
-
- /* 10/6 Changed cursor routines for cursor control without numlock - mdm*/
-
- /* * * * INCLUDE files * * * */
-
- #include <conio.h>
- #include <math.h>
- #include <malloc.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "imdef.h"
- #include "imdisp.h"
- #include "dispio.h"
- #include "refresh.h"
-
- /* * * * External functions * * * */
-
- extern int putmem(int, int, int);
-
- /* * * * Function declarations * * * */
-
- int DrawLine ( int, int, int, int, int);
- int Font (int);
- int DrawText ( char *, int, int, int, int, int);
- int EraseText (int, int, int, int, int);
- int LengthText (char *, int, int *);
- int DrawBox (int, int, int, int, int );
- int TypeText (char *);
- int AcceptText (char *);
- int WriteText (char *);
- int StatusLine (int, char *);
- int RemoveCursor (void);
- int PlaceCursor (int, int, int);
- int MoveCursorInput (int *, int *, unsigned char *);
- int MoveCursor (int *, int *);
- int InitDisplay (void);
- void FrameBox (int, int, int, int, int, int);
-
- /* * * * Global Variables * * * */
-
- unsigned char CursorShape[CURSORSIZE][CURSORSIZE]
- = { {0,0,0,0,1,0,0,0,0},
- {0,0,0,0,1,0,0,0,0},
- {0,0,0,0,1,0,0,0,0},
- {0,0,0,0,1,0,0,0,0},
- {1,1,1,1,1,1,1,1,1},
- {0,0,0,0,1,0,0,0,0},
- {0,0,0,0,1,0,0,0,0},
- {0,0,0,0,1,0,0,0,0},
- {0,0,0,0,1,0,0,0,0} };
-
- int CursorOn; /* cursor flag */
- int CursorLine, CursorSample; /* cursor location */
- int CursorInc; /* size of cursor steps */
- unsigned char CursorPatch[CURSORSIZE][CURSORSIZE];
- /* contains display pixels displaced by cursor */
-
-
- int TextLine, TextSample; /* line and sample where next text will go */
- int TextHeight; /* Default character size */
- int BigChars, SmallChars; /* multiples of character size */
- int thefont; /* The number of the font */
-
-
- struct FontDataType
- {
- unsigned char x, y, pen;
- } FontData[MAXFONTSTROKES];
- /* Contains the line strokes that define the characters for the
- current font. Stored in byte format. The x and y coordinates
- convert back to character coordinates with xc = (x-50)/100.
- pen=2 is pen down, pen=3 is pen up. */
-
- struct FontPtrType
- {
- int index;
- unsigned char strokes, width;
- } FontPointer[128];
- /* Contains the info on each ascii character in the current font.
- The index points to where the character starts in the FontData
- array. The strokes is the number of line strokes for this
- character. The width is the width of the character; stored
- the same as the x and y above. */
-
-
-
-
- int DrawLine (int x1, int y1, int x2, int y2, int color)
-
- /*** DrawLine draws a line of pixels from the first point to the
- second point with the desired DN value. Clipping is not performed.
-
- Parameter Type Description
- x1 int the line coordinate of the first point
- y1 int the sample coordinate of the first point
- x2 int the line coordinate of the second point
- y2 int the sample coordinate of the second point
- color int the DN value of the drawn pixels
- ***/
-
- {
- int x, y, delx, dely, absdelx, absdely, rem, address;
- unsigned char buffer[1];
- buffer[0]= color;
- delx = x2 - x1;
- dely = y2 - y1;
- absdelx = abs(delx);
- absdely = abs(dely);
- rem = 0;
-
- if (absdely < absdelx)
- {
- y = y1;
- if (delx > 0)
- {
- if (dely > 0)
- {
- for (x = x1; x <= x2; x++)
- {
- rem += absdely;
- if (rem > absdelx)
- {
- rem -= absdelx;
- y++;
- }
- if (IntoMem)
- PutRefresh(buffer,x,y,1);
- else
- WritePixel (x,y, color);
- }
- }
- else
- {
- for (x = x1; x <= x2; x++)
- {
- rem += absdely;
- if (rem > absdelx)
- {
- rem -= absdelx;
- y--;
- }
- if (IntoMem)
- PutRefresh(buffer,x,y,1);
- else
- WritePixel (x,y, color);
- }
- }
- }
-
- else
- {
- if (dely > 0)
- {
- for (x = x1; x >= x2; x--)
- {
- rem += absdely;
- if (rem > absdelx)
- {
- rem -= absdelx;
- y++;
- }
- if (IntoMem)
- PutRefresh(buffer,x,y,1);
- else
- WritePixel (x,y, color);
- }
- }
- else
- {
- for (x = x1; x >= x2; x--)
- {
- rem += absdely;
- if (rem > absdelx)
- {
- rem -= absdelx;
- y--;
- }
- if (IntoMem)
- PutRefresh(buffer,x,y,1);
- else
- WritePixel (x,y, color);
- }
- }
- }
- }
-
- else
- {
- x = x1;
- if (dely > 0)
- {
- if (delx > 0)
- {
- for (y = y1; y <= y2; y++)
- {
- rem += absdelx;
- if (rem > absdely)
- {
- rem -= absdely;
- x++;
- }
- if (IntoMem)
- PutRefresh(buffer,x,y,1);
- else
- WritePixel (x,y, color);
- }
- }
- else
- {
- for (y = y1; y <= y2; y++)
- {
- rem += absdelx;
- if (rem > absdely)
- {
- rem -= absdely;
- x--;
- }
- if (IntoMem)
- PutRefresh(buffer,x,y,1);
- else
- WritePixel (x,y, color);
- }
- }
- }
-
- else
- {
- if (delx > 0)
- {
- for (y = y1; y >= y2; y--)
- {
- rem += absdelx;
- if (rem > absdely)
- {
- rem -= absdely;
- x++;
- }
- if (IntoMem)
- PutRefresh(buffer,x,y,1);
- else
- WritePixel (x,y, color);
- }
- }
- else
- {
- for (y = y1; y >= y2; y--)
- {
- rem += absdelx;
- if (rem > absdely)
- {
- rem -= absdely;
- x--;
- }
- if (IntoMem)
- PutRefresh(buffer,x,y,1);
- else
- WritePixel (x,y, color);
- }
- }
- }
- }
- }
-
- /* The following is the internal default font.
- It is in the exact same format as the font files. */
-
- unsigned char DefaultFont[2560] = {
-
- 114,0,7,150,3,100,100,2,100,133,2,67,133,2,67,67,2,133,67,2,133,133,2,100,133,
- 1,11,150,3,100,100,2,100,133,2,83,133,2,67,117,2,67,83,2,83,67,2,117,67,2,133,
- 83,2,133,117,2,117,133,2,100,133,2,5,150,3,100,100,2,100,133,2,67,67,2,133,67,
- 2,100,133,3,4,150,3,100,133,2,100,67,3,67,100,2,133,100,4,4,150,3,67,67,2,133,
- 133,3,67,133,2,133,67,5,6,150,3,100,100,2,100,133,2,67,100,2,100,67,2,133,100,
- 2,100,133,6,6,150,3,100,100,2,67,100,2,100,133,2,133,100,2,100,100,2,100,67,7,
- 4,150,3,67,67,2,133,133,2,67,133,2,133,67,8,6,150,3,67,133,2,133,133,2,67,67,2,
- 133,67,3,83,100,2,117,100,9,5,150,3,100,100,2,67,133,3,133,133,2,100,100,2,100,
- 67,10,13,150,3,100,100,2,133,133,3,117,117,2,83,117,2,67,133,3,83,117,2,83,83,
- 2,67,67,3,83,83,2,117,83,2,133,67,3,117,83,2,117,117,11,8,150,3,67,67,2,133,
- 133,3,67,133,2,133,67,3,100,67,2,100,133,3,67,100,2,133,100,12,6,150,3,100,100,
- 2,67,133,2,133,133,2,67,67,2,133,67,2,100,100,13,2,150,3,100,67,2,100,133,14,2,
- 150,3,67,100,2,133,100,15,6,150,3,67,100,2,133,100,3,67,133,2,133,133,3,67,67,
- 2,133,67,16,6,150,3,67,117,2,133,117,3,67,83,2,133,83,3,83,67,2,117,133,17,6,
- 150,3,100,100,2,100,133,3,83,117,2,117,117,3,83,83,2,117,83,32,0,150,33,9,150,
- 3,83,50,2,100,50,2,100,67,2,83,67,2,83,50,3,100,83,2,83,150,2,100,150,2,100,83,
- 34,4,150,3,83,117,2,83,150,3,117,150,2,117,117,35,8,150,3,83,50,2,83,150,3,117,
- 150,2,117,50,3,67,117,2,133,117,3,133,83,2,67,83,36,10,150,3,67,67,2,117,67,2,
- 133,83,2,117,100,2,83,100,2,67,117,2,83,133,2,133,133,3,100,150,2,100,50,37,12,
- 150,3,67,67,2,133,133,3,83,133,2,67,133,2,67,150,2,83,150,2,83,133,3,133,50,2,
- 117,50,2,117,67,2,133,67,2,133,50,38,11,150,3,133,83,2,100,50,2,83,50,2,67,67,
- 2,67,83,2,117,117,2,117,133,2,100,150,2,83,133,2,83,100,2,133,50,39,3,150,3,83,
- 117,2,100,133,2,100,150,40,4,150,3,117,150,2,83,117,2,83,83,2,117,50,41,4,150,
- 3,83,150,2,117,117,2,117,83,2,83,50,42,6,150,3,100,67,2,100,133,3,133,117,2,
- 67,83,3,67,117,2,133,83,43,4,150,3,100,67,2,100,133,3,67,100,2,133,100,44,3,
- 150,3,67,50,2,83,67,2,83,83,45,2,150,3,67,100,2,133,100,46,2,150,3,83,50,2,83,
- 50,47,2,150,3,67,50,2,133,150,48,10,150,3,67,67,2,67,133,2,83,150,2,117,150,2,
- 133,133,2,133,67,2,117,50,2,83,50,2,67,67,2,133,133,49,5,150,3,83,50,2,117,50,
- 3,100,50,2,100,150,2,83,133,50,8,150,3,67,133,2,83,150,2,117,150,2,133,133,2,
- 133,117,2,67,67,2,67,50,2,133,50,51,10,150,3,67,150,2,133,150,2,133,133,2,100,
- 100,2,117,100,2,133,83,2,133,67,2,117,50,2,83,50,2,67,67,52,5,150,3,117,50,2,
- 117,150,2,67,100,2,67,83,2,133,83,53,9,150,3,67,67,2,83,50,2,117,50,2,133,67,2,
- 133,100,2,117,117,2,67,117,2,67,150,2,133,150,54,10,150,3,67,100,2,117,100,2,
- 133,83,2,133,67,2,117,50,2,83,50,2,67,67,2,67,117,2,100,150,2,133,150,55,5,150,
- 3,67,150,2,133,150,2,133,133,2,83,83,2,83,50,56,17,150,3,83,50,2,117,50,2,133,
- 67,2,133,83,2,117,100,2,83,100,2,67,117,2,67,133,2,83,150,2,117,150,2,133,133,
- 2,133,117,2,117,100,3,83,100,2,67,83,2,67,67,2,83,50,57,10,150,3,67,50,2,100,
- 50,2,133,83,2,133,133,2,117,150,2,83,150,2,67,133,2,67,117,2,83,100,2,133,100,
- 58,4,150,3,83,50,2,83,50,3,83,83,2,83,83,59,5,150,3,83,50,2,100,67,2,100,83,3,
- 100,117,2,100,117,60,3,150,3,117,50,2,67,100,2,117,150,61,4,150,3,67,83,2,133,
- 83,3,133,117,2,67,117,62,3,150,3,83,50,2,133,100,2,83,150,63,8,150,3,100,50,2,
- 100,50,3,100,83,2,133,117,2,133,133,2,117,150,2,83,150,2,67,133,64,11,150,3,
- 117,50,2,83,50,2,67,67,2,67,133,2,83,150,2,117,150,2,133,133,2,133,83,2,100,83,
- 2,100,100,2,133,133,65,7,150,3,67,50,2,67,117,2,100,150,2,133,117,2,133,50,3,
- 67,83,2,133,83,66,12,150,3,67,50,2,67,150,2,117,150,2,133,133,2,133,117,2,117,
- 100,2,67,100,3,117,100,2,133,83,2,133,67,2,117,50,2,67,50,67,8,150,3,133,133,2,
- 117,150,2,83,150,2,67,133,2,67,67,2,83,50,2,117,50,2,133,67,68,8,150,3,67,50,2,
- 117,50,2,133,67,2,133,133,2,117,150,2,67,150,3,83,150,2,83,50,69,7,150,3,67,50,
- 2,67,150,2,133,150,3,117,100,2,67,100,3,67,50,2,133,50,70,5,150,3,67,50,2,67,
- 150,2,133,150,3,100,100,2,67,100,71,9,150,3,133,133,2,117,150,2,83,150,2,67,
- 133,2,67,67,2,83,50,2,133,50,2,133,83,2,117,83,72,6,150,3,67,50,2,67,150,3,67,
- 100,2,133,100,3,133,150,2,133,50,73,6,150,3,83,50,2,117,50,3,100,50,2,100,150,
- 3,83,150,2,117,150,74,5,150,3,67,67,2,83,50,2,117,50,2,133,67,2,133,150,75,5,
- 150,3,67,50,2,67,150,3,133,150,2,67,100,2,133,50,76,4,150,3,67,50,2,67,150,3,
- 67,50,2,133,50,77,5,150,3,67,50,2,67,150,2,100,100,2,133,150,2,133,50,78,6,150,
- 3,67,50,2,67,150,3,67,133,2,133,67,3,133,150,2,133,50,79,9,150,3,67,67,2,83,50,
- 2,117,50,2,133,67,2,133,133,2,117,150,2,83,150,2,67,133,2,67,67,80,7,150,3,67,
- 50,2,67,150,2,117,150,2,133,133,2,133,117,2,117,100,2,67,100,81,11,150,3,67,67,
- 2,83,50,2,117,50,2,133,67,2,133,133,2,117,150,2,83,150,2,67,133,2,67,67,3,100,
- 83,2,133,50,82,9,150,3,67,50,2,67,150,2,117,150,2,133,133,2,133,117,2,117,100,
- 2,67,100,3,100,100,2,133,50,83,12,150,3,67,67,2,83,50,2,117,50,2,133,67,2,133,
- 83,2,117,100,2,83,100,2,67,117,2,67,133,2,83,150,2,117,150,2,133,133,84,4,150,
- 3,67,150,2,133,150,3,100,150,2,100,50,85,6,150,3,67,150,2,67,67,2,83,50,2,117,
- 50,2,133,67,2,133,150,86,3,150,3,67,150,2,100,50,2,133,150,87,5,150,3,67,150,2,
- 83,50,2,100,100,2,117,50,2,133,150,88,8,150,3,67,50,2,67,67,2,133,133,2,133,
- 150,3,67,150,2,67,133,2,133,67,2,133,50,89,7,150,3,67,150,2,67,133,2,100,100,2,
- 100,50,3,133,150,2,133,133,2,100,100,90,6,150,3,67,150,2,133,150,2,133,133,2,
- 67,67,2,67,50,2,133,50,91,4,150,3,100,150,2,67,150,2,67,50,2,100,50,92,2,150,3,
- 133,50,2,67,150,93,4,150,3,67,50,2,100,50,2,100,150,2,67,150,94,5,150,3,67,100,
- 2,100,133,2,133,100,3,100,133,2,100,67,95,5,150,3,100,67,2,67,100,2,100,133,3,
- 67,100,2,133,100,96,2,150,3,67,150,2,117,100,97,10,150,3,67,67,2,67,100,2,83,
- 117,2,100,117,2,133,83,2,100,50,2,83,50,2,67,67,3,133,117,2,133,50,98,10,150,3,
- 67,50,2,67,150,3,67,83,2,100,117,2,117,117,2,133,100,2,133,67,2,117,50,2,100,
- 50,2,67,83,99,6,150,3,133,117,2,83,117,2,67,100,2,67,67,2,83,50,2,133,50,100,
- 10,150,3,133,150,2,133,50,3,133,83,2,100,117,2,83,117,2,67,100,2,67,67,2,83,50,
- 2,100,50,2,133,83,101,9,150,3,67,83,2,133,83,2,133,100,2,117,117,2,83,117,2,
- 67,100,2,67,67,2,83,50,2,117,50,102,5,150,3,100,50,2,100,133,2,117,150,3,83,
- 100,2,117,100,103,12,150,3,83,17,2,117,17,2,133,33,2,133,117,3,133,83,2,100,
- 117,2,83,117,2,67,100,2,67,67,2,83,50,2,100,50,2,133,83,104,6,150,3,67,50,2,67,
- 150,3,67,117,2,117,117,2,133,100,2,133,50,105,7,150,3,83,50,2,117,50,3,100,50,
- 2,100,100,2,83,100,3,100,133,2,100,133,106,6,150,3,83,50,2,100,50,2,117,67,2,
- 117,117,3,117,150,2,117,150,107,6,150,3,67,50,2,67,150,3,133,133,2,67,67,3,100,
- 100,2,133,50,108,5,150,3,83,50,2,117,50,3,100,50,2,100,150,2,83,150,109,10,150,
- 3,67,50,2,67,117,3,67,100,2,83,117,2,100,100,2,100,50,3,100,100,2,117,117,2,
- 133,100,2,133,50,110,7,150,3,67,50,2,67,117,3,67,100,2,83,117,2,117,117,2,133,
- 100,2,133,50,111,9,150,3,67,67,2,67,100,2,83,117,2,117,117,2,133,100,2,133,67,
- 2,117,50,2,83,50,2,67,67,112,10,150,3,67,17,2,67,117,3,67,83,2,100,117,2,117,
- 117,2,133,100,2,133,67,2,117,50,2,100,50,2,67,83,113,10,150,3,133,17,2,133,117,
- 3,133,83,2,100,117,2,83,117,2,67,100,2,67,67,2,83,50,2,100,50,2,133,83,114,5,
- 150,3,67,50,2,67,117,3,67,83,2,100,117,2,133,117,115,8,150,3,67,50,2,117,50,2,
- 133,67,2,117,83,2,83,83,2,67,100,2,83,117,2,133,117,116,5,150,3,83,117,2,117,
- 117,3,100,150,2,100,67,2,117,50,117,7,150,3,67,117,2,67,67,2,83,50,2,117,50,2,
- 133,67,3,133,117,2,133,50,118,3,150,3,67,117,2,100,50,2,133,117,119,5,150,3,67,
- 117,2,83,50,2,100,83,2,117,50,2,133,117,120,4,150,3,67,50,2,133,117,3,67,117,2,
- 133,50,121,8,150,3,83,17,2,117,17,2,133,33,2,133,117,3,67,117,2,67,67,2,83,50,
- 2,133,50,122,4,150,3,67,117,2,133,117,2,67,50,2,133,50,123,7,150,3,100,50,2,83,
- 67,2,83,83,2,67,100,2,83,117,2,83,133,2,100,150,124,4,150,3,100,50,2,100,83,3,
- 100,117,2,100,150,125,7,150,3,83,50,2,100,67,2,100,83,2,117,100,2,100,117,2,
- 100,133,2,83,150,126,4,150,3,67,83,2,83,100,2,117,100,2,133,117,127,8,150,3,67,
- 50,2,67,150,2,133,150,2,133,50,2,67,50,2,133,150,3,67,150,2,133,50,0,0,0,0,0,
- 0 };
-
- int Font (int FontType)
-
- /*** Font reads in the font file for type FontType and fills the
- font arrays appropriately. If FontType = 0 the internal font file
- is used instead. FontType = 5 reads in font file 005.FNT, etc.
- The global variable thefont is set to the font number.
-
- The format of a font file is a sequence of bytes. The first byte
- is the number of characters defined in the font. For each
- character there is the following: the ascii code, the number of
- line strokes, the character width, and then the list of line strokes.
- Each line stroke consists of three bytes: the pen motion, and the
- x and y coordinate. The width, x, and y values are converted
- back into character coordinates by subtracting 50 and dividing
- by 100. The pen is 2 for pen down, and 3 for pen up.
-
- ***/
-
- {
- char FontName[16];
- FILE *FontFile;
- int i, j, ptr, bufptr, NumChar, ch;
- unsigned char NumStrokes, Ascii;
- unsigned char *TempBuf;
-
- if (thefont == FontType)
- return;
- if (FontType == 0)
- TempBuf = DefaultFont;
- else
- {
- sprintf (FontName, "%d", 1000+FontType);
- strcat (FontName, ".FNT");
- if ((FontFile = fopen (&FontName[1], "rb")) == NULL)
- return;
- while ((TempBuf = malloc(9000)) == NULL)
- FreeRefresh("font");
- i = 0;
- while ( ((ch = getc(FontFile)) != EOF) && (i < 9000) )
- TempBuf[i++] = ch;
- fclose (FontFile);
- }
-
- thefont = FontType;
-
- for (Ascii = 0; Ascii <= 127; Ascii++)
- {
- FontPointer[Ascii].width = 50;
- FontPointer[Ascii].strokes = 0;
- }
-
- bufptr = 0;
- ptr = 1;
- NumChar = TempBuf[bufptr++];
- for (i = 1; i <= NumChar; i++)
- {
- Ascii = TempBuf[bufptr++];
- NumStrokes = TempBuf[bufptr++];
- FontPointer[Ascii].index = ptr;
- FontPointer[Ascii].strokes = NumStrokes;
- FontPointer[Ascii].width = TempBuf[bufptr++];
- for (j = 1; j <= NumStrokes; j++)
- {
- FontData[ptr].pen = TempBuf[bufptr++];
- FontData[ptr].x = TempBuf[bufptr++];
- FontData[ptr].y = TempBuf[bufptr++];
- ptr++;
- }
- }
- if (FontType != 0)
- free (TempBuf);
- }
-
-
-
- int DrawText (char * text, int line, int sample, int height, int angle, int DNvalue)
-
- /*** DrawText draws a text string on the display using the
- current font.
-
- Parameter Type Description
- text char ptr text string to display
- line int line coordinate of lower left of first char
- sample int sample coordinate of lower left of first char
- height int height of characters in pixels
- angle int angle in degrees ccw from positive sample direction
- DNvalue int the DN value to draw the pixels in with
- ***/
-
- {
- int i, j, k, ascii, numstrokes;
- int linep, sampp, secth, cscth, dist;
- int chl, chs, pixl, pixs, oldl, olds;
-
-
- linep = line; sampp = sample;
- secth = 100.0/(cos(0.0174533*angle)+0.01) + 0.5;
- cscth = 100.0/(sin(0.0174533*angle)+0.01) + 0.5;
-
- for (i = 0; i < strlen(text); i++)
- {
- ascii = text[i];
- j = FontPointer[ascii].index;
- numstrokes = FontPointer[ascii].strokes;
- for (k = 1; k <= numstrokes; k++)
- {
- chs = height*(FontData[j].x-50);
- chl = -height*(FontData[j].y-50);
- pixs = (chs / secth) + (chl / cscth) + sampp;
- pixl = -(chs / cscth) + (chl / secth) + linep;
- if (FontData[j].pen == 2)
- {
- if (ascii==95) /* patch to fix underscore font char */
- {
- if (k==2)
- DrawLine (oldl, olds-5, oldl, olds+5, DNvalue);
- }
- else
- DrawLine (oldl, olds, pixl, pixs, DNvalue);
- oldl = pixl; olds = pixs;
- }
- else
- {
- oldl = pixl; olds = pixs;
- }
- j++;
- }
- dist = height*(FontPointer[ascii].width-50);
- linep -= dist/cscth;
- sampp += dist/secth;
- if (sampp >= dispns) break;
- }
- }
-
- int EraseText (int line, int samp, int height, int len, int color)
-
- /*** EraseText erases a string of text from the screen by writing over
- it using blocks of the background color. Calls DrawBox to do the
- actual erasing.
-
- Parameter Type Description
- line int starting line of text string
- samp int starting sample of text string
- height int size of text characters
- len int length of text string
- color int background color to use
- ***/
-
- {
- int e_line, e_samp, e_height, e_len;
-
- e_line = line - height - 1;
- e_samp = samp;
- e_height = height + 7;
- e_len = len;
- if (dispns < e_len+e_samp)
- e_len = dispns-e_samp-1;
- DrawBox( e_line, e_samp, e_height, e_len, color);
- }
-
- int LengthText (char * text, int height, int * p_TextLength)
-
- /*** LengthText finds the length in pixels of a given text string.
-
- Parameter Type Description
- text char ptr text string to display
- height int height of characters in pixels
- p_TextLength int ptr where to return length of string
-
- ***/
-
- {
- int i, ascii;
-
- if (thefont == -1)
- Font (0);
-
- *p_TextLength = 0;
- for (i = 0; i < strlen(text); i++)
- {
- ascii = text[i];
- *p_TextLength += (height*(FontPointer[ascii].width-50)) / 100;
- }
- }
-
-
-
- int DrawBox (int line, int samp, int lsize, int ssize, int color)
-
- /*** DrawBox draws a solid rectangle on the screen.
- Used for erasing parts of the screen.
-
- Parameter Type Description
- line int starting line coordinate of rectangle
- samp int starting sample coordinate of rectangle
- lsize int number of lines in rectangle
- ssize int number of samples in rectangle
- color int the DN value to draw the box
- ***/
-
- {
- int l, s;
- unsigned char linebuf[MAXDISPNS];
-
- for (s = 0; s < ssize; s++)
- linebuf[s] = color;
- for (l = line; l < line+lsize; l++)
- {
- if (IntoMem)
- PutRefresh(linebuf,l,samp,ssize);
- else
- DisplayLine (linebuf, l, samp, ssize);
- }
- }
-
-
-
- int TypeText (char * TypeString)
-
- /*** TypeText displays a line of text on the screen at the current
- text location with a height of 15 pixels. The area is first erased.
- The text position is advanced to the next position after the last
- character.
-
- Parameter Type Description
- TypeString char ptr text string to display
- ***/
-
- {
- int TextLength, n_chars;
-
- LengthText (TypeString, TextHeight, &TextLength);
- EraseText (TextLine, TextSample, TextHeight, TextLength, 0);
-
- DrawText (TypeString, TextLine, TextSample, TextHeight, 0, numDN-1);
- TextSample += TextLength;
- }
-
- int WriteText (char * text)
-
- /*** WriteText writes out a line of text to the user. If there
- is only one screen then the text is written on the image display.
- Otherwise it is written to the terminal.
- Parameter Type Description
- text char ptr text string to display
- ***/
-
- {
- if (OneScreen)
- {
- if (TextLine >= dispnl)
- {
- ClearDisplay (0);
- TextLine = TextHeight+2; TextSample = 1;
- }
- TypeText (text);
- TextLine += TextHeight+5;
- TextSample = 1;
- }
- else
- printf ("%s", text);
- }
-
-
- int AcceptText (char * AcceptString)
-
- /*** AcceptString gets a string from the keyboard. The characters
- are echoed on the display screen using DrawText. The string is
- terminated with a return (ascii 13). Backspace deleting is supported.
- The text position is left at the beginning of the next line.
-
- Parameter Type Description
- AcceptString char ptr returned text string from user
- ***/
-
- {
- char ch[2];
- int len, last, n_chars;
-
- strcpy (AcceptString, "");
- ch[0] = 0; ch[1] = 0;
- while (ch[0] != 13)
- {
- EraseText (TextLine, TextSample, TextHeight, 15, 0);
- ch[0] = getch();
- if ( (ch[0] == 8) && (strlen(AcceptString) > 0) )
- {
- last = strlen(AcceptString)-1;
- LengthText (&AcceptString[last], TextHeight, &len);
- TextSample -= len;
- AcceptString[last] = 0;
- }
- else if (ch[0] >= ' ')
- {
- DrawText (ch, TextLine, TextSample, TextHeight, 0, numDN-1);
- LengthText (ch, TextHeight, &len);
- TextSample += len;
- strcat (AcceptString, ch);
- }
- }
- TextSample = 1;
- }
-
- int StatusLine (int WhichLine, char * TextString)
-
- /*** StatusText puts a line of text on the screen at the top, (error
- reporting), or one of two lines on the bottom of the screen (file
- name and command line). It erases the previous line before writing
- the new one.
-
- Parameter Type Description
- WhichLine int which line to erase and display
- TextString char ptr returned text string from user
- ***/
-
- {
- static int Last0=0, Last1=0, Last2=0;
- int TextLength, n_chars;
-
- {
- if (WhichLine == 0)
- {
- TextLine = TextHeight+5; TextSample = 1;
- TextLength = Last0;
- }
- if (WhichLine == 1)
- {
- TextLine = dispnl-TextHeight-12; TextSample = 1;
- TextLength = Last1;
- }
- if (WhichLine == 2)
- {
- TextLine = dispnl-5; TextSample = 1;
- TextLength = Last2;
- }
- if (TextLength > 0)
- {
- EraseText (TextLine, TextSample, TextHeight, TextLength, 0);
- }
-
- LengthText (TextString, TextHeight, &TextLength);
- if (WhichLine == 0) Last0 = TextLength;
- if (WhichLine == 1) Last1 = TextLength;
- if (WhichLine == 2) Last2 = TextLength;
- TypeText (TextString);
- }
- }
-
- int RemoveCursor(void)
-
- /*** RemoveCursor removes the cursor, if it is on, from the display
- screen, replacing the original pixel values.
- ***/
- {
- int lcorn, scorn, l, s, DN;
- int ls, le, ss, se;
-
- if (CursorOn)
- {
- lcorn = CursorLine - (CURSORSIZE / 2) - 1;
- scorn = CursorSample - (CURSORSIZE / 2) - 1;
- ls = (lcorn < 0) ? 1 - lcorn : 1;
- le = (lcorn > dispnl-CURSORSIZE) ? dispnl-lcorn : CURSORSIZE;
- ss = (scorn < 0) ? 1 - scorn : 1;
- se = (scorn > dispns-CURSORSIZE) ? dispns-scorn : CURSORSIZE;
-
- for (l = ls; l <= le; l++)
- for (s = ss; s <= se; s++)
- if (CursorShape[l-1][s-1] > 0)
- {
- DN = CursorPatch[l-1][s-1];
- WritePixel (lcorn+l, scorn+s, DN);
- }
- CursorOn = 0;
- }
- }
-
-
- int PlaceCursor (int line, int sample, int cursDN)
-
- /*** PlaceCursor puts the cursor, if it is not already on, on the
- screen, while storing the original pixel values.
- Parameter Type Description
- line int the line coordinate to put the cursor at
- sample int the sample coordinate to put the cursor at
- cursDN int the DN value of the cursor
-
- ***/
-
- {
- int lcorn, scorn, l, s, DN;
- int ls, le, ss, se, ld, sd;
-
- if (!CursorOn)
- {
- lcorn = line - (CURSORSIZE / 2) - 1;
- scorn = sample - (CURSORSIZE / 2) - 1;
- ls = (lcorn < 0) ? 1 - lcorn : 1;
- le = (lcorn > dispnl-CURSORSIZE) ? dispnl-lcorn : CURSORSIZE;
- ss = (scorn < 0) ? 1 - scorn : 1;
- se = (scorn > dispns-CURSORSIZE) ? dispns-scorn : CURSORSIZE;
-
- for (l = ls; l <= le; l++)
- for (s = ss; s <= se; s++)
- if (CursorShape[l-1][s-1] > 0)
- {
- ld = lcorn + l;
- sd = scorn + s;
- ReadPixel (ld, sd, &DN);
- CursorPatch[l-1][s-1] = DN;
- WritePixel (ld, sd, cursDN );
- }
- CursorLine = line;
- CursorSample = sample;
- CursorOn = 1;
- }
- }
-
- int MoveCursorInput (int *p_line, int *p_sample, unsigned char *ch)
-
- /*** MoveCursorInput puts the cursor at the given place, waits
- for a character from the keyboard, performs the cursor command
- for the input character, and removes the cursor.
- Parameter Type Description
- p_line int ptr the cursor line coordinate
- p_sample int ptr the cursor sample coordinate
- ch char ptr the character input
- ***/
-
- {
- int DN, center, len;
- char dispstr[32];
-
- PlaceCursor (*p_line, *p_sample, numDN-1);
-
- /* moved display of curs here - otherwise 1 behind mdm 3/88 */
- center = CURSORSIZE/2;
- DN = CursorPatch[center][center];
-
- sprintf (dispstr, "%4d %4d %3d", *p_line, *p_sample, DN);
- StatusLine(2,dispstr);
-
- if ((*ch = getch()) == 0) /* mdm 10/6 */
- *ch = 0x80 | getch();
-
- switch (*ch)
- {
- case UP_ARROW:
- case '8' :
- *p_line = max(*p_line-CursorInc, 1);
- break;
- case DOWN_ARROW:
- case '2' :
- *p_line = min(*p_line+CursorInc, dispnl);
- break;
- case LEFT_ARROW:
- case '4' :
- *p_sample = max(*p_sample-CursorInc, 1);
- break;
- case RIGHT_ARROW:
- case '6' :
- *p_sample = min(*p_sample+CursorInc, dispns);
- break;
- case UP_LEFT_ARROW:
- case '7' :
- *p_line = max(*p_line-CursorInc, 1);
- *p_sample = max(*p_sample-CursorInc, 1);
- break;
- case UP_RIGHT_ARROW:
- case '9' :
- *p_line = max(*p_line-CursorInc, 1);
- *p_sample = min(*p_sample+CursorInc, dispns);
- break;
- case DOWN_RIGHT_ARROW:
- case '3' :
- *p_line = min(*p_line+CursorInc, dispnl);
- *p_sample = min(*p_sample+CursorInc, dispns);
- break;
- case DOWN_LEFT_ARROW:
- case '1' :
- *p_line = min(*p_line+CursorInc, dispnl);
- *p_sample = max(*p_sample-CursorInc, 1);
- break;
- case '-' :
- case '_' : /* accept as unshifted minus */
- CursorInc = max(CursorInc / 2, 1);
- break;
- case '=' : /* accept as unshifted plus */
- case '+' :
- CursorInc = min(2*CursorInc, dispnl / 4);
- break;
- }
-
- RemoveCursor();
- }
-
- int MoveCursor (int * p_line, int * p_sample)
-
- /*** MoveCursor performs the cursor mode operation.
- The user moves the cursor around using the numeric keypad.
- The cursor moves in discrete steps whose size can be changed.
- The final cursor position is returned.
-
- The following cursor command are performed:
-
- Character Action
- 8 cursor up one step
- 9 cursor up and right one step
- 6 cursor right one step
- 3 cursor down and right one step
- 2 cursor down one step
- 1 cursor down and left one step
- 4 cursor left one step
- 7 cursor up and left one step
- 5 cursor position and correspoding pixel value
- display at upper right of screen
- - cursor step size decreased by factor of 2
- + cursor step size increased by factor of 2
- . exits cursor mode
-
- Parameter Type Description
- p_line int ptr the cursor line coordinate
- p_sample int ptr the cursor sample coordinate
- ***/
-
- {
- unsigned char ch; /* mdm 10/6 */
-
- *p_line = CursorLine;
- *p_sample = CursorSample;
- do
- {
- MoveCursorInput (p_line, p_sample, &ch);
- if (ch == RETURN || ch == ESCAPE)
- ch = '.';
- }
- while (ch != '.');
-
- }
-
- int InitDisplay(void)
-
- /*** InitDisplay turns the display device on, loads the default palette,
- initializes the global variables, and loads the font arrays.
- ***/
-
- {
- int i;
- char *devname;
-
- thefont = -1;
- Font (0);
- DisplayDevice = 0;
-
- if ((devname = getenv("IMDISP")) != NULL)
- {
- if (stricmp(devname, "cga" ) == 0) DisplayDevice = CGA;
- if (stricmp(devname, "ega480" ) == 0) DisplayDevice = EGA480;
- if (stricmp(devname, "ega" ) == 0) DisplayDevice = EGA350;
- if (stricmp(devname, "pga" ) == 0) DisplayDevice = PGA;
- if (stricmp(devname, "vga320" ) == 0) DisplayDevice = VGA200;
- if (stricmp(devname, "vga" ) == 0) DisplayDevice = VGA480;
- if (stricmp(devname, "orchid1024") == 0) DisplayDevice = ORCHID768;
- if (stricmp(devname, "orchid800" ) == 0) DisplayDevice = ORCHID600;
- if (stricmp(devname, "orchid" ) == 0) DisplayDevice = ORCHID480;
- if (stricmp(devname, "evga640" ) == 0) DisplayDevice = EVGA640;
- if (stricmp(devname, "evga512" ) == 0) DisplayDevice = EVGA512;
- if (stricmp(devname, "evga800" ) == 0) DisplayDevice = EVGA800;
- if (stricmp(devname, "bios" ) == 0) DisplayDevice = BIOS;
- if (stricmp(devname, "ati640" ) == 0) DisplayDevice = ATI640;
- if (stricmp(devname, "ati800" ) == 0) DisplayDevice = ATI800;
- if (stricmp(devname, "ati1024" ) == 0) DisplayDevice = ATI1024;
- if (stricmp(devname, "paradise" ) == 0) DisplayDevice = PARADISE;
- }
- else if (getenv("orchid") != NULL) DisplayDevice = ORCHID480;
- else if (getenv("ega480") != NULL) DisplayDevice = EGA480;
- else if (getenv("vga") != NULL) DisplayDevice = VGA480;
-
-
- DisplayOn();
- WritePalette (DefaultPalette);
-
- CursorOn = 0;
- CursorLine = dispnl / 2; CursorSample = dispns / 2;
- CursorInc = 16;
-
- TextLine = TextHeight+5; TextSample = 1;
- }
-
- void FrameBox( int top, int left, int bottom, int right, int color, int flag)
- {
- DrawLine( bottom, right, bottom, left, color);
- DrawLine( bottom, left, top, left, color);
- if (flag == TRUE)
- {
- DrawLine( top, left, top, right, color);
- DrawLine( top, right, bottom, right, color);
- }
- }
-