summaryrefslogtreecommitdiff
path: root/app/x11perf/do_movewin.c
blob: b7f0b44ade2b3ce91cf67df86bec85e965504ec3 (plain)
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
/*****************************************************************************
Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, 
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in 
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.  

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************************/

#include "x11perf.h"

static Window *children;
static XPoint *positions;
static Window cover;
static int rows;
static int x_offset, y_offset;  /* Private global data for DoMoveWindows */
static int xmax, ymax;
static int delta1;		/* Private global data for DoResizeWindows */

#define STACK (4*(HEIGHT-10)/CHILDSIZE)

int 
InitMoveWindows(XParms xp, Parms p, int64_t reps)
{
    rows = (p->objects + MAXCOLS - 1) / MAXCOLS;
    
    x_offset = 0;
    y_offset = 0;
    delta1   = 1;

    children = malloc(p->objects * sizeof (Window));
    positions = malloc(p->objects * sizeof(XPoint));

    xmax = (CHILDSIZE+CHILDSPACE) * (rows > 1 ? MAXCOLS : p->objects);
    ymax = rows * (CHILDSIZE+CHILDSPACE);

    for (int i = 0; i != p->objects; i++) {
	positions[i].x = (CHILDSIZE+CHILDSPACE) * (i/rows) + CHILDSPACE/2;
	positions[i].y = (CHILDSIZE+CHILDSPACE) * (i%rows) + CHILDSPACE/2;
	children[i] = XCreateSimpleWindow(xp->d, xp->w,
	    positions[i].x, positions[i].y,
	    CHILDSIZE, CHILDSIZE, 0, xp->foreground, xp->foreground);
    }
    if (p->special)
	XMapSubwindows (xp->d, xp->w);
    return reps;
}

void 
DoMoveWindows(XParms xp, Parms p, int64_t reps)
{
    for (int i = 0; i != reps; i++) {
	x_offset += 1;
	y_offset += 3;
	if (y_offset + ymax > HEIGHT)
	    y_offset = 0;
	if (x_offset + xmax > WIDTH)
	    x_offset = 0;
	for (int j = 0; j != p->objects; j++) {
	    XMoveWindow(xp->d, children[j],
	    positions[j].x + x_offset, positions[j].y + y_offset);
	}
	CheckAbort ();
    }
}

void 
EndMoveWindows(XParms xp, Parms p)
{
    free(children);
    free(positions);
}

void 
DoResizeWindows(XParms xp, Parms p, int64_t reps)
{
    for (int i = 0; i != reps; i++) {
	int	delta2;

	delta1 = -delta1;
	delta2 = delta1;
	for (int j = 0; j != p->objects; j++) {
	    delta2 = -delta2;
	    XResizeWindow(xp->d, children[j],
		CHILDSIZE+delta2, CHILDSIZE-delta2);
	}
	CheckAbort ();
    }
}

int
InitCircWindows(XParms xp, Parms p, int64_t reps)
{
    children = malloc (p->objects * sizeof (Window));
    for (int i = 0; i != p->objects; i++) {
	int pos = i % STACK;
	int color = (i & 1 ? xp->foreground : xp->background);
	children[i] = XCreateSimpleWindow (xp->d, xp->w, 
	    pos*CHILDSIZE/4 + (i/STACK)*2*CHILDSIZE, pos*CHILDSIZE/4,
	    CHILDSIZE, CHILDSIZE, 0, color, color);
    }
    if (p->special)
	XMapSubwindows (xp->d, xp->w);
    return reps;
}

void 
DoCircWindows(XParms xp, Parms p, int64_t reps)
{
    for (int i = 0; i != reps; i++)
    {
	for (int j = 0; j != p->objects; j++)
	    XCirculateSubwindows (xp->d, xp->w, RaiseLowest);
	CheckAbort ();
    }
}

void 
EndCircWindows(XParms xp, Parms p)
{
    free(children);
}


int 
InitMoveTree(XParms xp, Parms p, int64_t reps)
{
    rows = (p->objects + MAXCOLS - 1) / MAXCOLS;
    
    x_offset = 0;
    y_offset = 0;
    delta1   = 1;

    children = malloc(p->objects * sizeof (Window));
    positions = malloc(p->objects * sizeof(XPoint));

    xmax = (CHILDSIZE+CHILDSPACE) * (rows > 1 ? MAXCOLS : p->objects);
    ymax = rows * (CHILDSIZE+CHILDSPACE);

    cover = XCreateSimpleWindow(xp->d, xp->w,
				0, 0, xmax, ymax, 0,
				xp->background, xp->background);
				
    for (int i = 0; i != p->objects; i++) {
	positions[i].x = (CHILDSIZE+CHILDSPACE) * (i/rows) + CHILDSPACE/2;
	positions[i].y = (CHILDSIZE+CHILDSPACE) * (i%rows) + CHILDSPACE/2;
	children[i] = XCreateSimpleWindow(xp->d, cover,
	    positions[i].x, positions[i].y,
	    CHILDSIZE, CHILDSIZE, 0, xp->foreground, xp->foreground);
    }
    XMapSubwindows (xp->d, cover);
    XMapWindow (xp->d, cover);
    return reps;
}

void 
DoMoveTree(XParms xp, Parms p, int64_t reps)
{
    for (int i = 0; i != reps; i++) {
	x_offset += 1;
	y_offset += 3;
	if (y_offset + ymax > HEIGHT)
	    y_offset = 0;
	if (x_offset + xmax > WIDTH)
	    x_offset = 0;
	XMoveWindow(xp->d, cover, x_offset, y_offset);
	CheckAbort ();
    }
}

void 
EndMoveTree(XParms xp, Parms p)
{
    XDestroyWindow(xp->d, cover);
    free(children);
    free(positions);
}