Update to lasso handling. Adjust scroll amount based on difference between mouse...
[AROS.git] / rom / graphics / drawellipse.c
blobacbe80eb3ab6012233ce34bd1d3f270419de448d
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
99 RELEASE_HIDD_BM(bm_obj, bm);
103 else
105 struct ClipRect *CR;
106 WORD xrel;
107 WORD yrel;
108 struct Rectangle torender, intersect;
109 OOP_Object *bm_obj;
111 LockLayerRom(L);
113 CR = L->ClipRect;
115 xrel = L->bounds.MinX;
116 yrel = L->bounds.MinY;
118 xCenter -= L->Scroll_X;
119 yCenter -= L->Scroll_Y;
121 have_rp_cliprectangle = GetRPClipRectangleForLayer(rp, L, &rp_clip_rectangle, GfxBase);
123 torender.MinX = rr.MinX + xrel - L->Scroll_X;
124 torender.MinY = rr.MinY + yrel - L->Scroll_Y;
125 torender.MaxX = rr.MaxX + xrel - L->Scroll_X;
126 torender.MaxY = rr.MaxY + yrel - L->Scroll_Y;
128 for (;NULL != CR; CR = CR->Next)
130 D(bug("Cliprect (%d, %d, %d, %d), lobs=%p\n",
131 CR->bounds.MinX, CR->bounds.MinY, CR->bounds.MaxX, CR->bounds.MaxY,
132 CR->lobs));
134 /* Does this cliprect intersect with area to rectfill ? */
135 if (_AndRectRect(&CR->bounds, &torender, &intersect))
137 if (!have_rp_cliprectangle || _AndRectRect(&rp_clip_rectangle, &intersect, &intersect))
139 if (NULL == CR->lobs)
142 /* Set clip rectangle */
143 /* bug("Setting cliprect: %d %d %d %d : layerrel: %d %d %d %d\n"
144 , intersect.MinX
145 , intersect.MinY
146 , intersect.MaxX
147 , intersect.MaxY
149 , intersect.MinX - xrel
150 , intersect.MinY - yrel
151 , intersect.MaxX - xrel
152 , intersect.MaxY - yrel
155 HIDD_GC_SetClipRect(gc
156 , intersect.MinX
157 , intersect.MinY
158 , intersect.MaxX
159 , intersect.MaxY
162 bm_obj = OBTAIN_HIDD_BM(bm);
163 if (bm_obj)
165 HIDD_BM_DrawEllipse(bm_obj
166 , gc
167 , xCenter + xrel
168 , yCenter + yrel
173 RELEASE_HIDD_BM(bm_obj, bm);
176 HIDD_GC_UnsetClipRect(gc);
180 else
182 /* Render into offscreen cliprect bitmap */
183 if (L->Flags & LAYERSIMPLE)
184 continue;
185 else if (L->Flags & LAYERSUPER)
187 D(bug("do_render_func(): Superbitmap not handled yet\n"));
189 else
191 LONG bm_rel_minx, bm_rel_miny, bm_rel_maxx, bm_rel_maxy;
192 LONG layer_rel_x, layer_rel_y;
194 layer_rel_x = intersect.MinX - xrel;
195 layer_rel_y = intersect.MinY - yrel;
197 bm_rel_minx = intersect.MinX - CR->bounds.MinX;
198 bm_rel_miny = intersect.MinY - CR->bounds.MinY;
199 bm_rel_maxx = intersect.MaxX - CR->bounds.MinX;
200 bm_rel_maxy = intersect.MaxY - CR->bounds.MinY;
202 HIDD_GC_SetClipRect(gc
203 , bm_rel_minx + ALIGN_OFFSET(CR->bounds.MinX)
204 , bm_rel_miny
205 , bm_rel_maxx + ALIGN_OFFSET(CR->bounds.MinX)
206 , bm_rel_maxy
209 bm_obj = OBTAIN_HIDD_BM(CR->BitMap);
210 if (bm_obj)
212 HIDD_BM_DrawEllipse(bm_obj
213 , gc
214 , bm_rel_minx - (layer_rel_x - xCenter) + ALIGN_OFFSET(CR->bounds.MinX)
215 , bm_rel_miny - (layer_rel_y - yCenter)
220 RELEASE_HIDD_BM(bm_obj, CR->BitMap);
223 HIDD_GC_UnsetClipRect(gc);
226 } /* if (CR->lobs == NULL) */
228 } /* if it also intersects with possible rastport clip rectangle */
230 } /* if (cliprect intersects with area to render into) */
232 } /* for (each cliprect in the layer) */
234 UnlockLayerRom(L);
236 } /* if (rp->Layer) */
238 RELEASE_DRIVERDATA(rp, GfxBase);
240 AROS_LIBFUNC_EXIT
242 } /* DrawEllipse */