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 / CustomScr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  9.5 KB  |  349 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 <intuition/intuition.h>
  12. #include <intuition/gadgetclass.h>
  13. #include <graphics/displayinfo.h>
  14. #include <graphics/gfxbase.h>
  15. #include <graphics/gfxmacros.h>
  16. #include <libraries/gadtools.h>
  17. #include <libraries/dos.h>
  18. #include <libraries/asl.h>
  19.  
  20. #include <clib/exec_protos.h>
  21. #include <clib/intuition_protos.h>
  22. #include <clib/gadtools_protos.h>
  23. #include <clib/graphics_protos.h>
  24. #include <clib/utility_protos.h>
  25. #include <clib/alib_protos.h>
  26. #include <clib/dos_protos.h>
  27. #include <clib/asl_protos.h>
  28. #include "string.h" 
  29.  
  30. #define ID_ok                                         0
  31. #define ID_ok11                                       1
  32.  
  33. #define CustomNumGads            2
  34. #include "CustomScr.h" 
  35.  
  36. int okObj(struct VAobject VAObject);
  37. int ok11Obj(struct VAobject VAObject);
  38.  
  39. int SetupScreen(void);
  40. void CloseDownScreen(void);
  41. int OpenCustomWindow(char windtitle[80]);
  42. void CloseCustomWindow(void);
  43. int CustomHandler(void);
  44. int CustomMainHandler(void);
  45. void DrawCustomObjs(void);
  46. int main(int argc, char *argv[]);
  47.  
  48. struct Screen            *PubScr=NULL;
  49. struct DrawInfo            *ScrDrawInfo=NULL;
  50. APTR                 VisualInfo = NULL;
  51. struct Screen            *Scr = NULL;
  52. struct Window            *CustomWnd = NULL;
  53. struct Menu            *CustomMenus = NULL;
  54. struct Gadget            *CustomGList = NULL;
  55. struct Gadget            *CustomGadgets[2];
  56. struct IntuiMessage         CustomMsg;
  57. UWORD                 CustomLeft = 88;
  58. UWORD                 CustomTop = 79;
  59. UWORD                 CustomWidth = 415;
  60. UWORD                 CustomHeight = 179;
  61. struct NewMenu CustomNewMenu1[] = {
  62.  
  63.   { NM_TITLE, "Project", 0 , 0 , 0 , 0,},
  64.   {  NM_ITEM, "About", 0 ,  0L , 0 ,  0,},
  65.   {   NM_SUB, "Visual Arts V1", 0 ,  0L , 0 , (APTR)Visual_Arts_V1MenuObj,},
  66.   {   NM_SUB, "Copyright 1994 Danny Y Wong", 0 ,  0L , 0 , (APTR)Copyright_1994_Danny_Y_WongMenuObj,},
  67.   {   NM_SUB, "All Rights Reserved", 0 ,  0L , 0 , (APTR)All_Rights_ReservedMenuObj,},
  68.   {  NM_ITEM, NM_BARLABEL, 0 , 0 , 0 , 0,},
  69.   {  NM_ITEM, "Open", "O",  0L  , 0, (APTR)OpenMenuObj,},
  70.   {  NM_ITEM, "Save", "S",  0L  , 0, (APTR)SaveMenuObj,},
  71.   {  NM_ITEM, NM_BARLABEL, 0 , 0 , 0 , 0,},
  72.   {  NM_ITEM, "Print", 0 ,  0L , 0 ,  0,},
  73.   {   NM_SUB, "Printer", "1", CHECKED  , 0, (APTR)PrinterMenuObj,},
  74.   {   NM_SUB, "File", "2",  0L  , 0, (APTR)FileMenuObj,},
  75.   {   NM_SUB, "Plotter", "3",  0L  , 0, (APTR)PlotterMenuObj,},
  76.   {   NM_SUB, "Postscript", "4",  0L  , 0, (APTR)PostscriptMenuObj,},
  77.   {  NM_ITEM, NM_BARLABEL, 0 , 0 , 0 , 0,},
  78.   {  NM_ITEM, "Quit", "Q",  0L  , 0, (APTR)QuitMenuObj,},
  79.  
  80.   { NM_TITLE, "Edit", 0 , 0 , 0 , 0,},
  81.   {  NM_ITEM, "Undo", "Z",  0L  , 0, (APTR)UndoMenuObj,},
  82.   {  NM_ITEM, NM_BARLABEL, 0 , 0 , 0 , 0,},
  83.   {  NM_ITEM, "Copy", "C",  0L  , 0, (APTR)CopyMenuObj,},
  84.   {  NM_ITEM, "Paste", "V",  0L  , 0, (APTR)PasteMenuObj,},
  85.   {  NM_ITEM, "Cut", "X",  0L  , 0, (APTR)CutMenuObj,},
  86.  
  87.   { NM_TITLE, "Misc", 0 , 0 , 0 , 0,},
  88.   {  NM_ITEM, "Font", 0 ,  0L , 0 , (APTR)FontMenuObj,},
  89.   {  NM_ITEM, "Prefs", 0 ,  0L , 0 , (APTR)PrefsMenuObj,},
  90.  
  91.   {   NM_END, NULL, 0 , 0 , 0 , 0,},
  92. };
  93.  
  94. struct TextAttr topaz8 = { (STRPTR)"topaz.font", 8, 0x00, 0x01 };
  95. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  96.  
  97. struct IntuiText CustomIText[] = {
  98.   2, 0, JAM2, 98, 19, &topaz800, (UBYTE *)"This is a custom screen demo", &CustomIText[1],
  99.   1, 0, JAM2, 50, 37, &topaz800, (UBYTE *)"Creating requester like window is easy", &CustomIText[2],
  100.   1, 0, JAM2, 134, 50, &topaz800, (UBYTE *)"in Visual Arts.", &CustomIText[3],
  101.   1, 3, JAM2, 39, 75, &topaz800, (UBYTE *)"Try out the menus.  Menus was constructed", &CustomIText[4],
  102.   2, 0, JAM2, 39, 87, &topaz800, (UBYTE *)"in minutes with Visual Arts Menu Manager.", &CustomIText[5],
  103.   2, 1, JAM2, 106, 103, &topaz800, (UBYTE *)"Select OK to quit Demo", NULL,
  104. };
  105.  
  106. WORD CustomGadTypes[] = {
  107.     BUTTON_KIND,
  108.     BUTTON_KIND,
  109. };
  110.  
  111. struct NewGadget CustomNGads[] = {
  112.     17, 136, 93, 22, (UBYTE *)"_OK",&topaz800, ID_ok, PLACETEXT_IN, NULL, (APTR)okObj,
  113.     297, 136, 93, 22, (UBYTE *)"_Cancel",&topaz800, ID_ok11, PLACETEXT_IN, NULL, (APTR)ok11Obj,
  114. };
  115.  
  116. ULONG CustomNTags[] = {
  117.     (GT_Underscore), '_', TAG_DONE,
  118.     (GT_Underscore), '_', TAG_DONE,
  119. };
  120.  
  121. int SetupScreen(void)
  122. {
  123.   PubScr = LockPubScreen("Workbench");
  124.   if (PubScr != NULL)
  125.   {
  126.     ScrDrawInfo = GetScreenDrawInfo(PubScr);
  127.     if (!(Scr = OpenScreenTags(NULL,
  128.         SA_Left,    0,
  129.         SA_Top,     0,
  130.         SA_Width,    640,
  131.         SA_Height,    400,
  132.         SA_Depth,    2,
  133.         SA_Font,    &topaz800,
  134.         SA_Type,    CUSTOMSCREEN,
  135.         SA_DisplayID,    102404,
  136.         SA_AutoScroll,    TRUE,
  137.         SA_Overscan,    1,
  138.         SA_Pens,    (ULONG)(ScrDrawInfo->dri_Pens),
  139.         SA_Title,    "Visual Arts V1.0 Copyright 1994 Danny Y. Wong  All Rights Reserved.", 
  140.         TAG_DONE)))
  141.         return(1L);
  142.   }
  143.   else
  144.   return(1L);
  145.  
  146.   if (!(VisualInfo =  GetVisualInfo(Scr, TAG_DONE)))
  147.     return(2L);
  148.   return(0L);
  149. }
  150.  
  151. void CloseDownScreen(void)
  152. {
  153.   if (ScrDrawInfo)
  154.     FreeScreenDrawInfo(PubScr, ScrDrawInfo);
  155.   if (VisualInfo)
  156.     FreeVisualInfo(VisualInfo);
  157.   if (Scr)
  158.     CloseScreen(Scr);
  159.   if (PubScr)
  160.     UnlockPubScreen(NULL, PubScr);
  161. }
  162.  
  163. int OpenCustomWindow(char windtitle[80])
  164. {
  165.   struct NewGadget    NewGad;
  166.   struct Gadget       *Gad;
  167.   register UWORD i, j;
  168.   UWORD offsetx = Scr->WBorLeft;
  169.   UWORD offsety = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  170.  
  171.   if (!(Gad = CreateContext(&CustomGList)))
  172.       return(1L);
  173.  
  174.   for (i=0, j=0; i < CustomNumGads; i++)
  175.   {
  176.     CopyMem((char *)&CustomNGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
  177.  
  178.     NewGad.ng_VisualInfo = VisualInfo;
  179.     NewGad.ng_LeftEdge += offsetx;
  180.     NewGad.ng_TopEdge  += offsety;
  181.  
  182.     CustomGadgets[i] = Gad = CreateGadgetA((ULONG)CustomGadTypes[i], Gad,&NewGad,
  183.     (struct TagItem *)&CustomNTags[j]);
  184.     while (CustomNTags[j])
  185.         j +=2;
  186.     j++;
  187.     if (!Gad)
  188.        return(2L);
  189.   }
  190.  
  191.   if (!(CustomMenus = CreateMenus(CustomNewMenu1,
  192.      GTMN_FrontPen, 0L, TAG_DONE)))
  193.     return(3L);
  194.   LayoutMenus(CustomMenus, VisualInfo, GTMN_TextAttr,
  195.      &topaz800, TAG_DONE);
  196.  
  197.   if (!(CustomWnd = OpenWindowTags(NULL,
  198.       WA_Left,    CustomLeft,
  199.       WA_Top,     CustomTop,
  200.       WA_Width,    CustomWidth,
  201.       WA_Height,    CustomHeight - Scr->WBorTop,
  202.       WA_IDCMP,    IDCMP_CLOSEWINDOW | IDCMP_GADGETUP | IDCMP_VANILLAKEY | IDCMP_REFRESHWINDOW |  IDCMP_MENUPICK ,
  203.       WA_Flags,    WFLG_CLOSEGADGET  |  WFLG_SIMPLE_REFRESH |  WFLG_ACTIVATE |  WFLG_DRAGBAR ,
  204.       WA_Gadgets,    CustomGList,
  205.       WA_Title,    windtitle,
  206.       WA_ScreenTitle,    "Visual Arts V1.0 Copyright 1994 Danny Y. Wong  All Rights Reserved.",
  207.       WA_CustomScreen,    Scr,
  208.       WA_AutoAdjust,    TRUE,
  209.       WA_MinWidth,    20,
  210.       WA_MinHeight,    10,
  211.       WA_MaxWidth,    640,
  212.       WA_MaxHeight,    400,
  213.       TAG_DONE)))
  214.           return(3L);
  215.  
  216.   SetMenuStrip(CustomWnd, CustomMenus);
  217.   DrawCustomObjs();
  218.   GT_RefreshWindow(CustomWnd, NULL);
  219.   RefreshGadgets(CustomGadgets[0], CustomWnd, NULL);
  220.   return(0L);
  221. }
  222.  
  223. void CloseCustomWindow(void)
  224. {
  225.   if (CustomWnd)
  226.     CloseWindow(CustomWnd);
  227.   if (CustomGList)
  228.     FreeGadgets(CustomGList);
  229.   if (CustomMenus)
  230.   {
  231.     ClearMenuStrip(CustomWnd);
  232.     FreeMenus(CustomMenus);
  233.   }
  234. }
  235.  
  236. int CustomHandler(void)
  237. {
  238.   struct MenuItem    *menu;
  239.   struct IntuiMessage    *msg;
  240.   struct VAobject    VAObject;
  241.   int running    = 1;
  242.   int (*func)(struct VAobject VAObject);
  243.   ULONG class;
  244.   UWORD code;
  245.  
  246.   while (msg=GT_GetIMsg(CustomWnd->UserPort))
  247.   {
  248.     CopyMem((char *)msg, (char *)&CustomMsg, (long)sizeof(struct IntuiMessage));
  249.     class = msg->Class;
  250.     code  = msg->Code;
  251.  
  252.     GT_ReplyIMsg(msg);
  253.     switch(class)
  254.     {
  255.  
  256.       case IDCMP_REFRESHWINDOW:
  257.         GT_BeginRefresh(CustomWnd);
  258.         DrawCustomObjs();
  259.         GT_EndRefresh(CustomWnd, NULL);
  260.         break;
  261.  
  262.       case IDCMP_CLOSEWINDOW:
  263.          return(0);
  264.          break;
  265.  
  266.       case IDCMP_GADGETUP:
  267.         VAObject.va_Window = (struct Window *)CustomWnd;
  268.         VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
  269.         VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  270.         VAObject.va_Flags = 0;
  271.         VAObject.va_UserData = 0;
  272.         func = (void *)((struct Gadget *)CustomMsg.IAddress)->UserData;
  273.         running =  func(VAObject);
  274.         break;
  275.  
  276.  
  277.       case   IDCMP_VANILLAKEY:
  278.         switch(code)
  279.         {
  280.           case 'O':
  281.               case 'o': //added
  282.             ButtonSelected(CustomWnd, CustomGadgets[0]);
  283.                 running = -1; //added
  284.                 break;
  285.           case 'C':
  286.             ButtonSelected(CustomWnd, CustomGadgets[1]);
  287.             break;
  288.         }
  289.         break;
  290.  
  291.       case IDCMP_MENUPICK:
  292.         while ( code != MENUNULL)
  293.         {
  294.           VAObject.va_Window = (struct Window *)CustomWnd;
  295.           VAObject.va_Gadget = NULL;
  296.           VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  297.           VAObject.va_Flags = NULL;
  298.           VAObject.va_UserData = 0;
  299.           menu = ItemAddress(CustomMenus, code);
  300.           func = (void *)(GTMENUITEM_USERDATA(menu));
  301.           running =  func(VAObject);
  302.           code =  menu->NextSelect;
  303.         }
  304.         break;
  305.     }
  306.   }
  307.   return(running);
  308. }
  309.  
  310. void DrawCustomObjs(void)
  311. {
  312.   CustomDrawRects(CustomWnd);
  313.   CustomDrawLine(CustomWnd);
  314.   PrintIText(CustomWnd->RPort, CustomIText, CustomWnd->BorderLeft, CustomWnd->BorderTop);
  315.  
  316. }
  317.  
  318. int CustomMainHandler(void)
  319. {
  320.   int running = 1;
  321.   ULONG windsig, signals;
  322.  
  323.   while (running == 1)
  324.   {
  325.     windsig = 1L << CustomWnd->UserPort->mp_SigBit;
  326.     signals = Wait( windsig );
  327.     if (signals & windsig)
  328.     {
  329.       running = CustomHandler();
  330.     }
  331.   }
  332.   return(running);
  333. }
  334.  
  335. int main(int argc, char *argv[])
  336. {
  337.   int rc;
  338.  
  339.   if (!(SetupScreen()))
  340.   {
  341.     if (!(OpenCustomWindow("Menu and Custom Screen Demo")))
  342.     {
  343.       rc = CustomMainHandler();
  344.       CloseCustomWindow();
  345.     }
  346.     CloseDownScreen();
  347.   }
  348. }
  349.