some fixes to accented characters
[tangerine.git] / rom / intuition / drawimagestate.c
blob44aa336c6d90da6e400782de9c28ed2575563a8a
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, penmode;
81 EXTENDWORD(leftOffset);
82 EXTENDWORD(topOffset);
84 SANITY_CHECK(rp)
85 SANITY_CHECK(image)
87 if (rp->Layer) LockLayer(0,rp->Layer);
89 /* Store important variables of the RastPort */
90 #ifdef __MORPHOS__
91 GetRPAttrs(rp,RPTAG_PenMode,(ULONG)&penmode,RPTAG_APen,(ULONG)&apen,
92 RPTAG_BPen,(ULONG)&bpen,RPTAG_DrMd,(ULONG)&drmd,TAG_DONE);
93 #else
94 GetRPAttrs(rp,RPTAG_APen,(ULONG)&apen,
95 RPTAG_BPen,(ULONG)&bpen,RPTAG_DrMd,(ULONG)&drmd,TAG_DONE);
96 #endif
98 while(image)
100 if (image->Depth == CUSTOMIMAGEDEPTH)
102 struct impDraw method;
104 method.MethodID = IM_DRAW;
105 method.imp_RPort = rp;
106 method.imp_Offset.X = leftOffset;
107 method.imp_Offset.Y = topOffset;
108 method.imp_State = state;
109 method.imp_DrInfo = drawInfo;
110 DoMethodA ((Object *)image, (Msg)&method);
112 else
114 WORD x, y, d;
115 UWORD shift;
116 ULONG planeonoff, planepick;
118 #if !USE_BLTBITMAPRASTPORT
120 ULONG lastPen = 0;
121 ULONG pen = 0;
122 UWORD offset;
123 UWORD bitmask;
124 UWORD * bits[8];
125 WORD xoff, yoff, plane;
127 #define START_BITMASK 0x8000
129 /* Change RastPort to the mode I need */
130 SetDrMd (rp, JAM1);
132 #endif
134 /* kprintf("*** Drawing Image %x. Next Image = %x\n widht = %d height = %d depth = %d planepick = %d planeonoff = %d\n",
135 image,image->NextImage,
136 image->Width,image->Height,image->Depth,image->PlanePick,image->PlaneOnOff);*/
139 planepick = image->PlanePick;
140 planeonoff = image->PlaneOnOff & ~planepick;
142 #if USE_FASTPLANEPICK0
144 if (planepick == 0)
146 SetAPen(rp, planeonoff);
147 RectFill(rp, leftOffset + image->LeftEdge,
148 topOffset + image->TopEdge,
149 leftOffset + image->LeftEdge + image->Width - 1,
150 topOffset + image->TopEdge + image->Height - 1);
152 image = image->NextImage;
153 continue;
156 #endif
158 /* Use x to store size of one image plane */
159 x = ((image->Width + 15) >> 4) * image->Height;
160 y = 0;
162 shift = 1;
164 #if USE_BLTBITMAPRASTPORT
166 struct BitMap bitmap;
167 int depth;
169 #if 0
170 /* The "8" (instead of image->Depth) seems to be correct,
171 as for example DOpus uses prop gadget knob images with
172 a depth of 0 (planepick 0, planeonoff color) */
174 depth = 8;
175 #else
176 /* That makes far more sense than just a 8
177 * R.Schmidt...still doesn`t resolve some weird icon problem i have
179 //depth = rp->BitMap->Depth;
182 ** Be system friendly. - Piru
184 depth = GetBitMapAttr(rp->BitMap, BMA_DEPTH);
185 if (depth > 8)
186 depth = 8;
187 #endif
188 InitBitMap(&bitmap, depth, image->Width, image->Height);
190 for(d = 0; d < depth; d++)
192 if (planepick & shift)
194 bitmap.Planes[d] = (PLANEPTR)(image->ImageData + (y++) * x);
196 else
198 bitmap.Planes[d] = (planeonoff & shift) ? (PLANEPTR)-1 : NULL;
200 shift <<= 1;
203 BltBitMapRastPort(&bitmap,
204 0, 0,
206 leftOffset + image->LeftEdge, topOffset + image->TopEdge,
207 image->Width, image->Height,
208 0xC0);
211 #else
214 for(d = 0; d < image->Depth;d++)
216 bits[d] = (planepick & shift) ? image->ImageData + (y++) * x : NULL;
217 shift <<= 1;
220 offset = 0;
222 yoff = image->TopEdge + topOffset;
224 for (y=0; y < image->Height; y++, yoff++)
227 bitmask = START_BITMASK;
229 xoff = image->LeftEdge + leftOffset;
231 for (x=0; x < image->Width; x++, xoff++)
233 pen = planeonoff;
234 shift = 1;
235 plane = 0;
237 for(d = 0; d < image->Depth; d++)
239 if (planepick & shift)
241 UWORD dat;
243 dat = bits[d][offset];
244 dat = AROS_WORD2BE(dat);
246 if (dat & bitmask)
248 pen |= shift;
252 shift <<= 1;
255 if (!x)
257 lastPen = pen;
258 Move (rp, xoff, yoff);
261 if (pen != lastPen)
263 SetAPen (rp, lastPen);
264 Draw (rp, xoff, yoff);
265 lastPen = pen;
268 bitmask >>= 1;
270 if (!bitmask)
272 bitmask = START_BITMASK;
273 offset ++;
276 } /* for (x=0; x < image->Width; x++, xoff++) */
278 SetAPen (rp, pen);
279 Draw (rp, xoff-1, yoff);
281 if (bitmask != START_BITMASK)
282 offset ++;
284 } /* for (y=0; y < image->Height; y++, yoff++) */
286 #endif
289 image = image->NextImage;
292 #ifdef __MORPHOS__
293 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,RPTAG_PenMode,penmode,TAG_DONE);
294 #else
295 SetRPAttrs(rp,RPTAG_APen,apen,RPTAG_BPen,bpen,RPTAG_DrMd,drmd,TAG_DONE);
296 #endif
298 if (rp->Layer) UnlockLayer(rp->Layer);
300 AROS_LIBFUNC_EXIT
301 } /* DrawImageState */