home *** CD-ROM | disk | FTP | other *** search
- // ScaledImageClass.c
- // 27 Jul 1996 11:26:02
-
-
- #include <exec/types.h>
- #include <graphics/gfxmacros.h>
- #include <graphics/gfxbase.h>
- #include <graphics/text.h>
- #include <graphics/rpattr.h>
- #include <graphics/scale.h>
- #include <libraries/dos.h>
- #include <libraries/iffparse.h>
- #include <intuition/intuition.h>
- #include <intuition/intuitionBase.h>
- #include <intuition/gadgetclass.h>
- #include <intuition/imageclass.h>
- #include <intuition/icclass.h>
- #include <intuition/screens.h>
- #include <proto/all.h>
- #include <clib/alib_protos.h>
- #include <clib/utility_protos.h>
- #include <pragmas/utility_pragmas.h>
- #include <dos.h>
- #include <assert.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <limits.h>
- #include <stddef.h>
- #include <stdarg.h>
- #include <math.h>
-
-
- #define d(x) ;
- #define d2(x) x;
- #define d3(x) ;
-
-
- struct ScaledImageINST
- {
- struct BitMap *sii_ScaledBitMap;
- };
-
- // The functions in this module
- static ULONG __saveds __interrupt dispatchScaledImageClass(Class *cl, Object *o, Msg msg);
- static BOOL InitScaledImage(struct ScaledImageINST *inst, const struct opSet *ops, const struct Image *NewImage);
- static void DisposeScaledImage(struct ScaledImageINST *inst);
- static void DrawScaledImage(struct ScaledImageINST *inst, struct impDraw *Msg, struct Image *myImage);
-
-
- Class *ScaledImageClass;
-
-
- /***********************************************************/
- /** Make the class and set up the dispatcher's hook **/
- /***********************************************************/
- Class *initScaledImageClass(void)
- {
- Class *cl;
- extern ULONG HookEntry(); /* defined in amiga.lib */
-
- if ( cl = MakeClass( NULL,
- (STRPTR) IMAGECLASS, NULL,
- sizeof(struct ScaledImageINST),
- 0 ))
- {
- // initialize the cl_Dispatcher Hook
- cl->cl_Dispatcher.h_Entry = HookEntry;
- cl->cl_Dispatcher.h_SubEntry = dispatchScaledImageClass;
- }
- return ( cl );
- }
-
- /***********************************************************/
- /****************** Free the class ****************/
- /***********************************************************/
- BOOL freeScaledImageClass( Class *cl )
- {
- return (FreeClass(cl));
- }
-
- /**************************************************************************/
- /********** The ScaledImageCLASS class dispatcher *********/
- /**************************************************************************/
- static ULONG __saveds __interrupt dispatchScaledImageClass(Class *cl, Object *o, Msg msg)
- {
- struct ScaledImageINST *inst;
- ULONG retval;
- Object *object;
-
- d3(kprintf(__FUNC__ "/%ld Class=%l08x SuperClass=%08lx Method=%08lx\n", __LINE__, cl, cl->cl_Super, msg->MethodID));
-
- switch (msg->MethodID)
- {
- case OM_NEW: /* First, pass up to superclass */
- if (object = (Object *) DoSuperMethodA(cl, o, msg))
- {
- struct opSet *ops = (struct opSet *) msg;
-
- /* Initial local instance data */
- inst = INST_DATA(cl, object);
-
- d(kprintf(__FUNC__ "/%ld: Left=%ld Top=%ld\n", __LINE__, \
- ((struct Image *) object)->LeftEdge, ((struct Image *) object)->TopEdge));
-
- if (!InitScaledImage(inst, ops, (struct Image *) object))
- {
- DisposeObject(object);
- object = NULL;
- }
-
- retval = (ULONG) object;
- d(kprintf("OM_NEW: %08lx\n", inst);)
- }
- break;
-
- case OM_DISPOSE:
- d(kprintf("OM_DISPOSE: %08lx\n", inst);)
-
- inst = INST_DATA(cl, o);
-
- DisposeScaledImage(inst);
-
- DoSuperMethodA(cl, o, msg);
- break;
-
- case IM_DRAW:
- d(kprintf(__FUNC__ "/%ld: IM_DRAW State=%ld\n", __LINE__, ((struct impDraw *) msg)->imp_State));
-
- inst = INST_DATA(cl, o);
-
- DrawScaledImage(inst, (struct impDraw *) msg, (struct Image *) o);
- break;
-
- default: /* ScaledImageCLASS does not recognize the methodID, let the superclass's */
- /* dispatcher take a look at it. */
- d3(kprintf(__FUNC__ "/%ld: Class=%08lx Obj=%08lx msg=%08lx Method=%08lx\n", __LINE__, cl, o, msg, msg->MethodID));
- retval = DoSuperMethodA(cl, o, msg);
- d(kprintf(__FUNC__ "/%ld\n", __LINE__));
- break;
- }
-
- d3(kprintf(__FUNC__ "/%ld retval=%l08x\n", __LINE__, retval));
-
- return(retval);
- }
-
-
- static BOOL InitScaledImage(struct ScaledImageINST *inst, const struct opSet *ops, const struct Image *NewImage)
- {
- struct Image *SourceImage;
- struct RastPort SourceRP;
- struct BitMap *SourceBM;
- struct BitScaleArgs ScaleArgs;
- UWORD BMWidth, BMHeight;
-
- inst->sii_ScaledBitMap = NULL;
-
- SourceImage = (struct Image *) GetTagData(IA_Data, NULL, ops->ops_AttrList);
- if (NULL == SourceImage)
- return FALSE;
-
- SourceBM = AllocBitMap(SourceImage->Width, SourceImage->Height, SourceImage->Depth, BMF_CLEAR|BMF_DISPLAYABLE, NULL);
- if (NULL == SourceBM)
- return FALSE;
-
- InitRastPort(&SourceRP);
- SourceRP.BitMap = SourceBM;
-
- // NewImage wird über SourceRP in SourceBM gezeichnet
- DrawImage(&SourceRP, SourceImage, -SourceImage->LeftEdge, -SourceImage->TopEdge);
-
- BMWidth = ScalerDiv(SourceImage->Width, NewImage->Width, SourceImage->Width);
- BMHeight = ScalerDiv(SourceImage->Height, NewImage->Height, SourceImage->Height);
-
- inst->sii_ScaledBitMap = AllocBitMap(BMWidth, BMHeight, SourceImage->Depth, BMF_CLEAR|BMF_DISPLAYABLE, NULL);
- if (NULL == inst->sii_ScaledBitMap)
- {
- FreeBitMap(SourceBM);
- return FALSE;
- }
-
- ScaleArgs.bsa_SrcX = ScaleArgs.bsa_DestX = 0;
- ScaleArgs.bsa_SrcY = ScaleArgs.bsa_DestY = 0;
-
- ScaleArgs.bsa_SrcWidth = SourceImage->Width;
- ScaleArgs.bsa_SrcHeight = SourceImage->Height;
-
- ScaleArgs.bsa_XSrcFactor = SourceImage->Width;
- ScaleArgs.bsa_XDestFactor = NewImage->Width;
-
- ScaleArgs.bsa_YSrcFactor = SourceImage->Height;
- ScaleArgs.bsa_YDestFactor = NewImage->Height;
-
- ScaleArgs.bsa_SrcBitMap = SourceBM;
- ScaleArgs.bsa_DestBitMap = inst->sii_ScaledBitMap;
-
- ScaleArgs.bsa_Flags = 0;
-
- BitMapScale(&ScaleArgs);
- WaitBlit();
-
- FreeBitMap(SourceBM);
-
- return TRUE;
- }
-
-
- static void DisposeScaledImage(struct ScaledImageINST *inst)
- {
- if (inst->sii_ScaledBitMap)
- {
- FreeBitMap(inst->sii_ScaledBitMap);
- inst->sii_ScaledBitMap = NULL;
- }
- }
-
-
- static void DrawScaledImage(struct ScaledImageINST *inst, struct impDraw *Msg, struct Image *myImage)
- {
- if (inst->sii_ScaledBitMap)
- {
- struct RastPort *rp = Msg->imp_RPort;
- short x = myImage->LeftEdge + Msg->imp_Offset.X;
- short y = myImage->TopEdge + Msg->imp_Offset.Y;
-
- BltBitMapRastPort(inst->sii_ScaledBitMap,
- 0, 0,
- rp,
- x, y,
- myImage->Width, myImage->Height,
- (ABC|ABNC)
- );
-
- switch (Msg->imp_State)
- {
- case IDS_NORMAL:
- case IDS_SELECTED:
- break;
-
- case IDS_INACTIVEDISABLED:
- case IDS_SELECTEDDISABLED:
- case IDS_DISABLED:
- {
- // jetzt "DISABLED" Markierung zu Fuß nachholen!
- static USHORT myPattern[] =
- { 0x8888, 0x2222 };
-
- SetABPenDrMd(rp, 1, 0, JAM1);
- SetAfPt(rp, myPattern, 1);
- RectFill(rp, x, y,
- x + myImage->Width - 1,
- y + myImage->Height - 1);
- }
- break;
- }
- }
- }
-
-