Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / muimaster / classes / dtpic.c
blob410b398f20cfc4c54212d751993e2b311f742b70
1 /*
2 Copyright © 2002-2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /* Dtpic.mui. Source based on the one from MUIUndoc */
8 #define MUIMASTER_YES_INLINE_STDARG
10 #include <stdio.h>
11 #include <stdlib.h>
13 #include <graphics/gfx.h>
14 #include <graphics/view.h>
15 #include <clib/alib_protos.h>
17 #include <datatypes/datatypesclass.h>
18 #include <datatypes/pictureclass.h>
19 #include <cybergraphx/cybergraphics.h>
21 #include <proto/exec.h>
22 #include <proto/graphics.h>
23 #include <proto/cybergraphics.h>
24 #include <proto/utility.h>
25 #include <proto/intuition.h>
26 #include <proto/muimaster.h>
27 #include <proto/datatypes.h>
29 #include <string.h>
31 /* #define MYDEBUG 1 */
32 #include "debug.h"
34 #include "mui.h"
35 #include "muimaster_intern.h"
36 #include "support.h"
37 #include "support_classes.h"
38 #include "dtpic_private.h"
40 extern struct Library *MUIMasterBase;
42 #ifdef DataTypesBase
43 #undef DataTypesBase
44 #endif
46 #define DataTypesBase data->datatypesbase
48 static void killdto(struct Dtpic_DATA *data)
50 data->bm = NULL;
51 data->bmhd = NULL;
53 if (data->dto)
55 DisposeDTObject(data->dto);
56 data->dto = NULL;
59 if (data->datatypesbase)
61 CloseLibrary(data->datatypesbase);
67 * We copy the filename, as the file is opened later in setup and
68 * not at once.
70 IPTR Dtpic__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
72 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
74 if (obj)
76 struct Dtpic_DATA *data = INST_DATA(cl, obj);
77 struct TagItem *tags = msg->ops_AttrList;
78 struct TagItem *tag;
80 while ((tag = NextTagItem((const struct TagItem**)&tags)) != NULL)
82 switch (tag->ti_Tag)
84 case MUIA_Dtpic_Name:
85 data->name = (STRPTR) AllocVec((ULONG) (strlen((char *)tag->ti_Data)+1) * sizeof(char),MEMF_ANY);
86 strcpy((char *)data->name,(char *)tag->ti_Data);
87 break;
92 return (IPTR)obj;
95 IPTR setup_datatype(struct IClass *cl, Object *obj)
97 struct Dtpic_DATA *data = INST_DATA(cl, obj);
99 if (data->dto) killdto(data); /* Object already existed */
101 if (data->name)
103 if ((data->datatypesbase = OpenLibrary("datatypes.library", 39)))
105 /* Prevent DOS Requesters from showing up */
107 struct Process *me = (struct Process *)FindTask(0);
108 APTR oldwinptr = me->pr_WindowPtr;
110 me->pr_WindowPtr = (APTR)-1;
112 data->dto = NewDTObject(data->name, DTA_GroupID, GID_PICTURE,
113 OBP_Precision, PRECISION_IMAGE,
114 PDTA_Screen, _screen(obj),
115 PDTA_DestMode, PMODE_V43,
116 PDTA_UseFriendBitMap, TRUE,
117 TAG_DONE);
118 me->pr_WindowPtr = oldwinptr;
120 if (data->dto)
122 struct FrameInfo fri = {0};
124 DoMethod(data->dto, DTM_FRAMEBOX, 0, &fri, &fri, sizeof(struct FrameInfo), 0);
126 if (fri.fri_Dimensions.Depth > 0)
129 if (DoMethod(data->dto, DTM_PROCLAYOUT, 0, 1))
132 get(data->dto, PDTA_BitMapHeader, &data->bmhd);
134 if (data->bmhd)
136 if (data->bmhd->bmh_Masking != mskNone)
137 set(obj, MUIA_FillArea, TRUE);
138 else
139 set(obj, MUIA_FillArea, FALSE);
141 GetDTAttrs(data->dto, PDTA_DestBitMap, &data->bm, TAG_DONE);
143 if (!data->bm)
145 GetDTAttrs(data->dto, PDTA_BitMap, &data->bm, TAG_DONE);
148 if (data->bm) return TRUE;
150 } /* if (data->bmhd) */
152 } /* if (DoMethod(data->dto, DTM_PROCLAYOUT, 0, 1)) */
154 } /* if (fri.fri_Dimensions.Depth > 0) */
156 } /* if (data->dto) */
158 } /* if ((data->datatypesbase = OpenLibrary("datatypes.library", 39))) */
160 } /* if (data->name) */
162 killdto(data);
165 return TRUE;
167 IPTR Dtpic__MUIM_Setup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
169 if (!DoSuperMethodA(cl, obj, (Msg)msg)) return FALSE;
171 return setup_datatype(cl, obj);
174 IPTR Dtpic__MUIM_Cleanup(struct IClass *cl, Object *obj, struct MUIP_Cleanup *msg)
176 struct Dtpic_DATA *data = INST_DATA(cl, obj);
178 killdto(data);
180 return DoSuperMethodA(cl,obj,(Msg)msg);
183 IPTR Dtpic__MUIM_AskMinMax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
185 struct Dtpic_DATA *data = INST_DATA(cl, obj);
186 IPTR retval;
188 retval = DoSuperMethodA(cl, obj, (Msg) msg);
190 if (data->bm)
192 msg->MinMaxInfo->MinWidth += data->bmhd->bmh_Width;
193 msg->MinMaxInfo->MinHeight += data->bmhd->bmh_Height;
194 msg->MinMaxInfo->DefWidth += data->bmhd->bmh_Width;
195 msg->MinMaxInfo->DefHeight += data->bmhd->bmh_Height;
196 msg->MinMaxInfo->MaxWidth += data->bmhd->bmh_Width;
197 msg->MinMaxInfo->MaxHeight += data->bmhd->bmh_Height;
200 return retval;
203 IPTR Dtpic__MUIM_Draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
205 struct Dtpic_DATA *data = INST_DATA(cl, obj);
207 DoSuperMethodA(cl, obj, (Msg)msg);
209 if ((msg->flags & MADF_DRAWOBJECT) && data->bm)
211 /* Note: codes taken from picture.datatype GM_RENDER routine */
212 ULONG depth = (ULONG) GetBitMapAttr(_rp(obj)->BitMap, BMA_DEPTH);
214 if ((depth >= 15) && (data->bmhd->bmh_Masking == mskHasAlpha))
216 /* Transparency on high color rast port with alpha channel in picture*/
217 ULONG * img = (ULONG *) AllocVec(_mwidth(obj) * _mheight(obj) * 4, MEMF_ANY);
218 if (img)
220 struct pdtBlitPixelArray pa;
221 pa.MethodID = PDTM_READPIXELARRAY;
222 pa.pbpa_PixelData = (UBYTE *) img;
223 pa.pbpa_PixelFormat = PBPAFMT_ARGB;
224 pa.pbpa_PixelArrayMod = _mwidth(obj) * 4;
225 pa.pbpa_Left = 0;
226 pa.pbpa_Top = 0;
227 pa.pbpa_Width = _mwidth(obj);
228 pa.pbpa_Height = _mheight(obj);
229 if(DoMethodA(data->dto, (Msg) &pa))
230 WritePixelArrayAlpha(img, 0, 0, _mwidth(obj) * 4, _rp(obj), _mleft(obj), _mtop(obj), _mwidth(obj), _mheight(obj), 0xffffffff);
231 FreeVec((APTR) img);
234 else
236 if (data->bmhd->bmh_Masking == mskHasMask)
238 /* Transparency with mask */
239 APTR mask = NULL;
241 GetDTAttrs(data->dto, PDTA_MaskPlane, (IPTR)&mask, TAG_DONE);
243 if (mask)
244 BltMaskBitMapRastPort(data->bm, 0, 0, _rp(obj), _mleft(obj),
245 _mtop(obj), _mwidth(obj), _mheight(obj), 0xE0, (PLANEPTR)mask);
247 else
249 /* All other cases */
250 BltBitMapRastPort(data->bm, 0, 0, _rp(obj), _mleft(obj), _mtop(obj),
251 _mwidth(obj), _mheight(obj), 0xC0);
256 return 0;
259 IPTR Dtpic__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
261 struct Dtpic_DATA *data = INST_DATA(cl, obj);
263 if(data->name)
264 FreeVec(data->name);
266 return DoSuperMethodA(cl, obj, msg);
269 IPTR Dtpic__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
271 struct Dtpic_DATA *data = INST_DATA(cl, obj);
272 struct TagItem *tags = msg->ops_AttrList;
273 struct TagItem *tag;
274 ULONG needs_redraw = 0;
276 while ((tag = NextTagItem((const struct TagItem**)&tags)) != NULL)
278 switch (tag->ti_Tag)
280 case MUIA_Dtpic_Name:
281 if (!data->name || strcmp(data->name, (char *)tag->ti_Data)) /* If no filename or different filenames */
283 if (data->name) FreeVec(data->name);
284 data->name = (STRPTR) AllocVec((ULONG) (strlen((char *)tag->ti_Data)+1) * sizeof(char), MEMF_ANY);
285 strcpy((char *)data->name,(char *)tag->ti_Data);
286 if (_flags(obj) & MADF_SETUP) setup_datatype(cl, obj); /* Run immediate setup only if base class is setup up */
287 needs_redraw = 1;
289 break;
293 if (needs_redraw)
295 MUI_Redraw(obj,MADF_DRAWOBJECT);
298 return DoSuperMethodA(cl, obj, (Msg)msg);
301 IPTR Dtpic__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
303 struct Dtpic_DATA *data = INST_DATA(cl, obj);
305 switch(msg->opg_AttrID)
307 case MUIA_Dtpic_Name:
308 *(msg->opg_Storage) = (IPTR)data->name;
309 return TRUE;
312 return DoSuperMethodA(cl, obj, (Msg)msg);
315 #if ZUNE_BUILTIN_DTPIC
316 BOOPSI_DISPATCHER(IPTR, Dtpic_Dispatcher, cl, obj, msg)
318 switch (msg->MethodID)
320 case OM_NEW: return Dtpic__OM_NEW(cl, obj, (struct opSet *)msg);
321 case MUIM_Setup: return Dtpic__MUIM_Setup(cl, obj, (struct MUIP_Setup *)msg);
322 case MUIM_Cleanup: return Dtpic__MUIM_Cleanup(cl, obj, (struct MUIP_Clean *)msg);
323 case MUIM_AskMinMax: return Dtpic__MUIM_AskMinMax(cl, obj, (struct MUIP_AskMinMax *)msg);
324 case MUIM_Draw: return Dtpic__MUIM_Draw(cl, obj, (struct MUIP_Draw *)msg);
325 case OM_DISPOSE: return Dtpic__OM_DISPOSE(cl, obj, msg);
326 case OM_SET: return Dtpic__OM_SET(cl, obj, (struct opSet *)msg);
327 case OM_GET: return Dtpic__OM_GET(cl, obj, (struct opGet *)msg);
328 default: return DoSuperMethodA(cl, obj, msg);
331 BOOPSI_DISPATCHER_END
333 const struct __MUIBuiltinClass _MUI_Dtpic_desc =
335 MUIC_Dtpic,
336 MUIC_Area,
337 sizeof(struct Dtpic_DATA),
338 (void*)Dtpic_Dispatcher
340 #endif /* ZUNE_BUILTIN_DTPIC */