use struct timeval to obtain the cputime. disable display atm until the code is corre...
[AROS.git] / rom / intuition / drawimagestate.c
blob21e7a00d10cac3f13cf52f70a4c49dcf7e54a68d
1 /*
2 Copyright © 1995-2013, 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 *****************************************************************************/
73 AROS_LIBFUNC_INIT
75 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
76 struct LayersBase *LayersBase = GetPrivIBase(IntuitionBase)->LayersBase;
77 IPTR apen, bpen, drmd;
78 #ifdef __MORPHOS__
79 IPTR penmode;
80 #endif
82 EXTENDWORD(leftOffset);
83 EXTENDWORD(topOffset);
85 SANITY_CHECK(rp)
86 SANITY_CHECK(image)
88 if (rp->Layer) LockLayer(0,rp->Layer);
90 /* Store important variables of the RastPort */
91 #ifdef __MORPHOS__
92 GetRPAttrs(rp, RPTAG_PenMode, &penmode, RPTAG_APen, &apen,
93 RPTAG_BPen, &bpen, RPTAG_DrMd, &drmd, TAG_DONE);
94 #else
95 GetRPAttrs(rp, RPTAG_APen, &apen,
96 RPTAG_BPen, &bpen, RPTAG_DrMd, &drmd, TAG_DONE);
97 #endif
99 while(image)
101 if (image->Depth == CUSTOMIMAGEDEPTH)
103 struct impDraw method;
105 method.MethodID = IM_DRAW;
106 method.imp_RPort = rp;
107 method.imp_Offset.X = leftOffset;
108 method.imp_Offset.Y = topOffset;
109 method.imp_State = state;
110 method.imp_DrInfo = drawInfo;
111 DoMethodA ((Object *)image, (Msg)&method);
113 else
115 WORD x, y, d;
116 UWORD shift;
117 ULONG planeonoff, planepick;
119 #if !USE_BLTBITMAPRASTPORT
121 ULONG lastPen = 0;
122 ULONG pen = 0;
123 UWORD offset;
124 UWORD bitmask;
125 UWORD * bits[8];
126 WORD xoff, yoff, plane;
128 #define START_BITMASK 0x8000
130 /* Change RastPort to the mode I need */
131 SetDrMd (rp, JAM1);
133 #endif
135 /* kprintf("*** Drawing Image %x. Next Image = %x\n widht = %d height = %d depth = %d planepick = %d planeonoff = %d\n",
136 image,image->NextImage,
137 image->Width,image->Height,image->Depth,image->PlanePick,image->PlaneOnOff);*/
140 planepick = image->PlanePick;
141 planeonoff = image->PlaneOnOff & ~planepick;
143 #if USE_FASTPLANEPICK0
145 if (planepick == 0)
147 SetAPen(rp, planeonoff);
148 RectFill(rp, leftOffset + image->LeftEdge,
149 topOffset + image->TopEdge,
150 leftOffset + image->LeftEdge + image->Width - 1,
151 topOffset + image->TopEdge + image->Height - 1);
153 image = image->NextImage;
154 continue;
157 #endif
159 /* Use x to store size of one image plane */
160 x = ((image->Width + 15) >> 4) * image->Height;
161 y = 0;
163 shift = 1;
165 #if USE_BLTBITMAPRASTPORT
167 struct BitMap bitmap;
168 int depth;
169 int imagedepth = image->Depth;
171 #if 0
172 /* The "8" (instead of image->Depth) seems to be correct,
173 as for example DOpus uses prop gadget knob images with
174 a depth of 0 (planepick 0, planeonoff color) */
176 depth = 8;
177 #else
178 /* That makes far more sense than just a 8
179 * R.Schmidt...still doesn`t resolve some weird icon problem i have
181 //depth = rp->BitMap->Depth;
184 ** Be system friendly. - Piru
186 depth = GetBitMapAttr(rp->BitMap, BMA_DEPTH);
187 if (depth > 8)
188 depth = 8;
189 #endif
190 InitBitMap(&bitmap, depth, image->Width, image->Height);
192 for(d = 0; d < depth; d++)
194 /* Don't use more planes than image->depth. This solves
195 corrupt images of Garshneblanker's FlyingToaster which
196 uses a PlanePick of 0xff. */
197 if ((imagedepth > 0) && (planepick & shift))
199 imagedepth--;
200 bitmap.Planes[d] = (PLANEPTR)(image->ImageData + (y++) * x);
202 else
204 bitmap.Planes[d] = (planeonoff & shift) ? (PLANEPTR)-1 : NULL;
206 shift <<= 1;
209 BltBitMapRastPort(&bitmap,
210 0, 0,
212 leftOffset + image->LeftEdge, topOffset + image->TopEdge,
213 image->Width, image->Height,
214 (state == IDS_SELECTED) ? 0x30 : 0xC0);
217 #else
220 for(d = 0; d < image->Depth;d++)
222 bits[d] = (planepick & shift) ? image->ImageData + (y++) * x : NULL;
223 shift <<= 1;
226 offset = 0;
228 yoff = image->TopEdge + topOffset;
230 for (y=0; y < image->Height; y++, yoff++)
233 bitmask = START_BITMASK;
235 xoff = image->LeftEdge + leftOffset;
237 for (x=0; x < image->Width; x++, xoff++)
239 pen = planeonoff;
240 shift = 1;
241 plane = 0;
243 for(d = 0; d < image->Depth; d++)
245 if (planepick & shift)
247 UWORD dat;
249 dat = bits[d][offset];
250 dat = AROS_WORD2BE(dat);
252 if (dat & bitmask)
254 pen |= shift;
258 shift <<= 1;
261 if (!x)
263 lastPen = pen;
264 Move (rp, xoff, yoff);
267 if (pen != lastPen)
269 SetAPen (rp, lastPen);
270 Draw (rp, xoff, yoff);
271 lastPen = pen;
274 bitmask >>= 1;
276 if (!bitmask)
278 bitmask = START_BITMASK;
279 offset ++;
282 } /* for (x=0; x < image->Width; x++, xoff++) */
284 SetAPen (rp, pen);
285 Draw (rp, xoff-1, yoff);
287 if (bitmask != START_BITMASK)
288 offset ++;
290 } /* for (y=0; y < image->Height; y++, yoff++) */
292 #endif
295 image = image->NextImage;
298 #ifdef __MORPHOS__
299 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,RPTAG_PenMode,penmode,TAG_DONE);
300 #else
301 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,TAG_DONE);
302 #endif
304 if (rp->Layer) UnlockLayer(rp->Layer);
306 AROS_LIBFUNC_EXIT
307 } /* DrawImageState */