home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 98 / af098a.adf / archives / HDProgs.lzx / AGA-Morph-V1.3 / Source / AGA-Morph-Manage.c < prev    next >
C/C++ Source or Header  |  1997-04-14  |  10KB  |  347 lines

  1. /*----------------------------------------------------------------------------*
  2.  *                                                                            *
  3.  *  AGA-Morph-Manage.c V1.3                                                   *
  4.  *                                                                            *
  5.  *----------------------------------------------------------------------------*/
  6.  
  7. /*----------------------------------------------------------------------------*/
  8.  
  9. #include <libraries/diskfont.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/classes.h>
  12. #include <intuition/pointerclass.h>
  13. #include <datatypes/pictureclass.h>
  14. #include <datatypes/pictureclassext.h>
  15. #include <graphics/gfx.h>
  16. #include <exec/memory.h>
  17. #include <libraries/asl.h>
  18. #include <clib/macros.h>
  19.  
  20. #include "AGA-Morph-Language.h"
  21. #include "AGA-Morph-Struct.h"
  22.  
  23. /*----------------------------------------------------------------------------*/
  24.  
  25. #define GadgetOn(g,w,r) {Pos=RemoveGadget(w,g); (g)->Flags-=((g)->Flags & GFLG_DISABLED); AddGadget(w,g,Pos); RefreshGList(g,w,r,1);}
  26. #define GadgetOff(g,w,r) {Pos=RemoveGadget(w,g); (g)->Flags=((g)->Flags | GFLG_DISABLED); AddGadget(w,g,Pos); RefreshGList(g,w,r,1);}
  27.  
  28. /*----------------------------------------------------------------------------*/
  29.  
  30. extern struct DPoint Points;
  31. extern struct Gadget AddPButton,Change1Button,Change2Button,ChangeColorButton,
  32.                      ChangeSpButton,DeleteAllButton,DelPButton,DPicX,DPicY,
  33.                      EditWindowBar1,EditWindowBar2,ErrorCloseButton,InfoButton,
  34.                      Load1Button,Load2Button,LoadPButton,Pic2Slider,Pic2Val,
  35.                      Poi2Slider,Poi2Val,PointsB,PointsButton,QuitButton,
  36.                      RenderButton,ResetSplinesButton,SavePButton,SavePicButton,
  37.                      Show1Button,Show2Button,ShowRButton,SpLineButton,
  38.                      ViewWindowBar1,ViewWindowBar2,ZoomButton;
  39. extern struct IntuiText ErrorCloseButtonT;
  40. extern struct MPoint *Point1,*Point2;
  41. extern struct Screen *MorphScreen;
  42. extern struct StringInfo PointsBp;
  43. extern struct Window *CommandWindow,*EditWindow,*ErrorWindow,*ViewWindow;
  44. extern LONG i,j,k,Pos;
  45. extern ULONG Height,Width;
  46. extern UBYTE PointsBBuf[15];
  47.  
  48. /*----------------------------------------------------------------------------*/
  49.  
  50. void RethinkSelectedPoint();                             /* Internal use only */
  51. void DeletePoints();
  52. void DisableAll();
  53. void EnableAll();
  54. void ShowError(struct IntuiText *Error);
  55. void Hex(char *text,ULONG num);
  56. void SHex(char *text,LONG num);
  57. void Dez(char *text,LONG num);
  58. void WDez(char *text,WORD num);
  59.  
  60. /*----------------------------------------------------------------------------*/
  61.  
  62. void
  63. RethinkSelectedPoint()
  64. {
  65.   Pos=RemoveGadget(CommandWindow,&PointsB);
  66.   PointsBp.LongInt=MAX(MIN(PointsBp.LongInt,Points.NumPoints),0);
  67.   if (PointsBp.LongInt==0)
  68.   {
  69.     PointsBp.NumChars=1;
  70.     PointsBBuf[0]=48+0;
  71.     PointsBBuf[1]=0;
  72.   }
  73.   else
  74.   {
  75.     PointsBp.NumChars=0;
  76.     k=PointsBp.LongInt;
  77.     j=1000000000;
  78.     for (i=9;i>=0;i--)
  79.     {
  80.       if (PointsBp.LongInt>=j)
  81.       {
  82.         PointsBBuf[PointsBp.NumChars]=48+k/j;
  83.         PointsBp.NumChars++;
  84.         k=k%j;
  85.       }
  86.       j=j/10;
  87.     }
  88.     PointsBBuf[PointsBp.NumChars]=0;
  89.   }
  90.   AddGadget(CommandWindow,&PointsB,Pos);
  91.   RefreshGList(&PointsB,CommandWindow,0,1);
  92. }
  93.  
  94. /*----------------------------------------------------------------------------*/
  95.  
  96. void
  97. DeletePoints()
  98. {
  99.   Points.NumPoints=0;
  100.   Point1=Points.First;
  101.   while (Point1)
  102.   {
  103.     Point2=Point1;
  104.     Point1=Point1->Next;
  105.     FreeVec(Point2);
  106.   }
  107.   RethinkSelectedPoint();
  108. }
  109.  
  110. /*----------------------------------------------------------------------------*/
  111.  
  112. void
  113. DisableAll()
  114. {
  115.   GadgetOff(&Load1Button,CommandWindow,0);
  116.   GadgetOff(&Load2Button,CommandWindow,0);
  117.   GadgetOff(&LoadPButton,CommandWindow,0);
  118.   GadgetOff(&SavePicButton,CommandWindow,0);
  119.   GadgetOff(&SavePButton,CommandWindow,0);
  120.   GadgetOff(&Change1Button,CommandWindow,0);
  121.   GadgetOff(&Change2Button,CommandWindow,0);
  122.   GadgetOff(&ChangeSpButton,CommandWindow,0);
  123.   GadgetOff(&AddPButton,CommandWindow,0);
  124.   GadgetOff(&DelPButton,CommandWindow,0);
  125.   GadgetOff(&Pic2Slider,CommandWindow,0);
  126.   GadgetOff(&Pic2Val,CommandWindow,0);
  127.   GadgetOff(&Poi2Slider,CommandWindow,0);
  128.   GadgetOff(&Poi2Val,CommandWindow,0);
  129.   GadgetOff(&SpLineButton,CommandWindow,0);
  130.   GadgetOff(&RenderButton,CommandWindow,0);
  131.   GadgetOff(&Show1Button,CommandWindow,0);
  132.   GadgetOff(&Show2Button,CommandWindow,0);
  133.   GadgetOff(&ShowRButton,CommandWindow,0);
  134.   GadgetOff(&InfoButton,CommandWindow,0);
  135.   GadgetOff(&ZoomButton,CommandWindow,0);
  136.   GadgetOff(&QuitButton,CommandWindow,0);
  137.   GadgetOff(&DPicX,CommandWindow,0);
  138.   GadgetOff(&DPicY,CommandWindow,0);
  139.   GadgetOff(&PointsB,CommandWindow,0);
  140.   GadgetOff(&DeleteAllButton,CommandWindow,0);
  141.   GadgetOff(&ResetSplinesButton,CommandWindow,0);
  142.   GadgetOff(&PointsButton,CommandWindow,0);
  143.   GadgetOff(&ChangeColorButton,CommandWindow,0);
  144.  
  145.   GadgetOff(&EditWindowBar1,EditWindow,0);
  146.   GadgetOff(&EditWindowBar2,EditWindow,0);
  147.  
  148.   GadgetOff(&ViewWindowBar1,ViewWindow,0);
  149.   GadgetOff(&ViewWindowBar2,ViewWindow,0);
  150. }
  151.  
  152. /*----------------------------------------------------------------------------*/
  153.  
  154. void
  155. EnableAll()
  156. {
  157.   GadgetOn(&Load1Button,CommandWindow,0);
  158.   GadgetOn(&Load2Button,CommandWindow,0);
  159.   GadgetOn(&LoadPButton,CommandWindow,0);
  160.   GadgetOn(&SavePicButton,CommandWindow,0);
  161.   GadgetOn(&SavePButton,CommandWindow,0);
  162.   GadgetOn(&Change1Button,CommandWindow,0);
  163.   GadgetOn(&Change2Button,CommandWindow,0);
  164.   if (SpLineButton.Flags & GFLG_SELECTED)
  165.   {
  166.     GadgetOn(&ChangeSpButton,CommandWindow,0);
  167.   }
  168.   GadgetOn(&AddPButton,CommandWindow,0);
  169.   GadgetOn(&DelPButton,CommandWindow,0);
  170.   GadgetOn(&Pic2Slider,CommandWindow,0);
  171.   GadgetOn(&Pic2Val,CommandWindow,0);
  172.   GadgetOn(&Poi2Slider,CommandWindow,0);
  173.   GadgetOn(&Poi2Val,CommandWindow,0);
  174.   GadgetOn(&SpLineButton,CommandWindow,0);
  175.   GadgetOn(&RenderButton,CommandWindow,0);
  176.   GadgetOn(&Show1Button,CommandWindow,0);
  177.   GadgetOn(&Show2Button,CommandWindow,0);
  178.   GadgetOn(&ShowRButton,CommandWindow,0);
  179.   GadgetOn(&InfoButton,CommandWindow,0);
  180.   GadgetOn(&ZoomButton,CommandWindow,0);
  181.   GadgetOn(&QuitButton,CommandWindow,0);
  182.   GadgetOn(&DPicX,CommandWindow,0);
  183.   GadgetOn(&DPicY,CommandWindow,0);
  184.   GadgetOn(&PointsB,CommandWindow,0);
  185.   GadgetOn(&DeleteAllButton,CommandWindow,0);
  186.   GadgetOn(&PointsButton,CommandWindow,0);
  187.   GadgetOn(&ChangeColorButton,CommandWindow,0);
  188.  
  189.   GadgetOn(&EditWindowBar1,EditWindow,0);
  190.   GadgetOn(&EditWindowBar2,EditWindow,0);
  191.  
  192.   GadgetOn(&ViewWindowBar1,ViewWindow,0);
  193.   GadgetOn(&ViewWindowBar2,ViewWindow,0);
  194. }
  195.  
  196. /*----------------------------------------------------------------------------*/
  197.  
  198. void
  199. ShowError(struct IntuiText *Error)
  200. {
  201.   struct IntuiMessage *Mess2;
  202.   ErrorCloseButtonT.NextText=Error;
  203.   if (ErrorWindow=(struct Window *) OpenWindowTags(NULL,
  204.                                                    WA_Left,          (Width-240)/2,
  205.                                                    WA_Top,           (Height-100)/2,
  206.                                                    WA_Width,         240,
  207.                                                    WA_Height,        100,
  208.                                                    WA_Title,         Error_Window,
  209.                                                    WA_CustomScreen,  MorphScreen,
  210.                                                    WA_Gadgets,       &ErrorCloseButton,
  211.                                                    WA_Activate,      TRUE,
  212.                                                    WA_GimmeZeroZero, TRUE,
  213.                                                    WA_IDCMP,         IDCMP_GADGETUP,
  214.                                                    TAG_END))
  215.   {
  216.     DisableAll();
  217.     while (Mess2=(struct IntuiMessage *) GetMsg(CommandWindow->UserPort))
  218.     {
  219.       ReplyMsg((struct Message *) Mess2);
  220.     }
  221.   }
  222.   else
  223.   {
  224.     puts(Error_Error);
  225.     puts(Error->IText);
  226.   }
  227. }
  228.  
  229. /*----------------------------------------------------------------------------*/
  230.  
  231. void
  232. Hex(char *text,ULONG num)
  233. {
  234.   ULONG d,h;
  235.   WORD i;
  236.   d=num;
  237.   for (i=7;i>=0;i--)
  238.   {
  239.     h=d & 0xF;
  240.     if (h<10)
  241.     {
  242.       *(text+i)=(char) 48+h;
  243.     }
  244.     else
  245.     {
  246.       *(text+i)=(char) 55+h;
  247.     }
  248.     d=d >> 4;
  249.   }
  250. }
  251.  
  252. /*----------------------------------------------------------------------------*/
  253.  
  254. void
  255. SHex(char *text,LONG num)
  256. {
  257.   ULONG d,h;
  258.   WORD i;
  259.   if (num<0)
  260.   {
  261.     *(text)=(char) 45;
  262.     d=-num;
  263.   }
  264.   else
  265.   {
  266.     *(text)=(char) 43;
  267.     d=num;
  268.   }
  269.   for (i=7;i>=0;i--)
  270.   {
  271.     h=d & 0xF;
  272.     if (h<10)
  273.     {
  274.       *(text+i+1)=(char) 48+h;
  275.     }
  276.     else
  277.     {
  278.       *(text+i+1)=(char) 55+h;
  279.     }
  280.     d=d >> 4;
  281.   }
  282. }
  283.  
  284. /*----------------------------------------------------------------------------*/
  285.  
  286. void
  287. Dez(char *text,LONG num)
  288. {
  289.   ULONG d,h;
  290.   WORD i;
  291.   d=num;
  292.   i=9;
  293.   while ((i>=0) && (d>0))
  294.   {
  295.     h=d % 10;
  296.     *(text+i)=(char) 48+h;
  297.     d=(d-h)/10;
  298.     i--;
  299.   }
  300.   if (i==9)
  301.   {
  302.     *(text+i)=(char) 48;
  303.     i--;
  304.   }
  305.   if (i>=0)
  306.   {
  307.     for (;i>=0;i--)
  308.     {
  309.       *(text+i)=(char) 32;
  310.     }
  311.   }
  312. }
  313.  
  314. /*----------------------------------------------------------------------------*/
  315.  
  316. void
  317. WDez(char *text,WORD num)
  318. {
  319.   UWORD d,h;
  320.   WORD i;
  321.   d=num;
  322.   i=4;
  323.   while ((i>=0) && (d>0))
  324.   {
  325.     h=d % 10;
  326.     *(text+i)=(char) 48 +h;
  327.     d=(d-h)/10;
  328.     i--;
  329.   }
  330.   if (i==4)
  331.   {
  332.     *(text+i)=(char) 48;
  333.     i--;
  334.   }
  335.   if (i>=0)
  336.   {
  337.     for (;i>=0;i--)
  338.     {
  339.       *(text+i)=(char) 32;
  340.     }
  341.   }
  342. }
  343.  
  344. /*----------------------------------------------------------------------------*/
  345.  
  346. /* End of Text */
  347.