6 #include <exec/types.h>
7 #include <graphics/gels.h>
8 #include <graphics/gfxmacros.h>
9 #include <graphics/rastport.h>
10 #include <intuition/classes.h>
11 #include <intuition/classusr.h>
12 #include <intuition/imageclass.h>
13 #include <intuition/newmouse.h>
14 #include <utility/hooks.h>
15 #include <libraries/gadtools.h>
16 #include <datatypes/pictureclass.h>
17 #include <workbench/workbench.h>
18 #include <workbench/startup.h>
19 #include <cybergraphx/cybergraphics.h>
20 #include <dos/dostags.h>
21 #include <dos/datetime.h>
25 #include <proto/dos.h>
26 #include <proto/exec.h>
27 #include <proto/layers.h>
28 #include <proto/intuition.h>
29 #include <proto/graphics.h>
30 #include <proto/utility.h>
31 #include <proto/locale.h>
32 #include <proto/cybergraphics.h>
33 #include <proto/gadtools.h>
34 #include <proto/datatypes.h>
36 #include <proto/scalos.h>
38 #include <clib/alib_protos.h>
41 #include <scalos/scalos.h>
42 #include <scalos/GadgetBar.h>
48 #include "scalos_structures.h"
49 #include "DtImageClass.h"
50 #include "functions.h"
51 #include "Variables.h"
53 //----------------------------------------------------------------------------
55 // local data definitions
57 struct DtImageClassInst
59 struct DatatypesImage
*bmicl_DtImage
;
60 struct DatatypesImage
*bmicl_SelDtImage
;
61 struct DatatypesImage
*bmicl_DisabledDtImage
;
64 //----------------------------------------------------------------------------
68 static SAVEDS(IPTR
) INTERRUPT
DtImageClassDispatcher(Class
*cl
, Object
*o
, Msg msg
);
69 static IPTR
DtImage_New(Class
*cl
, Object
*o
, Msg msg
);
70 static ULONG
DtImage_Dispose(Class
*cl
, Object
*o
, Msg msg
);
71 static ULONG
DtImage_Draw(Class
*cl
, Object
*o
, Msg msg
);
72 static ULONG
DtImage_Get(Class
*cl
, Object
*o
, Msg msg
);
74 //----------------------------------------------------------------------------
76 // public data items :
78 //----------------------------------------------------------------------------
80 Class
*initDtImageClass(void)
84 DtImageClass
= MakeClass( NULL
,
87 sizeof(struct DtImageClassInst
),
92 // initialize the cl_Dispatcher Hook
93 SETHOOKFUNC(DtImageClass
->cl_Dispatcher
, DtImageClassDispatcher
);
99 //----------------------------------------------------------------------------
101 static SAVEDS(IPTR
) INTERRUPT
DtImageClassDispatcher(Class
*cl
, Object
*o
, Msg msg
)
105 switch (msg
->MethodID
)
108 Result
= DtImage_New(cl
, o
, msg
);
111 Result
= DtImage_Dispose(cl
, o
, msg
);
114 Result
= DtImage_Draw(cl
, o
, msg
);
117 Result
= DtImage_Get(cl
, o
, msg
);
120 Result
= DoSuperMethodA(cl
, o
, msg
);
127 //----------------------------------------------------------------------------
129 static IPTR
DtImage_New(Class
*cl
, Object
*o
, Msg msg
)
131 struct opSet
*ops
= (struct opSet
*) msg
;
132 struct DtImageClassInst
*inst
;
133 CONST_STRPTR ImageName
;
136 o
= (Object
*) DoSuperMethodA(cl
, o
, msg
);
137 d1(KPrintF("%s/%s/%ld: o=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, o
));
141 inst
= INST_DATA(cl
, o
);
143 memset(inst
, 0, sizeof(struct DtImageClassInst
));
145 ImageName
= (CONST_STRPTR
) GetTagData(DTIMG_ImageName
, (IPTR
) "", ops
->ops_AttrList
);
146 d1(KPrintF("%s/%s/%ld: o=%08lx ImageName=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, o
, ImageName
));
148 inst
->bmicl_DtImage
= CreateDatatypesImage(ImageName
, 0);
149 d1(KPrintF("%s/%s/%ld: bmicl_DtImage=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, inst
->bmicl_DtImage
));
150 if (NULL
== inst
->bmicl_DtImage
)
152 DoMethod(o
, OM_DISPOSE
);
156 // Selected image is optional
157 ImageName
= (CONST_STRPTR
) GetTagData(DTIMG_SelImageName
, (IPTR
) "", ops
->ops_AttrList
);
158 d1(KPrintF("%s/%s/%ld: o=%08lx SelImageName=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, o
, ImageName
));
160 if (ImageName
&& strlen(ImageName
) > 0)
161 inst
->bmicl_SelDtImage
= CreateDatatypesImage(ImageName
, 0);
162 d1(KPrintF("%s/%s/%ld: bmicl_SelDtImage=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, inst
->bmicl_SelDtImage
));
164 // Disabled image is optional
165 ImageName
= (CONST_STRPTR
) GetTagData(DTIMG_DisabledImageName
, (IPTR
) "", ops
->ops_AttrList
);
166 d1(KPrintF("%s/%s/%ld: o=%08lx DisabledImageName=<%s>\n", __FILE__
, __FUNC__
, __LINE__
, o
, ImageName
));
168 if (ImageName
&& strlen(ImageName
) > 0)
169 inst
->bmicl_DisabledDtImage
= CreateDatatypesImage(ImageName
, 0);
170 d1(KPrintF("%s/%s/%ld: bmicl_DisabledDtImage=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, inst
->bmicl_DisabledDtImage
));
174 // set dimensions in superclass
175 Width
= inst
->bmicl_DtImage
->dti_BitMapHeader
->bmh_Width
;
176 Height
= inst
->bmicl_DtImage
->dti_BitMapHeader
->bmh_Height
;
178 if (inst
->bmicl_SelDtImage
)
180 // use largest dimensions of normal and selected images
181 if (inst
->bmicl_SelDtImage
->dti_BitMapHeader
->bmh_Width
> Width
)
182 Width
= inst
->bmicl_SelDtImage
->dti_BitMapHeader
->bmh_Width
;
183 if (inst
->bmicl_SelDtImage
->dti_BitMapHeader
->bmh_Height
> Height
)
184 Height
= inst
->bmicl_SelDtImage
->dti_BitMapHeader
->bmh_Height
;
195 //----------------------------------------------------------------------------
197 static ULONG
DtImage_Dispose(Class
*cl
, Object
*o
, Msg msg
)
199 struct DtImageClassInst
*inst
= INST_DATA(cl
, o
);
201 d1(KPrintF("%s/%s/%ld: o=%08lx bmicl_DtImage=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, o
, inst
->bmicl_DtImage
));
203 DisposeDatatypesImage(&inst
->bmicl_DtImage
);
204 DisposeDatatypesImage(&inst
->bmicl_SelDtImage
);
205 DisposeDatatypesImage(&inst
->bmicl_DisabledDtImage
);
207 return DoSuperMethodA(cl
, o
, msg
);
210 //----------------------------------------------------------------------------
212 static ULONG
DtImage_Draw(Class
*cl
, Object
*o
, Msg msg
)
214 struct impDraw
*imp
= (struct impDraw
*) msg
;
215 struct DtImageClassInst
*inst
= INST_DATA(cl
, o
);
216 struct Image
*img
= (struct Image
*) o
;
217 struct DatatypesImage
*dtImg
;
219 d1(KPrintF("%s/%s/%ld: o=%08lx Left=%ld Top=%ld\n", __FILE__
, __FUNC__
, __LINE__
, o
, img
->LeftEdge
, img
->TopEdge
));
220 d1(KPrintF("%s/%s/%ld: Width=%ld Height=%ld imp_State=%ld\n", __FILE__
, __FUNC__
, __LINE__
, img
->Width
, img
->Height
, imp
->imp_State
));
221 d1(KPrintF("%s/%s/%ld: bmicl_SelDtImage=%08lx\n", __FILE__
, __FUNC__
, __LINE__
, inst
->bmicl_SelDtImage
));
223 if ((IDS_SELECTED
== imp
->imp_State
) && inst
->bmicl_SelDtImage
)
225 dtImg
= inst
->bmicl_SelDtImage
;
227 else if ((IDS_DISABLED
== imp
->imp_State
) && inst
->bmicl_DisabledDtImage
)
229 dtImg
= inst
->bmicl_DisabledDtImage
;
233 dtImg
= inst
->bmicl_DtImage
;
240 x
= img
->LeftEdge
+ imp
->imp_Offset
.X
;
241 y
= img
->TopEdge
+ imp
->imp_Offset
.Y
;
243 // if normal and selected images have different dimensions, center image in bounding rectangle
244 x
+= (img
->Width
- dtImg
->dti_BitMapHeader
->bmh_Width
) / 2;
245 y
+= (img
->Height
- dtImg
->dti_BitMapHeader
->bmh_Height
) / 2;
247 d1(kprintf("%s/%s/%ld: x=%ld y=%ld\n", __FILE__
, __FUNC__
, __LINE__
, x
, y
));
253 dtImg
->dti_BitMapHeader
->bmh_Width
,
254 dtImg
->dti_BitMapHeader
->bmh_Height
258 if ((IDS_DISABLED
== imp
->imp_State
) && NULL
== inst
->bmicl_DisabledDtImage
)
260 static UWORD myPattern
[] =
264 x
= img
->LeftEdge
+ imp
->imp_Offset
.X
;
265 y
= img
->TopEdge
+ imp
->imp_Offset
.Y
;
267 // if normal and selected images have different dimensions, center image in bounding rectangle
268 x
+= (img
->Width
- dtImg
->dti_BitMapHeader
->bmh_Width
) / 2;
269 y
+= (img
->Height
- dtImg
->dti_BitMapHeader
->bmh_Height
) / 2;
271 SetABPenDrMd(imp
->imp_RPort
, 1, 0, JAM1
);
272 SetAfPt(imp
->imp_RPort
, myPattern
, 1);
274 RectFill(imp
->imp_RPort
, x
, y
,
276 y
+ img
->Height
- 1);
279 d1(kprintf("%s/%s/%ld: END\n", __FILE__
, __FUNC__
, __LINE__
));
284 //----------------------------------------------------------------------------
286 static ULONG
DtImage_Get(Class
*cl
, Object
*o
, Msg msg
)
288 struct opGet
*opg
= (struct opGet
*) msg
;
289 struct DtImageClassInst
*inst
= INST_DATA(cl
, o
);
292 if (NULL
== opg
->opg_Storage
)
295 switch (opg
->opg_AttrID
)
297 case IA_SupportsDisable
:
298 *(opg
->opg_Storage
) = (ULONG
) (NULL
!= inst
->bmicl_DisabledDtImage
);
301 Result
= DoSuperMethodA(cl
, o
, msg
);
308 //----------------------------------------------------------------------------