move delay code into separate function.
[AROS.git] / rom / hyperlayers / deletelayer.c
blob7945624ac1ad13a046908b0f01079ec23826d46a
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <aros/libcall.h>
10 #include <exec/types.h>
11 #include <proto/exec.h>
12 #include <proto/graphics.h>
13 #include <graphics/layers.h>
14 #include <graphics/regions.h>
15 #define DEBUG 0
16 #include <aros/debug.h>
17 #include "layers_intern.h"
18 #include "basicfuncs.h"
20 /*****************************************************************************
22 NAME */
23 #include <proto/layers.h>
25 AROS_LH2(LONG, DeleteLayer,
27 /* SYNOPSIS */
28 AROS_LHA(LONG , dummy, A0),
29 AROS_LHA(struct Layer *, l , A1),
31 /* LOCATION */
32 struct LayersBase *, LayersBase, 15, Layers)
34 /* FUNCTION
35 Deletes the layer. Other layers that were hidden (partially)
36 will become visible. If parts of a simple layer become
37 visible those parts are added to the damagelist of the
38 layer and the LAYERREFRESH flags is set.
40 INPUTS
41 dummy - nothing special
42 LD - layer to be deleted
44 RESULT
45 TRUE - layer was successfully deleted
46 FALSE - layer could not be delete (out of memory)
48 NOTES
50 EXAMPLE
52 BUGS
54 SEE ALSO
56 INTERNALS
58 HISTORY
59 27-11-96 digulla automatically created from
60 layers_lib.fd and clib/layers_protos.h
62 *****************************************************************************/
64 AROS_LIBFUNC_INIT
66 struct Layer * _l, * lparent;
68 * all children must have been destroyed before.
70 LockLayers(l->LayerInfo);
72 if (l != GetFirstFamilyMember(l))
74 bug("[Layers] DeleteLayer: There are still children around! Cannot destroy layer %p\n",l);
75 UnlockLayers(l->LayerInfo);
76 return FALSE;
79 if (IS_VISIBLE(l))
81 struct Region r;
82 InitRegion(&r);
84 SetRegion(l->VisibleRegion, &r);
85 _l = l->back;
86 lparent = l->parent;
89 * Visit all layers behind this layer until my parent comes
90 * I also visit my parent. If my parent is invisible I must
91 * go further to the parent of that parent etc.
93 while (1)
95 if (IS_VISIBLE(_l) && DO_OVERLAP(&r.bounds, &_l->shape->bounds))
97 ClearRegion(_l->VisibleRegion);
98 _ShowPartsOfLayer(_l, &r, LayersBase);
100 else
101 SetRegion(&r,_l->VisibleRegion);
103 if (IS_VISIBLE(_l) || IS_ROOTLAYER(_l))
104 AndRegionRegion(_l->VisibleRegion, l->shape);
106 if (_l == lparent)
108 if (IS_VISIBLE(_l) || (NULL == lparent->parent))
109 break;
110 else
111 lparent = lparent->parent;
114 * The part that this layer is hiding I cannot make
115 * visible on the layers behind it. Therefore I
116 * have to take it out.
118 if (IS_VISIBLE(_l))
119 ClearRegionRegion(_l->visibleshape, &r);
121 _l = _l->back;
124 ClearRegion(&r);
126 if (!IS_EMPTYREGION(l->shape))
128 D(bug("[Layers] DeleteLayer: lparent: %p, l->parent: %p\n",lparent,l->parent));
129 if (lparent && IS_ROOTLAYER(lparent))
130 _BackFillRegion(lparent, l->shape, FALSE, LayersBase);
132 else
133 D(bug("[Layers] DeleteLayer: NOTHING TO CLEAR!\n"));
138 * Take the layer out of the list
140 if (l->front)
141 l->front->back = l->back;
142 else
143 l->LayerInfo->top_layer = l->back;
145 if (l->back)
146 l->back->front = l->front;
148 UnlockLayers(l->LayerInfo);
150 _FreeLayer(l, LayersBase);
152 return TRUE;
154 AROS_LIBFUNC_EXIT
155 } /* DeleteLayer */