home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / AROS / intuition / imageclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1978-03-06  |  11.0 KB  |  481 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: imageclass.c,v 1.6 1996/10/25 14:25:14 aros Exp $
  4.  
  5.     Desc: Implementation of IMAGECLASS
  6.     Lang: english
  7. */
  8. #ifdef _SASC
  9.  
  10. #define USE_SYSBASE
  11. #define USE_BUILTIN_MATH
  12. #define INTUI_V36_NAMES_ONLY
  13.  
  14. #endif
  15.  
  16. #include <exec/types.h>
  17.  
  18. #include <dos/dos.h>
  19. #include <dos/dosextens.h>
  20.  
  21. #include <intuition/intuition.h>
  22. #include <intuition/intuitionbase.h>
  23. #include <intuition/classes.h>
  24. #include <intuition/classusr.h>
  25. #include <intuition/imageclass.h>
  26. #include <intuition/cghooks.h>
  27. #include <intuition/icclass.h>
  28.  
  29. #include <graphics/gfxbase.h>
  30. #include <graphics/gfxmacros.h>
  31.  
  32. #include <utility/tagitem.h>
  33. #include <utility/hooks.h>
  34.  
  35. #include <clib/macros.h>
  36.  
  37. #include <string.h>
  38.  
  39. #ifdef _SASC
  40. #include <proto/exec.h>
  41. #include <proto/intuition.h>
  42. #include <proto/graphics.h>
  43. #include <proto/utility.h>
  44. #elif __GNUC__
  45. #include <clib/exec_protos.h>
  46. #include <clib/intuition_protos.h>
  47. #include <clib/graphics_protos.h>
  48. #include <clib/utility_protos.h>
  49. #endif
  50.  
  51. #ifdef _AROS
  52. #include <aros/asmcall.h>
  53. #include <clib/alib_protos.h>
  54. #include "intuition_intern.h"
  55. #endif
  56.  
  57. #if 0 /* This doesn't belong here, but don't loose it */
  58. /* Image data */
  59. #define ARROWDOWN_WIDTH    18
  60. #define ARROWDOWN_HEIGHT   11
  61.  
  62. UWORD ArrowDown0Data[] =
  63. {
  64.     0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000, 0x0C0C, 0x4000,
  65.     0x0738, 0x4000, 0x03F0, 0x4000, 0x01E0, 0x4000, 0x00C0, 0x4000,
  66.     0x0000, 0x4000, 0x0000, 0x4000, 0x7FFF, 0xC000,
  67.  
  68.     0xFFFF, 0x8000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  69.     0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  70.     0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  71. };
  72.  
  73. UWORD ArrowDown1Data[] =
  74. {
  75.     0xFFFF, 0x8000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8C0C, 0x0000,
  76.     0x8738, 0x0000, 0x83F0, 0x0000, 0x81E0, 0x0000, 0x80C0, 0x0000,
  77.     0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  78.  
  79.     0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000,
  80.     0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000,
  81.     0x0000, 0x4000, 0x0000, 0x4000, 0x7FFF, 0xC000,
  82. };
  83.  
  84. #define ARROWUP_WIDTH     18
  85. #define ARROWUP_HEIGHT     11
  86.  
  87. UWORD ArrowUp0Data[] =
  88. {
  89.     0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000, 0x00C0, 0x4000,
  90.     0x01E0, 0x4000, 0x03F0, 0x4000, 0x0738, 0x4000, 0x0C0C, 0x4000,
  91.     0x0000, 0x4000, 0x0000, 0x4000, 0x7FFF, 0xC000,
  92.  
  93.     0xFFFF, 0x8000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  94.     0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  95.     0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  96. };
  97.  
  98. UWORD ArrowUp1Data[] =
  99. {
  100.     0xFFFF, 0x8000, 0x8000, 0x0000, 0x8000, 0x0000, 0x80C0, 0x0000,
  101.     0x81E0, 0x0000, 0x83F0, 0x0000, 0x8738, 0x0000, 0x8C0C, 0x0000,
  102.     0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x0000,
  103.  
  104.     0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000,
  105.     0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000, 0x0000, 0x4000,
  106.     0x0000, 0x4000, 0x0000, 0x4000, 0x7FFF, 0xC000,
  107. };
  108.  
  109. #define ARROWLEFT_WIDTH    11
  110. #define ARROWLEFT_HEIGHT   16
  111.  
  112. UWORD ArrowLeft0Data[] =
  113. {
  114.     0x0000, 0x0020, 0x0020, 0x0120, 0x0320, 0x0620, 0x0E20, 0x1C20,
  115.     0x1C20, 0x0E20, 0x0620, 0x0320, 0x0120, 0x0020, 0x0020, 0xFFE0,
  116.  
  117.     0xFFE0, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
  118.     0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000,
  119. };
  120.  
  121. UWORD ArrowLeft1Data[] =
  122. {
  123.     0xFFE0, 0x8000, 0x8000, 0x8100, 0x8300, 0x8600, 0x8E00, 0x9C00,
  124.     0x9C00, 0x8E00, 0x8600, 0x8300, 0x8100, 0x8000, 0x8000, 0x0000,
  125.  
  126.     0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
  127.     0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0xFFE0,
  128. };
  129.  
  130. #define ARROWRIGHT_WIDTH    11
  131. #define ARROWRIGHT_HEIGHT   16
  132.  
  133. UWORD ArrowRight0Data[] =
  134. {
  135.     0x0000, 0x0020, 0x0020, 0x1020, 0x1820, 0x0C20, 0x0E20, 0x0720,
  136.     0x0720, 0x0E20, 0x0C20, 0x1820, 0x1020, 0x0020, 0x0020, 0xFFE0,
  137.  
  138.     0xFFE0, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
  139.     0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000,
  140. };
  141.  
  142. UWORD ArrowRight1Data[] =
  143. {
  144.     0xFFE0, 0x8000, 0x8000, 0x9000, 0x9800, 0x8C00, 0x8E00, 0x8700,
  145.     0x8700, 0x8E00, 0x8C00, 0x9800, 0x9000, 0x8000, 0x8000, 0x0000,
  146.  
  147.     0x0000, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
  148.     0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0xFFE0,
  149. };
  150.  
  151. #endif
  152.  
  153.  
  154. /****************************************************************************/
  155.  
  156. /* Set if to 1 to enable kprintf debugging
  157.  */
  158. #if 0
  159. #define D(x) x
  160. #else
  161. #define D(x)
  162. #endif
  163.  
  164. /* Some handy transparent base class object casting defines.
  165.  */
  166. #define G(o)  ((struct Gadget *)o)
  167. #define EG(o) ((struct ExtGadget *)o)
  168. #define IM(o) ((struct Image *)o)
  169.  
  170. /****************************************************************************/
  171.  
  172. /****************************************************************************/
  173.  
  174. #undef IntuitionBase
  175. #define IntuitionBase    ((struct IntuitionBase *)(cl->cl_UserData))
  176.  
  177. /* Our imageclass dispatcher.
  178.  */
  179. AROS_UFH3(static IPTR, dispatch_imageclass,
  180.     AROS_UFHA(Class *,  cl,  A0),
  181.     AROS_UFHA(Object *, o,   A2),
  182.     AROS_UFHA(Msg,      msg, A1)
  183. )
  184. {
  185.     IPTR retval = 0UL;
  186.  
  187.     switch (msg->MethodID)
  188.     {
  189.     case OM_NEW:
  190.     {
  191.     D(kprintf("ImageClass OM_NEW\n"));
  192.  
  193.     /*
  194.         We are paranoid, and will check validity of objects.
  195.         I believe the AmigaOS, at least at some level, allows NULL.
  196.     */
  197.  
  198.     if (o)
  199.     {
  200.         if (!cl)
  201.         cl = OCLASS(o);
  202.  
  203.         if (cl)
  204.         {
  205.         D( kprintf("ImageClass Instance Size; %ld bytes\n", SIZEOF_INSTANCE(cl)) );
  206.  
  207.         retval = (IPTR)DoSuperMethodA(cl, o, msg);
  208.  
  209.         if(retval)
  210.         {
  211.             /*
  212.             This is how Intuition knows an image is a boopsi
  213.             object!
  214.             */
  215.             memset ((void *)retval, 0, SIZEOF_INSTANCE(cl));
  216.             IM(retval)->Depth = CUSTOMIMAGEDEPTH;
  217.         }
  218.         }
  219.         D( else { kprintf("Class pointer is NULL\n") } );
  220.     }
  221.     D( else { kprintf("Carrier Object pointer is NULL\n") } );
  222.  
  223.     o = (Object *)retval;
  224.     /*
  225.         Fall through -> allow the class the set all the initial
  226.         attributes
  227.     */
  228.     }
  229.  
  230.     case OM_SET:
  231.     D( kprintf("ImageClass OM_SET\n") );
  232.  
  233.     if (o)
  234.     {
  235.         struct TagItem *tstate = ((struct opSet *)msg)->ops_AttrList;
  236.         struct TagItem *tag;
  237.         IPTR tidata;
  238.         BOOL unsupported;
  239.  
  240.         unsupported = FALSE;
  241.  
  242.         while ((tag = NextTagItem(&tstate)))
  243.         {
  244.         tidata = tag->ti_Data;
  245.  
  246.         switch (tag->ti_Tag)
  247.         {
  248.         case IA_Left:
  249.             IM(o)->LeftEdge = (WORD) tidata;
  250.             break;
  251.  
  252.         case IA_Top:
  253.             IM(o)->TopEdge = (WORD) tidata;
  254.             break;
  255.  
  256.         case IA_Width:
  257.             IM(o)->Width = (WORD) tidata;
  258.             break;
  259.  
  260.         case IA_Height:
  261.             IM(o)->Height = (WORD) tidata;
  262.             break;
  263.  
  264.         case IA_FGPen:
  265.             IM(o)->PlanePick = (WORD) tidata;
  266.             break;
  267.  
  268.         case IA_BGPen:
  269.             IM(o)->PlaneOnOff = (WORD) tidata;
  270.             break;
  271.  
  272.         case IA_Data:
  273.             IM(o)->ImageData = (UWORD *) tidata;
  274.             break;
  275.  
  276. #if 0 /* This doesn't belong here, but don't loose it */
  277.         case SYSIA_Which:
  278.             switch (tidata)
  279.             {
  280.             case DEPTHIMAGE:
  281.             case ZOOMIMAGE:
  282.             case SIZEIMAGE:
  283.             case CLOSEIMAGE:
  284.             case SDEPTHIMAGE:
  285.             IM(o)->ImageData = NULL;
  286.             unsupported = TRUE;
  287.             break;
  288.  
  289.             case LEFTIMAGE:
  290.             IM(o)->ImageData = ArrowLeft0Data;
  291.             IM(o)->Width     = ARROWLEFT_WIDTH;
  292.             IM(o)->Height    = ARROWLEFT_HEIGHT;
  293.             break;
  294.  
  295.             case UPIMAGE:
  296.             IM(o)->ImageData = ArrowUp0Data;
  297.             IM(o)->Width     = ARROWUP_WIDTH;
  298.             IM(o)->Height    = ARROWUP_HEIGHT;
  299.             break;
  300.  
  301.             case RIGHTIMAGE:
  302.             IM(o)->ImageData = ArrowRight0Data;
  303.             IM(o)->Width     = ARROWRIGHT_WIDTH;
  304.             IM(o)->Height    = ARROWRIGHT_HEIGHT;
  305.             break;
  306.  
  307.             case DOWNIMAGE:
  308.             IM(o)->ImageData = ArrowDown0Data;
  309.             IM(o)->Width     = ARROWDOWN_WIDTH;
  310.             IM(o)->Height    = ARROWDOWN_HEIGHT;
  311.             break;
  312.  
  313.             case CHECKIMAGE:
  314.             case MXIMAGE:
  315.             case MENUCHECK:
  316.             case AMIGAKEY:
  317.             IM(o)->ImageData = NULL;
  318.             unsupported = TRUE;
  319.             break;
  320.  
  321.             } /* Which image ? */
  322.  
  323.             break;
  324. #endif
  325.  
  326.         default:
  327.             unsupported = TRUE;
  328.             break;
  329.  
  330.         } /* switch (Tag) */
  331.         } /* while (Tag) */
  332.  
  333.         /*
  334.         If all attributes were supported and there is no retval yet,
  335.         set retval to 1.
  336.         */
  337.         if (!unsupported && !retval)
  338.         retval = 1UL;
  339.         /*
  340.         Because we are a direct subclass of rootclass
  341.         which has no settable/gettable attributes we
  342.         we will NOT pass this method to our superclass!
  343.         */
  344.     }
  345.     D( else { kprintf("Object pointer is NULL\n") } );
  346.     break;
  347.  
  348.     case OM_GET:
  349.     D( kprintf("ImageClass OM_GET\n") );
  350.  
  351.     if (o)
  352.     {
  353.         retval = 1UL;
  354.  
  355.         switch (((struct opGet *)msg)->opg_AttrID)
  356.         {
  357.         case IA_Left:
  358.         *((struct opGet *)msg)->opg_Storage = (IPTR) IM(o)->LeftEdge;
  359.         break;
  360.  
  361.         case IA_Top:
  362.         *((struct opGet *)msg)->opg_Storage = (IPTR) IM(o)->TopEdge;
  363.         break;
  364.  
  365.         case IA_Width:
  366.         *((struct opGet *)msg)->opg_Storage = (IPTR) IM(o)->Width;
  367.         break;
  368.  
  369.         case IA_Height:
  370.         *((struct opGet *)msg)->opg_Storage = (IPTR) IM(o)->Height;
  371.         break;
  372.  
  373.         case IA_FGPen:
  374.         *((struct opGet *)msg)->opg_Storage = (IPTR) IM(o)->PlanePick;
  375.         break;
  376.  
  377.         case IA_BGPen:
  378.         *((struct opGet *)msg)->opg_Storage = (IPTR) IM(o)->PlaneOnOff;
  379.         break;
  380.  
  381.         case IA_Data:
  382.         *((struct opGet *)msg)->opg_Storage = (IPTR) IM(o)->ImageData;
  383.         break;
  384.  
  385.         default:
  386.         retval = 0UL;
  387.         break;
  388.  
  389.         } /* switch */
  390.  
  391.         /*
  392.         Because we are a direct subclass of rootclass
  393.         which has no settable/gettable attributes we
  394.         we will NOT pass this method to our superclass!
  395.         */
  396.     }
  397.     break;
  398.  
  399.     case IM_ERASE:
  400.     /*
  401.         Both erase methods are documented as handled the same
  402.         at this level, so we will fall thru...
  403.     */
  404.     case IM_ERASEFRAME:
  405.     D(kprintf("ImageClass IM_ERASE(FRAME)\n") );
  406.  
  407.     if (o)
  408.     {
  409.         WORD left, top, width, height;
  410.  
  411.         left   = IM(o)->LeftEdge + ((struct impErase *)msg)->imp_Offset.X;
  412.         top    = IM(o)->TopEdge + ((struct impErase *)msg)->imp_Offset.Y;
  413.         width  = IM(o)->Width - 1;
  414.         height = IM(o)->Height - 1;
  415.  
  416.         EraseRect(((struct impErase *)msg)->imp_RPort,
  417.         left, top,
  418.         left + width, top + height
  419.         );
  420.  
  421.         /* Leave retval=0: No further rendering necessary */
  422.     } /* if */
  423.     break;
  424.  
  425.     case IM_HITTEST:
  426.     /*
  427.         Both hitmethods are documented as handled the same
  428.         at this level, so we will fall thru...
  429.     */
  430.     case IM_HITFRAME:
  431.     if(o)
  432.     {
  433.         struct impHitTest *imp = (struct impHitTest *)msg;
  434.  
  435.         /*
  436.         Loosing my sanity, better check that I do not have
  437.         have my X/Y mixed up here. :)
  438.         */
  439.         if( (imp->imp_Point.X >= IM(o)->LeftEdge && imp->imp_Point.X <= IM(o)->LeftEdge + IM(o)->Width) &&
  440.         (imp->imp_Point.Y >= IM(o)->TopEdge  && imp->imp_Point.Y <= IM(o)->TopEdge + IM(o)->Height)
  441.         )
  442.         {
  443.         retval = 1UL;
  444.         } /* if */
  445.     }
  446.     break;
  447.  
  448.     /* case OM_DISPOSE */
  449.     default:
  450.     retval = DoSuperMethodA(cl, o, msg);
  451.     break;
  452.  
  453.     } /* switch */
  454.  
  455.     return (retval);
  456. } /* dispatch_imageclass */
  457.  
  458. #undef IntuitionBase
  459.  
  460. /****************************************************************************/
  461.  
  462. /* Initialize our image class. */
  463. struct IClass *InitImageClass (struct IntuitionBase * IntuitionBase)
  464. {
  465.     struct IClass *cl = NULL;
  466.  
  467.     /* This is the code to make the image class...
  468.     */
  469.     if ((cl = MakeClass(IMAGECLASS, ROOTCLASS, NULL, sizeof(struct Image), 0)))
  470.     {
  471.     cl->cl_Dispatcher.h_Entry    = (APTR)AROS_ASMFUNC_NAME(dispatch_imageclass);
  472.     cl->cl_Dispatcher.h_SubEntry = NULL;
  473.     cl->cl_UserData          = (IPTR)IntuitionBase;
  474.  
  475.     AddClass (cl);
  476.     }
  477.  
  478.     return (cl);
  479. }
  480.  
  481.