📄 x11u.c
字号:
/*************************************************************/
/***** FEAPpv DRIVER FOR X WINDOWS VERSION 11, RELEASE 4 *****/
/*************************************************************/
/*********************************/
/* Driver configuration */
/* X11 DEVICE DRIVER */
/* Change 5-places for EACH */
/* Type of workstation Search */
/* for string FORTRAN to change */
/* Currently set: Underscore */
/* Version for: SUN & DEC */
/*********************************/
/* This driver supports the traditional GIN mode, i.e. point the cursor */
/* and strike a key! It also supports the use of the mouse buttons */
/* during GIN input. Below is the mouse button to "key" relationships. */
#define BUTTON1_KEY 'l'
#define BUTTON2_KEY 'm'
#define BUTTON3_KEY 'r'
/* This driver has the capability to store all the lines drawn into the */
/* X Window and to use these saved lines to refresh the screen. */
/* Using this feature and the routine "gdx11_refresh_window" should */
/* make using FEAP under X11 easier than before! */
/* If you don't want/need this feature or if you can't afford the */
/* memory usage, set MAX_SEG to 1, MAX_POINTS to something around 100 */
#define MAX_POINTS 20000 /* Maximum points in all polylines stored */
#define MAX_SEG 10000 /* Maximum polylines stored */
#define MAX_TEXT 10000 /* Maximum 80-character text string */
#define DEBUG 0 /* 0 == No debugging. */
/* 1 == Soft X11 errors */
/* 2 == Above plus caller bugs */
/* 3 == Above plus Driver tracing messages */
/* 4 == Above plus all tracing messages */
/****************************/
/* Non-FEAP include files */
/****************************/
#include <stdio.h> /* Unix standard I/O definitions */
#include <stdlib.h> /* We use Unix "malloc" and "free" */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
/* Note: if you don't have the file "malloc.h", then use the following: */
/* extern char *malloc(); */
/* extern void free(); */
/**************************/
/* Gray scale definitions */
/**************************/
#define gray1_width 16
#define gray1_height 16
static char gray1_bits [] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
#define gray2_width 4
#define gray2_height 4
static char gray2_bits [] = {0x07, 0x0d, 0x07, 0x0d};
#define gray3_width 16
#define gray3_height 4
static char gray3_bits [] = {0x55, 0x55, 0xee, 0xee, 0x55, 0x55, 0xbb, 0xbb};
#define gray4_width 16
#define gray4_height 16
static char gray4_bits [] = {0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33,
0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33,
0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33,
0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33};
#define gray5_width 2
#define gray5_height 2
static char gray5_bits [] = {0x01, 0x02};
#define gray6_width 16
#define gray6_height 16
static char gray6_bits [] = {0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22,
0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22,
0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22,
0x55, 0x55, 0x88, 0x88, 0x55, 0x55, 0x22, 0x22};
#define gray7_width 4
#define gray7_height 4
static char gray7_bits [] = {0x08, 0x02, 0x08, 0x02};
#define gray8_width 16
#define gray8_height 16
static char gray8_bits [] = {0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00};
/***************************/
/* FEAP Window Structure */
/***************************/
/* Note: User's should treat all DIGWin structures as READ-ONLY */
/* However, in general, user's should even read these fields! */
typedef struct
{
Window xwin;
Display *xdisplay;
XWindowAttributes xwa;
GC xgc;
GC xgc_mono_fill;
Pixmap gray[8];
int num_fg_colors;
int pixel_value_for_color[8];
int current_x;
int current_y;
int current_pixel_value;
int current_gray_value;
int min_x;
int max_x;
int min_y;
int max_y;
int abs_min_max;
int x_border;
int y_border;
int x_offset;
int x_len;
float x_scale;
int y_offset;
int y_len;
float y_scale;
int next_point;
int npolylines;
int nstrings;
int *npoints;
int *polyline_pixel_value;
int *polyline_gray_value;
int *strlen;
int *strflg;
int *textx;
int *texty;
char *strings;
XPoint *points;
} DIGWin;
#define STROKE_DEVICE 0
#define RASTER_DEVICE 1
#define DVST_DEVICE 2
#define PLOTTER_DEVICE 3
#define CAN_DRAW_IN_BACKGROUND 4
#define HARDCOPY_DEVICE 8
#define SHARED_DEVICE 16
#define HLS_SETABLE_COLORS 32
#define RGB_SETABLE_COLORS 64
#define CAN_DO_GIN 128
#define CAN_DRAW_FILLED_POLYGONS 256
#define CONVEX_POLYGONS_ONLY 512
#define CAN_DO_LOCATOR_INPUT 1024
/***************************/
/* Some global definitions */
/***************************/
#define MAX_OPCODE 16 /* number of op-code values */
#define DEFAULT_X 245 /* X Window Location on Screen */
#define DEFAULT_Y 065 /* Y Window Location on Screen */
static XButtonPressedEvent DiglibEvent;/* Button event variable */
static DIGWin *current_dw = NULL;
static DIGWin *default_dw = NULL;
static int default_width = 768; /* X Window width (default) */
static int default_height = 600; /* Y Window width (default) */
#define Min(x,y) ( ((float)x < (float)y ) ? (float)x : (float)y )
/*******************************************************************/
/* Device coordinates <--> Virtual corrdinates, translation macros */
/*******************************************************************/
#define x_translate(dw,x) (int)((x)*dw->x_scale-1.5)+dw->x_offset
#define y_translate(dw,y) (int)(dw->y_len-(y)*dw->y_scale-1.5)+dw->y_offset
#define x_untranslate(dw,x) ((x)-dw->x_offset)/dw->x_scale
#define y_untranslate(dw,y) (dw->y_len+dw->y_offset-(y))/dw->y_scale
/*********************************/
/*** Window Management Support ***/
/*********************************/
/*******************************************************************/
/* Adjust the scale of the diglib device to fit the current window */
/* given the user's guidelines for what part of the window to use.*/
/*******************************************************************/
void gdx11_adjust_digwin(dw)
DIGWin *dw;
{
if (dw->abs_min_max)
{
dw->x_offset = dw->min_x + dw->x_border;
dw->y_offset = dw->min_y + dw->y_border;
dw->x_len = (dw->max_x-dw->x_border) - dw->x_offset;
dw->y_len = (dw->max_y-dw->y_border) - dw->y_offset;
}
else
{
XGetWindowAttributes(dw->xdisplay,dw->xwin,&(dw->xwa));
dw->x_offset = (dw->min_x*dw->xwa.width)/100+dw->x_border;
dw->y_offset = (dw->min_y*dw->xwa.height)/100+dw->y_border;
dw->x_len = ((dw->max_x-dw->min_x)*dw->xwa.width)/100-dw->x_border;
dw->y_len = ((dw->max_y-dw->min_y)*dw->xwa.height)/100-dw->y_border;
}
}
/*****************************/
/* Refresh the FEAP window */
/*****************************/
void gdx11_refresh_digwin(dw)
DIGWin *dw;
{
int i,j,x,y,l,flag,width ;
int start = 0;
Display *disp = dw->xdisplay;
unsigned long fg_pv;
unsigned long bg_pv;
int fg_gray;
int pv;
int gray_pv;
int np;
char text[80] ;
Font nfont ;
XFontStruct *nfont_struct ;
fg_pv = dw->polyline_pixel_value[0];
XSetForeground(disp,dw->xgc,fg_pv);
if(dw->num_fg_colors == 1) {
fg_gray = dw->polyline_gray_value[0];
XSetStipple(disp,dw->xgc_mono_fill,dw->gray[fg_gray]);
}
for (i=0;i<dw->npolylines;++i)
{
if ((pv=dw->polyline_pixel_value[i])!=fg_pv)
{
fg_pv = pv;
XSetForeground(disp,dw->xgc,fg_pv);
}
np = dw->npoints[i];
if (np<0)
{
np = -np;
if (dw->num_fg_colors > 1)
XFillPolygon(disp,dw->xwin,dw->xgc,&(dw->points[start]),np,
Complex,CoordModeOrigin);
/*Monochrome gray scale stuff */
else {
if( (gray_pv=dw->polyline_gray_value[i]) != fg_gray) {
fg_gray = gray_pv;
XSetStipple(disp,dw->xgc_mono_fill,dw->gray[fg_gray]);
}
XFillPolygon(disp,dw->xwin,dw->xgc_mono_fill,
&(dw->points[start]),np,Complex,CoordModeOrigin);
}
}
else
XDrawLines(disp,dw->xwin,dw->xgc,&(dw->points[start]),
np,CoordModeOrigin);
start = start+np;
}
if (dw->nstrings == 0) return ;
fg_pv = dw->pixel_value_for_color[1];
bg_pv = dw->pixel_value_for_color[0];
XSetBackground(disp,dw->xgc,bg_pv);
XSetForeground(disp,dw->xgc,fg_pv);
if ( Min ( dw->x_len , 1.27*dw->y_len ) < 440 )
nfont = XLoadFont(disp,"*helvetica-medium-r-normal--8*");
else if ( Min ( dw->x_len , 1.27*dw->y_len ) < 600. )
nfont = XLoadFont(disp,"*helvetica-bold-r-normal--10*");
else if ( Min ( dw->x_len , 1.27*dw->y_len ) < 760. )
nfont = XLoadFont(disp,"*helvetica-bold-r-normal--12*");
else if ( Min ( dw->x_len , 1.27*dw->y_len ) < 920. )
nfont = XLoadFont(disp,"*helvetica-bold-r-normal--14*");
else if ( Min ( dw->x_len , 1.27*dw->y_len ) < 1080. )
nfont = XLoadFont(disp,"*helvetica-bold-r-normal--18*");
else
nfont = XLoadFont(disp,"*helvetica-bold-r-normal--20*");
nfont_struct = XQueryFont(disp,nfont);
XSetFont(disp,dw->xgc,nfont);
start = 0 ;
for (i = 0 ; i < dw->nstrings ; ++i )
{
x = dw->textx[i] ;
y = dw->texty[i] ;
l = dw->strlen[i] ;
flag = dw->strflg[i] ;
for (j = 0 ; j < l ; ++j )
{
text[j] = dw->strings[start+j] ;
}
if (flag == 1)
{
width = XTextWidth(nfont_struct,text,l) ;
x = x - width/2 ;
}
XDrawImageString(disp,dw->xwin,dw->xgc,x,y,text,l);
start = start + 80 ;
}
return;
}
/**********************************/
/* Make XWindow into FEAP XWindow */
/**********************************/
static char colors[6][10] = { "RED" , "GREEN" , "BLUE",
"YELLOW", "MAGENTA", "CYAN"};
DIGWin *gdx11_make_digwin_from_xwin(display,xwindow,
back_pixel,fore_pixel,
x_border,y_border,
min_x,max_x,min_y,max_y,
abs_min_max)
Display *display;
Window xwindow;
unsigned long back_pixel, fore_pixel;
int x_border, y_border;
int min_x, max_x, min_y, max_y;
int abs_min_max;
{
DIGWin *dw;
Screen *screen;
Colormap cmap;
XColor screen_def, exact_def;
XGCValues setgc;
int color;
int colors_allocated;
if ((dw = (DIGWin *)calloc(1, sizeof(DIGWin)))==NULL)
{
fprintf(stderr,"FEAP X11 Driver unable to get window memory!\n");
exit(0);
}
dw->npoints = (int *)calloc(1, MAX_SEG*sizeof(int));
dw->strlen = (int *)calloc(1, MAX_TEXT*sizeof(int));
dw->strflg = (int *)calloc(1, MAX_TEXT*sizeof(int));
dw->strings = (char *)calloc(1, 80*MAX_TEXT*sizeof(char));
dw->textx = (int *)calloc(1, MAX_TEXT*sizeof(int));
dw->texty = (int *)calloc(1, MAX_TEXT*sizeof(int));
dw->polyline_pixel_value = (int *)calloc(1, MAX_SEG*sizeof(int));
dw->polyline_gray_value = (int *)calloc(1, MAX_SEG*sizeof(int));
dw->points = (XPoint *)calloc(1, MAX_POINTS*sizeof(XPoint));
dw->xdisplay = display;
dw->xwin = xwindow;
XGetWindowAttributes(display,xwindow,&(dw->xwa));
screen = dw->xwa.screen;
cmap = dw->xwa.colormap;
/* Get default colors */
dw->pixel_value_for_color[0] = back_pixel;
dw->pixel_value_for_color[1] = fore_pixel;
colors_allocated = 2;
if (CellsOfScreen(screen)>=3)
{
for (color=2;color<8;++color)
{
if (XAllocNamedColor(display,cmap,colors[color-2],
&screen_def,&exact_def))
{
dw->pixel_value_for_color[colors_allocated++] = screen_def.pixel;
if (DEBUG>=3)
fprintf(stderr,"Color %s is pixel %d\n",
colors[color-2],dw->pixel_value_for_color[color]);
}
else
if (DEBUG>=2)
fprintf(stderr,"FEAP-X11: Unable to allocate color %s\n",
colors[color-2]);
}
}
else
if (DEBUG>=3) fprintf(stderr,"FEAP-X11: Monochrome window - no colors!\n");
dw->gray[0] = XCreateBitmapFromData(display,xwindow,gray1_bits,
gray1_width,gray1_height);
dw->gray[1] = XCreateBitmapFromData(display,xwindow,gray2_bits,
gray2_width,gray2_height);
dw->gray[2] = XCreateBitmapFromData(display,xwindow,gray3_bits,
gray3_width,gray3_height);
dw->gray[3] = XCreateBitmapFromData(display,xwindow,gray4_bits,
gray4_width,gray4_height);
dw->gray[4] = XCreateBitmapFromData(display,xwindow,gray5_bits,
gray5_width,gray5_height);
dw->gray[5] = XCreateBitmapFromData(display,xwindow,gray6_bits,
gray6_width,gray6_height);
dw->gray[6] = XCreateBitmapFromData(display,xwindow,gray7_bits,
gray7_width,gray7_height);
dw->gray[7] = XCreateBitmapFromData(display,xwindow,gray8_bits,
gray8_width,gray8_height);
dw->num_fg_colors = colors_allocated - 1;
dw->current_pixel_value = dw->pixel_value_for_color[1];
/* Get scale factors for the screen (and therefore for the window) */
dw->x_scale = ((double)WidthOfScreen(screen))/
(((double)WidthMMOfScreen(screen))/10.0);
dw->y_scale = ((double)HeightOfScreen(screen))/
(((double)HeightMMOfScreen(screen))/10.0);
/* Use portion of window user wants */
dw->x_border = x_border;
dw->y_border = y_border;
dw->abs_min_max = abs_min_max;
dw->min_x = min_x;
dw->max_x = max_x;
dw->min_y = min_y;
dw->max_y = max_y;
/* Create a GC for this window */
setgc.foreground = dw->pixel_value_for_color[1];
setgc.background = dw->pixel_value_for_color[0];
setgc.function = GXcopy;
setgc.line_width = 0;
setgc.line_style = LineSolid;
setgc.fill_style = FillSolid;
dw->xgc = XCreateGC(display,xwindow,
(GCForeground|GCBackground|GCFunction|GCLineWidth|
GCLineStyle|GCFillStyle),
&setgc);
/* Monochrome gray scale stuff */
if(dw->num_fg_colors == 1){
setgc.fill_style = FillStippled;
dw->xgc_mono_fill = XCreateGC(display,xwindow,
(GCForeground|GCBackground|GCFunction|GCLineWidth|
GCLineStyle|GCFillStyle),
&setgc);
XSetFillStyle(display,dw->xgc_mono_fill,FillOpaqueStippled);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -