home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.eri.u-tokyo.ac.jp
/
2014.03.ftp.eri.u-tokyo.ac.jp.zip
/
ftp.eri.u-tokyo.ac.jp
/
pub
/
seisv
/
src
/
3.02a
/
graph.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-04-23
|
30KB
|
1,255 lines
/* SeisView alone/client Copyright (C) 1992,1999 K.Koketsu
<history>
99-12-31 Linux has the Courier fonts.
99-11-12 Remove the color cell short warning.
99-01-08 Specify the WinSock version explicitly.
98-11-25 Check no adobe fonts automatically.
98-11-03 Remove CR.
98-10-06 Printers appear again.
Some global variables are replaced by constants.
98-10-02 MONOCHROME drops from the support list.
98-02-25 Abandon DOS, but take Windows 95/NT.
96-06-19 floating color values. */
#include <string.h>
#include <stdio.h>
#include "seis.h"
#include "ctlname.h"
extern char VERSION[];
extern char fk[61*3+1]; /* display strings for function keys */
extern char z$[11], w$[81]; /* work string */
extern char prn$[5], drvo$[65];
#define FontHeight 16
#define SmallFontHeight 14
#define MenuFontHeight 14
#define FontWidth 8
#define LineHeight (FontHeight+1)
#define Lines 24
#define XOffset 4
#define YOffset 7
#define XExtra 9
#ifdef UNIX
#define YExtra 0
#else /* Title bar and borders should be included on Windows.*/
#define YExtra 26
#endif
#define HeaderHeight 38
#define WindowWidth 640+XOffset+XExtra
#define WindowHeight YPixels+HeaderHeight+YOffset+YExtra
#define Color8 130
/* 190 is not appropriate for the Windows 256-color mode. */
#define Color9 192
#define Color10 230
struct xycoord { short xcoord; short ycoord; };
short xo = 0, yo = 0;
int psflag = 0;
short xoff = 0, yoff = 0;
short forecolor = 7;
short fontmode = 0;
/* Naming Convention
pfunction(xp, yp): xp, yp = window coordinates.
_function(x_, y_): x_, y_ = application coordinates (x_ = xp - offset).
xfunction(xx, yx): xx, yx = column-row coordinates. */
void pmoveto(), plineto(), windows_menu(),
pouttext(), _menu_font(), _lineto(), _moveto();
int mouse2key(), menux1[10], menux2[10], oldfunc;
int menuy1 = 1, menuy2 = LineHeight - 1;
char menuitem[10][10] = {"Select", "Browse", "Print", "saVe", "soRt",
"Map", "Time", "maGnitude", "Option", "Exit" };
int barx1[10], barx2[10];
int bary1 = LineHeight + 4, bary2 = LineHeight*2 + 4;
/******************* Windows routines *********************/
#ifdef WIN32
#define MouseX LOWORD(lParam)
#define MouseY HIWORD(lParam)
#define MAX_PEN_BRUSH 13
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
void main();
char szWinName[] = "SeisView";
HINSTANCE hInst;
HWND hwnd;
HDC hdc, hdc2, memdc;
extern HDC pmemdc;
LPARAM lParam;
DWORD ThreadID;
HANDLE hSema;
HBITMAP hbit;
HPEN hPen[MAX_PEN_BRUSH] ;
HBRUSH hBrush[MAX_PEN_BRUSH];
LOGFONT lFont;
HFONT hFont, hSmallFont, hMenuFont;
HCURSOR hCursor0, hCursor1;
int ScreenWidth, ScreenHeight;
int cursor = 0;
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR lpszArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
hInst = hThisInst;
wcl.hInstance = hThisInst;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.cbSize = sizeof( WNDCLASSEX );
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
wcl.lpszMenuName = 0;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = GetStockObject( LTGRAY_BRUSH );
if(!RegisterClassEx(&wcl)) return 0;
hwnd = CreateWindow(
szWinName, VERSION,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
WindowWidth, WindowHeight,
HWND_DESKTOP, NULL, hThisInst, NULL
);
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
short key, cflag = 0;
char str[255];
LRESULT CALLBACK WindowFunc(HWND hwndD, UINT message,
WPARAM wParam, LPARAM lParamD)
{
short scancode;
PAINTSTRUCT paintstruct;
hwnd = hwndD;
lParam = lParamD;
switch(message) {
case WM_CREATE:
hSema = CreateSemaphore(NULL, 1, 1, "mysem");
WaitForSingleObject(hSema, INFINITE);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)main,
NULL, 0, &ThreadID);
break;
case WM_KEYDOWN:
scancode = ((lParam & 0xff0000) >> 16) + 0x100;
if(scancode == Ctrl) { cflag = 1; break; }
if((lParam & 0x01000000) || (scancode>=F1 && scancode<=F9)) {
key = scancode;
cflag = 0;
ReleaseSemaphore(hSema, 1, NULL);
WaitForSingleObject(hSema, INFINITE);
}
break;
case WM_RBUTTONDOWN:
case WM_LBUTTONDOWN:
key = mouse2key();
cflag = 0;
case WM_CHAR:
if(message == WM_CHAR) {
key = wParam;
if(key==cr && cflag) key = CtlM;
cflag = 0;
}
ReleaseSemaphore(hSema, 1, NULL);
WaitForSingleObject(hSema, INFINITE);
break;
case WM_SETCURSOR:
if( cursor ) SetCursor( hCursor1 );
else SetCursor( hCursor0 );
break;
case WM_PAINT:
hdc2 = BeginPaint(hwnd, &paintstruct);
BitBlt(hdc2, 0, 0, ScreenWidth, ScreenHeight, memdc, 0, 0,SRCCOPY);
EndPaint(hwnd, &paintstruct);
break;
case WM_DESTROY:
/* PostQuitMessage() must be posted within this thread, but
DestroyWindow() exists for this problem. See win_finish().*/
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
/*
int exitbox()
{ return( MessageBox(hwnd, "Quit SeisView?", "Exit", MB_YESNO) ); }
*/
color2RGB( color )
int color;
{
int rgb;
switch( color ) {
case 8: rgb = RGB(Color8 ,Color8 ,Color8 ); break;
case 9: rgb = RGB(Color9 ,Color9 ,Color9 ); break;
case 10: rgb = RGB(Color10,Color10,Color10); break;
case 11: rgb = RGB( 0 , 0 ,Color8 ); break;
default: rgb = (color & 1) * 0xff0000;
if(color & 2) rgb = rgb | 0x00ff00;
if(color & 4) rgb = rgb | 0x0000ff;
break;
}
return( rgb );
}
RGB2color( rgb )
COLORREF rgb;
{
int color;
switch( rgb ) {
case RGB(Color8 ,Color8 ,Color8 ): color = 8; break;
case RGB(Color9 ,Color9 ,Color9 ): color = 9; break;
case RGB(Color10,Color10,Color10): color = 10; break;
case RGB( 0 , 0 ,Color8 ): color = 11; break;
default: color = 0;
if(rgb & 0xff0000) color = color | 1;
if(rgb & 0x00ff00) color = color | 2;
if(rgb & 0x0000ff) color = color | 4;
break;
}
return( color );
}
void win_init()
{
int i;
WORD wVersionRequested;
WSADATA wsaData;
ScreenWidth = GetSystemMetrics( SM_CXSCREEN );
ScreenHeight = GetSystemMetrics( SM_CYSCREEN );
hdc = GetDC( hwnd );
memdc = CreateCompatibleDC( hdc );
hbit = CreateCompatibleBitmap(hdc, ScreenWidth, ScreenHeight);
SelectObject(memdc, hbit);
PatBlt(memdc, 0, 0, ScreenWidth, ScreenHeight, PATCOPY);
SetBkColor(memdc, color2RGB(9));
for(i=0; i<MAX_PEN_BRUSH-1; i++) {
hPen[i] = CreatePen(PS_SOLID, 1, color2RGB(i));
hBrush[i] = CreateSolidBrush( color2RGB(i) );
}
hBrush[MAX_PEN_BRUSH-1] = GetStockObject( HOLLOW_BRUSH );
memset(&lFont, 0, sizeof(LOGFONT));
lFont.lfHeight = FontHeight;
lFont.lfHeight = FontHeight;
strcpy((LPSTR)&(lFont.lfFaceName), "Courier New");
hFont = CreateFontIndirect( &lFont );
SelectObject(memdc, hFont);
lFont.lfHeight = SmallFontHeight;
strcpy((LPSTR)&(lFont.lfFaceName), "Courier New");
hSmallFont = CreateFontIndirect( &lFont );
lFont.lfHeight = MenuFontHeight;
strcpy((LPSTR)&(lFont.lfFaceName), "Modern");
hMenuFont = CreateFontIndirect( &lFont );
hCursor0 = LoadCursor(NULL, IDC_ARROW);
hCursor1 = LoadCursor(NULL, IDC_CROSS);
/* Version 1.1: This is required for 98 and NT (1999-01-08). */
wVersionRequested = MAKEWORD(1, 1);
WSAStartup(wVersionRequested, &wsaData);
}
void win_finish() {
int i;
ReleaseDC(hwnd, hdc);
DeleteDC( memdc ); /* Delete, not release a created DC. */
for(i=0; i<MAX_PEN_BRUSH; i++){
DeleteObject( hPen[i] );
DeleteObject( hBrush[i] );
}
DestroyCursor( hCursor0 );
DestroyCursor( hCursor1 );
DestroyWindow( hwnd );
WSACleanup();
}
void pmoveto(x, y) short x, y; { xo = x; yo = y;
MoveToEx(hdc, x, y, NULL); MoveToEx(memdc, x, y, NULL); }
void plineto(x, y) short x, y;
{ LineTo(hdc, x, y); LineTo(memdc, x, y); }
void _setcolor( color )
short color;
{
forecolor = color;
SelectObject(hdc , hPen[color]);
SelectObject(memdc, hPen[color]);
SetTextColor( hdc, (COLORREF)color2RGB(color));
SetTextColor(memdc, (COLORREF)color2RGB(color));
}
void _setbkcolor( color ) /* color = 12 for hollow background */
short color;
{
SelectObject(hdc , hBrush[color]);
SelectObject(memdc, hBrush[color]);
if(color < 12) {
SetBkColor( hdc, (COLORREF)color2RGB(color));
SetBkColor(memdc, (COLORREF)color2RGB(color));
}
}
void beep() { MessageBeep( MB_OK); }
void prectangle(flag, x1, y1, x2, y2)
short flag, x1, y1, x2, y2;
{
if(flag == 1) _setbkcolor( forecolor );
else _setbkcolor( 12 );
Rectangle(hdc , x1, y1, x2, y2);
Rectangle(memdc, x1, y1, x2, y2);
}
short getcchr()
{
short c;
WaitForSingleObject(hSema, INFINITE);
c = key;
ReleaseSemaphore(hSema, 1, NULL);
return ( c );
}
void _setviewport(x1, y1, x2, y2)
short x1, y1, x2, y2;
{
HRGN hrgn;
int left, right, top, bottom;
if(x1==0 && y1==0 && x2==639 && y2==YPixels-1) { /* Full Screen */
left = 0;
top = 0;
right = WindowWidth;
bottom = WindowHeight;
}
else {
left = xx( x1 );
top = yy( y1 );
right = xx( x2 );
bottom = yy( y2 );
}
hrgn = CreateRectRgn(left, top, right, bottom);
SelectClipRgn(hdc , hrgn);
SelectClipRgn(memdc, hrgn);
xoff = x1;
yoff = y1;
}
void _setpixel(x, y)
int x, y;
{
SetPixel(hdc , xx(x), yy(y), (COLORREF)color2RGB(forecolor));
SetPixel(memdc, xx(x), yy(y), (COLORREF)color2RGB(forecolor));
}
void _getimage() {}
int _getpixel(x, y)
int x, y;
{
COLORREF rgb;
rgb = GetPixel(hdc, xx(x), yy(y));
return( RGB2color( rgb ) );
}
void _circle(flag, x, y, r)
short flag, x, y, r;
{
if(flag == 1) _setbkcolor( forecolor );
else _setbkcolor( 12 );
if(r <= 1) _setpixel(x, y);
else {
Ellipse(hdc , xx(x)-r, yy(y)-r, xx(x)+r, yy(y)+r);
Ellipse(memdc, xx(x)-r, yy(y)-r, xx(x)+r, yy(y)+r);
}
}
void _fillpolygon(pq, n)
short n;
struct xycoord *pq;
{
POINT qr[10]; /* # of points should be less than 11.*/
short i;
for(i=0; i<n; i++) {
qr[i].x = xx(pq[i].xcoord);
qr[i].y = yy(pq[i].ycoord);
}
_setbkcolor( forecolor );
Polygon(hdc , qr, n);
Polygon(memdc, qr, n);
}
void _settextmode( mode )
int mode;
{
if(mode > 0) {
SetBkMode(hdc , OPAQUE);
SetBkMode(memdc, OPAQUE);
}
else {
SetBkMode(hdc , TRANSPARENT);
SetBkMode(memdc, TRANSPARENT);
}
}
void pouttext(x, y, s)
int x, y;
char *s;
{
TextOut(hdc , x, y, s, strlen(s));
TextOut(memdc, x, y, s, strlen(s));
}
void _normal_font()
{
SelectObject(hdc , hFont);
SelectObject(memdc, hFont);
}
void _small_font()
{
SelectObject(hdc , hSmallFont);
SelectObject(memdc, hSmallFont);
}
void _menu_font()
{
SelectObject(hdc , hMenuFont);
SelectObject(memdc, hMenuFont);
}
_gettextextent( s )
char *s;
{
SIZE size;
GetTextExtentPoint32(memdc, s, strlen(s), &size);
return( size.cx );
}
void gcursor(kx0, ky0, kx1, ky1, xo, yo, flg)
int kx0, ky0, kx1, ky1, *xo, *yo, flg;
{
POINT point;
int x, y, crx, cry;
cursor = 1;
point.x = xx( *xo );
point.y = yy( *yo );
ClientToScreen(hwnd, &point);
SetCursorPos(point.x, point.y);
crx = 5; cry = 5;
*xo = -2;
for(;;) {
if(getcchr() >= 0x200) {
GetCursorPos( &point );
ScreenToClient(hwnd, &point);
x = point.x - xoff - XOffset;
y = point.y - yoff - YOffset - HeaderHeight;
if(x<kx0 || x>kx1 || y<ky0 || y>ky1) beep();
else {
*xo = x;
*yo = y;
}
}
if(*xo > -2) break;
}
if( flg ) {
_setcolor( 2 );
_moveto(*xo, *yo-cry); _lineto(*xo, *yo+cry);
_moveto(*xo-crx, *yo); _lineto(*xo+crx, *yo);
}
cursor = 0;
}
void xflush(){}
/****************** X Window routines **********************/
#else
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/cursorfont.h>
#define MouseX ev.xbutton.x
#define MouseY ev.xbutton.y
Display *d;
Window w;
Pixmap p;
GC gc;
XEvent ev;
XImage *im;
Cursor cs;
Font ft, nft, sft, mft;
int fh, nfh, sfh, mfh;
unsigned long mycolor, bkcolor;
unsigned long color2RGB();
int mywidth = 1;
int mystyle = LineSolid;
int textmode = 1;
int ehandler(d, e)
Display *d;
XErrorEvent *e;
{
if(e->error_code==15 && e->request_code==45) {
fontmode = 1;
/* 99-12-31 Linux has the Courier fonts. */
/* nft = XLoadFont(d, "7x14"); */
mft = XLoadFont(d, "6x13");
}
}
void win_init()
{
XWMHints hints;
XFontStruct *fs;
Colormap cmap;
unsigned long pixels[12], planes[1];
int rc;
XSetErrorHandler( ehandler );
d = XOpenDisplay( 0 );
if(d == NULL) {
puts( "You are not in the X Window environment!" );
exit( 1 );
}
w = XCreateSimpleWindow(d, DefaultRootWindow(d), 0, 0,
WindowWidth, WindowHeight,
5, color2RGB(9), color2RGB(9));
XSelectInput(d, w, ExposureMask | KeyPressMask | ButtonPressMask);
XChangeProperty(d, w, XA_WM_NAME, XA_STRING, 8, PropModeReplace,
VERSION, strlen(VERSION));
hints.flags = InputHint;
hints.input = True;
XSetWMHints(d, w, &hints);
XMapWindow(d, w);
gc = XCreateGC(d, w, 0, 0);
p = XCreatePixmap(d, w, WindowWidth, WindowHeight, DefaultDepth(d,0));
cmap = DefaultColormap(d, 0);
nft = XLoadFont(d, "*-courier-medium-r-*-14-*");
sft = XLoadFont(d, "7x14");
mft = XLoadFont(d, "*-palatino-medium-r-*-12-*");
fs = XQueryFont(d, nft);
nfh = (*fs).max_bounds.ascent;
fs = XQueryFont(d, sft);
sfh = (*fs).max_bounds.ascent;
fs = XQueryFont(d, mft);
mfh = (*fs).max_bounds.ascent - 1;
cs = XCreateFontCursor(d, XC_arrow);
XDefineCursor(d, w, cs);
do XNextEvent(d, &ev); /* Wait for exposure */
while(ev.type != Expose);
}
void win_finish(){}
void pmoveto(x, y)
short x, y;
{ xo = x; yo = y; }
void plineto(x, y)
short x, y;
{
XDrawLine(d, w, gc, xo, yo, x, y);
XDrawLine(d, p, gc, xo, yo, x, y);
pmoveto(x, y);
}
prectangle(flag, x1, y1, x2, y2)
short flag, x1, y1, x2, y2;
{
if(flag == 1) {
XFillRectangle(d, w, gc, x1, y1, x2-x1, y2-y1);
XFillRectangle(d, p, gc, x1, y1, x2-x1, y2-y1);
}
else {
XDrawRectangle(d, w, gc, x1, y1, x2-x1, y2-y1);
XDrawRectangle(d, p, gc, x1, y1, x2-x1, y2-y1);
}
}
void _circle(flag, x, y, r)
short flag, x, y, r;
{
if(r == 0) XDrawPoint(d, w, gc, xx(x), yy(y));
else {
if(flag) XFillArc(d, w, gc, xx(x)-r, yy(y)-r, r*2, r*2, 0, 360*64);
else XDrawArc(d, w, gc, xx(x)-r, yy(y)-r, r*2, r*2, 0, 360*64);
}
}
_fillpolygon(pq, n)
short n;
struct xycoord *pq;
{
XPoint qr[10]; /* # of points should be less than 11.*/
short i;
for(i=0; i<n; i++) {
qr[i].x = xx(pq[i].xcoord);
qr[i].y = yy(pq[i].ycoord);
}
XFillPolygon(d, w, gc, qr, n, Nonconvex, CoordModeOrigin);
XFillPolygon(d, p, gc, qr, n, Nonconvex, CoordModeOrigin);
}
int _gettextextent( s )
char *s;
{
XFontStruct *fs;
XCharStruct cs;
int dir, ascent, descent;
fs = XQueryFont(d, ft);
XTextExtents(fs, s, strlen(s), &dir, &ascent, &descent, &cs);
return(cs.rbearing - cs.lbearing);
}
_setviewport(x1, y1, x2, y2)
short x1, y1, x2, y2;
{
XRectangle rec;
if(x1==0 && y1==0 && x2==639 && y2==YPixels-1) { /* Full Screen */
rec.x = 0;
rec.y = 0;
rec.width = WindowWidth;
rec.height = WindowHeight;
}
else {
rec.x = xx( x1 );
rec.y = yy( y1 );
rec.width = x2 - x1;
rec.height = y2 - y1;
}
XSetClipRectangles(d, gc, 0, 0, &rec, 1, Unsorted);
xoff = x1;
yoff = y1;
}
void _setcolor( color )
short color;
{
char s[9];
forecolor = color;
mycolor = color2RGB( color );
MyLineAttributes();
}
void _setbkcolor( color )
short color;
{
char s[9];
bkcolor = color2RGB( color );
MyLineAttributes();
}
void _getimage()
{ im = XGetImage(d, w, 0, 0, WindowWidth, WindowHeight, -1, XYPixmap); }
int _getpixel(x, y)
int x, y;
{
unsigned long pixel;
pixel = XGetPixel(im, xx(x), yy(y));
if(pixel == BlackPixel(d,0)) return( 0 );
else return( 1 );
}
void _normal_font() {
fh = nfh; ft = nft;
XSetFont(d, gc, ft);
}
void _small_font() {
fh = sfh; ft = sft;
XSetFont(d, gc, ft);
}
void _menu_font() {
fh = mfh; ft = mft;
XSetFont(d, gc, ft);
}
void _settextmode( mode ) int mode; { textmode = mode; }
void pouttext(x, y, s)
int x, y;
char *s;{
/* The base is defined to be the bottom on X Window. */
if(textmode == 0) {
XDrawString(d, w, gc, x, y+fh, s, strlen(s));
XDrawString(d, p, gc, x, y+fh, s, strlen(s));
}
else {
XDrawImageString(d, w, gc, x, y+fh, s, strlen(s));
XDrawImageString(d, p, gc, x, y+fh, s, strlen(s));
}
}
void xflush() { XFlush( d ); }
short getcchr()
{
KeySym key;
char buf[2];
short c, flag, cflag;
flag = 0;
cflag = 0;
for(;;) {
XNextEvent(d, &ev);
switch( ev.type ) {
case Expose:
XCopyArea(d, p, w, gc, 0, 0,
WindowWidth, WindowHeight, 0, 0);
break;
case ButtonPress:
return( mouse2key() );
case KeyPress:
XLookupString(&ev.xkey, buf, 2, &key, NULL);
flag = 1;
switch( key ) {
case XK_Control_L:
case XK_Control_R: cflag = 1;
case XK_Shift_R :
case XK_Shift_L : flag = 0 ; break;
case XK_Left : c = LEFT ; break;
case XK_Right : c = RIGHT; break;
case XK_Up : c = UP ; break;
case XK_Down : c = DOWN ; break;
default:
if(IsFunctionKey(key)) c = key - XK_F1 + F1;
else { c = buf[0]; if(c==cr && cflag) c = CtlM; }
}
if( flag ) return( c );
}
}
}
void beep() { XBell(d, 0); }
XColor RGB(r, g, b)
unsigned short r, g, b;
{
XColor c;
c.red = r * 255;
c.green = g * 255;
c.blue = b * 255;
return( c );
}
unsigned long color2RGB( color )
int color;
{
Colormap cmap;
XColor c, c0;
Status rc;
cmap = DefaultColormap(d, 0);
switch( color ) {
case 8: c = RGB(Color8 ,Color8 ,Color8 ); break;
case 9: c = RGB(Color9 ,Color9 ,Color9 ); break;
case 10: c = RGB(Color10,Color10,Color10); break;
case 11: c = RGB( 0 , 0 ,Color8 ); break;
default: c = RGB((color&4)/4*255, (color&2)/2*255, (color&1)*255);
break;
}
rc = XAllocColor(d, cmap, &c);
if(rc == 0) {
switch( color ) {
case 11:
case 1: rc = XAllocNamedColor(d, cmap, "blue" , &c, &c0); break;
case 2: rc = XAllocNamedColor(d, cmap, "green" , &c, &c0); break;
case 3: rc = XAllocNamedColor(d, cmap, "cyan" , &c, &c0); break;
case 4: rc = XAllocNamedColor(d, cmap, "red" , &c, &c0); break;
case 5: rc = XAllocNamedColor(d, cmap, "magenta", &c, &c0); break;
case 6: rc = XAllocNamedColor(d, cmap, "yellow" , &c, &c0); break;
case 7: rc = XAllocNamedColor(d, cmap, "white" , &c, &c0); break;
case 8:
case 9:
case 10: rc = XAllocNamedColor(d, cmap, "gray" , &c, &c0); break;
}
}
return( c.pixel );
}
MyLineAttributes()
{
XGCValues gv;
gv.foreground = mycolor;
gv.background = bkcolor;
gv.line_width = mywidth;
gv.line_style = mystyle;
gv.cap_style = CapProjecting;
gv.arc_mode = ArcChord;
XChangeGC(d, gc, GCBackground |GCForeground |
GCLineWidth | GCLineStyle | GCCapStyle | GCArcMode, &gv);
}
void gcursor(kx0, ky0, kx1, ky1, xo, yo, flg)
int kx0, ky0, kx1, ky1, *xo, *yo, flg;
{
int x, y, crx, cry;
cs = XCreateFontCursor(d, XC_tcross);
XDefineCursor(d, w, cs);
XWarpPointer(d, None, w, 0, 0, 0, 0, xx(*xo), yy(*yo));
crx = 5; cry = 5;
for(;;) {
XNextEvent(d, &ev);
if(ev.type == Expose) XCopyArea(d, p, w, gc, 0, 0,
WindowWidth, WindowHeight, 0, 0);
if(ev.type == ButtonPress) {
x = ev.xbutton.x - xoff - XOffset;
y = ev.xbutton.y - yoff - YOffset - HeaderHeight;
if(x<kx0 || x>kx1 || y<ky0 || y>ky1) beep();
else {
*xo = x; *yo = y; break;
}
}
}
if( flg ) {
_setcolor( 2 );
_moveto(*xo, *yo-cry); _lineto(*xo, *yo+cry);
_moveto(*xo-crx, *yo); _lineto(*xo+crx, *yo);
}
cs = XCreateFontCursor(d, XC_arrow);
XDefineCursor(d, w, cs);
}
#endif
/****************** common routines **********************/
void psviewport(), psmoveto(), pslineto(), psbox(), pscircle(),
pstext(), psnormal_font(), pssmall_font();
short xx( x ) short x;
{ return( x + xoff + XOffset ); }
short yy( y ) short y;
{ return( y + yoff + YOffset + HeaderHeight ); }
void _moveto(x, y) short x, y; { pmoveto(xx(x), yy(y)); }
void _lineto(x, y) short x, y; { plineto(xx(x), yy(y)); }
int _getcolor() { return( forecolor ); }
void _outgtext( s )
char *s;
{ pouttext(xo, yo, s); }
void _rectangle(flag, x1, y1, x2, y2)
short flag, x1, y1, x2, y2;
{ prectangle(flag, xx(x1), yy(y1), xx(x2), yy(y2)); }
int widespace = 0;
void _wide_spacing() { widespace = 1; }
void _normal_spacing() {widespace = 0; }
void xouttext(row, col, s)
short row, col;
char *s;
{
int yw, xw;
if( widespace ) yw = yy(row * LineHeight);
else yw = yy(row * FontHeight);
xw = xx(col * FontWidth);
pouttext(xw, yw, s);
}
void physical_clear( clr )
int clr;
{
_setcolor( clr );
prectangle(1, 0, yy(0), WindowWidth, WindowHeight);
}
void gviewport(x1, y1, x2, y2)
short x1, y1, x2, y2;
{
if( psflag ) psviewport(x1, y1, x2, y2);
else _setviewport(x1, y1, x2, y2);
}
void gmoveto(x, y) { if(psflag) psmoveto(x, y); else _moveto(x, y); }
void glineto(x, y) { if(psflag) pslineto(x, y); else _lineto(x, y); }
void gbox(flag, x1, y1, x2, y2)
short flag, x1, y1, x2, y2;
{
if( psflag ) psbox(flag, x1, y1, x2, y2);
else {
if( flag ) _rectangle(1, x1, y1, x2, y2);
else _rectangle(0, x1, y1, x2, y2);
}
}
void gcircle(flag, x, y, r)
short flag, x, y, r;
{
if( psflag ) pscircle(x, y, r);
else _circle(flag, x, y, r);
}
void gfillpolygon(p, q, n)
int p[], q[], n;
{
struct xycoord pq[10]; /* # of points should be less than 11.*/
short i;
for(i=0; i<n; i++) {
pq[i].xcoord = p[i]; pq[i].ycoord = q[i];
}
_fillpolygon(pq, n);
}
void gsymbol(x, y, r, style)
short x, y, r, style;
{
int a;
/* Symbols correspond to colors. */
switch( style ) {
case 4: gcircle(0, x, y, r); break;
case 5: a = (int)(0.9*r+0.5);
gbox(0, x-a, y-a, x+a, y+a); break;
case 6: a = (int)(1.13*r+0.5); gmoveto(x-a,y); glineto(x,y-a);
glineto(x+a,y); glineto(x,y+a); glineto(x-a,y); break;
case 2: a = r; gmoveto(x-a,y+a);
glineto(x+a,y+a); glineto(x,y-a); glineto(x-a,y+a); break;
case 3: a = r; gmoveto(x-a,y-a);
glineto(x+a,y-a); glineto(x,y+a); glineto(x-a,y-a); break;
case 1: a = (int)(0.85*r+0.5); gmoveto(x-a,y+a); glineto(x+a,y-a-1);
gmoveto(x-a,y-a); glineto(x+a,y+a+1); break;
case 7: a = (int)(1.1*r+0.5); gmoveto(x-a+1,y); glineto(x+a,y);
gmoveto(x,y-a); glineto(x,y+a); break;
default: gcircle(0, x, y, r); break;
}
}
void gfprint(x, y, str, clr)
int x, y, clr;
char *str;
{
gmoveto(x, y);
if( psflag ) pstext(x, y, str);
else {
_setcolor( clr ); _outgtext( str );
}
}
void gnormal_font()
{
if( psflag ) psnormal_font();
else _normal_font();
}
void gprint(x, y, str, clr)
int x, y, clr;
char *str;
{ gfprint((x-1)*8, (y-1)*RowPixels, str, clr); }
void gsmall_font()
{
if( psflag ) pssmall_font();
else _small_font();
}
int fgkey(key, flg)
int key, flg;
{
int i;
char s[61];
if( psflag ) { pshcopy( psflag ); psflag = 0; }
strncpy(s, fk+key*49, 49);
strncpy(s, "hcpyL ", 6); strncpy(s+6, "hcpyS ", 6);
strcpy(s+48, " help "); strcat(s, "Enter ");
windows_toolbar( s );
_normal_font();
_setcolor( 7 );
for(;;) {
i = getcchr();
switch( i ) {
case cr: if(flg) return(F6); else return(i);
case CtlE: check_exit(); break;
case F1:
case F2:
blueF1_2( i-F1+1 );
if(lpinit()) { psflag = i-F1+1; psinit(); return(F1); }
else return( 0 );
case F3:
case F6: return(i);
case F8: if(key == 1) return(i); else beep(); break;
default: beep();
}
}
}
void inputarea(col, row, len)
int col, row, len;
{
int yw, xw;
yw = yy(row * LineHeight) - 2;
xw = xx(col * FontWidth ) - 1;
_setcolor( 7 );
prectangle(1, xw, yw+1, xw+len*FontWidth+1, yw+FontHeight+1);
_setcolor( 10 );
prectangle(0, xw, yw+1, xw+len*FontWidth+1, yw+FontHeight+1);
_setcolor( 0 );
pmoveto(xw, yw+FontHeight);
plineto(xw, yw+1);
plineto(xw+len*FontWidth, yw+1);
}
void check_exit()
{ windows_menu( EXIT ); finish(); }
void menu_init()
{
int i, x, dx;
_menu_font();
x = 10;
for(i=0; i<10; i++) {
dx = _gettextextent( menuitem[i] );
menux1[i] = x - 1;
menux2[i] = x + dx + 1;
x = x + dx + 16;
}
}
void windows_menu( func )
int func;
{
int i;
_setcolor( 9 );
prectangle(1, 0, menuy1-1, WindowWidth, menuy2+4);
_menu_font();
for(i=SELECT; i<=EXIT; i++) {
if(i == func) {
_setcolor( 11 );
prectangle(1, (menux1[i]-8<4)?4:menux1[i]-8, menuy1-1,
menux2[i]+8, menuy2+1);
_setcolor( 7 );
_setbkcolor( 11 );
}
else {
_setcolor( 0 );
_setbkcolor( 9 );
}
if(func>=SELECT && i!=func && i<EXIT) {
_settextmode( 0 );
_setcolor( 7 );
pouttext(menux1[i]+2, menuy1+1, menuitem[i]);
_setcolor( 8 );
pouttext(menux1[i]+1, menuy1, menuitem[i]);
_settextmode( 1 );
}
else pouttext(menux1[i]+1, menuy1, menuitem[i]);
}
_setcolor( 8 );
pmoveto(XOffset, menuy2+2);
plineto(FontWidth*80, menuy2+2);
_setcolor( 7 );
pmoveto(XOffset, menuy2+3);
plineto(FontWidth*80, menuy2+3);
if(func != EXIT) oldfunc = func;
}
void windows_toolbar( s )
char *s;
{
int i, x, dx;
unsigned j;
char baritem[11];
_setcolor( 9 );
prectangle(1, 0, bary1-1, WindowWidth, bary2+7);
if(*s != 0) {
_menu_font();
x = 10;
for(i=0; i<10; i++) {
strncpy(baritem, s+i*6, 6); baritem[6] = 0;
if(strcmp(baritem," ")!=0 && i<9) {
for(j=strlen(baritem); j>0; j--) {
if(baritem[j-1] == ' ') baritem[j-1] = 0;
else break;
}
for(j=0; j<strlen(baritem); j++) {
if(baritem[j] == ' ') strcpy(baritem, baritem+j+1);
else break;
}
*baritem = *baritem - ('a'-'A');
sprintf(baritem+strlen(baritem), ":F%1d", i+1);
}
else strcat(baritem, " ");
dx = _gettextextent( baritem );
barx1[i] = x - 4;
barx2[i] = x + dx + 2;
x = x + dx + 14;
if(i == 8) x += 15;
standend();
if( fontmode ) pouttext(barx1[i]+4, bary1+3, baritem);
else pouttext(barx1[i]+4, bary1+1, baritem);
_setcolor( 8 );
prectangle(0, barx1[i], bary1+1, barx2[i]+1, bary2);
if(strcmp(baritem," ") != 0) {
_setcolor(0);
prectangle(0, barx1[i]-1, bary1, barx2[i]+2, bary2+1);
_setcolor(7);
pmoveto(barx1[i]-1, bary2-1);
plineto(barx1[i]-1, bary1);
plineto(barx2[i]+1, bary1);
_setcolor(10);
pmoveto(barx1[i], bary2-2);
plineto(barx1[i], bary1+1);
plineto(barx2[i], bary1+1);
}
}
}
_setcolor( 8 );
pmoveto(XOffset, bary2+2);
plineto(FontWidth*80, bary2+2);
_setcolor( 7 );
pmoveto(XOffset, bary2+3);
plineto(FontWidth*80, bary2+3);
}
mouse2key()
{
int i;
for(i=0; i<10; i++) {
if(MouseX>=menux1[i] && MouseX<=menux2[i] &&
MouseY>=menuy1 && MouseY<=menuy2) {
switch( i ) {
case 0: return( CtlS );
case 1: return( CtlB );
case 2: return( CtlP );
case 3: return( CtlV );
case 4: return( CtlR );
case 5: return( CtlM );
case 6: return( CtlT );
case 7: return( CtlG );
case 8: return( CtlO );
case 9: return( CtlE );
}
}
}
for(i=0; i<10; i++) {
if(MouseX>=barx1[i] && MouseX<=barx2[i] &&
MouseY>=bary1 && MouseY<=bary2) {
if(i == 9) return( cr );
else return(F1 + i);
}
}
if(MouseX>=XOffset && MouseX<=WindowWidth &&
MouseY>=YOffset+HeaderHeight && MouseY<=WindowHeight)
return( 0x200 + (MouseX-XOffset)/FontWidth
+ (MouseY-YOffset-HeaderHeight)/LineHeight*80 );
return( -1 );
}
void restore_box(oldx, oldy)
int oldx, oldy;
{
if(_iswritable(oldy,oldx)) {
if(_iswritable(oldy,oldx-1))_setcolor(7); else _setcolor(0);
pmoveto(xx(oldx*FontWidth)-1, yy(oldy*LineHeight)+ 2);
plineto(xx(oldx*FontWidth)-1, yy(oldy*LineHeight)+14);
}
if(oldx>0 && _iswritable(oldy,oldx-1) && !_iswritable(oldy,oldx)) {
_setcolor( 10 );
pmoveto(xx(oldx*FontWidth)-1, yy(oldy*LineHeight)+1);
plineto(xx(oldx*FontWidth)-1, yy(oldy*LineHeight)+FontHeight+1);
}
}
void blueF1_2( key )
int key;
{
char s[10]; int bx;
_menu_font();
_setcolor( 7 );
_setbkcolor( 11 );
switch( key ) {
case 0: bx = barx1[0]; strcpy(s, "Hcopy:F1" ); break;
case 1: bx = barx1[0]; strcpy(s, "HcopyL:F1"); break;
case 2: bx = barx1[1]; strcpy(s, "HcopyS:F2"); break;
}
if( fontmode ) pouttext(bx, bary1+3, s);
else pouttext(bx, bary1+1, s);
xflush();
}