r4493@vps: verhaegs | 2007-04-19 14:44:00 -0400
[AROS.git] / rom / hyperlayers / sortlayercr.c
bloba549702e5bdfee55b73f5d92562a22c53265aa81
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include <graphics/clip.h>
9 #include <aros/libcall.h>
10 #include <aros/asmcall.h>
12 #define DEBUG 0
13 #include <aros/debug.h>
14 #undef kprintf
16 AROS_UFP2(BOOL, _SLCR_CompFunc_Down,
17 AROS_UFPA(struct ClipRect *, cr1, A0),
18 AROS_UFPA(struct ClipRect *, cr2, A1));
19 AROS_UFP2(BOOL, _SLCR_CompFunc_Up,
20 AROS_UFPA(struct ClipRect *, cr1, A0),
21 AROS_UFPA(struct ClipRect *, cr2, A1));
22 AROS_UFP2(BOOL, _SLCR_CompFunc_Right,
23 AROS_UFPA(struct ClipRect *, cr1, A0),
24 AROS_UFPA(struct ClipRect *, cr2, A1));
25 AROS_UFP2(BOOL, _SLCR_CompFunc_Left,
26 AROS_UFPA(struct ClipRect *, cr1, A0),
27 AROS_UFPA(struct ClipRect *, cr2, A1));
28 AROS_UFP2(BOOL, _SLCR_CompFunc_RightDown,
29 AROS_UFPA(struct ClipRect *, cr1, A0),
30 AROS_UFPA(struct ClipRect *, cr2, A1));
31 AROS_UFP2(BOOL, _SLCR_CompFunc_RightUp,
32 AROS_UFPA(struct ClipRect *, cr1, A0),
33 AROS_UFPA(struct ClipRect *, cr2, A1));
34 AROS_UFP2(BOOL, _SLCR_CompFunc_LeftDown,
35 AROS_UFPA(struct ClipRect *, cr1, A0),
36 AROS_UFPA(struct ClipRect *, cr2, A1));
37 AROS_UFP2(BOOL, _SLCR_CompFunc_LeftUp,
38 AROS_UFPA(struct ClipRect *, cr1, A0),
39 AROS_UFPA(struct ClipRect *, cr2, A1));
41 void _SLCR_SortClipRects(struct Layer *layer,
42 AROS_UFP2(BOOL, (*CompFunc),
43 AROS_UFPA(struct ClipRect *, cr1, A0),
44 AROS_UFPA(struct ClipRect *, cr2, A1))
47 /*****************************************************************************
49 NAME */
50 #include <proto/layers.h>
51 #include "layers_intern.h"
53 AROS_LH3(void, SortLayerCR,
55 /* SYNOPSIS */
56 AROS_LHA(struct Layer *, layer, A0),
57 AROS_LHA(LONG , dx, D0),
58 AROS_LHA(LONG , dy, D1),
60 /* LOCATION */
61 struct LayersBase *, LayersBase, 35, Layers)
63 /* FUNCTION
64 Sorts the list of ClipRects associated with the given layer.
65 The direction of the sort is indicated by dx and dy.
67 INPUTS
68 layer -- the layer with the ClipRect list to sort
69 dx -- the left/right ordering
70 dy -- the up/down ordering
72 RESULT
73 The layer->ClipRect pointer now points to a sorted list of ClipRects.
75 NOTES
77 EXAMPLE
79 BUGS
81 SEE ALSO
83 INTERNALS
84 Implemented as an InsertSort on a singly linked list.
86 HISTORY
87 27-11-96 digulla automatically created from
88 layers_lib.fd and clib/layers_protos.h
90 *****************************************************************************/
92 AROS_LIBFUNC_INIT
93 AROS_LIBBASE_EXT_DECL(struct LayersBase *,LayersBase)
95 D(bug("SortLayerCR(layer @ $%lx, dx %ld, dy %ld)\n", layer, dx, dy));
97 if(dy > 0)
99 _SLCR_SortClipRects(layer, _SLCR_CompFunc_Down);
101 if (dx > 0)
102 _SLCR_SortClipRects(layer, _SLCR_CompFunc_RightDown);
103 else
104 if (dx < 0)
105 _SLCR_SortClipRects(layer, _SLCR_CompFunc_LeftDown);
107 else
108 if (dy < 0)
110 _SLCR_SortClipRects(layer, _SLCR_CompFunc_Up);
112 if (dx > 0)
113 _SLCR_SortClipRects(layer, _SLCR_CompFunc_RightUp);
114 else
115 if (dx < 0)
116 _SLCR_SortClipRects(layer, _SLCR_CompFunc_LeftUp);
118 else
120 if (dx > 0)
121 _SLCR_SortClipRects(layer, _SLCR_CompFunc_Right);
122 else
123 if (dx < 0)
124 _SLCR_SortClipRects(layer, _SLCR_CompFunc_Left);
127 AROS_LIBFUNC_EXIT
128 } /* SortLayerCR */
130 AROS_UFH2(BOOL, _SLCR_CompFunc_Down,
131 AROS_UFHA(struct ClipRect *, cr1, A0),
132 AROS_UFHA(struct ClipRect *, cr2, A1))
134 AROS_USERFUNC_INIT
135 return (BOOL)(cr1->bounds.MinY <= cr2->bounds.MinY);
136 AROS_USERFUNC_EXIT
139 AROS_UFH2(BOOL, _SLCR_CompFunc_Up,
140 AROS_UFHA(struct ClipRect *, cr1, A0),
141 AROS_UFHA(struct ClipRect *, cr2, A1))
143 AROS_USERFUNC_INIT
144 return (BOOL)(cr1->bounds.MaxY >= cr2->bounds.MaxY);
145 AROS_USERFUNC_EXIT
148 AROS_UFH2(BOOL, _SLCR_CompFunc_Right,
149 AROS_UFHA(struct ClipRect *, cr1, A0),
150 AROS_UFHA(struct ClipRect *, cr2, A1))
152 AROS_USERFUNC_INIT
153 return (BOOL)(cr1->bounds.MinX <= cr2->bounds.MinX);
154 AROS_USERFUNC_EXIT
157 AROS_UFH2(BOOL, _SLCR_CompFunc_Left,
158 AROS_UFHA(struct ClipRect *, cr1, A0),
159 AROS_UFHA(struct ClipRect *, cr2, A1))
161 AROS_USERFUNC_INIT
162 return (BOOL)(cr1->bounds.MaxX >= cr2->bounds.MaxX);
163 AROS_USERFUNC_EXIT
166 AROS_UFH2(BOOL, _SLCR_CompFunc_RightDown,
167 AROS_UFHA(struct ClipRect *, cr1, A0),
168 AROS_UFHA(struct ClipRect *, cr2, A1))
170 AROS_USERFUNC_INIT
171 if(cr1->bounds.MinY > cr2->bounds.MaxY) return 0;
172 return (BOOL)(cr1->bounds.MinX <= cr2->bounds.MaxX);
173 AROS_USERFUNC_EXIT
176 AROS_UFH2(BOOL, _SLCR_CompFunc_RightUp,
177 AROS_UFHA(struct ClipRect *, cr1, A0),
178 AROS_UFHA(struct ClipRect *, cr2, A1))
180 AROS_USERFUNC_INIT
181 if(cr1->bounds.MaxY < cr2->bounds.MinY) return 0;
182 return (BOOL)(cr1->bounds.MinX <= cr2->bounds.MaxX);
183 AROS_USERFUNC_EXIT
186 AROS_UFH2(BOOL, _SLCR_CompFunc_LeftDown,
187 AROS_UFHA(struct ClipRect *, cr1, A0),
188 AROS_UFHA(struct ClipRect *, cr2, A1))
190 AROS_USERFUNC_INIT
191 if(cr1->bounds.MinY > cr2->bounds.MaxY) return 0;
192 return (BOOL)(cr1->bounds.MaxX >= cr2->bounds.MinX);
193 AROS_USERFUNC_EXIT
196 AROS_UFH2(BOOL, _SLCR_CompFunc_LeftUp,
197 AROS_UFHA(struct ClipRect *, cr1, A0),
198 AROS_UFHA(struct ClipRect *, cr2, A1))
200 AROS_USERFUNC_INIT
201 if(cr1->bounds.MaxY < cr2->bounds.MinY) return 0;
202 return (BOOL)(cr1->bounds.MaxX >= cr2->bounds.MinX);
203 AROS_USERFUNC_EXIT
206 void _SLCR_SortClipRects(struct Layer *layer,
207 AROS_UFP2(BOOL, (*CompFunc),
208 AROS_UFPA(struct ClipRect *, cr1, A0),
209 AROS_UFPA(struct ClipRect *, cr2, A1))
213 struct ClipRect *CurCR;
214 struct ClipRect *NextCR;
215 struct ClipRect **CRptr;
216 struct ClipRect *FirstCR;
218 if(!layer->ClipRect)
219 return;
221 FirstCR = NULL;
223 for(CurCR = layer->ClipRect, CRptr = &FirstCR; ; )
225 NextCR = CurCR->Next;
226 CurCR->Next = *CRptr;
227 *CRptr = CurCR;
229 if(!NextCR)
230 break;
232 for(CurCR = NextCR, CRptr = &FirstCR; ; )
234 if(!(NextCR = *CRptr))
235 break;
237 if(AROS_UFC2(BOOL, (*CompFunc),
238 AROS_UFCA(struct ClipRect *, CurCR, A0),
239 AROS_UFCA(struct ClipRect *, NextCR, A1)))
241 break;
243 CRptr = &NextCR->Next;
247 layer->ClipRect = FirstCR;
249 return;