define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / rom / graphics / drawellipse.c
bloba275107fbedb1bd97d318fdb33fc14d5e9268e5f
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$ $Log
5 Desc: Graphics function DrawEllipse
6 Lang: english
7 */
8 #include <aros/debug.h>
9 #include <clib/macros.h>
10 #include "graphics_intern.h"
11 #include <graphics/rastport.h>
12 #include "gfxfuncsupport.h"
13 #include "intregions.h"
15 /*****************************************************************************
17 NAME */
18 #include <graphics/rastport.h>
19 #include <proto/graphics.h>
21 AROS_LH5(void, DrawEllipse,
23 /* SYNOPSIS */
24 AROS_LHA(struct RastPort *, rp, A1),
25 AROS_LHA(LONG , xCenter, D0),
26 AROS_LHA(LONG , yCenter, D1),
27 AROS_LHA(LONG , a, D2),
28 AROS_LHA(LONG , b, D3),
30 /* LOCATION */
31 struct GfxBase *, GfxBase, 30, Graphics)
33 /* FUNCTION
34 Draw an ellipse
36 INPUTS
37 rp - destination RastPort
38 xCenter,yCenter - coordinate of centerpoint
39 a - radius in x direction
40 b - radius in y direction
42 RESULT
44 NOTES
46 EXAMPLE
48 BUGS
50 SEE ALSO
52 INTERNALS
54 HISTORY
55 29-10-95 digulla automatically created from
56 graphics_lib.fd and clib/graphics_protos.h
58 *****************************************************************************/
60 AROS_LIBFUNC_INIT
62 struct Rectangle rr;
63 OOP_Object *gc;
64 struct Layer *L = rp->Layer;
65 struct BitMap *bm = rp->BitMap;
66 struct Rectangle rp_clip_rectangle;
67 BOOL have_rp_cliprectangle;
69 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
70 return;
72 FIX_GFXCOORD(xCenter);
73 FIX_GFXCOORD(yCenter);
74 FIX_GFXCOORD(a);
75 FIX_GFXCOORD(b);
77 /* bug("driver_DrawEllipse(%d %d %d %d)\n", xCenter, yCenter, a, b);
78 */ gc = GetDriverData(rp)->dd_GC;
80 rr.MinX = xCenter - a;
81 rr.MinY = yCenter - b;
82 rr.MaxX = xCenter + a;
83 rr.MaxY = yCenter + b;
85 if (NULL == L)
87 /* No layer, probably a screen, but may be a user inited bitmap */
88 OOP_Object *bm_obj;
90 bm_obj = OBTAIN_HIDD_BM(bm);
91 if (bm_obj)
93 /* No need for clipping */
94 HIDD_BM_DrawEllipse(bm_obj, gc
95 , xCenter, yCenter
96 , a, b
98 HIDD_BM_UpdateRect(bm_obj, xCenter - a, yCenter - b, a + a, b + b);
100 RELEASE_HIDD_BM(bm_obj, bm);
104 else
106 struct ClipRect *CR;
107 WORD xrel;
108 WORD yrel;
109 struct Rectangle torender, intersect;
110 OOP_Object *bm_obj;
112 LockLayerRom(L);
114 CR = L->ClipRect;
116 xrel = L->bounds.MinX;
117 yrel = L->bounds.MinY;
119 xCenter -= L->Scroll_X;
120 yCenter -= L->Scroll_Y;
122 have_rp_cliprectangle = GetRPClipRectangleForLayer(rp, L, &rp_clip_rectangle, GfxBase);
124 torender.MinX = rr.MinX + xrel - L->Scroll_X;
125 torender.MinY = rr.MinY + yrel - L->Scroll_Y;
126 torender.MaxX = rr.MaxX + xrel - L->Scroll_X;
127 torender.MaxY = rr.MaxY + yrel - L->Scroll_Y;
129 for (;NULL != CR; CR = CR->Next)
131 D(bug("Cliprect (%d, %d, %d, %d), lobs=%p\n",
132 CR->bounds.MinX, CR->bounds.MinY, CR->bounds.MaxX, CR->bounds.MaxY,
133 CR->lobs));
135 /* Does this cliprect intersect with area to rectfill ? */
136 if (_AndRectRect(&CR->bounds, &torender, &intersect))
138 if (!have_rp_cliprectangle || _AndRectRect(&rp_clip_rectangle, &intersect, &intersect))
140 if (NULL == CR->lobs)
143 /* Set clip rectangle */
144 /* bug("Setting cliprect: %d %d %d %d : layerrel: %d %d %d %d\n"
145 , intersect.MinX
146 , intersect.MinY
147 , intersect.MaxX
148 , intersect.MaxY
150 , intersect.MinX - xrel
151 , intersect.MinY - yrel
152 , intersect.MaxX - xrel
153 , intersect.MaxY - yrel
156 HIDD_GC_SetClipRect(gc
157 , intersect.MinX
158 , intersect.MinY
159 , intersect.MaxX
160 , intersect.MaxY
163 bm_obj = OBTAIN_HIDD_BM(bm);
164 if (bm_obj)
166 HIDD_BM_DrawEllipse(bm_obj
167 , gc
168 , xCenter + xrel
169 , yCenter + yrel
173 HIDD_BM_UpdateRect(bm_obj, xCenter + xrel - a, yCenter + yrel - b, a + a, b + b);
175 RELEASE_HIDD_BM(bm_obj, bm);
178 HIDD_GC_UnsetClipRect(gc);
182 else
184 /* Render into offscreen cliprect bitmap */
185 if (L->Flags & LAYERSIMPLE)
186 continue;
187 else if (L->Flags & LAYERSUPER)
189 D(bug("do_render_func(): Superbitmap not handled yet\n"));
191 else
193 LONG bm_rel_minx, bm_rel_miny, bm_rel_maxx, bm_rel_maxy;
194 LONG layer_rel_x, layer_rel_y;
196 layer_rel_x = intersect.MinX - xrel;
197 layer_rel_y = intersect.MinY - yrel;
199 bm_rel_minx = intersect.MinX - CR->bounds.MinX;
200 bm_rel_miny = intersect.MinY - CR->bounds.MinY;
201 bm_rel_maxx = intersect.MaxX - CR->bounds.MinX;
202 bm_rel_maxy = intersect.MaxY - CR->bounds.MinY;
204 HIDD_GC_SetClipRect(gc
205 , bm_rel_minx + ALIGN_OFFSET(CR->bounds.MinX)
206 , bm_rel_miny
207 , bm_rel_maxx + ALIGN_OFFSET(CR->bounds.MinX)
208 , bm_rel_maxy
211 bm_obj = OBTAIN_HIDD_BM(CR->BitMap);
212 if (bm_obj)
214 HIDD_BM_DrawEllipse(bm_obj
215 , gc
216 , bm_rel_minx - (layer_rel_x - xCenter) + ALIGN_OFFSET(CR->bounds.MinX)
217 , bm_rel_miny - (layer_rel_y - yCenter)
221 HIDD_BM_UpdateRect(bm_obj, bm_rel_minx - (layer_rel_x - xCenter) + ALIGN_OFFSET(CR->bounds.MinX) - a,
222 bm_rel_miny - (layer_rel_y - yCenter) - b,
223 a + a, b + b);
225 RELEASE_HIDD_BM(bm_obj, CR->BitMap);
228 HIDD_GC_UnsetClipRect(gc);
231 } /* if (CR->lobs == NULL) */
233 } /* if it also intersects with possible rastport clip rectangle */
235 } /* if (cliprect intersects with area to render into) */
237 } /* for (each cliprect in the layer) */
239 UnlockLayerRom(L);
241 } /* if (rp->Layer) */
243 RELEASE_DRIVERDATA(rp, GfxBase);
245 AROS_LIBFUNC_EXIT
247 } /* DrawEllipse */