home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / visualarts-1.0.lha / VisualArts-1.0 / Demo / Source / Funny.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  7.2 KB  |  289 lines

  1. /* ******************************************************************** */
  2. /* C code generated by:                            */
  3. /* Visual Arts Version 1.0                        */
  4. /* Copyright 1994 Danny Y. Wong  All rights reserved            */
  5. /* Calgary, Alberta (CANADA)                                    */
  6. /* Partial of the code is copyright by Jaba Development            */
  7. /* ******************************************************************** */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <exec/lists.h>
  12. #include <exec/nodes.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/gadgetclass.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <graphics/gfxmacros.h>
  18. #include <libraries/gadtools.h>
  19. #include <libraries/dos.h>
  20. #include <libraries/asl.h>
  21.  
  22. #include <clib/exec_protos.h>
  23. #include <clib/intuition_protos.h>
  24. #include <clib/gadtools_protos.h>
  25. #include <clib/graphics_protos.h>
  26. #include <clib/utility_protos.h>
  27. #include <clib/alib_protos.h>
  28. #include <clib/dos_protos.h>
  29. #include <clib/asl_protos.h>
  30. #include "string.h" 
  31.  
  32. #define ID_ok                                         0
  33. #define ID_ok1                                        1
  34. #define ID_wanted                                     2
  35.  
  36. #define FunnyNumGads            3
  37. #include "Funny.h" 
  38.  
  39. int okObj(struct VAobject VAObject);
  40. int ok1Obj(struct VAobject VAObject);
  41. int wantedObj(struct VAobject VAObject);
  42.  
  43. int GetPubScreen(void);
  44. void ClosePubScreen(void);
  45. int OpenFunnyWindow(char windtitle[80]);
  46. void CloseFunnyWindow(void);
  47. int FunnyHandler(void);
  48. int FunnyMainHandler(void);
  49. void DrawFunnyObjs(void);
  50. int main(int argc, char *argv[]);
  51.  
  52. UBYTE                *PubScrName = NULL;
  53. APTR                 VisualInfo = NULL;
  54. struct Screen            *Scr = NULL;
  55. struct Window            *FunnyWnd = NULL;
  56. struct Gadget            *FunnyGList = NULL;
  57. struct Gadget            *FunnyGadgets[3];
  58. struct IntuiMessage         FunnyMsg;
  59. UWORD                 FunnyLeft = 128;
  60. UWORD                 FunnyTop = 22;
  61. UWORD                 FunnyWidth = 315;
  62. UWORD                 FunnyHeight = 152;
  63. struct TextAttr topaz8 = { (STRPTR)"topaz.font", 8, 0x00, 0x01 };
  64. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  65.  
  66. struct IntuiText FunnyIText[] = {
  67.   2, 0, JAM2, 55, 94, &topaz800, (UBYTE *)"Wanted", &FunnyIText[1],
  68.   2, 0, JAM2, 17, 105, &topaz800, (UBYTE *)"$1,000,000 Alive", &FunnyIText[2],
  69.   1, 0, JAM2, 163, 5, &topaz800, (UBYTE *)"Name: Slippy Joe", &FunnyIText[3],
  70.   1, 0, JAM2, 243, 81, &topaz800, (UBYTE *)"", &FunnyIText[4],
  71.   1, 0, JAM2, 161, 14, &topaz800, (UBYTE *)"Age: 17 - 20", &FunnyIText[5],
  72.   1, 0, JAM2, 161, 24, &topaz800, (UBYTE *)"Weight: 160Lbs", &FunnyIText[6],
  73.   1, 0, JAM2, 161, 34, &topaz800, (UBYTE *)"Height: 5'10", &FunnyIText[7],
  74.   1, 0, JAM2, 160, 44, &topaz800, (UBYTE *)"Hair Color: Black", NULL,
  75. };
  76.  
  77. UBYTE *WantedLabels[] = {
  78.     (UBYTE *)"Slippy Joe", 
  79.     (UBYTE *)"Cool Kid", 
  80.     (UBYTE *)"Freddy", 
  81.     (UBYTE *)"Homer", 
  82.     (UBYTE *)"Dead Eye", 
  83.     (UBYTE *)"Sneakers", 
  84.     NULL
  85. };
  86.  
  87. WORD FunnyGadTypes[] = {
  88.     BUTTON_KIND,
  89.     BUTTON_KIND,
  90.     LISTVIEW_KIND,
  91. };
  92.  
  93. struct NewGadget FunnyNGads[] = {
  94.     70, 125, 73, 12, (UBYTE *)"OK",&topaz800, ID_ok, PLACETEXT_IN, NULL, (APTR)okObj,
  95.     169, 125, 73, 12, (UBYTE *)"Cancel",&topaz800, ID_ok1, PLACETEXT_IN, NULL, (APTR)ok1Obj,
  96.     161, 53, 144, 68, (UBYTE *)"", &topaz800, ID_wanted, PLACETEXT_ABOVE, NULL, (APTR)wantedObj,
  97. };
  98.  
  99. ULONG FunnyNTags[] = {
  100.     TAG_DONE,
  101.     TAG_DONE,
  102.     (GTLV_Labels), NULL, (GTLV_Top), 0, (GTLV_ScrollWidth), 16, (LAYOUTA_Spacing), 0, TAG_DONE,
  103. };
  104.  
  105.  
  106. int GetPubScreen(void)
  107. {
  108.   if (!(Scr = LockPubScreen(PubScrName)))
  109.     return(1L);
  110.  
  111.   if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
  112.     return(2L);
  113.   return(0L);
  114. }
  115.  
  116. void ClosePubScreen(void)
  117. {
  118.   if (VisualInfo)
  119.     FreeVisualInfo(VisualInfo);
  120.   if (Scr)
  121.     UnlockPubScreen(NULL,  Scr);
  122. }
  123.  
  124. int OpenFunnyWindow(char windtitle[80])
  125. {
  126.   struct NewGadget    NewGad;
  127.   struct Gadget       *Gad;
  128.   register UWORD i, j;
  129.   UWORD offsetx = Scr->WBorLeft;
  130.   UWORD offsety = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  131.  
  132.   if (!(Gad = CreateContext(&FunnyGList)))
  133.       return(1L);
  134.  
  135.   for (i=0, j=0; i < FunnyNumGads; i++)
  136.   {
  137.     CopyMem((char *)&FunnyNGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
  138.  
  139.     NewGad.ng_VisualInfo = VisualInfo;
  140.     NewGad.ng_LeftEdge += offsetx;
  141.     NewGad.ng_TopEdge  += offsety;
  142.  
  143.     FunnyGadgets[i] = Gad = CreateGadgetA((ULONG)FunnyGadTypes[i], Gad,&NewGad,
  144.     (struct TagItem *)&FunnyNTags[j]);
  145.     while (FunnyNTags[j])
  146.         j +=2;
  147.     j++;
  148.     if (!Gad)
  149.        return(2L);
  150.   }
  151.   if (!(FunnyWnd = OpenWindowTags(NULL,
  152.       WA_Left,    FunnyLeft,
  153.       WA_Top,     FunnyTop,
  154.       WA_Width,    FunnyWidth,
  155.       WA_Height,    FunnyHeight - Scr->WBorTop,
  156.       WA_IDCMP,    IDCMP_CLOSEWINDOW |  IDCMP_NEWSIZE | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_REFRESHWINDOW | IDCMP_INTUITICKS ,
  157.       WA_Flags,    WFLG_CLOSEGADGET | WFLG_DEPTHGADGET  |  WFLG_SMART_REFRESH |  WFLG_ACTIVATE |  WFLG_DRAGBAR ,
  158.       WA_Gadgets,    FunnyGList,
  159.       WA_Title,    windtitle,
  160.       WA_ScreenTitle,    "Visual Arts V1.0 Copyright 1994 Danny Y. Wong  All Rights Reserved.",
  161.       WA_PubScreen,    Scr,
  162.       WA_MinWidth,    20,
  163.       WA_MinHeight,    10,
  164.       WA_MaxWidth,    640,
  165.       WA_MaxHeight,    200,
  166.       TAG_DONE)))
  167.           return(3L);
  168.  
  169.   InitTempArea();
  170.   FunnyWnd->RPort->TmpRas=&Temprast;
  171.   FunnyWnd->RPort->AreaInfo=&areaInfo;
  172.   DrawFunnyObjs();
  173.   GT_RefreshWindow(FunnyWnd, NULL);
  174.   CreateFunnyLists();
  175.   GT_SetGadgetAttrs(FunnyGadgets[2], FunnyWnd, NULL,
  176.      GTLV_Labels, FunnyLists[0], TAG_END);
  177.   RefreshGadgets(FunnyGadgets[0], FunnyWnd, NULL);
  178.   return(0L);
  179. }
  180.  
  181. void CloseFunnyWindow(void)
  182. {
  183.   if (FunnyWnd)
  184.     CloseWindow(FunnyWnd);
  185.   if (FunnyGList)
  186.     FreeGadgets(FunnyGList);
  187. }
  188.  
  189. int FunnyHandler(void)
  190. {
  191.   struct IntuiMessage    *msg;
  192.   struct VAobject    VAObject;
  193.   int running    = 1;
  194.   int (*func)(struct VAobject VAObject);
  195.   ULONG class;
  196.   UWORD code;
  197.  
  198.   while (msg=GT_GetIMsg(FunnyWnd->UserPort))
  199.   {
  200.     CopyMem((char *)msg, (char *)&FunnyMsg, (long)sizeof(struct IntuiMessage));
  201.     class = msg->Class;
  202.     code  = msg->Code;
  203.  
  204.     GT_ReplyIMsg(msg);
  205.     switch(class)
  206.     {
  207.  
  208.       case IDCMP_MOUSEBUTTONS :
  209.         break;
  210.  
  211.       case IDCMP_MOUSEMOVE :
  212.         break;
  213.  
  214.       case IDCMP_GADGETDOWN :
  215.         break;
  216.  
  217.       case IDCMP_INTUITICKS :
  218.         break;
  219.  
  220.       case IDCMP_REFRESHWINDOW:
  221.         GT_BeginRefresh(FunnyWnd);
  222.         DrawFunnyObjs();
  223.         GT_EndRefresh(FunnyWnd, NULL);
  224.         break;
  225.  
  226.       case IDCMP_CLOSEWINDOW:
  227.          return(0);
  228.          break;
  229.  
  230.       case IDCMP_GADGETUP:
  231.         VAObject.va_Window = (struct Window *)FunnyWnd;
  232.         VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
  233.         VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  234.         VAObject.va_Flags = 0;
  235.         VAObject.va_UserData = 0;
  236.         func = (void *)((struct Gadget *)FunnyMsg.IAddress)->UserData;
  237.         running =  func(VAObject);
  238.         break;
  239.  
  240.     }
  241.   }
  242.   return(running);
  243. }
  244.  
  245. void DrawFunnyObjs(void)
  246. {
  247.   FunnyDrawRects(FunnyWnd);
  248.   FunnyDrawCircles(FunnyWnd);
  249.   FunnyDrawLine(FunnyWnd);
  250.   PrintIText(FunnyWnd->RPort, FunnyIText, FunnyWnd->BorderLeft, FunnyWnd->BorderTop);
  251.  
  252. }
  253.  
  254. int FunnyMainHandler(void)
  255. {
  256.   int running = 1;
  257.   ULONG windsig, signals;
  258.  
  259.   while (running == 1)
  260.   {
  261.     windsig = 1L << FunnyWnd->UserPort->mp_SigBit;
  262.     signals = Wait( windsig );
  263.     if (signals & windsig)
  264.     {
  265.       running = FunnyHandler();
  266.     }
  267.   }
  268.   return(running);
  269. }
  270.  
  271. int main(int argc, char *argv[])
  272. {
  273.   int rc;
  274.  
  275.   if (!(GetPubScreen()))
  276.   {
  277.     for (rc=0; rc < 1; rc++)
  278.       FunnyLists[rc]=GetNewList();
  279.     if (!(OpenFunnyWindow("Funny Demo")))
  280.     {
  281.       rc = FunnyMainHandler();
  282.       CloseFunnyWindow();
  283.     }
  284.     for (rc=0; rc < 1; rc++)
  285.       FreeList(FunnyLists[rc]);
  286.     ClosePubScreen();
  287.   }
  288. }
  289.