Added kernel module for starting the usb stack at boot time. It's not activated thoug...
[cake.git] / rom / intuition / drawimagestate.c
blob90483e30801880c781cfc4726f6308a8e34bf5d5
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <proto/graphics.h>
8 #include <proto/layers.h>
9 #include "intuition_intern.h"
10 #include <intuition/classusr.h>
11 #include <proto/alib.h>
13 #include <aros/macros.h>
15 #undef DEBUG
16 #define DEBUG 0
17 # include <aros/debug.h>
18 //#include <proto/arossupport.h>
20 #define USE_BLTBITMAPRASTPORT 1
21 #define USE_FASTPLANEPICK0 1
23 /*****************************************************************************
25 NAME */
26 #include <graphics/rastport.h>
27 #include <graphics/rpattr.h>
28 #include <intuition/intuition.h>
29 #include <intuition/imageclass.h>
30 #include <proto/intuition.h>
32 AROS_LH6(void, DrawImageState,
34 /* SYNOPSIS */
35 AROS_LHA(struct RastPort *, rp, A0),
36 AROS_LHA(struct Image *, image, A1),
37 AROS_LHA(LONG , leftOffset, D0),
38 AROS_LHA(LONG , topOffset, D1),
39 AROS_LHA(ULONG , state, D2),
40 AROS_LHA(struct DrawInfo *, drawInfo, A2),
42 /* LOCATION */
43 struct IntuitionBase *, IntuitionBase, 103, Intuition)
45 /* FUNCTION
46 This function renders an image in a certain state.
48 INPUTS
49 rp - Render in this RastPort
50 image - Render this image
51 leftOffset, topOffset - Add this offset to the position stored in the
52 image.
53 state - Which state (see intuition/imageclass.h for possible
54 values).
55 drawInfo - The DrawInfo from the screen.
57 RESULT
58 None.
60 NOTES
61 DrawImageState(), handles both boopsi and conventional images.
63 EXAMPLE
65 BUGS
67 SEE ALSO
69 INTERNALS
71 HISTORY
72 29-10-95 digulla automatically created from
73 intuition_lib.fd and clib/intuition_protos.h
75 *****************************************************************************/
77 AROS_LIBFUNC_INIT
79 IPTR apen, bpen, drmd;
80 #ifdef __MORPHOS__
81 IPTR penmode;
82 #endif
84 EXTENDWORD(leftOffset);
85 EXTENDWORD(topOffset);
87 SANITY_CHECK(rp)
88 SANITY_CHECK(image)
90 if (rp->Layer) LockLayer(0,rp->Layer);
92 /* Store important variables of the RastPort */
93 #ifdef __MORPHOS__
94 GetRPAttrs(rp,RPTAG_PenMode,(ULONG)&penmode,RPTAG_APen,(ULONG)&apen,
95 RPTAG_BPen,(ULONG)&bpen,RPTAG_DrMd,(ULONG)&drmd,TAG_DONE);
96 #else
97 GetRPAttrs(rp,RPTAG_APen,(ULONG)&apen,
98 RPTAG_BPen,(ULONG)&bpen,RPTAG_DrMd,(ULONG)&drmd,TAG_DONE);
99 #endif
101 while(image)
103 if (image->Depth == CUSTOMIMAGEDEPTH)
105 struct impDraw method;
107 method.MethodID = IM_DRAW;
108 method.imp_RPort = rp;
109 method.imp_Offset.X = leftOffset;
110 method.imp_Offset.Y = topOffset;
111 method.imp_State = state;
112 method.imp_DrInfo = drawInfo;
113 DoMethodA ((Object *)image, (Msg)&method);
115 else
117 WORD x, y, d;
118 UWORD shift;
119 ULONG planeonoff, planepick;
121 #if !USE_BLTBITMAPRASTPORT
123 ULONG lastPen = 0;
124 ULONG pen = 0;
125 UWORD offset;
126 UWORD bitmask;
127 UWORD * bits[8];
128 WORD xoff, yoff, plane;
130 #define START_BITMASK 0x8000
132 /* Change RastPort to the mode I need */
133 SetDrMd (rp, JAM1);
135 #endif
137 /* kprintf("*** Drawing Image %x. Next Image = %x\n widht = %d height = %d depth = %d planepick = %d planeonoff = %d\n",
138 image,image->NextImage,
139 image->Width,image->Height,image->Depth,image->PlanePick,image->PlaneOnOff);*/
142 planepick = image->PlanePick;
143 planeonoff = image->PlaneOnOff & ~planepick;
145 #if USE_FASTPLANEPICK0
147 if (planepick == 0)
149 SetAPen(rp, planeonoff);
150 RectFill(rp, leftOffset + image->LeftEdge,
151 topOffset + image->TopEdge,
152 leftOffset + image->LeftEdge + image->Width - 1,
153 topOffset + image->TopEdge + image->Height - 1);
155 image = image->NextImage;
156 continue;
159 #endif
161 /* Use x to store size of one image plane */
162 x = ((image->Width + 15) >> 4) * image->Height;
163 y = 0;
165 shift = 1;
167 #if USE_BLTBITMAPRASTPORT
169 struct BitMap bitmap;
170 int depth;
172 #if 0
173 /* The "8" (instead of image->Depth) seems to be correct,
174 as for example DOpus uses prop gadget knob images with
175 a depth of 0 (planepick 0, planeonoff color) */
177 depth = 8;
178 #else
179 /* That makes far more sense than just a 8
180 * R.Schmidt...still doesn`t resolve some weird icon problem i have
182 //depth = rp->BitMap->Depth;
185 ** Be system friendly. - Piru
187 depth = GetBitMapAttr(rp->BitMap, BMA_DEPTH);
188 if (depth > 8)
189 depth = 8;
190 #endif
191 InitBitMap(&bitmap, depth, image->Width, image->Height);
193 for(d = 0; d < depth; d++)
195 if (planepick & shift)
197 bitmap.Planes[d] = (PLANEPTR)(image->ImageData + (y++) * x);
199 else
201 bitmap.Planes[d] = (planeonoff & shift) ? (PLANEPTR)-1 : NULL;
203 shift <<= 1;
206 BltBitMapRastPort(&bitmap,
207 0, 0,
209 leftOffset + image->LeftEdge, topOffset + image->TopEdge,
210 image->Width, image->Height,
211 0xC0);
214 #else
217 for(d = 0; d < image->Depth;d++)
219 bits[d] = (planepick & shift) ? image->ImageData + (y++) * x : NULL;
220 shift <<= 1;
223 offset = 0;
225 yoff = image->TopEdge + topOffset;
227 for (y=0; y < image->Height; y++, yoff++)
230 bitmask = START_BITMASK;
232 xoff = image->LeftEdge + leftOffset;
234 for (x=0; x < image->Width; x++, xoff++)
236 pen = planeonoff;
237 shift = 1;
238 plane = 0;
240 for(d = 0; d < image->Depth; d++)
242 if (planepick & shift)
244 UWORD dat;
246 dat = bits[d][offset];
247 dat = AROS_WORD2BE(dat);
249 if (dat & bitmask)
251 pen |= shift;
255 shift <<= 1;
258 if (!x)
260 lastPen = pen;
261 Move (rp, xoff, yoff);
264 if (pen != lastPen)
266 SetAPen (rp, lastPen);
267 Draw (rp, xoff, yoff);
268 lastPen = pen;
271 bitmask >>= 1;
273 if (!bitmask)
275 bitmask = START_BITMASK;
276 offset ++;
279 } /* for (x=0; x < image->Width; x++, xoff++) */
281 SetAPen (rp, pen);
282 Draw (rp, xoff-1, yoff);
284 if (bitmask != START_BITMASK)
285 offset ++;
287 } /* for (y=0; y < image->Height; y++, yoff++) */
289 #endif
292 image = image->NextImage;
295 #ifdef __MORPHOS__
296 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,RPTAG_PenMode,penmode,TAG_DONE);
297 #else
298 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,TAG_DONE);
299 #endif
301 if (rp->Layer) UnlockLayer(rp->Layer);
303 AROS_LIBFUNC_EXIT
304 } /* DrawImageState */