1/*****************************************************************************
2Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
3
4                        All Rights Reserved
5
6Permission to use, copy, modify, and distribute this software and its
7documentation for any purpose and without fee is hereby granted,
8provided that the above copyright notice appear in all copies and that
9both that copyright notice and this permission notice appear in
10supporting documentation, and that the name of Digital not be
11used in advertising or publicity pertaining to distribution of the
12software without specific, written prior permission.
13
14DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
15ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
16DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
17ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
19ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
20SOFTWARE.
21
22******************************************************************************/
23
24#include "x11perf.h"
25
26static Window *children;
27static XPoint *positions;
28static Window cover;
29static int rows;
30static int x_offset, y_offset;  /* Private global data for DoMoveWindows */
31static int xmax, ymax;
32static int delta1;		/* Private global data for DoResizeWindows */
33
34#define STACK (4*(HEIGHT-10)/CHILDSIZE)
35
36int
37InitMoveWindows(XParms xp, Parms p, int64_t reps)
38{
39    rows = (p->objects + MAXCOLS - 1) / MAXCOLS;
40
41    x_offset = 0;
42    y_offset = 0;
43    delta1   = 1;
44
45    children = malloc(p->objects * sizeof (Window));
46    positions = malloc(p->objects * sizeof(XPoint));
47
48    xmax = (CHILDSIZE+CHILDSPACE) * (rows > 1 ? MAXCOLS : p->objects);
49    ymax = rows * (CHILDSIZE+CHILDSPACE);
50
51    for (int i = 0; i != p->objects; i++) {
52	positions[i].x = (CHILDSIZE+CHILDSPACE) * (i/rows) + CHILDSPACE/2;
53	positions[i].y = (CHILDSIZE+CHILDSPACE) * (i%rows) + CHILDSPACE/2;
54	children[i] = XCreateSimpleWindow(xp->d, xp->w,
55	    positions[i].x, positions[i].y,
56	    CHILDSIZE, CHILDSIZE, 0, xp->foreground, xp->foreground);
57    }
58    if (p->special)
59	XMapSubwindows (xp->d, xp->w);
60    return reps;
61}
62
63void
64DoMoveWindows(XParms xp, Parms p, int64_t reps)
65{
66    for (int i = 0; i != reps; i++) {
67	x_offset += 1;
68	y_offset += 3;
69	if (y_offset + ymax > HEIGHT)
70	    y_offset = 0;
71	if (x_offset + xmax > WIDTH)
72	    x_offset = 0;
73	for (int j = 0; j != p->objects; j++) {
74	    XMoveWindow(xp->d, children[j],
75	    positions[j].x + x_offset, positions[j].y + y_offset);
76	}
77	CheckAbort ();
78    }
79}
80
81void
82EndMoveWindows(XParms xp, Parms p)
83{
84    free(children);
85    free(positions);
86}
87
88void
89DoResizeWindows(XParms xp, Parms p, int64_t reps)
90{
91    for (int i = 0; i != reps; i++) {
92	int	delta2;
93
94	delta1 = -delta1;
95	delta2 = delta1;
96	for (int j = 0; j != p->objects; j++) {
97	    delta2 = -delta2;
98	    XResizeWindow(xp->d, children[j],
99		CHILDSIZE+delta2, CHILDSIZE-delta2);
100	}
101	CheckAbort ();
102    }
103}
104
105int
106InitCircWindows(XParms xp, Parms p, int64_t reps)
107{
108    children = malloc (p->objects * sizeof (Window));
109    for (int i = 0; i != p->objects; i++) {
110	int pos = i % STACK;
111	int color = (i & 1 ? xp->foreground : xp->background);
112	children[i] = XCreateSimpleWindow (xp->d, xp->w,
113	    pos*CHILDSIZE/4 + (i/STACK)*2*CHILDSIZE, pos*CHILDSIZE/4,
114	    CHILDSIZE, CHILDSIZE, 0, color, color);
115    }
116    if (p->special)
117	XMapSubwindows (xp->d, xp->w);
118    return reps;
119}
120
121void
122DoCircWindows(XParms xp, Parms p, int64_t reps)
123{
124    for (int i = 0; i != reps; i++)
125    {
126	for (int j = 0; j != p->objects; j++)
127	    XCirculateSubwindows (xp->d, xp->w, RaiseLowest);
128	CheckAbort ();
129    }
130}
131
132void
133EndCircWindows(XParms xp, Parms p)
134{
135    free(children);
136}
137
138
139int
140InitMoveTree(XParms xp, Parms p, int64_t reps)
141{
142    rows = (p->objects + MAXCOLS - 1) / MAXCOLS;
143
144    x_offset = 0;
145    y_offset = 0;
146    delta1   = 1;
147
148    children = malloc(p->objects * sizeof (Window));
149    positions = malloc(p->objects * sizeof(XPoint));
150
151    xmax = (CHILDSIZE+CHILDSPACE) * (rows > 1 ? MAXCOLS : p->objects);
152    ymax = rows * (CHILDSIZE+CHILDSPACE);
153
154    cover = XCreateSimpleWindow(xp->d, xp->w,
155				0, 0, xmax, ymax, 0,
156				xp->background, xp->background);
157
158    for (int i = 0; i != p->objects; i++) {
159	positions[i].x = (CHILDSIZE+CHILDSPACE) * (i/rows) + CHILDSPACE/2;
160	positions[i].y = (CHILDSIZE+CHILDSPACE) * (i%rows) + CHILDSPACE/2;
161	children[i] = XCreateSimpleWindow(xp->d, cover,
162	    positions[i].x, positions[i].y,
163	    CHILDSIZE, CHILDSIZE, 0, xp->foreground, xp->foreground);
164    }
165    XMapSubwindows (xp->d, cover);
166    XMapWindow (xp->d, cover);
167    return reps;
168}
169
170void
171DoMoveTree(XParms xp, Parms p, int64_t reps)
172{
173    for (int i = 0; i != reps; i++) {
174	x_offset += 1;
175	y_offset += 3;
176	if (y_offset + ymax > HEIGHT)
177	    y_offset = 0;
178	if (x_offset + xmax > WIDTH)
179	    x_offset = 0;
180	XMoveWindow(xp->d, cover, x_offset, y_offset);
181	CheckAbort ();
182    }
183}
184
185void
186EndMoveTree(XParms xp, Parms p)
187{
188    XDestroyWindow(xp->d, cover);
189    free(children);
190    free(positions);
191}
192