home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / disk utilities / backup / backup_restore / backup_src_v3.20.lha / ScaledImageClass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-27  |  6.6 KB  |  261 lines

  1. // ScaledImageClass.c
  2. // 27 Jul 1996 11:26:02
  3.  
  4.  
  5. #include <exec/types.h>
  6. #include <graphics/gfxmacros.h>
  7. #include <graphics/gfxbase.h>
  8. #include <graphics/text.h>
  9. #include <graphics/rpattr.h>
  10. #include <graphics/scale.h>
  11. #include <libraries/dos.h>
  12. #include <libraries/iffparse.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/intuitionBase.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <intuition/imageclass.h>
  17. #include <intuition/icclass.h>
  18. #include <intuition/screens.h>
  19. #include <proto/all.h>
  20. #include <clib/alib_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <pragmas/utility_pragmas.h>
  23. #include <dos.h>
  24. #include <assert.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29. #include <limits.h>
  30. #include <stddef.h>
  31. #include <stdarg.h>
  32. #include <math.h>
  33.  
  34.  
  35. #define    d(x)    ;
  36. #define    d2(x)    x;
  37. #define    d3(x)    ;
  38.  
  39.  
  40. struct ScaledImageINST
  41.     {
  42.     struct BitMap *sii_ScaledBitMap;
  43.     };
  44.  
  45. // The functions in this module
  46. static ULONG __saveds __interrupt dispatchScaledImageClass(Class *cl, Object *o, Msg msg);
  47. static BOOL InitScaledImage(struct ScaledImageINST *inst, const struct opSet *ops, const struct Image *NewImage);
  48. static void DisposeScaledImage(struct ScaledImageINST *inst);
  49. static void DrawScaledImage(struct ScaledImageINST *inst, struct impDraw *Msg, struct Image *myImage);
  50.  
  51.  
  52. Class *ScaledImageClass;
  53.  
  54.  
  55. /***********************************************************/
  56. /**    Make the class and set up the dispatcher's hook    **/
  57. /***********************************************************/
  58. Class *initScaledImageClass(void)
  59. {
  60.     Class *cl;
  61.     extern ULONG HookEntry();     /* defined in amiga.lib */
  62.  
  63.     if ( cl =  MakeClass( NULL,
  64.             (STRPTR) IMAGECLASS, NULL,
  65.             sizeof(struct ScaledImageINST),
  66.             0 ))
  67.         {
  68.         // initialize the cl_Dispatcher Hook
  69.         cl->cl_Dispatcher.h_Entry = HookEntry;
  70.         cl->cl_Dispatcher.h_SubEntry = dispatchScaledImageClass;
  71.         }
  72.     return ( cl );
  73. }
  74.  
  75. /***********************************************************/
  76. /******************     Free the class      ****************/
  77. /***********************************************************/
  78. BOOL freeScaledImageClass( Class *cl )
  79. {
  80.     return (FreeClass(cl));
  81. }
  82.  
  83. /**************************************************************************/
  84. /**********       The ScaledImageCLASS class dispatcher      *********/
  85. /**************************************************************************/
  86. static ULONG __saveds __interrupt dispatchScaledImageClass(Class *cl, Object *o, Msg msg)
  87. {
  88.     struct ScaledImageINST *inst;
  89.     ULONG retval;
  90.     Object *object;
  91.  
  92.     d3(kprintf(__FUNC__ "/%ld  Class=%l08x  SuperClass=%08lx  Method=%08lx\n", __LINE__, cl, cl->cl_Super, msg->MethodID));
  93.  
  94.     switch (msg->MethodID)
  95.         {
  96.     case OM_NEW:       /* First, pass up to superclass */
  97.         if (object = (Object *) DoSuperMethodA(cl, o, msg))
  98.             {
  99.             struct opSet *ops = (struct opSet *) msg;
  100.  
  101.             /* Initial local instance data */
  102.             inst = INST_DATA(cl, object);
  103.  
  104.             d(kprintf(__FUNC__ "/%ld: Left=%ld  Top=%ld\n", __LINE__, \
  105.                 ((struct Image *) object)->LeftEdge, ((struct Image *) object)->TopEdge));
  106.  
  107.             if (!InitScaledImage(inst, ops, (struct Image *) object))
  108.                 {
  109.                 DisposeObject(object);
  110.                 object = NULL;
  111.                 }
  112.  
  113.             retval = (ULONG) object;
  114.             d(kprintf("OM_NEW: %08lx\n", inst);)
  115.             }
  116.         break;
  117.  
  118.     case OM_DISPOSE:
  119.         d(kprintf("OM_DISPOSE: %08lx\n", inst);)
  120.  
  121.         inst = INST_DATA(cl, o);
  122.  
  123.         DisposeScaledImage(inst);
  124.  
  125.         DoSuperMethodA(cl, o, msg);
  126.         break;
  127.  
  128.     case IM_DRAW:
  129.         d(kprintf(__FUNC__ "/%ld: IM_DRAW  State=%ld\n", __LINE__, ((struct impDraw *) msg)->imp_State));
  130.  
  131.         inst = INST_DATA(cl, o);
  132.  
  133.         DrawScaledImage(inst, (struct impDraw *) msg, (struct Image *) o);
  134.         break;
  135.  
  136.     default:    /* ScaledImageCLASS does not recognize the methodID, let the superclass's */
  137.             /* dispatcher take a look at it. */
  138.         d3(kprintf(__FUNC__ "/%ld: Class=%08lx  Obj=%08lx  msg=%08lx  Method=%08lx\n", __LINE__, cl, o, msg, msg->MethodID));
  139.         retval = DoSuperMethodA(cl, o, msg);
  140.         d(kprintf(__FUNC__ "/%ld\n", __LINE__));
  141.         break;
  142.         }
  143.  
  144.     d3(kprintf(__FUNC__ "/%ld  retval=%l08x\n", __LINE__, retval));
  145.  
  146.     return(retval);
  147. }
  148.  
  149.  
  150. static BOOL InitScaledImage(struct ScaledImageINST *inst, const struct opSet *ops, const struct Image *NewImage)
  151. {
  152.     struct Image *SourceImage;
  153.     struct RastPort SourceRP;
  154.     struct BitMap *SourceBM;
  155.     struct BitScaleArgs ScaleArgs;
  156.     UWORD BMWidth, BMHeight;
  157.  
  158.     inst->sii_ScaledBitMap = NULL;
  159.  
  160.     SourceImage = (struct Image *) GetTagData(IA_Data, NULL, ops->ops_AttrList);
  161.     if (NULL == SourceImage)
  162.         return FALSE;
  163.  
  164.     SourceBM = AllocBitMap(SourceImage->Width, SourceImage->Height, SourceImage->Depth, BMF_CLEAR|BMF_DISPLAYABLE, NULL);
  165.     if (NULL == SourceBM)
  166.         return FALSE;
  167.  
  168.     InitRastPort(&SourceRP);
  169.     SourceRP.BitMap = SourceBM;
  170.  
  171.     // NewImage wird über SourceRP in SourceBM gezeichnet
  172.     DrawImage(&SourceRP, SourceImage, -SourceImage->LeftEdge, -SourceImage->TopEdge);
  173.  
  174.     BMWidth = ScalerDiv(SourceImage->Width, NewImage->Width, SourceImage->Width);
  175.     BMHeight = ScalerDiv(SourceImage->Height, NewImage->Height, SourceImage->Height);
  176.  
  177.     inst->sii_ScaledBitMap = AllocBitMap(BMWidth, BMHeight, SourceImage->Depth, BMF_CLEAR|BMF_DISPLAYABLE, NULL);
  178.     if (NULL == inst->sii_ScaledBitMap)
  179.         {
  180.         FreeBitMap(SourceBM);
  181.         return FALSE;
  182.         }
  183.  
  184.     ScaleArgs.bsa_SrcX = ScaleArgs.bsa_DestX = 0;
  185.     ScaleArgs.bsa_SrcY = ScaleArgs.bsa_DestY = 0;
  186.  
  187.     ScaleArgs.bsa_SrcWidth = SourceImage->Width;
  188.     ScaleArgs.bsa_SrcHeight = SourceImage->Height;
  189.  
  190.     ScaleArgs.bsa_XSrcFactor = SourceImage->Width;
  191.     ScaleArgs.bsa_XDestFactor = NewImage->Width;
  192.  
  193.     ScaleArgs.bsa_YSrcFactor = SourceImage->Height;
  194.     ScaleArgs.bsa_YDestFactor = NewImage->Height;
  195.  
  196.     ScaleArgs.bsa_SrcBitMap = SourceBM;
  197.     ScaleArgs.bsa_DestBitMap = inst->sii_ScaledBitMap;
  198.  
  199.     ScaleArgs.bsa_Flags = 0;
  200.  
  201.     BitMapScale(&ScaleArgs);
  202.     WaitBlit();
  203.  
  204.     FreeBitMap(SourceBM);
  205.  
  206.     return TRUE;
  207. }
  208.  
  209.  
  210. static void DisposeScaledImage(struct ScaledImageINST *inst)
  211. {
  212.     if (inst->sii_ScaledBitMap)
  213.         {
  214.         FreeBitMap(inst->sii_ScaledBitMap);
  215.         inst->sii_ScaledBitMap = NULL;
  216.         }
  217. }
  218.  
  219.  
  220. static void DrawScaledImage(struct ScaledImageINST *inst, struct impDraw *Msg, struct Image *myImage)
  221. {
  222.     if (inst->sii_ScaledBitMap)
  223.         {
  224.         struct RastPort *rp = Msg->imp_RPort;
  225.         short x = myImage->LeftEdge + Msg->imp_Offset.X;
  226.         short y = myImage->TopEdge + Msg->imp_Offset.Y;
  227.  
  228.         BltBitMapRastPort(inst->sii_ScaledBitMap,
  229.                 0, 0,
  230.                 rp,
  231.                 x, y,
  232.                 myImage->Width, myImage->Height,
  233.                 (ABC|ABNC)
  234.                 );
  235.  
  236.         switch (Msg->imp_State)
  237.             {
  238.         case IDS_NORMAL:
  239.         case IDS_SELECTED:
  240.             break;
  241.  
  242.         case IDS_INACTIVEDISABLED:
  243.         case IDS_SELECTEDDISABLED:
  244.         case IDS_DISABLED:
  245.             {
  246.             // jetzt "DISABLED" Markierung zu Fuß nachholen!
  247.             static USHORT myPattern[] =
  248.                 { 0x8888, 0x2222 };
  249.  
  250.             SetABPenDrMd(rp, 1, 0, JAM1);
  251.             SetAfPt(rp, myPattern, 1);
  252.             RectFill(rp, x, y,
  253.                 x + myImage->Width - 1,
  254.                 y + myImage->Height - 1);
  255.             }
  256.             break;
  257.             }
  258.         }
  259. }
  260.  
  261.