home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / intuition / imageclass.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  11KB  |  474 lines

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