[3613] in Athena Bugs
Problem with XDrawLines
daemon@ATHENA.MIT.EDU (rburkhar@ATHENA.MIT.EDU)
Thu Nov 9 14:47:51 1989
From: rburkhar@ATHENA.MIT.EDU
To: bugs@ATHENA.MIT.EDU
Date: Thu, 09 Nov 89 14:45:49 EST
I'm working on a mapping application and XDrawLines seems to hang up
at a particular location in the array when drawing it. I'm attaching
a program which shows the problem. It draws the map three times and
holds the screen in between by waiting for a key press. The third
version works, but uses XDrawLine to draw the array segment by segment.
Is there a way to get around this problem so I can use XDrawLines? I would
like to do the lines with patterns.
/* drawlinesbug.c document problem with XDrawLines */
/* compilation cc -o test drawlinesbug.c -lX11 -lm */
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#define LDT_APPNAME "LDT Forest Map"
typedef struct
{
double x, y;
}
Mpoint;
Mpoint pk_bound_pts[] =
{
/* quadrant 1,1 */
0.399997, 0.497172, 0.398227, 0.488698, 0.398227, 0.466099,
0.390262, 0.463274, 0.384952, 0.446325, 0.361944, 0.442088,
0.361944, 0.409602, 0.356634, 0.411014, 0.353094, 0.454799,
0.343359, 0.473161, 0.323005, 0.481636, 0.297342, 0.474573,
0.268138, 0.467511, 0.271678, 0.381353, 0.291147, 0.381353,
0.307076, 0.403952, 0.307961, 0.420901, 0.336280, 0.411014,
0.338050, 0.387003, 0.356634, 0.387003, 0.359289, 0.370054,
0.370793, 0.371466, 0.375218, 0.402540, 0.403536, 0.402540,
0.401767, 0.381353, 0.396457, 0.355929, 0.381413, 0.338980,
0.399112, 0.322031, 0.395572, 0.314969, 0.408846, 0.300845,
0.400882, 0.271184, 0.393802, 0.269771, 0.392032, 0.259884,
0.408846, 0.248585, 0.388492, 0.234460, 0.432740, 0.199150,
0.376988, 0.170901, 0.296457, 0.107342, 0.304421, 0.094630,
0.316811, 0.096042, 0.322121, 0.093217, 0.340705, 0.076268,
0.376988, 0.072031, 0.389377, 0.076268, 0.399997, 0.079093,
0.408846, 0.084743, 0.419466, 0.086155, 0.430085, 0.086155,
0.443359, 0.090393, 0.476103, 0.097455, 0.484952, 0.100280,
0.490262, 0.097455,
/* quadrant 2,1 */
0.499997, 0.098867, 0.516811, 0.091805, 0.539820, 0.079093,
0.538935, 0.129941, 0.574333, 0.135590, 0.572563, 0.172314,
0.580528, 0.173726, 0.580528, 0.173726, 0.580528, 0.173726,
0.575218, 0.199150, 0.589377, 0.207624, 0.588492, 0.207624,
0.586722, 0.218924, 0.672563, 0.258472, 0.609731, 0.372878,
0.611501, 0.394065, 0.661944, 0.365816, 0.663713, 0.374291,
0.669023, 0.385590, 0.675218, 0.394065, 0.673448, 0.406777,
0.685837, 0.409602, 0.687607, 0.446325, 0.663713, 0.447737,
0.649554, 0.483048, 0.661059, 0.490110, 0.717696, 0.477398,
0.726545, 0.408189, 0.752209, 0.418076, 0.761944, 0.405364,
0.775218, 0.409602, 0.776988, 0.394065, 0.781413, 0.384178,
0.790262, 0.381353, 0.800882, 0.382765, 0.810616, 0.382765,
0.827430, 0.381353, 0.827430, 0.409602, 0.830085, 0.433613,
0.834510, 0.461862, 0.807076, 0.473161, 0.771678, 0.456212,
0.773448, 0.447737, 0.755749, 0.440675, 0.748669, 0.456212,
0.761059, 0.457624, 0.755749, 0.470336, 0.779643, 0.488698,
/* quadrant 2,2 */
0.803536, 0.511297, 0.823890, 0.532483, 0.792917, 0.570619,
0.725660, 0.553669, 0.684952, 0.652539, 0.664598, 0.603104,
0.638935, 0.596042, 0.651324, 0.533895, 0.605306, 0.521184,
0.626545, 0.556494, 0.596457, 0.601692, 0.585837, 0.629941,
0.576988, 0.659602, 0.559289, 0.666664, 0.559289, 0.696325,
0.586722, 0.682201, 0.594687, 0.672314, 0.601767, 0.655364,
0.607961, 0.673726, 0.596457, 0.680788, 0.569908, 0.769771,
0.525660, 0.741523, 0.504421, 0.689263, 0.580528, 0.622878,
0.588492, 0.587568, 0.583183, 0.566381, 0.568138, 0.553669,
0.584067, 0.529658, 0.605306, 0.522596, 0.566368, 0.499997,
0.530085, 0.580506, 0.538050, 0.600280, 0.528315, 0.600280,
0.522121, 0.601692, 0.502652, 0.628528,
/* quadrant 1,2 */
0.495572, 0.629941, 0.489377, 0.632766, 0.463713, 0.634178,
0.454864, 0.614404, 0.395572, 0.639828, 0.376103, 0.612992,
0.374333, 0.588980, 0.396457, 0.593217, 0.430970, 0.580506,
0.422121, 0.562144, 0.408846, 0.557907, 0.411501, 0.522596,
0.399997, 0.497172 /* first point repeated */
/* 148 points */
};
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 900
#define X_OFFSET 100
#define Y_OFFSET 100
#define CHUNK_SIZE 30 /* num of points per XDrawLines call */
main (argc, argv)
int argc;
char **argv;
{
Display *ldt_display;
Window ldt_window;
GC ldt_gc;
XEvent ldt_event;
KeySym ldt_key;
XSizeHints ldt_hint;
XPoint buffer[400], left, right;
int ldt_screen;
unsigned long ldt_black, ldt_white;
int i, j, done;
char text[10];
/* setup */
ldt_display = XOpenDisplay("");
ldt_screen = DefaultScreen(ldt_display);
ldt_white = WhitePixel(ldt_display, ldt_screen);
ldt_black = BlackPixel(ldt_display, ldt_screen);
ldt_hint.x = X_OFFSET; ldt_hint.y = Y_OFFSET;
ldt_hint.width = SCREEN_WIDTH; ldt_hint.height = SCREEN_HEIGHT;
ldt_hint.flags = PPosition | PSize;
ldt_window = XCreateSimpleWindow(ldt_display,
DefaultRootWindow(ldt_display),
ldt_hint.x, ldt_hint.y,
ldt_hint.width, ldt_hint.height,
5, ldt_black, ldt_white);
XSetStandardProperties(ldt_display, ldt_window, LDT_APPNAME, LDT_APPNAME,
None, argv, argc, &ldt_hint);
ldt_gc = XCreateGC(ldt_display, ldt_window, 0, 0);
XSetBackground(ldt_display, ldt_gc, ldt_white);
XSetForeground(ldt_display, ldt_gc, ldt_black);
XSelectInput(ldt_display, ldt_window, KeyPressMask | ExposureMask);
XMapWindow(ldt_display, ldt_window);
/* wait for expose */
do XNextEvent(ldt_display, &ldt_event); while (ldt_event.type != Expose);
/* draw some lines */
XSetLineAttributes(ldt_display, ldt_gc, 1, LineSolid, CapButt, JoinMiter);
/* this doesn't work */
for (i = 0; i < sizeof(pk_bound_pts)/sizeof(Mpoint); i++)
{
buffer[i].x = SCREEN_WIDTH*(1.0 - pk_bound_pts[i].y);
buffer[i].y = SCREEN_HEIGHT*(1.0 - pk_bound_pts[i].x);
}
XDrawLines(ldt_display, ldt_window, ldt_gc, buffer, i,
CoordModeOrigin);
/* wait for KeyPress */
do XNextEvent(ldt_display, &ldt_event);
while (ldt_event.type != KeyPress);
XClearWindow(ldt_display, ldt_window);
/* this doesn't work */
for (j = 0; j < sizeof(pk_bound_pts)/sizeof(Mpoint);
j += CHUNK_SIZE - 1 /* so next line takes up where last left off */)
{
for (i = 0;
i < CHUNK_SIZE && j + i < sizeof(pk_bound_pts)/sizeof(Mpoint);
i++)
{
buffer[i].x = SCREEN_WIDTH*(1.0 - pk_bound_pts[j + i].y);
buffer[i].y = SCREEN_HEIGHT*(1.0 - pk_bound_pts[j + i].x);
}
XDrawLines(ldt_display, ldt_window, ldt_gc, buffer, i,
CoordModeOrigin);
}
/* wait for KeyPress */
do XNextEvent(ldt_display, &ldt_event);
while (ldt_event.type != KeyPress);
XClearWindow(ldt_display, ldt_window);
/* this works - I'd do it this way, but patterns don't turn out
well without XDrawLines */
left.x = SCREEN_WIDTH*(1.0 - pk_bound_pts[0].y);
left.y = SCREEN_HEIGHT*(1.0 - pk_bound_pts[0].x);
for (i = 1; i < sizeof(pk_bound_pts)/sizeof(Mpoint); i++)
{
right = left;
left.x = SCREEN_WIDTH*(1.0 - pk_bound_pts[i].y);
left.y = SCREEN_HEIGHT*(1.0 - pk_bound_pts[i].x);
XDrawLine(ldt_display, ldt_window, ldt_gc,
right.x, right.y, left.x, left.y);
}
/* wait for KeyPress */
do XNextEvent(ldt_display, &ldt_event);
while (ldt_event.type != KeyPress);
/* termination */
XFreeGC(ldt_display, ldt_gc);
XDestroyWindow(ldt_display, ldt_window);
XCloseDisplay(ldt_display);
exit(0);
}