home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / printer / graphpaper / src / src.lha / main.c < prev    next >
C/C++ Source or Header  |  1993-04-06  |  4KB  |  137 lines

  1. #include "graph.h"
  2.  
  3. USHORT quit_flag = FALSE;
  4.  
  5. /* This is for the event handler */
  6. void quit(APTR object)
  7. {
  8.         quit_flag = TRUE;
  9. }
  10.  
  11. struct IntuitionBase *IntuitionBase;
  12. struct GfxBase *GfxBase;
  13.  
  14. struct Window *OpenWindow();
  15. struct Screen *OpenScreen();
  16. struct MenuItem *ItemAddress();
  17.  
  18. /* get the PowerWindows 2.0 code */
  19. #include "pw.h"
  20.  
  21. struct Window *wG;    /* we fetch the RastPort pointer from here */
  22.  
  23. int main(void)
  24. {
  25.         UWORD code;
  26.         ULONG class;
  27.         APTR object;
  28.  
  29. #ifdef NEWSCREENSTRUCTURE
  30.         struct Screen *sC;
  31.         struct ViewPort vP;
  32. #endif
  33.         struct RastPort *rpG;
  34.         struct IntuiMessage *message;   /* the message the IDCMP sends us */
  35.  
  36.         initialize();
  37.  
  38.         IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library", 0L);
  39.         if (IntuitionBase == NULL)
  40.         {
  41.                 printf("intuition is not here.  where are we?\n");
  42.                 goto cleanup1;
  43.         }
  44.         GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0L);
  45.  
  46. #ifdef NEWSCREENSTRUCTURE
  47.         sC = OpenScreen(&NewScreenStructure);    /* open screen if present */
  48.         NewWindowStructure1.Screen = sC;
  49. #ifdef PALETTE
  50.         vP = sC->ViewPort;
  51.         LoadRGB4(&vP,&Palette,(long)PaletteColorCount);
  52. #endif
  53. #endif
  54.  
  55.         wG = OpenWindow(&NewWindowStructure1);  /* open the window */
  56.         if ( wG == NULL )
  57.         {
  58.                 printf ("open window failed\n");
  59.                 goto cleanup1;
  60.         }
  61.  
  62.         rpG = wG->RPort;        /* get a rastport pointer for the window */
  63.  
  64. #ifdef MenuList1
  65.         SetMenuStrip(wG,&MenuList1);        /* attach any Menu */
  66. #endif
  67.  
  68. #ifdef IntuiTextList1
  69.         PrintIText(rpG,&IntuiTextList1,0L,0L); /* Print the text if there is
  70.                                                   any */
  71. #endif
  72.  
  73. #ifdef BorderList1
  74.         DrawBorder(rpG,&BorderList1,0L,0L);    /* Draw the borders if there are
  75.                                                   any */
  76. #endif
  77.  
  78. #ifdef ImageList1
  79.         DrawImage(rpG,&ImageList1,0L,0L);      /* Draw the images if there are any */
  80. #endif
  81.  
  82.         button_init();
  83.  
  84.         size_init();
  85.         grids_init();
  86.         minors_init();
  87.         load_settings("s:", "GraphPaperDefaults");
  88.         initmessage();
  89.         RefreshGadgets(wG->FirstGadget, wG, NULL); /* needed? */
  90.  
  91.         do
  92.         {
  93.                 WaitPort(wG->UserPort);
  94.                 while( (message = (struct IntuiMessage *)
  95.                         GetMsg(wG->UserPort) ) != NULL)
  96.                 {
  97.                         code = message->Code;  /* MENUNUM */
  98.                         object = message->IAddress;  /* Gadget */
  99.                         class = message->Class;
  100.                         ReplyMsg(message);
  101.                         if ( class == CLOSEWINDOW ) (quit_flag = TRUE);
  102. #ifdef HANDLEEVENT
  103.                         if (( class == GADGETUP ) ||   /* Gagdets */
  104.                                 ( class == GADGETDOWN ))
  105.                                 HandleEvent(object);
  106. #ifdef MenuList1
  107.                         if ( class == MENUPICK )        /* MenuItems */
  108.                                 HandleEvent(ItemAddress(&MenuList1,(LONG)code));
  109. #endif
  110. #endif
  111. #if 0
  112.                         if ( class == MOUSEMOVE) {
  113.                             printf("Mouse moved\n"); /* experimental */
  114.                         }
  115. #endif
  116.                 }
  117.         } while (quit_flag == FALSE);
  118.  
  119. cleanup3:
  120. #ifdef MenuList1
  121.         ClearMenuStrip(wG);
  122. #endif
  123.  
  124. cleanup2:
  125.         CloseWindow(wG);
  126. #ifdef NEWSCREENSTRUCTURE
  127.         CloseScreen(sC);
  128. #endif
  129.  
  130. cleanup1:
  131.         if (GfxBase != NULL) CloseLibrary(GfxBase);
  132.         if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  133.         cleanup_drawing();
  134.         return(0);
  135.  
  136. }
  137.