⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x11.c

📁 支持数字元件仿真的SPICE插件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	$Header: //pepper/atesse_spice/spice3/FTE/RCS/x11.c,v 1.3 92/06/26 15:38:04 bill Exp $	Copyright 1988 Jeffrey M. Hsu	X11 drivers.*/#include "prefix.h"#ifdef GI_X11#include <sys/time.h>#include "FTEgraph.h"#ifndef CMS#include "FTEdbgraph.h"#else  /* CMS */#include "FTEdbgra.h"#endif /* CMS */#ifndef CMS#include "FTEdevice.h"#else  /* CMS */#include "FTEdevic.h"#endif /* CMS */#include "FTEinput.h"#include "CPdefs.h"#include "FTEdefs.h"/* gtri - begin - Update include files for X11 R4+ */#define XAW_BC#include <IntrinsicP.h>#include <Xatom.h>#include <StringDefs.h>#include <Xutil.h>#include <cursorfont.h>#include <Box.h>#include <Command.h>#include <Form.h>#include <Shell.h>/* gtri - end - Update include files for X11 R4+ */#ifdef DEBUGextern int _Xdebug;#endif/* forward declarations */extern void handlebuttonev(), handlekeypressed(), killwin(), hardcopy(),	    redraw(), resize();int errorhandler();/* X dependent default parameters */#define DEF_FONT "6x10"#define NUMLINESTYLES 8#define NXPLANES 5      /* note: What is this used for? */#define BOXSIZE 30      /* initial size of bounding box for zoomin */typedef struct {	Window window;	Widget shell, form, view, buttonbox, buttons[2];	XFontStruct *font;	GC gc;	int lastx, lasty;   /* used in X_DrawLine */	int lastlinestyle;  /* used in X_DrawLine */} X11devdep;#define DEVDEP(g) (*((X11devdep *) (g)->devdep))static Display *display;static GC xorgc;static char *xlinestyles[NUMLINESTYLES] = {	/* test patterns XXX */	"\001\001\001\001",	/* solid */	"\001\003\001\003",	/* spaced dots */	"\001\002\001\002",	/* dots */	"\003\003\003\003",	/* shortdash */	"\001\004\006\004",	/* dots longdash */	"\007\007\007\007",	/* longdash */	"\001\004\004\004",	/* dots shortdash */	"\003\003\007\003",	/* short/longdash */};static Widget toplevel;static Bool noclear = False;static GRAPH *lasthardcopy; /* graph user selected */#ifdef notdefstatic Bool KEYwaiting;     /* if user typed something */#endifX11_Init(){	char buf[512];	char *displayname;	XGCValues gcvalues;	/* grrr, Xtk forced contortions */	char *argv[2];	int argc = 2;	if (cp_getvar("display", VT_STRING, buf)) {	  displayname = buf;	} else if (!(displayname = getenv("DISPLAY"))) {	  internalerror("Can't open X display.");	  return (1);	}#ifdef DEBUG	_Xdebug = 1;#endif	argv[0] = "nutmeg";	argv[1] = displayname;/*	argv[2] = "-geometry";	argv[3] = "=1x1+2+2";*/	/* initialize X toolkit */	toplevel = XtInitialize("nutmeg", "Nutmeg", NULL, 0, &argc, argv);	display = XtDisplay(toplevel);#ifdef notdef	/* note: set up input sources and handlers for Xt */	XtAddInput(fileno(stdin), XtInputReadMask,	        keyhandler, NULL);#endif/* note: don't realize the top level widget */	gcvalues.function = GXxor;	gcvalues.line_width = 1;	/* we intend to xor */	gcvalues.foreground = WhitePixel(display, DefaultScreen(display));	gcvalues.background = BlackPixel(display, DefaultScreen(display));	xorgc = XCreateGC(display, DefaultRootWindow(display),	        GCLineWidth | GCFunction | GCForeground | GCBackground,	        &gcvalues);	/* set correct information */	dispdev->numlinestyles = NUMLINESTYLES;	dispdev->numcolors = NUMCOLORS;	dispdev->width = DisplayWidth(display, DefaultScreen(display));	dispdev->height = DisplayHeight(display, DefaultScreen(display));	/* we don't want non-fatal X errors to call exit */	XSetErrorHandler(errorhandler);	return (0);}interrorhandler(display, errorev)Display *display;XErrorEvent *errorev;{	XGetErrorText(display, errorev->error_code, ErrorMessage, 1024);	externalerror(ErrorMessage);	return;}/* Recover from bad NewViewPort call. */#define RECOVERNEWVIEWPORT()    free((char *) graph);\	            graph = (GRAPH *) NULL; 	    /* need to do this or else DestroyGraph will free it again *//* NewViewport is responsible for filling in graph->viewport */X11_NewViewport(graph)GRAPH *graph;{	char geometry[32], defaultgeometry[32];	char fontname[64];	Cursor cursor;	XGCValues gcvalues;	static Arg viewargs[] = {	    { XtNresizable, (XtArgVal) TRUE },	    { XtNwidth, (XtArgVal) 300 },	    { XtNheight, (XtArgVal) 300 },	};/*	static Arg formargs[] = {	    { NULL, (XtArgVal) NULL },	};*/	Arg bboxargs[1];	Arg buttonargs[1];	graph->devdep = calloc(1, sizeof(X11devdep));	/* set up new shell */	DEVDEP(graph).shell = XtCreateApplicationShell("shell",	        topLevelShellWidgetClass, NULL, 0);	/* set up form widget */	DEVDEP(graph).form = XtCreateManagedWidget("some name",	    formWidgetClass, DEVDEP(graph).shell, NULL, 0);	/* set up viewport *//* note: allow user to specify geometry XXX */	DEVDEP(graph).view = XtCreateManagedWidget("viewport", widgetClass,	    DEVDEP(graph).form, viewargs, XtNumber(viewargs));/* note: what about error handling?  What if XtCreateWidget fails? XXX */	/* set up button box */	XtSetArg(bboxargs[0], XtNfromHoriz, DEVDEP(graph).view);	DEVDEP(graph).buttonbox = XtCreateManagedWidget("buttonbox",	    boxWidgetClass, DEVDEP(graph).form, bboxargs, 1);	/* set up buttons */	XtSetArg(buttonargs[0], XtNlabel, "quit");	DEVDEP(graph).buttons[0] = XtCreateManagedWidget("quit",	    commandWidgetClass, DEVDEP(graph).buttonbox,	    buttonargs, 1);	XtAddCallback(DEVDEP(graph).buttons[0], XtNcallback, killwin, graph);	buttonargs[0].value = (XtArgVal) "hardcopy";	DEVDEP(graph).buttons[1] = XtCreateManagedWidget("quit",	    commandWidgetClass, DEVDEP(graph).buttonbox,	    buttonargs, 1);	XtAddCallback(DEVDEP(graph).buttons[1], XtNcallback, hardcopy, graph);	/* set up fonts */	if (!cp_getvar("font", VT_STRING, fontname)) {	  (void) strcpy(fontname, DEF_FONT);	}	if (!(DEVDEP(graph).font = XLoadQueryFont(display, fontname))) {	  sprintf(ErrorMessage, "can't open font %s", fontname);	  internalerror(ErrorMessage);	  RECOVERNEWVIEWPORT();	  return(1);	}	graph->fontwidth = DEVDEP(graph).font->max_bounds.rbearing -	        DEVDEP(graph).font->min_bounds.lbearing;	graph->fontheight = DEVDEP(graph).font->max_bounds.ascent +	        DEVDEP(graph).font->max_bounds.descent;	XtRealizeWidget(DEVDEP(graph).shell);	DEVDEP(graph).window = XtWindow(DEVDEP(graph).view);	gcvalues.line_width = 1;	gcvalues.cap_style = CapNotLast;	DEVDEP(graph).gc = XCreateGC(display, DEVDEP(graph).window,	        GCLineWidth | GCCapStyle, &gcvalues);	/* should absolute.positions really be shell.pos? */	graph->absolute.xpos = DEVDEP(graph).view->core.x;	graph->absolute.ypos = DEVDEP(graph).view->core.y;	graph->absolute.width = DEVDEP(graph).view->core.width;	graph->absolute.height = DEVDEP(graph).view->core.height;	initlinestyles();	initcolors(graph);	/* set up cursor */	cursor = XCreateFontCursor(display, XC_left_ptr);	XDefineCursor(display, DEVDEP(graph).window, cursor);#ifdef notdef	static String table =	    "<Configure>:resize()\n\	    <";	translations = XtParseTranslationTable(table);	XtAugmentTranslations(DEVDEP(graph).view, translations);#endif	/* set up input events	    Why bother with event translations? */	XtAddEventHandler(DEVDEP(graph).view, ButtonPressMask, FALSE,	        handlebuttonev, graph);/*  XtAddEventHandler(DEVDEP(graph).view, ButtonMotionMask, FALSE,	        handlemotionev, graph); */	XtAddEventHandler(DEVDEP(graph).view, KeyPressMask, FALSE,	        handlekeypressed, graph);	XtAddEventHandler(DEVDEP(graph).view, StructureNotifyMask, FALSE,	        resize, graph);	XtAddEventHandler(DEVDEP(graph).view, ExposureMask, FALSE,	        redraw, graph);	return (0);}staticinitlinestyles(){	int i;	if (XDisplayPlanes(display, DefaultScreen(display)) > 1) {	  /* Dotted lines are a distraction when we have colors. */	  for (i = 2; i < NUMLINESTYLES; i++) {	    xlinestyles[i] = xlinestyles[0];	  }	}	return;}staticinitcolors(graph)GRAPH *graph;{	int numdispplanes = DisplayPlanes(display, DefaultScreen(display));	int i;	static char *colornames[] = {   "white",    /* white */	                "black",	                "red",	                "blue",	                "orange",	                "green",	                "pink",	                "brown",	                "khaki",	                "plum",	                "orchid",	                "violet",	                "maroon",	                "turquoise",	                "sienna",	                "coral",	                "cyan",	                "magenta",	                "gold",	                "yellow",	                ""	            } ;	XColor visualcolor, exactcolor;	char buf[BSIZE], colorstring[BSIZE];	int xmaxcolors = NUMCOLORS; /* note: can we get rid of this? */	if (numdispplanes == 1) {	  /* black and white */	  graph->colors[0] = WhitePixel(display, DefaultScreen(display));	  graph->colors[1] = BlackPixel(display, DefaultScreen(display));	  xmaxcolors = 2;	  return;	} else if (numdispplanes < NXPLANES) {	  xmaxcolors = 1;	  while (numdispplanes-- > 1)	    xmaxcolors *= 2;	}	for (i = 0; i < xmaxcolors; i++) {	  (void) sprintf(buf, "color%d", i);	  if (!cp_getvar(buf, VT_STRING, colorstring))	    (void) strcpy(colorstring, colornames[i]);	  if (!XAllocNamedColor(display,	        DefaultColormap(display, DefaultScreen(display)),	        colorstring, &visualcolor, &exactcolor)) {	    (void) sprintf(ErrorMessage,	      "can't get color %s\n", colorstring);	    externalerror(ErrorMessage);	    graph->colors[i] = i ? BlackPixel(display, DefaultScreen(display))	                : WhitePixel(display, DefaultScreen(display));	    continue;	  }	  graph->colors[i] = visualcolor.pixel;	}	return;}/* This routine closes the X connection.	It is not to be called for finishing a graph. */X11_Close(){	XCloseDisplay(display);}X11_DrawLine(x1, y1, x2, y2)int x1, y1, x2, y2;{	XDrawLine(display, DEVDEP(currentgraph).window,	        DEVDEP(currentgraph).gc,	        x1, currentgraph->absolute.height - y1,	        x2, currentgraph->absolute.height - y2);}/*ARGSUSED*/X11_Arc(x0, y0, radius, theta1, theta2)int x0, y0, radius;double theta1, theta2;{	/* never used and not in previous code and XArc doesn't work,	    so why bother? */	internalerror("X11_Arc not implemented");}/* note: x and y are the LOWER left corner of text */X11_Text(text, x, y)char *text;int x, y;{/* We specify text position by lower left corner, so have to adjust for	X11's font nonsense. */	XDrawString(display, DEVDEP(currentgraph).window,	    DEVDEP(currentgraph).gc, x,	    currentgraph->absolute.height	        - (y + DEVDEP(currentgraph).font->max_bounds.descent),	    text, strlen(text));	/* note: unlike before, we do not save any text here */}/*ARGSUSED*/X11_DefineColor(colorid, red, green, blue)int colorid;double red, green, blue;{	internalerror("X11_DefineColor not implemented.");	return(0);}/*ARGSUSED*/X11_DefineLinestyle(linestyleid, mask)int linestyleid;int mask;{	internalerror("X11_DefineLinestyle not implemented.");}X11_SetLinestyle(linestyleid)int linestyleid;{	XGCValues values;	if (currentgraph->linestyle != linestyleid) {	  if ((linestyleid == 0) ||		(DisplayPlanes(display, DefaultScreen(display)) > 1 &&		linestyleid != 1)) {	    /* solid if linestyle 0 or if has color,				allow only one dashed linestyle */	    values.line_style = LineSolid;	  } else {	    values.line_style = LineOnOffDash;	  }	  XChangeGC(display, DEVDEP(currentgraph).gc, GCLineStyle, &values);	  currentgraph->linestyle = linestyleid;	  XSetDashes(display, DEVDEP(currentgraph).gc, 0,		xlinestyles[linestyleid], 4);	}}X11_SetColor(colorid)int colorid;{	currentgraph->currentcolor = colorid;	XSetForeground(display, DEVDEP(currentgraph).gc,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -