1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
/* ----------------------------------------------------------------------------
* Animated display of collapse and expansion of nodes in a tree.
* ----------------------------------------------------------------------------
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_USLEEP
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#else
int usleep(unsigned long microSeconds);
#endif /* HAVE_USLEEP */
#include <X11/Xlib.h>
#include "dissolve.h"
#define NUM_DISSOLVE_STEPS 8
#define NUM_LINE_STEPS 4
#define first_width 16
#define first_height 16
static unsigned char first_bits[] = {
0x88, 0x04, 0x00, 0x80, 0x20, 0x10, 0x00, 0x81, 0x12, 0x00, 0x00, 0x00,
0x00, 0x02, 0x82, 0x40, 0x00, 0x00, 0x12, 0x14, 0x00, 0x00, 0x0a, 0x28,
0x40, 0x01, 0x05, 0x00, 0xa0, 0x92, 0x08, 0x00 };
#define second_width 16
#define second_height 16
static unsigned char second_bits[] = {
0x51, 0x20, 0x04, 0x02, 0x00, 0x88, 0x02, 0x00, 0x08, 0x09, 0x40, 0x00,
0x04, 0x04, 0x00, 0xa0, 0x80, 0x08, 0x08, 0x00, 0x00, 0xa8, 0x00, 0x00,
0x28, 0x28, 0x00, 0x80, 0x01, 0x00, 0x10, 0x82 };
#define third_width 16
#define third_height 16
static unsigned char third_bits[] = {
0x00, 0x01, 0x12, 0x44, 0x00, 0x01, 0x00, 0x08, 0x00, 0x42, 0x2a, 0x08,
0x80, 0x00, 0x04, 0x10, 0x01, 0x04, 0x00, 0x80, 0xa9, 0x04, 0x00, 0x00,
0x00, 0x10, 0x0a, 0x05, 0x40, 0x00, 0x00, 0x50 };
#define fourth_width 16
#define fourth_height 16
static unsigned char fourth_bits[] = {
0x02, 0x88, 0x80, 0x00, 0x04, 0x40, 0x11, 0x02, 0x40, 0x90, 0x05, 0x00,
0x00, 0x08, 0x11, 0x01, 0x40, 0x00, 0x00, 0x41, 0x14, 0x00, 0x00, 0x12,
0x10, 0x00, 0x40, 0x40, 0x08, 0x00, 0xa0, 0x04 };
#define fifth_width 16
#define fifth_height 16
static unsigned char fifth_bits[] = {
0x24, 0x00, 0x00, 0x08, 0x09, 0x20, 0x20, 0x04, 0x00, 0x00, 0x00, 0x85,
0x10, 0x20, 0x40, 0x02, 0x14, 0x40, 0x00, 0x08, 0x02, 0x01, 0x10, 0x40,
0x04, 0x04, 0x20, 0x20, 0x00, 0x00, 0x42, 0x29 };
#define sixth_width 16
#define sixth_height 16
static unsigned char sixth_bits[] = {
0x00, 0x12, 0x28, 0x00, 0x02, 0x00, 0x88, 0x00, 0x01, 0x20, 0x90, 0x02,
0x01, 0x50, 0x20, 0x04, 0x08, 0xa0, 0x41, 0x00, 0x00, 0x00, 0x24, 0x05,
0x00, 0x80, 0x00, 0x10, 0x10, 0x40, 0x05, 0x00 };
#define seventh_width 16
#define seventh_height 16
static unsigned char seventh_bits[] = {
0x00, 0x40, 0x01, 0x10, 0x90, 0x02, 0x00, 0x50, 0xa4, 0x04, 0x00, 0x20,
0x20, 0x80, 0x08, 0x08, 0x00, 0x01, 0x04, 0x00, 0x40, 0x52, 0x00, 0x00,
0x81, 0x42, 0x10, 0x00, 0x04, 0x25, 0x00, 0x00 };
#define eighth_width 16
#define eighth_height 16
static unsigned char eighth_bits[] = {
0x00, 0x00, 0x40, 0x21, 0x40, 0x04, 0x44, 0x20, 0x00, 0x00, 0x00, 0x50,
0x4a, 0x01, 0x00, 0x00, 0x22, 0x12, 0xa0, 0x22, 0x00, 0x00, 0xc1, 0x80,
0x02, 0x00, 0x80, 0x0a, 0x02, 0x08, 0x00, 0x00 };
static Pixmap DissolvePixmaps[NUM_DISSOLVE_STEPS];
static GC DissolveInGC;
static GC DissolveOutGC;
static GC DissolveInLineGC[NUM_LINE_STEPS];
static GC DissolveOutLineGC[NUM_LINE_STEPS];
static char first_dash[] = {1, 3};
static char second_dash[] = {1, 1};
void
InitializeDissolveEffect(Display *dpy,
Drawable drawable,
int fg_pixel,
int bg_pixel)
{
unsigned long gcvaluemask;
XGCValues gcvalues;
int i;
/* make DissolveOutGC */
gcvalues.background = bg_pixel;
gcvalues.foreground = bg_pixel;
gcvalues.function = GXcopy;
gcvalues.fill_style = FillStippled;
gcvalues.line_width = 0;
gcvaluemask = GCFunction | GCForeground | GCBackground | GCFillStyle |
GCLineWidth;
DissolveOutGC = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
XSetTSOrigin(dpy, DissolveOutGC, 0, 0);
/* make DissolveInGC */
gcvalues.foreground = fg_pixel;
DissolveInGC = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
XSetTSOrigin(dpy, DissolveInGC, 0, 0);
/* make DissolveOutLineGC */
i = 0;
gcvalues.foreground = bg_pixel;
gcvalues.fill_style = FillSolid;
gcvalues.line_style = LineOnOffDash;
gcvalues.line_width = 0;
gcvaluemask = GCFunction | GCForeground | GCBackground |
GCFillStyle | GCLineStyle | GCLineWidth ;
DissolveOutLineGC[i] = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
XSetDashes(dpy, DissolveOutLineGC[i], 0, first_dash, 2);
i++;
DissolveOutLineGC[i] = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
XSetDashes(dpy, DissolveOutLineGC[i], 0, second_dash, 2);
i++;
DissolveOutLineGC[i] = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
XSetDashes(dpy, DissolveOutLineGC[i], 3, first_dash, 2);
i++;
gcvalues.line_style = LineSolid;
DissolveOutLineGC[i] = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
/* make DissolveInLineGC */
i = 0;
gcvalues.foreground = fg_pixel;
gcvalues.fill_style = FillSolid;
gcvalues.line_style = LineOnOffDash;
gcvalues.line_width = 0;
gcvaluemask = GCFunction | GCForeground | GCBackground |
GCFillStyle | GCLineStyle | GCLineWidth;
DissolveInLineGC[i] = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
XSetDashes(dpy, DissolveInLineGC[i], 0, first_dash, 2);
i++;
DissolveInLineGC[i] = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
XSetDashes(dpy, DissolveInLineGC[i], 0, second_dash, 2);
i++;
DissolveInLineGC[i] = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
XSetDashes(dpy, DissolveInLineGC[i], 3, first_dash, 2);
i++;
gcvalues.line_style = LineSolid;
DissolveInLineGC[i] = XCreateGC(dpy, drawable, gcvaluemask, &gcvalues);
i = 0;
DissolvePixmaps[i] =
XCreateBitmapFromData(dpy, drawable,
(char *) first_bits, first_width, first_height);
i++;
DissolvePixmaps[i] =
XCreateBitmapFromData(dpy, drawable,
(char *) second_bits, second_width, second_height);
i++;
DissolvePixmaps[i] =
XCreateBitmapFromData(dpy, drawable,
(char *) third_bits, third_width, third_height);
i++;
DissolvePixmaps[i] =
XCreateBitmapFromData(dpy, drawable,
(char *) fourth_bits, fourth_width, fourth_height);
i++;
DissolvePixmaps[i] =
XCreateBitmapFromData(dpy, drawable,
(char *) fifth_bits, fifth_width, fifth_height);
i++;
DissolvePixmaps[i] =
XCreateBitmapFromData(dpy, drawable,
(char *) sixth_bits, sixth_width, sixth_height);
i++;
DissolvePixmaps[i] =
XCreateBitmapFromData(dpy, drawable,
(char *) seventh_bits, seventh_width, seventh_height);
i++;
DissolvePixmaps[i] =
XCreateBitmapFromData(dpy, drawable,
(char *) eighth_bits, eighth_width, eighth_height);
}
#if 0 /* Currently Unused */
void
DissolveRectangle(Display *dpy, Window drawable,
int x, int y, int width, int height, int mode)
{
int i;
GC gc;
gc = mode ? DissolveOutGC : DissolveInGC;
for (i = 0 ; i < NUM_DISSOLVE_STEPS ; i++) {
XSetStipple(dpy, gc, DissolvePixmaps[i]);
if (mode)
XFillRectangle(dpy, drawable, gc, x, y, width, height);
else
XDrawRectangle(dpy, drawable, gc, x, y, width, height);
XFlush(dpy);
usleep(50000);
}
}
void
DissolveRectangles(Display *dpy,
Window drawable,
XRectangle rectangles[],
int nrectangles,
int mode)
{
int i;
GC gc;
gc = mode ? DissolveOutGC : DissolveInGC;
for (i = 0 ; i < NUM_DISSOLVE_STEPS ; i++) {
XSetStipple(dpy, gc, DissolvePixmaps[i]);
if (mode)
XFillRectangles(dpy, drawable, gc, rectangles, nrectangles);
else
XDrawRectangles(dpy, drawable, gc, rectangles, nrectangles);
XFlush(dpy);
usleep(50000);
}
}
void
DissolveSegments(Display *dpy, Window drawable,
XSegment segments[], int nsegments, int mode)
{
int i;
GC *gc;
gc = mode ? DissolveOutLineGC : DissolveInLineGC;
for (i = 0 ; i < NUM_LINE_STEPS ; i++) {
XDrawSegments(dpy, drawable, gc[i], segments, nsegments);
XFlush(dpy);
usleep(50000);
}
}
#endif /* 0 - Unused */
void
DissolveTree(Display *dpy,
Window drawable,
XRectangle rectangles[],
int nrectangles,
XSegment segments[],
int nsegments,
int mode)
{
int i;
int j = 0;
int idle;
GC gc;
GC *lineGC;
gc = mode ? DissolveOutGC : DissolveInGC;
lineGC = mode ? DissolveOutLineGC : DissolveInLineGC;
/* speed up if there are lots of nodes */
idle = nrectangles > 50 ? 0 : 25000;
for (i = 0 ; i < NUM_DISSOLVE_STEPS ; i++) {
XSetStipple(dpy, gc, DissolvePixmaps[i]);
if (mode)
XFillRectangles(dpy, drawable, gc, rectangles, nrectangles);
else
XDrawRectangles(dpy, drawable, gc, rectangles, nrectangles);
if (i % 2)
XDrawSegments(dpy, drawable, lineGC[j++], segments, nsegments);
XFlush(dpy);
usleep(idle);
}
}
#if 0 /* Currently Unused */
void
DissolvePolygon(Display *dpy,
Window drawable,
XPoint *pts,
int num_pts,
int mode)
{
int i;
GC gc;
gc = mode ? DissolveOutGC : DissolveInGC;
for (i = 0 ; i < NUM_DISSOLVE_STEPS ; i++) {
XSetStipple(dpy, gc, DissolvePixmaps[i]);
XFillPolygon(dpy, drawable, gc, pts, num_pts,
Nonconvex, CoordModeOrigin);
XFlush(dpy);
usleep(50000);
}
}
#endif /* Currently Unused */
|