Small modification to diskinfo and info tool layout
[AROS.git] / rom / hyperlayers / sortlayercr.c
blobabda4dfba7ff644cf2708ac3a696033d343277dc
1 /*
2 Copyright © 1995-2007, 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
94 D(bug("SortLayerCR(layer @ $%lx, dx %ld, dy %ld)\n", layer, dx, dy));
96 if(dy > 0)
98 _SLCR_SortClipRects(layer, _SLCR_CompFunc_Down);
100 if (dx > 0)
101 _SLCR_SortClipRects(layer, _SLCR_CompFunc_RightDown);
102 else
103 if (dx < 0)
104 _SLCR_SortClipRects(layer, _SLCR_CompFunc_LeftDown);
106 else
107 if (dy < 0)
109 _SLCR_SortClipRects(layer, _SLCR_CompFunc_Up);
111 if (dx > 0)
112 _SLCR_SortClipRects(layer, _SLCR_CompFunc_RightUp);
113 else
114 if (dx < 0)
115 _SLCR_SortClipRects(layer, _SLCR_CompFunc_LeftUp);
117 else
119 if (dx > 0)
120 _SLCR_SortClipRects(layer, _SLCR_CompFunc_Right);
121 else
122 if (dx < 0)
123 _SLCR_SortClipRects(layer, _SLCR_CompFunc_Left);
126 AROS_LIBFUNC_EXIT
127 } /* SortLayerCR */
129 AROS_UFH2(BOOL, _SLCR_CompFunc_Down,
130 AROS_UFHA(struct ClipRect *, cr1, A0),
131 AROS_UFHA(struct ClipRect *, cr2, A1))
133 AROS_USERFUNC_INIT
134 return (BOOL)(cr1->bounds.MinY <= cr2->bounds.MinY);
135 AROS_USERFUNC_EXIT
138 AROS_UFH2(BOOL, _SLCR_CompFunc_Up,
139 AROS_UFHA(struct ClipRect *, cr1, A0),
140 AROS_UFHA(struct ClipRect *, cr2, A1))
142 AROS_USERFUNC_INIT
143 return (BOOL)(cr1->bounds.MaxY >= cr2->bounds.MaxY);
144 AROS_USERFUNC_EXIT
147 AROS_UFH2(BOOL, _SLCR_CompFunc_Right,
148 AROS_UFHA(struct ClipRect *, cr1, A0),
149 AROS_UFHA(struct ClipRect *, cr2, A1))
151 AROS_USERFUNC_INIT
152 return (BOOL)(cr1->bounds.MinX <= cr2->bounds.MinX);
153 AROS_USERFUNC_EXIT
156 AROS_UFH2(BOOL, _SLCR_CompFunc_Left,
157 AROS_UFHA(struct ClipRect *, cr1, A0),
158 AROS_UFHA(struct ClipRect *, cr2, A1))
160 AROS_USERFUNC_INIT
161 return (BOOL)(cr1->bounds.MaxX >= cr2->bounds.MaxX);
162 AROS_USERFUNC_EXIT
165 AROS_UFH2(BOOL, _SLCR_CompFunc_RightDown,
166 AROS_UFHA(struct ClipRect *, cr1, A0),
167 AROS_UFHA(struct ClipRect *, cr2, A1))
169 AROS_USERFUNC_INIT
170 if(cr1->bounds.MinY > cr2->bounds.MaxY) return 0;
171 return (BOOL)(cr1->bounds.MinX <= cr2->bounds.MaxX);
172 AROS_USERFUNC_EXIT
175 AROS_UFH2(BOOL, _SLCR_CompFunc_RightUp,
176 AROS_UFHA(struct ClipRect *, cr1, A0),
177 AROS_UFHA(struct ClipRect *, cr2, A1))
179 AROS_USERFUNC_INIT
180 if(cr1->bounds.MaxY < cr2->bounds.MinY) return 0;
181 return (BOOL)(cr1->bounds.MinX <= cr2->bounds.MaxX);
182 AROS_USERFUNC_EXIT
185 AROS_UFH2(BOOL, _SLCR_CompFunc_LeftDown,
186 AROS_UFHA(struct ClipRect *, cr1, A0),
187 AROS_UFHA(struct ClipRect *, cr2, A1))
189 AROS_USERFUNC_INIT
190 if(cr1->bounds.MinY > cr2->bounds.MaxY) return 0;
191 return (BOOL)(cr1->bounds.MaxX >= cr2->bounds.MinX);
192 AROS_USERFUNC_EXIT
195 AROS_UFH2(BOOL, _SLCR_CompFunc_LeftUp,
196 AROS_UFHA(struct ClipRect *, cr1, A0),
197 AROS_UFHA(struct ClipRect *, cr2, A1))
199 AROS_USERFUNC_INIT
200 if(cr1->bounds.MaxY < cr2->bounds.MinY) return 0;
201 return (BOOL)(cr1->bounds.MaxX >= cr2->bounds.MinX);
202 AROS_USERFUNC_EXIT
205 void _SLCR_SortClipRects(struct Layer *layer,
206 AROS_UFP2(BOOL, (*CompFunc),
207 AROS_UFPA(struct ClipRect *, cr1, A0),
208 AROS_UFPA(struct ClipRect *, cr2, A1))
212 struct ClipRect *CurCR;
213 struct ClipRect *NextCR;
214 struct ClipRect **CRptr;
215 struct ClipRect *FirstCR;
217 if(!layer->ClipRect)
218 return;
220 FirstCR = NULL;
222 for(CurCR = layer->ClipRect, CRptr = &FirstCR; ; )
224 NextCR = CurCR->Next;
225 CurCR->Next = *CRptr;
226 *CRptr = CurCR;
228 if(!NextCR)
229 break;
231 for(CurCR = NextCR, CRptr = &FirstCR; ; )
233 if(!(NextCR = *CRptr))
234 break;
236 if(AROS_UFC2(BOOL, (*CompFunc),
237 AROS_UFCA(struct ClipRect *, CurCR, A0),
238 AROS_UFCA(struct ClipRect *, NextCR, A1)))
240 break;
242 CRptr = &NextCR->Next;
246 layer->ClipRect = FirstCR;
248 return;