home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / MUI / MCC_NList / Developer / C / Examples / NList-Demo3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-30  |  6.7 KB  |  268 lines

  1.  
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <dos/dos.h>
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <exec/ports.h>
  9. #include <exec/io.h>
  10. #include <libraries/dos.h>
  11. #include <libraries/dosextens.h>
  12. #include <libraries/gadtools.h>
  13. #include <libraries/asl.h>
  14. #include <libraries/mui.h>
  15. #include <devices/clipboard.h>
  16. #include <workbench/workbench.h>
  17. #include <intuition/intuition.h>
  18. #include <intuition/classusr.h>
  19. #include <graphics/gfxmacros.h>
  20.  
  21. #ifdef __GNUC__
  22. #include <proto/alib.h>
  23. #include <proto/exec.h>
  24. #include <proto/dos.h>
  25. #include <proto/gadtools.h>
  26. #include <proto/asl.h>
  27. #include <clib/muimaster_protos.h>
  28. #endif
  29.  
  30. #ifdef __SASC
  31. #include <clib/alib_protos.h>
  32. #include <clib/exec_protos.h>
  33. #include <clib/dos_protos.h>
  34. #include <clib/icon_protos.h>
  35. #include <clib/graphics_protos.h>
  36. #include <clib/intuition_protos.h>
  37. #include <clib/gadtools_protos.h>
  38. #include <clib/utility_protos.h>
  39. #include <clib/asl_protos.h>
  40. #define REG(x) register __ ## x
  41. #define ASM    __asm
  42. #define SAVEDS __saveds
  43. #include <pragmas/exec_sysbase_pragmas.h>
  44. #include <pragmas/dos_pragmas.h>
  45. #include <pragmas/icon_pragmas.h>
  46. #include <pragmas/graphics_pragmas.h>
  47. #include <pragmas/intuition_pragmas.h>
  48. #include <pragmas/gadtools_pragmas.h>
  49. #include <pragmas/utility_pragmas.h>
  50. #include <pragmas/asl_pragmas.h>
  51. #include <pragmas/muimaster_pragmas.h>
  52. extern struct Library *SysBase,*IntuitionBase,*UtilityBase,*GfxBase,*DOSBase,*IconBase;
  53. #endif
  54.  
  55. extern struct Library *MUIMasterBase;
  56.  
  57. #include <MUI/NListview_mcc.h>
  58. #include <MUI/NFloattext_mcc.h>
  59.  
  60. #include "NList-Demo3.h"
  61.  
  62.  
  63. #ifdef __SASC
  64. #include <proto/muimaster.h>
  65. #endif
  66.  
  67.  
  68. /* *********************************************** */
  69.  
  70.  
  71. struct MUI_CustomClass *NLI_Class = NULL;
  72.  
  73.  
  74. /* *********************************************** */
  75.  
  76.  
  77. struct NLIData
  78. {
  79.   LONG special;
  80.   LONG EntryCurrent;
  81.   LONG EntryHeight;
  82. };
  83.  
  84.  
  85. /* *********************************************** */
  86.  
  87.  
  88. ULONG mNLI_Draw(struct IClass *cl,Object *obj,struct MUIP_Draw *msg)
  89. {
  90.   register struct NLIData *data = INST_DATA(cl,obj);
  91.   DoSuperMethodA(cl,obj,(Msg) msg);
  92.   if ((msg->flags & MADF_DRAWOBJECT) || (msg->flags & MADF_DRAWUPDATE))
  93.   { WORD x1,x2,x3,x4,x5,y1,y2,y3,y4,y5;
  94.     y1 = _top(obj);
  95.     y2 = _bottom(obj);
  96.     x1 = _left(obj);
  97.     x2 = _right(obj);
  98.     if ((data->special == 0) || (data->special == 1))
  99.     {
  100.       y3 = (y1+y2)/2;
  101.       x3 = (x1+x2)/2;
  102.       SetAPen(_rp(obj),_pens(obj)[MPEN_MARK]);
  103.       SetBPen(_rp(obj),_pens(obj)[MPEN_SHADOW]);
  104.       SetDrMd(_rp(obj),JAM2);
  105.       SetDrPt(_rp(obj),(UWORD) ~0);
  106.       if      (data->special == 0)
  107.       { Move(_rp(obj), x3-2, y1+1);
  108.         Draw(_rp(obj), x3-2, y2-1);
  109.         Move(_rp(obj), x3, y1+1);
  110.         Draw(_rp(obj), x3, y2-1);
  111.         Move(_rp(obj), x3+2, y1+1);
  112.         Draw(_rp(obj), x3+2, y2-1);
  113.       }
  114.       else if (data->special == 1)
  115.       { Move(_rp(obj), x1, y3-2);
  116.         Draw(_rp(obj), x2, y3-2);
  117.         Move(_rp(obj), x1, y3);
  118.         Draw(_rp(obj), x2, y3);
  119.         Move(_rp(obj), x1, y3+2);
  120.         Draw(_rp(obj), x2, y3+2);
  121.       }
  122.       SetAPen(_rp(obj),_pens(obj)[MPEN_SHADOW]);
  123.       Move(_rp(obj), x1, y2-1);
  124.       Draw(_rp(obj), x1, y1+1);
  125.       Draw(_rp(obj), x2, y1+1);
  126.       SetAPen(_rp(obj),_pens(obj)[MPEN_SHINE]);
  127.       Draw(_rp(obj), x2, y2-1);
  128.       Draw(_rp(obj), x1, y2-1);
  129.       SetDrMd(_rp(obj),JAM1);
  130.     }
  131.     else if (((x2 - x1) >= 10) && ((y2 - y1) >= 8))   /* and special==2 to 9 */
  132.     {
  133.       y3 = (y1+y2)/2;
  134.       x3 = x1 + 1;
  135.       x2--;
  136.       SetAPen(_rp(obj),_pens(obj)[MPEN_SHADOW]);
  137.       SetDrMd(_rp(obj),JAM1);
  138.  
  139.       y4 = y1;
  140.       x4 = x3 + 2;
  141.       y5 = y2;
  142.       x5 = x2-6;
  143.       if ((data->EntryHeight & 1) && (data->EntryCurrent & 1))
  144.         y4++;
  145.       if ((y4 & 1) != (y3 & 1))
  146.         x4--;
  147.       if (data->special > 5)
  148.         x5 = x2;
  149.       if (data->special & 1)
  150.         y5 = y3;
  151.       while (y4 <= y5)
  152.       { WritePixel(_rp(obj), x3, y4);
  153.         y4 += 2;
  154.       }
  155.       if (data->special <= 7)
  156.       {
  157.         while (x4 <= x5)
  158.         { WritePixel(_rp(obj), x4, y3);
  159.           x4 += 2;
  160.         }
  161.       }
  162.       if (data->special <= 5)
  163.       {
  164.         Move(_rp(obj), x2-6, y3);
  165.         Draw(_rp(obj), x2-6, y3-3);
  166.         Draw(_rp(obj),   x2, y3-3);
  167.         Draw(_rp(obj),   x2, y3+3);
  168.         Draw(_rp(obj), x2-6, y3+3);
  169.         Draw(_rp(obj), x2-6, y3);
  170.         Move(_rp(obj), x2-4, y3);
  171.         Draw(_rp(obj), x2-2, y3);
  172.         if ((data->special == 2) || (data->special == 3))
  173.         { Move(_rp(obj), x2-3, y3-1);
  174.           Draw(_rp(obj), x2-3, y3+1);
  175.         }
  176.       }
  177.     }
  178.   }
  179.   msg->flags = 0;
  180.   return(0);
  181. }
  182.  
  183.  
  184. ULONG mNLI_New(struct IClass *cl,Object *obj,struct opSet *msg)
  185. {
  186.   register struct NLIData *data;
  187.   if (!(obj = (Object *)DoSuperMethodA(cl,obj,(Msg) msg)))
  188.     return(0);
  189.   data = INST_DATA(cl,obj);
  190.   data->special = 0;
  191.   return((ULONG) obj);
  192. }
  193.  
  194.  
  195. ULONG mNLI_AskMinMax(struct IClass *cl,Object *obj,struct MUIP_AskMinMax *msg)
  196. {
  197.   DoSuperMethodA(cl,obj,(Msg) msg);
  198.   msg->MinMaxInfo->MinWidth  += 8;
  199.   msg->MinMaxInfo->DefWidth  += 18; /* the only width def value really used by NList object */
  200.   msg->MinMaxInfo->MaxWidth  += MUI_MAXMAX;
  201.   msg->MinMaxInfo->MinHeight += 7;  /* the only height def value really used by NList object */
  202.   msg->MinMaxInfo->DefHeight += 12;
  203.   msg->MinMaxInfo->MaxHeight += MUI_MAXMAX;
  204.   return(0);
  205. }
  206.  
  207.  
  208. ULONG mNLI_Set(struct IClass *cl,Object *obj,Msg msg)
  209. {
  210.   register struct NLIData *data = INST_DATA(cl,obj);
  211.   struct TagItem *tags,*tag;
  212.   for (tags=((struct opSet *)msg)->ops_AttrList;tag=(struct TagItem *) NextTagItem(&tags);)
  213.   { switch (tag->ti_Tag)
  214.     {
  215.       case MUIA_NLIMG_EntryCurrent:
  216.         data->EntryCurrent = tag->ti_Data;
  217.         break;
  218.       case MUIA_NLIMG_EntryHeight:
  219.         data->EntryHeight = tag->ti_Data;
  220.         break;
  221.       case MUIA_NLIMG_Spec:
  222.         data->special = tag->ti_Data;
  223.         break;
  224.     }
  225.   }
  226.   return (0);
  227. }
  228.  
  229.  
  230. #ifdef __SASC
  231. SAVEDS ASM ULONG NLI_Dispatcher(REG(a0) struct IClass *cl, REG(a2) Object *obj, REG(a1) Msg msg)
  232. {
  233. #endif
  234. #ifdef __GNUC__
  235. ULONG NLI_Dispatcher(void)
  236. { register struct IClass *a0 __asm("a0"); struct IClass *cl = a0;
  237.   register Object *a2 __asm("a2");        Object *obj = a2;
  238.   register Msg a1 __asm("a1");            Msg msg = a1;
  239. #endif
  240.   switch (msg->MethodID)
  241.   {
  242.     case OM_NEW         : return (      mNLI_New(cl,obj,(APTR)msg));
  243.     case OM_SET         : return (      mNLI_Set(cl,obj,(APTR)msg));
  244.     case MUIM_AskMinMax : return (mNLI_AskMinMax(cl,obj,(APTR)msg));
  245.     case MUIM_Draw      : return (     mNLI_Draw(cl,obj,(APTR)msg));
  246.   }
  247.   return(DoSuperMethodA(cl,obj,msg));
  248. }
  249.  
  250.  
  251.  
  252.  
  253. struct MUI_CustomClass *NLI_Create(void)
  254. {
  255.   NLI_Class = MUI_CreateCustomClass(NULL,MUIC_Area,NULL,sizeof(struct NLIData),NLI_Dispatcher);
  256.   return (NLI_Class);
  257. }
  258.  
  259.  
  260. void NLI_Delete(void)
  261. {
  262.   if (NLI_Class)
  263.     MUI_DeleteCustomClass(NLI_Class);
  264.   NLI_Class = NULL;
  265. }
  266.  
  267.  
  268.