home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 594a.lha / maker_v0.1 / init.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  5KB  |  221 lines

  1. #include "maker.h"
  2. #include "proto.h"
  3. #include "global.h"
  4.  
  5. #include <exec/memory.h>
  6.  
  7. #include <proto/intuition.h>
  8. #include <proto/graphics.h>
  9. #include <proto/asl.h>
  10. #include <proto/exec.h>
  11. #include <proto/gadtools.h>
  12. #include <proto/layers.h>
  13. #include <proto/diskfont.h>
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17.  
  18. /* ===================================================================================== */
  19.  
  20. void init()
  21. {
  22.     struct Node    *nodePtr;
  23.     USHORT        i;
  24.     
  25.  
  26.     //    Check for OS 2.0
  27.     
  28.     if (    (*((struct Library **) 4L))->lib_Version < 36)
  29.         quit("Sorry, but I can only work under AmigaOS Version 2.0\n");
  30.  
  31.     //    Open all the libraries
  32.     
  33.     IntuitionBase = OpenLibrary("intuition.library", 36L);
  34.     if (!IntuitionBase)
  35.         quit("can't open intuition library\n");
  36.     
  37.     GfxBase = OpenLibrary("graphics.library", 36L);
  38.     if (!GfxBase)
  39.         quit("can't open graphics library\n");
  40.     
  41.     GadToolsBase = OpenLibrary("gadtools.library", 36L);
  42.     if (!GadToolsBase)
  43.         quit("can't open gadtools library\n");
  44.     
  45.     AslBase = OpenLibrary("asl.library", 36L);
  46.     if (!AslBase)
  47.         quit("can't open asl library\n");
  48.     
  49.     LayersBase = OpenLibrary("layers.library", 36L);
  50.     if (!LayersBase)
  51.         quit("can't open layers library\n");
  52.     
  53.     DiskfontBase = OpenLibrary("diskfont.library", 36L);
  54.     if (!DiskfontBase)
  55.         quit("can't open diskfont library\n");
  56.     
  57.     //    Initialize some variables
  58.     
  59.     NewList(&gDefaultList);
  60.     i = 0;
  61.     while (gLabelText[i])
  62.     {
  63.         nodePtr = (struct Node *) AllocRemember(&gRemKey, sizeof(struct Node), MEMF_CLEAR);
  64.         nodePtr->ln_Name = gLabelText[i++];
  65.         AddTail(&gDefaultList, nodePtr);
  66.     }
  67.     
  68.     gEditMode = TRUE;
  69.     gWindSizeable = TRUE;
  70.     
  71.     gFont = OpenDiskFont(&topaz8);
  72.  
  73.     //    Get a lock on the public screen.  We will keep this lock for the duration of program
  74.     // execution in case we need to close & reopen the window (to enable/disable sizing),
  75.     // or to open other windows
  76.     
  77.     if (!(gPubScreen = LockPubScreen(0L)))
  78.         quit("LockPubScreen failed?\n");
  79.  
  80.     if (!(gVI = GetVisualInfo(gPubScreen, TAG_DONE)))
  81.         quit("GetVisualInfo failed\n");
  82.  
  83.     gWindPtr = 
  84.             OpenWindowTags(0L,
  85.                                 WA_Left,        20,
  86.                                 WA_Top,        20,
  87.                                 WA_Width,    200,
  88.                                 WA_Height,    150,
  89.                                 WA_IDCMP,    WIND_IDCMP,
  90.                                 WA_Flags,    WIND_FLAG | (gWindSizeable ? WFLG_SIZEGADGET : 0),
  91.                                 WA_Title,    gWindTitle,
  92.                                 WA_PubScreen, gPubScreen,
  93.                                 WA_MinWidth,    70,
  94.                                 WA_MinHeight,    30,
  95.                                 WA_MaxWidth,    -1L,
  96.                                 WA_MaxHeight,    -1L,
  97.                                 TAG_DONE);
  98.                                 
  99.     if (!gWindPtr)
  100.         quit("failed to open a window\n");
  101.                                 
  102.     SetClip();
  103.     SetFont(gWindPtr->RPort, gFont);
  104.     
  105.     //    Open the info window
  106.     
  107.     gInfoWindPtr = 
  108.             OpenWindowTags(0L,
  109.                                 WA_Left,        300,
  110.                                 WA_Top,        100,
  111.                                 WA_Width,    120,
  112.                                 WA_Height,    65,
  113.                                 WA_IDCMP,    0L,
  114.                                 WA_Flags,    WFLG_DRAGBAR | WFLG_DEPTHGADGET |
  115.                                                 WFLG_SMART_REFRESH |    WFLG_NOCAREREFRESH,
  116.                                 WA_Title,    "Info",
  117.                                 WA_PubScreen, gPubScreen,
  118.                                 TAG_DONE);
  119.                                 
  120.     if (!gInfoWindPtr)
  121.         quit("failed to open the info window\n");
  122.     
  123.     SetAPen(gInfoWindPtr->RPort, 1);
  124.     SetFont(gInfoWindPtr->RPort, gFont);
  125.         
  126.     //    And the menus...
  127.     
  128.     if (!(gMenuPtr = CreateMenus(gNewMenu, GTMN_FrontPen, 2, TAG_DONE)))
  129.         quit("CreateMenus() failed!\n");
  130.  
  131.     if (!LayoutMenus(gMenuPtr, gVI, TAG_DONE))
  132.         quit("LayoutMenus() failed!\n");
  133.  
  134.     SetMenuStrip(gWindPtr, gMenuPtr);
  135.  
  136.     //    CreateContext() is the start of an extended relationship with the Gadtools library
  137.     
  138.     if (!CreateContext(&gGadgetContext))
  139.         quit("CreateContext() failed!\n");
  140.     
  141.     gFileRequest = AllocFileRequest();
  142.         
  143.     ReDraw();
  144. }
  145.  
  146. /* ===================================================================================== */
  147.  
  148. void quit(char *note)
  149. {
  150.     LinkNode        *nodePtr = gObjList,
  151.                     *nextNode;
  152.     
  153.     if (gRemKey)
  154.         FreeRemember(&gRemKey, TRUE);
  155.         
  156.     while (gObjList)
  157.         DisposeObj( gObjList );
  158. /*
  159.     while (nodePtr)
  160.     {
  161.         nextNode = nodePtr->next;
  162.  
  163.         DisposeObj( nodePtr );
  164.         nodePtr = nextNode;
  165.     }
  166. */
  167.     
  168.     if (gWindPtr)
  169.     {
  170.         InstallClipRegion(gWindPtr->WLayer, 0L);
  171.         ClearMenuStrip(gWindPtr);
  172.         CloseWindow(gWindPtr);
  173.     }
  174.     
  175.     if (gInfoWindPtr)
  176.         CloseWindow(gInfoWindPtr);
  177.         
  178.     if (gFont)
  179.         CloseFont(gFont);
  180.  
  181.     UnlockPubScreen(0L, gPubScreen);
  182.     
  183.     if (gFileRequest)
  184.         FreeFileRequest(gFileRequest);
  185.                 
  186.     if (gGadgetContext)
  187.         FreeGadgets(gGadgetContext);
  188.     
  189.     if (gMenuPtr)
  190.         FreeMenus(gMenuPtr);
  191.     
  192.     if (gVI)
  193.         FreeVisualInfo(gVI);
  194.         
  195.     if (IntuitionBase)
  196.         CloseLibrary(IntuitionBase);
  197.  
  198.     if (GfxBase)
  199.         CloseLibrary(GfxBase);
  200.  
  201.     if (GadToolsBase)
  202.         CloseLibrary(GadToolsBase);
  203.  
  204.     if (AslBase)
  205.         CloseLibrary(AslBase);
  206.  
  207.     if (LayersBase)
  208.         CloseLibrary(LayersBase);
  209.  
  210.     if (DiskfontBase)
  211.         CloseLibrary(DiskfontBase);
  212.  
  213.     if (note)    
  214.         printf(note);
  215.         
  216.     exit(0);
  217. }
  218.  
  219. /* ===================================================================================== */
  220.  
  221.