2 Copyright © 2002-2009, The AROS Development Team. All rights reserved.
6 /* Dtpic.mui. Source based on the one from MUIUndoc */
8 #define MUIMASTER_YES_INLINE_STDARG
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>
31 /* #define MYDEBUG 1 */
35 #include "muimaster_intern.h"
37 #include "support_classes.h"
38 #include "dtpic_private.h"
40 extern struct Library
*MUIMasterBase
;
46 #define DataTypesBase data->datatypesbase
48 static void killdto(struct Dtpic_DATA
*data
)
55 DisposeDTObject(data
->dto
);
59 if (data
->datatypesbase
)
61 CloseLibrary(data
->datatypesbase
);
67 * We copy the filename, as the file is opened later in setup and
70 IPTR
Dtpic__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
72 obj
= (Object
*)DoSuperMethodA(cl
, obj
, (Msg
)msg
);
76 struct Dtpic_DATA
*data
= INST_DATA(cl
, obj
);
77 struct TagItem
*tags
= msg
->ops_AttrList
;
80 while ((tag
= NextTagItem((const struct TagItem
**)&tags
)) != NULL
)
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
);
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 */
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
,
118 me
->pr_WindowPtr
= oldwinptr
;
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
);
136 if (data
->bmhd
->bmh_Masking
!= mskNone
)
137 set(obj
, MUIA_FillArea
, TRUE
);
139 set(obj
, MUIA_FillArea
, FALSE
);
141 GetDTAttrs(data
->dto
, PDTA_DestBitMap
, &data
->bm
, TAG_DONE
);
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) */
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
);
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
);
188 retval
= DoSuperMethodA(cl
, obj
, (Msg
) msg
);
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
;
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
);
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;
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);
236 if (data
->bmhd
->bmh_Masking
== mskHasMask
)
238 /* Transparency with mask */
241 GetDTAttrs(data
->dto
, PDTA_MaskPlane
, (IPTR
)&mask
, TAG_DONE
);
244 BltMaskBitMapRastPort(data
->bm
, 0, 0, _rp(obj
), _mleft(obj
),
245 _mtop(obj
), _mwidth(obj
), _mheight(obj
), 0xE0, (PLANEPTR
)mask
);
249 /* All other cases */
250 BltBitMapRastPort(data
->bm
, 0, 0, _rp(obj
), _mleft(obj
), _mtop(obj
),
251 _mwidth(obj
), _mheight(obj
), 0xC0);
259 IPTR
Dtpic__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
261 struct Dtpic_DATA
*data
= INST_DATA(cl
, obj
);
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
;
274 ULONG needs_redraw
= 0;
276 while ((tag
= NextTagItem((const struct TagItem
**)&tags
)) != NULL
)
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 */
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
;
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
=
337 sizeof(struct Dtpic_DATA
),
338 (void*)Dtpic_Dispatcher
340 #endif /* ZUNE_BUILTIN_DTPIC */