2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
10 #include <intuition/imageclass.h>
11 #include <graphics/gfx.h>
12 #include <graphics/view.h>
13 #include <clib/alib_protos.h>
14 #include <proto/exec.h>
15 #include <proto/graphics.h>
16 #include <proto/utility.h>
17 #include <proto/intuition.h>
18 #include <proto/muimaster.h>
22 /* #define MYDEBUG 1 */
25 #include "muimaster_intern.h"
27 #include "support_classes.h"
29 #include "imagedisplay_private.h"
31 extern struct Library
*MUIMasterBase
;
33 #define MIF_FREEVERT (1<<0)
34 #define MIF_FREEHORIZ (1<<1)
37 IPTR
Imagedisplay__OM_NEW(struct IClass
*cl
, Object
*obj
,
40 struct Imagedisplay_DATA
*data
;
41 struct TagItem
*tag
, *tags
;
43 D(bug("Imagedisplay_New starts\n"));
45 obj
= (Object
*) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
49 data
= INST_DATA(cl
, obj
);
50 data
->flags
= MIF_FREEHORIZ
| MIF_FREEVERT
;
52 /* parse initial taglist */
54 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
58 case MUIA_Imagedisplay_Spec
:
59 data
->spec
= zune_image_spec_duplicate(tag
->ti_Data
);
62 case MUIA_Imagedisplay_UseDefSize
:
63 _handle_bool_tag(data
->flags
, (!tag
->ti_Data
),
64 (MIF_FREEHORIZ
| MIF_FREEVERT
));
67 case MUIA_Imagedisplay_FreeHoriz
:
68 /* MUI implements some tag for optionnally prevent rescaling
69 * of displayed image - without affecting imagedisplay resize -
70 * see MUIPrefs/Buttons/Checkmarks/Look for nonrescaled image,
71 * and try a popimage for yourself to see that by default they
72 * get rescaled. It's not the same effect as MUI_Image_FreeHoriz.
75 _handle_bool_tag(data
->flags
, tag
->ti_Data
, MIF_FREEHORIZ
);
78 case MUIA_Imagedisplay_FreeVert
:
79 _handle_bool_tag(data
->flags
, tag
->ti_Data
, MIF_FREEVERT
);
86 data
->spec
= StrDup("0:128");
91 CoerceMethod(cl
, obj
, OM_DISPOSE
);
95 D(bug("Imagedisplay_New(%lx) spec=%lx\n", obj
, data
->img
));
99 IPTR
Imagedisplay__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
101 struct Imagedisplay_DATA
*data
= INST_DATA(cl
, obj
);
103 zune_image_spec_free(data
->spec
);
104 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
108 IPTR
Imagedisplay__OM_SET(struct IClass
*cl
, Object
*obj
,
111 struct Imagedisplay_DATA
*data
= INST_DATA(cl
, obj
);
112 struct TagItem
*tag
, *tags
;
114 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
118 case MUIA_Imagedisplay_Spec
:
120 zune_image_spec_free(data
->spec
);
121 data
->spec
= zune_image_spec_duplicate(tag
->ti_Data
);
123 if (_flags(obj
) & MADF_CANDRAW
)
124 zune_imspec_hide(data
->img
);
126 if (_flags(obj
) & MADF_SETUP
)
128 zune_imspec_cleanup(data
->img
);
130 zune_imspec_setup((IPTR
) data
->spec
,
134 if (_flags(obj
) & MADF_CANDRAW
)
135 zune_imspec_show(data
->img
, obj
);
137 MUI_Redraw(obj
, MADF_DRAWOBJECT
);
142 return (IPTR
) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
145 IPTR
Imagedisplay__OM_GET(struct IClass
*cl
, Object
*obj
,
148 struct Imagedisplay_DATA
*data
= INST_DATA(cl
, obj
);
149 switch (msg
->opg_AttrID
)
151 case MUIA_Imagedisplay_Spec
:
152 *msg
->opg_Storage
= (IPTR
) data
->spec
;
156 return (IPTR
) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
159 IPTR
Imagedisplay__MUIM_Setup(struct IClass
*cl
, Object
*obj
,
160 struct MUIP_Setup
*msg
)
162 struct Imagedisplay_DATA
*data
= INST_DATA(cl
, obj
);
164 if (!DoSuperMethodA(cl
, obj
, (Msg
) msg
))
169 zune_imspec_setup((IPTR
) data
->spec
, muiRenderInfo(obj
));
173 IPTR
Imagedisplay__MUIM_Cleanup(struct IClass
*cl
, Object
*obj
,
174 struct MUIP_Cleanup
*msg
)
176 struct Imagedisplay_DATA
*data
= INST_DATA(cl
, obj
);
179 zune_imspec_cleanup(data
->img
);
180 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
183 IPTR
Imagedisplay__MUIM_AskMinMax(struct IClass
*cl
, Object
*obj
,
184 struct MUIP_AskMinMax
*msg
)
186 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
188 msg
->MinMaxInfo
->MinWidth
+= 3;
189 msg
->MinMaxInfo
->MinHeight
+= 3;
191 msg
->MinMaxInfo
->DefWidth
+= 16;
192 msg
->MinMaxInfo
->DefHeight
+= 16;
194 msg
->MinMaxInfo
->MaxWidth
= MUI_MAXMAX
;
195 msg
->MinMaxInfo
->MaxHeight
= MUI_MAXMAX
;
200 IPTR
Imagedisplay__MUIM_Show(struct IClass
*cl
, Object
*obj
,
201 struct MUIP_Show
*msg
)
203 struct Imagedisplay_DATA
*data
= INST_DATA(cl
, obj
);
205 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
208 zune_imspec_show(data
->img
, obj
);
212 IPTR
Imagedisplay__MUIM_Hide(struct IClass
*cl
, Object
*obj
,
213 struct MUIP_Hide
*msg
)
215 struct Imagedisplay_DATA
*data
= INST_DATA(cl
, obj
);
218 zune_imspec_hide(data
->img
);
220 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
223 IPTR
Imagedisplay__MUIM_Draw(struct IClass
*cl
, Object
*obj
,
224 struct MUIP_Draw
*msg
)
226 struct Imagedisplay_DATA
*data
= INST_DATA(cl
, obj
);
228 DoSuperMethodA(cl
, obj
, (Msg
) msg
);
230 if (!(msg
->flags
& MADF_DRAWOBJECT
))
235 WORD left
, top
, width
, height
;
240 width
= _mwidth(obj
);
241 height
= _mheight(obj
);
243 /* if either horiz or vert is not rescalable, center it at def size */
244 if (!(data
->flags
& MIF_FREEVERT
) || !(data
->flags
& MIF_FREEHORIZ
))
246 struct MUI_MinMax minmax
;
248 zune_imspec_askminmax(data
->img
, &minmax
);
249 data
->defwidth
= minmax
.DefWidth
;
250 data
->defheight
= minmax
.DefHeight
;
252 if (!(data
->flags
& MIF_FREEVERT
) && (height
> data
->defheight
))
254 WORD freespace
= height
- data
->defheight
;
256 top
+= freespace
/ 2;
257 height
= data
->defheight
;
260 if (!(data
->flags
& MIF_FREEHORIZ
) && (width
> data
->defwidth
))
262 WORD freespace
= width
- data
->defwidth
;
264 left
+= freespace
/ 2;
265 width
= data
->defwidth
;
270 struct MUI_MinMax minmax
;
272 zune_imspec_askminmax(data
->img
, &minmax
);
274 if (width
> minmax
.MaxWidth
)
276 width
= minmax
.MaxWidth
;
277 left
= _mleft(obj
) + (_mwidth(obj
) - width
) / 2;
280 if (height
> minmax
.MaxHeight
)
282 height
= minmax
.MaxHeight
;
283 top
= _mtop(obj
) + (_mheight(obj
) - height
) / 2;
287 clip
= MUI_AddClipping(muiRenderInfo(obj
), _mleft(obj
), _mtop(obj
),
288 _mwidth(obj
), _mheight(obj
));
289 zune_imspec_draw(data
->img
, muiRenderInfo(obj
),
290 left
, top
, width
, height
, 0, 0, IDS_NORMAL
);
291 MUI_RemoveClipping(muiRenderInfo(obj
), clip
);
297 IPTR
Imagedisplay__MUIM_DragQuery(struct IClass
*cl
, Object
*obj
,
298 struct MUIP_DragQuery
*msg
)
303 return MUIV_DragQuery_Refuse
;
304 if (get(msg
->obj
, MUIA_Imagedisplay_Spec
, &dummy
)
305 || get(msg
->obj
, MUIA_Pendisplay_Spec
, &dummy
))
306 return MUIV_DragQuery_Accept
;
307 return MUIV_DragQuery_Refuse
;
310 IPTR
Imagedisplay__MUIM_DragDrop(struct IClass
*cl
, Object
*obj
,
311 struct MUIP_DragDrop
*msg
)
315 if (get(msg
->obj
, MUIA_Imagedisplay_Spec
, &spec
))
317 set(obj
, MUIA_Imagedisplay_Spec
, spec
);
319 else if (get(msg
->obj
, MUIA_Pendisplay_Spec
, &spec
))
324 strncpy(buf
+ 2, (const char *)spec
, 64);
326 set(obj
, MUIA_Imagedisplay_Spec
, (IPTR
) buf
);
332 #if ZUNE_BUILTIN_IMAGEDISPLAY
333 BOOPSI_DISPATCHER(IPTR
, Imagedisplay_Dispatcher
, cl
, obj
, msg
)
335 switch (msg
->MethodID
)
338 return Imagedisplay__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
340 return Imagedisplay__OM_DISPOSE(cl
, obj
, msg
);
342 return Imagedisplay__OM_SET(cl
, obj
, (APTR
) msg
);
344 return Imagedisplay__OM_GET(cl
, obj
, (APTR
) msg
);
346 return Imagedisplay__MUIM_AskMinMax(cl
, obj
, (APTR
) msg
);
348 return Imagedisplay__MUIM_Setup(cl
, obj
, (APTR
) msg
);
350 return Imagedisplay__MUIM_Cleanup(cl
, obj
, (APTR
) msg
);
352 return Imagedisplay__MUIM_Show(cl
, obj
, (APTR
) msg
);
354 return Imagedisplay__MUIM_Hide(cl
, obj
, (APTR
) msg
);
356 return Imagedisplay__MUIM_Draw(cl
, obj
, (APTR
) msg
);
358 return Imagedisplay__MUIM_DragQuery(cl
, obj
, (APTR
) msg
);
360 return Imagedisplay__MUIM_DragDrop(cl
, obj
, (APTR
) msg
);
362 return DoSuperMethodA(cl
, obj
, msg
);
365 BOOPSI_DISPATCHER_END
367 const struct __MUIBuiltinClass _MUI_Imagedisplay_desc
=
371 sizeof(struct Imagedisplay_DATA
),
372 (void *) Imagedisplay_Dispatcher
374 #endif /* ZUNE_BUILTIN_IMAGEDISPLAY */