home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 611.lha / AlgoRhythms_v2.0 / Source.LZH / Source / Window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-22  |  5.1 KB  |  190 lines

  1. /* Window.c
  2.    Copyright (c) 1990,1991,1992 by Thomas E. Janzen
  3.    All Rights Reserved
  4.  
  5.    THIS SOFTWARE IS FURNISHED FREE OF CHARGE FOR STUDY AND USE AND MAY
  6.    BE COPIED ONLY FOR PERSONAL USE OR COMPLETELY AS OFFERED WITH NO
  7.    CHANGES FOR FREE DISTRIBUTION.  NO TITLE TO AND OWNERSHIP OF THE
  8.    SOFTWARE IS HEREBY TRANSFERRED.  THOMAS E. JANZEN ASSUMES NO 
  9.    RESPONSBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE.
  10.    
  11.    Thomas E. Janzen
  12.    58A School St. Apt. 2-L
  13.    Hudson, MA 01749
  14.    (508)562-1295
  15. */
  16. /*
  17. **  FACILITY:
  18. **
  19. **    AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
  20. **    compiled with SAS/C V5.10b
  21. **
  22. **  ABSTRACT:
  23. **
  24. **    Window.c Opens and manages the Workbench-type window used by
  25. **    AlgoRhythms.
  26. **
  27. **  AUTHORS: Thomas E. Janzen
  28. **
  29. **  CREATION DATE:    26-MAR-1990
  30. **
  31. **  MODIFICATION HISTORY:
  32. **    DATE    NAME    DESCRIPTION
  33. **    24 SEP 91 T. Janzen use algorhythms.col to specify screen colors
  34. **    8 DEC 91 T. Janzen conform to SAS/C 5.10b remove extern from functs
  35. **  4 Jan 92 TEJ  last changes for 2.0
  36. **--
  37. */
  38. #include <stdio.h>
  39. #include <exec/types.h>
  40. #include <exec/nodes.h>
  41. #include <exec/lists.h>
  42. #include <intuition/intuition.h>
  43. #include <graphics/text.h>
  44. #include <proto/exec.h>
  45. #include <proto/graphics.h>
  46. #include <proto/intuition.h>
  47. #include <proto/dos.h>
  48. #include <proto/mathffp.h>
  49. #include <math.h>
  50. #include <stdlib.h>
  51. #include <graphics/display.h>
  52.  
  53. extern void OpenWind (void);
  54. extern void OpenLibs (void);
  55. extern void CloseLibs (void);
  56. extern void MakeWindow (void);
  57.  
  58. /* Library base addresses */
  59. struct IntuitionBase *IntuitionBase;
  60. struct GfxBase *GfxBase;
  61. struct DOSBase *DOSBase;
  62. struct MathBase *MathBase;
  63. struct ReqBase *ReqBase;
  64.  
  65. ULONG class,classb;    /* Intu Event class */
  66. USHORT code,codeb;    /* Intu Event code */
  67.  
  68. /*WINDOW*/
  69. static struct Screen *Screen_1;
  70. struct Window *w;
  71. struct RastPort *rp;
  72. static struct ViewPort *vp;
  73. struct IntuiMessage *message;
  74. struct TextAttr font_choice = {(STRPTR)"topaz.font", TOPAZ_EIGHTY, 0, 0};
  75.  
  76. void MakeWindow (void) 
  77. {
  78.     OpenLibs ();
  79.     OpenWind ();
  80.    return;
  81. }
  82.  
  83. void OpenWind (void) 
  84. {
  85.    FILE *Color_File;
  86.    static char Screen_Title[] = 
  87.    "AlgoRhythms ©1992 Thomas E. Janzen All Rights Reserved";
  88.    struct NewScreen ns = {
  89.       0, 0, 640, 200, 3 /*depth*/, 1 /* DetailPen*/, 2 /* BlockPen */,
  90.       HIRES, CUSTOMSCREEN, &font_choice, Screen_Title, NULL, NULL};
  91.    auto long int Reds[8]   = {0x4, 0xF, 0xC, 0x7, 0x8, 0xF, 0x0, 0xF};
  92.    auto long int Greens[8] = {0x0, 0xF, 0x0, 0x9, 0xF, 0xF, 0x0, 0x0};
  93.    auto long int Blues[8]  = {0x4, 0xF, 0x0, 0xF, 0x0, 0xF, 0x0, 0xF};
  94.    auto long int Color_Index;
  95.    
  96.     struct NewWindow nw = {
  97.        0, 10, 640, 190,       /* Left, Top, Width, height */
  98.        2, 1,                  /* detail, block pens */
  99.        REQSET|NEWSIZE|CLOSEWINDOW|MENUPICK|GADGETUP,    /* IDCMP flags */
  100.        WINDOWSIZING|SMART_REFRESH|WINDOWDEPTH|WINDOWDRAG|
  101.        WINDOWCLOSE|GIMMEZEROZERO|ACTIVATE,
  102.        NULL,                     /* Pointer to first gadget */
  103.        NULL,                     /* Pointer to checkmark */
  104.        "Random Form",           /* title */
  105.        NULL,                     /* screen pointer */
  106.        NULL,                     /* bitmap pointer */
  107.        400, 190, 640, 190,    /* window not sized */
  108.        CUSTOMSCREEN           /* type of screen */
  109.    };
  110.    Color_File = fopen ("AlgoRhythms.Col", "r");
  111.    if (Color_File != NULL)
  112.    {
  113.       fscanf (Color_File, "%d %d %d %d %d %d %d %d", &Reds[0], &Reds[1], 
  114.          &Reds[2], &Reds[3], &Reds[4], &Reds[5], &Reds[6], &Reds[7]);
  115.       fscanf (Color_File, "%d %d %d %d %d %d %d %d", &Greens[0], 
  116.          &Greens[1], &Greens[2], &Greens[3], &Greens[4], &Greens[5], 
  117.          &Greens[6], &Greens[7]);
  118.       fscanf (Color_File, "%d %d %d %d %d %d %d %d", &Blues[0], &Blues[1], 
  119.          &Blues[2], &Blues[3], &Blues[4], &Blues[5], &Blues[6], &Blues[7]);
  120.       fclose (Color_File);
  121.    }
  122.    Screen_1 = OpenScreen (&ns);
  123.    for (Color_Index = 0; Color_Index < 8; Color_Index++)
  124.    {
  125.       SetRGB4 (&Screen_1->ViewPort, 
  126.                Color_Index, 
  127.                Reds[Color_Index],                
  128.                Greens[Color_Index],
  129.                Blues[Color_Index]);
  130.    }
  131.    nw.Screen = Screen_1;
  132.     w = OpenWindow (&nw);
  133.     rp = w->RPort;            /* Get the raster port pointer */
  134.     vp = &w->WScreen->ViewPort;    /* Get the view port pointer */
  135.    return;
  136. }
  137.  
  138. void OpenLibs(void) 
  139. {
  140.     if (!(IntuitionBase =
  141.     (struct IntuitionBase *)OpenLibrary ("intuition.library", 0L)))
  142.    {
  143.         CloseLibs ();
  144.         exit (FALSE);
  145.     }
  146.     if (!(GfxBase = 
  147.     (struct GfxBase *)OpenLibrary ("graphics.library",0L)))
  148.    {
  149.         CloseLibs ();
  150.         exit(FALSE);
  151.     }
  152.     if ( !(MathBase = 
  153.     (struct MathBase *)OpenLibrary ("mathffp.library",0L)))
  154.    {
  155.         CloseLibs ();
  156.         exit (FALSE);
  157.     }
  158.     if (!(DOSBase = 
  159.     (struct DOSBase *)OpenLibrary ("dos.library",0L)))
  160.    {
  161.         CloseLibs ();
  162.         exit (FALSE);
  163.     }
  164.     if (!(ReqBase = 
  165.     (struct ReqBase *)OpenLibrary ("req.library",0L)))
  166.    {
  167.         ReqBase = NULL;
  168.     }
  169.    return;
  170. }
  171.  
  172. void CloseLibs(void) 
  173. {
  174.     if (GfxBase) CloseLibrary (GfxBase);
  175.     if (IntuitionBase) CloseLibrary (IntuitionBase);
  176.     if (MathBase) CloseLibrary (MathBase);
  177.       if (DOSBase) CloseLibrary (DOSBase);
  178.       if (ReqBase) CloseLibrary (ReqBase);
  179.    return;
  180. }
  181.  
  182. void ShutWindow(void) 
  183. {
  184.     CloseLibs ();
  185.     CloseWindow (w);
  186.    CloseScreen (Screen_1);
  187.    OpenWorkBench ();
  188.    return;
  189. }
  190.