1 #include <../../nrnconf.h>
4 #if defined(__TURBOC__) || defined(__linux__)
16 #if defined(IVX11_DYNAM)
17 #include <IV-X11/ivx11_declare.h>
18 #include <IV-X11/ivx11_redef.h>
20 #define return_if_no_x \
28 #include <X11/Xutil.h>
30 #define return_if_no_x \
47 #define Plot(x, y) XDrawPoint(display, win, gc, (x), (y))
48 #define Line(x1, y1, x2, y2) XDrawLine(display, win, gc, (x1), (y1), (x2), (y2))
55 static XPoint polyline[200];
56 static int maxnlinept = 200;
69 static unsigned long colors[Ncolors];
71 extern void x11_open_window();
72 extern void x11_draw_vec();
74 static int xnew, ynew;
75 static int xold, yold;
80 static void set_colors(
void);
82 void x11_fast(
int mode) {
88 if (fast && nlinept) {
94 static void getscale(
void) {
96 unsigned int width, height, border_width, depth;
99 XGetGeometry(
display, win, &
root, &x, &y, &width, &height, &border_width, &depth);
100 xscale = ((double) width) / TEKX;
101 yscale = ((double) height) / TEKY;
104 void x11_coord(
double x,
double y) {
105 xnew = (int) (
xscale * x);
106 ynew = (int) (
yscale * (TEKY - y));
109 void x11_draw_vec(
void) {
112 XDrawLines(
display, win, gc, polyline, nlinept, CoordModeOrigin);
117 void x11_vector(
void) {
121 polyline[0].x = xold;
122 polyline[0].y = yold;
125 if (nlinept >= maxnlinept) {
128 polyline[nlinept].x = xnew;
129 polyline[nlinept].y = ynew;
132 Line(xold, yold, xnew, ynew);
138 void x11_point(
void) {
146 void x11_move(
void) {
149 if (nlinept && (xnew != xold || ynew != yold)) {
155 void x11_clear(
void) {
162 void x11_cleararea(
void) {
179 XClearArea(
display, win, x, y, w, h, False);
185 void x11_put_text(
const char* s) {
187 if (fast && nlinept) {
190 XDrawString(
display, win, gc, xold, yold, s, strlen(s));
195 void x11_setcolor(
int c) {
197 if (!x11_init_done) {
213 void x11_open_window(
void) {
214 char* window_name =
"Xhocplot";
215 char* display_name =
NULL;
216 XSizeHints size_hints;
217 XWindowAttributes attr;
223 if ((
display = XOpenDisplay(display_name)) ==
NULL) {
224 (
void)
fprintf(stderr,
"cannot connect to X server %s\n", XDisplayName(display_name));
227 screen = DefaultScreen(
display);
229 win = XCreateSimpleWindow(
display,
239 XGetWindowAttributes(
display, win, &attr);
244 size_hints.flags = USPosition | USSize;
247 size_hints.width =
WIDTH;
248 size_hints.height =
HEIGHT;
249 XSetStandardProperties(
display, win, window_name,
NULL, 0,
NULL, 0, &size_hints);
262 XSelectInput(
display, win, ExposureMask);
264 XSelectInput(
display, win, 0L);
269 void x11_close_window(
void) {
279 char* color_names[Ncolors] = {
"black",
291 static void set_colors(
void) {
296 for (
n = 0;
n < Ncolors;
n++) {
297 if (XAllocNamedColor(
display, DefaultColormap(
display, 0), color_names[
n], &used, &exact)) {
300 fprintf(stderr,
"xhocplot: assuming %s:white\n", color_names[
n]);
int const size_t const size_t n