grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / hyperlayers / movelayerz.c
blobc2eaf310d19f350fa8d856349b2d0bab7e99acf4
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <exec/types.h>
10 #include <graphics/clip.h>
11 #include <proto/graphics.h>
12 #include <proto/layers.h>
13 #include "basicfuncs.h"
14 #include "layers_intern.h"
16 int _MoveLayerBehind(struct Layer *l,
17 struct Layer *lfront,
18 LIBBASETYPEPTR LayersBase)
20 struct Layer * lbackold, *_l, *first;
21 struct Region * hide = NewRegion(), show;
22 InitRegion(&show);
24 first = GetFirstFamilyMember(l);
26 lbackold = l->back;
29 * Take the family out of its old place.
31 if (NULL != first->front)
32 first->front->back = lbackold;
33 else
34 l->LayerInfo->top_layer = lbackold;
36 lbackold->front = first->front;
38 _l = lbackold;
40 * Collect the additional parts that have to be hidden
41 * on the layers that are to be moved. I need only
42 * collect those parts of layers that have the same
43 * parent as the layer l. Stop when I found lfront.
45 while (1)
48 * Must not add my own shape to the hide region...
50 if (_l == l)
51 break;
54 * Must add EVERY shape since it will be subtracted from
55 * the visible region
57 if (l->parent == _l->parent && IS_VISIBLE(_l))
58 OrRegionRegion(_l->visibleshape, hide);
60 if (_l == lfront)
61 break;
63 _l = _l->back;
66 SetRegion(first->VisibleRegion, &show);
69 * First back up the family ... this is like moving them behind the
70 * other layers.
73 _l = first;
74 while (1)
76 if (IS_VISIBLE(_l) && DO_OVERLAP(&_l->visibleshape->bounds, &hide->bounds))
77 _BackupPartsOfLayer(_l, hide, 0, FALSE, LayersBase);
78 else
79 ClearRegionRegion(hide, _l->VisibleRegion);
81 if (_l == l)
82 break;
84 _l = _l->back;
86 DisposeRegion(hide);
89 * Show the layers that appear now.
90 * Start with the layer that is behind the layer l.
92 _l = lbackold;
94 while (1)
96 if (IS_VISIBLE(_l) && DO_OVERLAP(&_l->visibleshape->bounds, &show.bounds))
98 ClearRegion(_l->VisibleRegion);
99 _ShowPartsOfLayer(_l, &show, LayersBase);
101 else
102 SetRegion(&show, _l->VisibleRegion);
104 if (_l == lfront)
105 break;
107 if (IS_VISIBLE(_l))
108 ClearRegionRegion(_l->visibleshape, &show);
110 _l = _l->back;
113 ClearRegion(&show);
116 * Link the family into its new place.
118 if (lfront->back)
119 lfront->back->front = l;
120 l->back = lfront->back;
122 first->front = lfront;
123 lfront->back = first;
125 return TRUE;
128 int _MoveLayerToFront(struct Layer * l,
129 struct Layer * lbehind,
130 LIBBASETYPEPTR LayersBase)
132 struct Layer * lfront, * first, * _l;
133 struct Region r, * backupr = NULL;
134 int backupr_allocated = FALSE;
136 InitRegion(&r);
138 first = GetFirstFamilyMember(l);
140 lfront = lbehind->front;
143 * Unlink the family of layers from its old place.
145 first->front->back = l->back;
146 l->back->front = first->front;
149 * I need exactly that layers visible region later on.
152 SetRegion(lbehind->VisibleRegion,&r);
155 * if the layer l is visible then I will have to backup
156 * its visible region in all layers behind it. Otherwise
157 * I will have to collect the visible shape of its whole
158 * family.
160 if (IS_VISIBLE(l))
161 backupr = l->visibleshape;
162 else
164 _l = l;
165 while (1)
167 if (IS_VISIBLE(_l))
169 if (NULL == backupr)
171 backupr = NewRegion();
172 backupr_allocated = TRUE;
174 if (backupr)
175 OrRegionRegion(_l->visibleshape, backupr);
177 if (_l == first)
178 break;
180 _l = _l->front;
184 _l = lbehind;
187 if (backupr)
190 * Now I have to move the layer family in front of layer lbehind.
191 * Nothing changes for the layers in front of layer lbehind, but on
192 * the layers behind (including first->front) I must back up some of
193 * their parts that the new family might be hiding no.
194 * Once I step on the layer that was behind the layer l
195 * I can stop because those layers are already hidden well
196 * enough.
200 if (IS_VISIBLE(_l) && DO_OVERLAP(&backupr->bounds, &_l->visibleshape->bounds))
201 _BackupPartsOfLayer(_l, backupr, 0, FALSE, LayersBase);
202 else
203 ClearRegionRegion(backupr, _l->VisibleRegion);
205 _l = _l->back;
207 while (_l != l->back /* this is l->back now since the family has
208 been unlinked already!*/ );
210 if (TRUE == backupr_allocated)
211 DisposeRegion(backupr);
214 * Now I must make the layer family of l visible
215 * (lfirst to and including l)
217 _l = first;
219 while (1)
221 if (IS_VISIBLE(_l) && DO_OVERLAP(&_l->visibleshape->bounds, &r.bounds))
223 ClearRegion(_l->VisibleRegion);
224 _ShowPartsOfLayer(_l, &r, LayersBase);
226 else
227 SetRegion(&r, _l->VisibleRegion);
229 if (_l == l)
230 break;
232 if (IS_VISIBLE(_l))
233 ClearRegionRegion(_l->visibleshape, &r);
235 _l = _l->back;
238 ClearRegion(&r);
241 * Link the family into its new place.
242 * First the frontmost kid and then l.
244 if (NULL != lfront)
245 lfront->back = first;
246 else
247 l->LayerInfo->top_layer = first;
249 first->front = lfront;
251 l->back = lbehind;
252 lbehind->front = l;
254 return TRUE;