Top level make file improvements and simplifications.
[AROS.git] / rom / graphics / draw.c
blobce470b4cefd797629a3e32535d204b31c1141314
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function Draw()
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <clib/macros.h>
11 #include <graphics/rastport.h>
12 #include <proto/graphics.h>
13 #include <proto/oop.h>
14 #include "gfxfuncsupport.h"
15 #include "graphics_intern.h"
16 #include "intregions.h"
17 #include <stdlib.h>
19 struct draw_render_data
21 struct render_special_info rsi;
22 LONG x1, y1, x2, y2;
25 static ULONG draw_render(APTR draw_rd, LONG srcx, LONG srcy,
26 OOP_Object *dstbm_obj, OOP_Object *dst_gc,
27 LONG x1, LONG y1, LONG x2, LONG y2, struct GfxBase *GfxBase);
29 /*****************************************************************************
31 NAME */
33 AROS_LH3(void, Draw,
35 /* SYNOPSIS */
36 AROS_LHA(struct RastPort *, rp, A1),
37 AROS_LHA(LONG , x, D0),
38 AROS_LHA(LONG , y, D1),
40 /* LOCATION */
41 struct GfxBase *, GfxBase, 41, Graphics)
43 /* FUNCTION
44 Draw a line from the current pen position to the given coordinate.
46 INPUTS
47 rp - destination RastPort.
48 x,y - line end coordinate.
50 RESULT
52 NOTES
53 Not yet implemented:
55 - handle layer->Scroll_X/Scroll_Y.
57 - handle FRST_DOT which indicates whether to draw
58 or to don't draw first pixel of line. Important
59 for COMPLEMENT drawmode.
61 EXAMPLE
63 BUGS
65 SEE ALSO
67 INTERNALS
69 HISTORY
70 29-10-95 digulla automatically created from
71 graphics_lib.fd and clib/graphics_protos.h
73 *****************************************************************************/
75 AROS_LIBFUNC_INIT
78 struct Rectangle rr;
79 OOP_Object *gc;
80 struct draw_render_data drd;
81 LONG dx;
82 LONG x1, y1;
84 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
85 return;
87 FIX_GFXCOORD(x);
88 FIX_GFXCOORD(y);
90 x1 = rp->cp_x;
91 y1 = rp->cp_y;
93 gc = GetDriverData(rp)->dd_GC;
95 if (x1 > x)
97 rr.MinX = x;
98 rr.MaxX = x1;
100 else
102 rr.MinX = x1;
103 rr.MaxX = x;
106 if (y1 > y)
108 rr.MinY = y;
109 rr.MaxY = y1;
111 else
113 rr.MinY = y1;
114 rr.MaxY = y;
118 UWORD lineptrn = rp->LinePtrn;
120 if (rp->DrawMode & INVERSVID) lineptrn = ~lineptrn;
123 struct TagItem gctags[] =
125 {aHidd_GC_LinePattern , lineptrn },
126 {aHidd_GC_LinePatternCnt, rp->linpatcnt },
127 {TAG_DONE }
130 OOP_SetAttrs( gc, gctags);
134 drd.x1 = x1 - rr.MinX;
135 drd.y1 = y1 - rr.MinY;
136 drd.x2 = x - rr.MinX;
137 drd.y2 = y - rr.MinY;
139 do_render_func(rp, NULL, &rr, draw_render, &drd, TRUE, TRUE, GfxBase);
141 dx = (drd.x2 > drd.y2) ? drd.x2 : drd.y2;
143 rp->linpatcnt = ((LONG)rp->linpatcnt - dx) & 15;
145 rp->cp_x = x;
146 rp->cp_y = y;
148 RELEASE_DRIVERDATA(rp, GfxBase);
150 AROS_LIBFUNC_EXIT
152 } /* Draw */
154 /****************************************************************************************/
156 static ULONG draw_render(APTR draw_rd, LONG srcx, LONG srcy,
157 OOP_Object *dstbm_obj, OOP_Object *dst_gc,
158 LONG x1, LONG y1, LONG x2, LONG y2, struct GfxBase *GfxBase)
160 struct draw_render_data *drd;
161 ULONG width, height;
163 width = x2 - x1 + 1;
164 height = y2 - y1 + 1;
166 drd = (struct draw_render_data *)draw_rd;
168 HIDD_GC_SetClipRect(dst_gc, x1, y1, x2, y2);
170 HIDD_BM_DrawLine(dstbm_obj, dst_gc, drd->x1 + x1 - srcx,
171 drd->y1 + y1 - srcy,
172 drd->x2 + x1 - srcx,
173 drd->y2 + y1 - srcy);
175 HIDD_GC_UnsetClipRect(dst_gc);
177 return 0;
180 /****************************************************************************************/