1 #include <../../nrnconf.h>
12 #if defined(IVX11_DYNAM)
13 #include <IV-X11/ivx11_declare.h>
14 #include <IV-X11/ivx11_redef.h>
16 #define return_if_no_x \
24 #include <X11/Xutil.h>
26 #define return_if_no_x \
43 #define Plot(x, y) XDrawPoint(display, win, gc, (x), (y))
44 #define Line(x1, y1, x2, y2) XDrawLine(display, win, gc, (x1), (y1), (x2), (y2))
51 static XPoint polyline[200];
52 static int maxnlinept = 200;
65 static unsigned long colors[Ncolors];
67 extern void x11_open_window();
68 extern void x11_draw_vec();
70 static int xnew, ynew;
71 static int xold, yold;
76 static void set_colors(
void);
78 void x11_fast(
int mode) {
84 if (fast && nlinept) {
90 static void getscale(
void) {
92 unsigned int width, height, border_width, depth;
95 XGetGeometry(display, win, &
root, &x, &y, &width, &height, &border_width, &depth);
96 xscale = ((double) width) / TEKX;
97 yscale = ((double) height) / TEKY;
100 void x11_coord(
double x,
double y) {
101 xnew = (int) (
xscale * x);
102 ynew = (int) (
yscale * (TEKY - y));
105 void x11_draw_vec(
void) {
108 XDrawLines(display, win, gc, polyline, nlinept, CoordModeOrigin);
113 void x11_vector(
void) {
117 polyline[0].x = xold;
118 polyline[0].y = yold;
121 if (nlinept >= maxnlinept) {
124 polyline[nlinept].x = xnew;
125 polyline[nlinept].y = ynew;
128 Line(xold, yold, xnew, ynew);
134 void x11_point(
void) {
142 void x11_move(
void) {
145 if (nlinept && (xnew != xold || ynew != yold)) {
151 void x11_clear(
void) {
153 XClearWindow(display, win);
158 void x11_cleararea(
void) {
175 XClearArea(display, win, x, y, w, h, False);
181 void x11_put_text(
const char*
s) {
183 if (fast && nlinept) {
186 XDrawString(display, win, gc, xold, yold,
s, strlen(
s));
191 void x11_setcolor(
int c) {
193 if (!x11_init_done) {
198 XSetForeground(display, gc, BlackPixel(display, screen));
200 XSetForeground(display, gc, WhitePixel(display, screen));
202 XSetForeground(display, gc,
colors[
c % Ncolors]);
209 void x11_open_window(
void) {
210 const char* window_name =
"Xhocplot";
211 char* display_name =
NULL;
212 XSizeHints size_hints;
213 XWindowAttributes attr;
219 if ((display = XOpenDisplay(display_name)) ==
NULL) {
220 (void) fprintf(stderr,
"cannot connect to X server %s\n", XDisplayName(display_name));
223 screen = DefaultScreen(display);
225 win = XCreateSimpleWindow(display,
226 RootWindow(display, screen),
232 BlackPixel(display, screen),
233 WhitePixel(display, screen));
235 XGetWindowAttributes(display, win, &attr);
240 size_hints.flags = USPosition | USSize;
243 size_hints.width =
WIDTH;
244 size_hints.height =
HEIGHT;
245 XSetStandardProperties(display, win, window_name,
NULL, 0,
NULL, 0, &size_hints);
247 gc = XCreateGC(display, win, 0,
NULL);
248 XSetWindowBackground(display, win, BlackPixel(display, screen));
249 XSetForeground(display, gc, WhitePixel(display, screen));
250 XSetBackground(display, gc, BlackPixel(display, screen));
251 XMapWindow(display, win);
258 XSelectInput(display, win, ExposureMask);
259 XNextEvent(display, &report);
260 XSelectInput(display, win, 0L);
265 void x11_close_window(
void) {
267 XFreeGC(display, gc);
268 XCloseDisplay(display);
275 const char* color_names[Ncolors] = {
"black",
287 static void set_colors(
void) {
292 for (
n = 0;
n < Ncolors;
n++) {
293 if (XAllocNamedColor(display, DefaultColormap(display, 0), color_names[
n], &used, &exact)) {
296 fprintf(stderr,
"xhocplot: assuming %s:white\n", color_names[
n]);
297 colors[
n] = WhitePixel(display, 0);
int const size_t const size_t n