Fixed AutoDoc indentation and grammar.
[AROS.git] / rom / intuition / drawimagestate.c
blobae59866e5e9893e63a20c89bb0bbaab88f1fb603
1 /*
2 Copyright © 1995-2011, 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 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
80 struct LayersBase *LayersBase = GetPrivIBase(IntuitionBase)->LayersBase;
81 IPTR apen, bpen, drmd;
82 #ifdef __MORPHOS__
83 IPTR penmode;
84 #endif
86 EXTENDWORD(leftOffset);
87 EXTENDWORD(topOffset);
89 SANITY_CHECK(rp)
90 SANITY_CHECK(image)
92 if (rp->Layer) LockLayer(0,rp->Layer);
94 /* Store important variables of the RastPort */
95 #ifdef __MORPHOS__
96 GetRPAttrs(rp, RPTAG_PenMode, &penmode, RPTAG_APen, &apen,
97 RPTAG_BPen, &bpen, RPTAG_DrMd, &drmd, TAG_DONE);
98 #else
99 GetRPAttrs(rp, RPTAG_APen, &apen,
100 RPTAG_BPen, &bpen, RPTAG_DrMd, &drmd, TAG_DONE);
101 #endif
103 while(image)
105 if (image->Depth == CUSTOMIMAGEDEPTH)
107 struct impDraw method;
109 method.MethodID = IM_DRAW;
110 method.imp_RPort = rp;
111 method.imp_Offset.X = leftOffset;
112 method.imp_Offset.Y = topOffset;
113 method.imp_State = state;
114 method.imp_DrInfo = drawInfo;
115 DoMethodA ((Object *)image, (Msg)&method);
117 else
119 WORD x, y, d;
120 UWORD shift;
121 ULONG planeonoff, planepick;
123 #if !USE_BLTBITMAPRASTPORT
125 ULONG lastPen = 0;
126 ULONG pen = 0;
127 UWORD offset;
128 UWORD bitmask;
129 UWORD * bits[8];
130 WORD xoff, yoff, plane;
132 #define START_BITMASK 0x8000
134 /* Change RastPort to the mode I need */
135 SetDrMd (rp, JAM1);
137 #endif
139 /* kprintf("*** Drawing Image %x. Next Image = %x\n widht = %d height = %d depth = %d planepick = %d planeonoff = %d\n",
140 image,image->NextImage,
141 image->Width,image->Height,image->Depth,image->PlanePick,image->PlaneOnOff);*/
144 planepick = image->PlanePick;
145 planeonoff = image->PlaneOnOff & ~planepick;
147 #if USE_FASTPLANEPICK0
149 if (planepick == 0)
151 SetAPen(rp, planeonoff);
152 RectFill(rp, leftOffset + image->LeftEdge,
153 topOffset + image->TopEdge,
154 leftOffset + image->LeftEdge + image->Width - 1,
155 topOffset + image->TopEdge + image->Height - 1);
157 image = image->NextImage;
158 continue;
161 #endif
163 /* Use x to store size of one image plane */
164 x = ((image->Width + 15) >> 4) * image->Height;
165 y = 0;
167 shift = 1;
169 #if USE_BLTBITMAPRASTPORT
171 struct BitMap bitmap;
172 int depth;
173 int imagedepth = image->Depth;
175 #if 0
176 /* The "8" (instead of image->Depth) seems to be correct,
177 as for example DOpus uses prop gadget knob images with
178 a depth of 0 (planepick 0, planeonoff color) */
180 depth = 8;
181 #else
182 /* That makes far more sense than just a 8
183 * R.Schmidt...still doesn`t resolve some weird icon problem i have
185 //depth = rp->BitMap->Depth;
188 ** Be system friendly. - Piru
190 depth = GetBitMapAttr(rp->BitMap, BMA_DEPTH);
191 if (depth > 8)
192 depth = 8;
193 #endif
194 InitBitMap(&bitmap, depth, image->Width, image->Height);
196 for(d = 0; d < depth; d++)
198 /* Don't use more planes than image->depth. This solves
199 corrupt images of Garshneblanker's FlyingToaster which
200 uses a PlanePick of 0xff. */
201 if ((imagedepth > 0) && (planepick & shift))
203 imagedepth--;
204 bitmap.Planes[d] = (PLANEPTR)(image->ImageData + (y++) * x);
206 else
208 bitmap.Planes[d] = (planeonoff & shift) ? (PLANEPTR)-1 : NULL;
210 shift <<= 1;
213 BltBitMapRastPort(&bitmap,
214 0, 0,
216 leftOffset + image->LeftEdge, topOffset + image->TopEdge,
217 image->Width, image->Height,
218 (state == IDS_SELECTED) ? 0x30 : 0xC0);
221 #else
224 for(d = 0; d < image->Depth;d++)
226 bits[d] = (planepick & shift) ? image->ImageData + (y++) * x : NULL;
227 shift <<= 1;
230 offset = 0;
232 yoff = image->TopEdge + topOffset;
234 for (y=0; y < image->Height; y++, yoff++)
237 bitmask = START_BITMASK;
239 xoff = image->LeftEdge + leftOffset;
241 for (x=0; x < image->Width; x++, xoff++)
243 pen = planeonoff;
244 shift = 1;
245 plane = 0;
247 for(d = 0; d < image->Depth; d++)
249 if (planepick & shift)
251 UWORD dat;
253 dat = bits[d][offset];
254 dat = AROS_WORD2BE(dat);
256 if (dat & bitmask)
258 pen |= shift;
262 shift <<= 1;
265 if (!x)
267 lastPen = pen;
268 Move (rp, xoff, yoff);
271 if (pen != lastPen)
273 SetAPen (rp, lastPen);
274 Draw (rp, xoff, yoff);
275 lastPen = pen;
278 bitmask >>= 1;
280 if (!bitmask)
282 bitmask = START_BITMASK;
283 offset ++;
286 } /* for (x=0; x < image->Width; x++, xoff++) */
288 SetAPen (rp, pen);
289 Draw (rp, xoff-1, yoff);
291 if (bitmask != START_BITMASK)
292 offset ++;
294 } /* for (y=0; y < image->Height; y++, yoff++) */
296 #endif
299 image = image->NextImage;
302 #ifdef __MORPHOS__
303 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,RPTAG_PenMode,penmode,TAG_DONE);
304 #else
305 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,TAG_DONE);
306 #endif
308 if (rp->Layer) UnlockLayer(rp->Layer);
310 AROS_LIBFUNC_EXIT
311 } /* DrawImageState */