home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d306 / rexxplplot.lha / RexxPlPlot / src / src.zoo / Amiga.c next >
Encoding:
C/C++ Source or Header  |  1990-01-06  |  7.8 KB  |  331 lines

  1. #include "plplot.h"
  2. #ifdef AZTEC_C
  3. #include <libraries/dos.h>
  4. #else
  5. #include <dos.h>
  6. #endif
  7. #include <stdio.h>
  8. #include <exec/types.h>
  9. #include <exec/ports.h>
  10. #include <graphics/display.h>
  11. #include <graphics/gfxbase.h>
  12. #include <intuition/intuition.h>
  13. #include <intuition/intuitionbase.h>
  14. #include <intuition/screens.h>
  15.  
  16. struct NewScreen NewScreen = {
  17.    0,        /* LeftEdge Position */
  18.    0,        /* TopEdge */
  19.    640,        /* Width (high-res) */
  20.    400,        /* Height (interlace) */
  21.    1,        /* Depth (1 color) */
  22.    0,1,        /* DetailPen and BlockPen */
  23.    HIRES|INTERLACE,
  24.    CUSTOMSCREEN,
  25.    NULL,        /* Use default font */
  26.    NULL,        /* Don't want a title */
  27.    NULL,        /* Gadgets?? */
  28.    NULL        /* No CustomBitMap */
  29. };
  30.     
  31. struct NewWindow NewWindow = {
  32.    0,0,640,400,
  33.    -1,-1,
  34.    MENUPICK|VANILLAKEY,
  35.    SMART_REFRESH|BACKDROP|BORDERLESS|ACTIVATE,
  36.    NULL,    /* Window Gadget Pointer */
  37.    NULL,    /* Checkmark image */
  38.    NULL,    /* No Title */
  39.    NULL,    /* My Screen Pointer (this is set below) */
  40.    NULL, /* Not a SuperBitMap */
  41.    0,0,0,0,
  42.    CUSTOMSCREEN
  43. };
  44.  
  45. struct IntuiText IText[] = {
  46.    { 0, 1, JAM1, 0, 0, (struct TextAttr *)NULL, (UBYTE *)"Screen to Back" },
  47.    { 0, 1, JAM1, 0, 0, (struct TextAttr *)NULL, (UBYTE *)"Clear Screen" },
  48.    { 0, 1, JAM1, 0, 0, (struct TextAttr *)NULL, (UBYTE *)"Close Screen" },
  49.    { 0, 1, JAM1, 0, 0, (struct TextAttr *)NULL, (UBYTE *)"Interrupt  <CTRL-C>"},
  50.    { 0, 1, JAM1, 0, 0, (struct TextAttr *)NULL, (UBYTE *)"Continue   <Return>"}
  51. };
  52.  
  53. struct MenuItem MenuItem[] = {
  54.    {
  55.       &MenuItem[1],
  56.       0, 0, (140 + COMMWIDTH), 9,
  57.       ITEMTEXT | COMMSEQ | ITEMENABLED | HIGHCOMP,
  58.       0,
  59.       (APTR)&IText[0],
  60.       NULL,
  61.       'F',
  62.       NULL,
  63.       NULL
  64.    },
  65.    {
  66.       &MenuItem[2],
  67.       0, 9, (140 + COMMWIDTH), 9,
  68.       ITEMTEXT | COMMSEQ | HIGHCOMP,
  69.       0,
  70.       (APTR)&IText[1],
  71.       NULL,
  72.       'C',
  73.       NULL,
  74.       NULL
  75.    },
  76.    {
  77.       NULL,
  78.       0, 18, (140 + COMMWIDTH), 9,
  79.       ITEMTEXT | COMMSEQ | HIGHCOMP,
  80.       0,
  81.       (APTR)&IText[2],
  82.       NULL,
  83.       'Q',
  84.       NULL,
  85.       NULL
  86.    },
  87.    {
  88.       &MenuItem[4],
  89.       0, 0, (140 + COMMWIDTH), 9,
  90.       ITEMTEXT | ITEMENABLED | HIGHCOMP,
  91.       0,
  92.       (APTR)&IText[3],
  93.       NULL,
  94.       NULL,
  95.       NULL,
  96.       NULL
  97.    },
  98.    {
  99.       NULL,
  100.       0, 9, (140 + COMMWIDTH), 9,
  101.       ITEMTEXT | HIGHCOMP,
  102.       0,
  103.       (APTR)&IText[4],
  104.       NULL,
  105.       NULL,
  106.       NULL,
  107.       NULL
  108.    }
  109. };
  110.     
  111. struct Menu Menu[] = {
  112.    {
  113.       &Menu[1],
  114.       0, 0, 140, 0,
  115.       MENUENABLED,
  116.       "Screen Control",
  117.       &MenuItem[0]
  118.    },        
  119.    {
  120.       NULL,
  121.       140, 0, 140, 0,
  122.       MENUENABLED,
  123.       "Graphics Control",
  124.       &MenuItem[3]
  125.    }
  126. };
  127.  
  128. #ifdef AZTEC_C
  129. struct IntuitionBase *IntuitionBase;
  130. struct GfxBase *GfxBase;
  131. #else
  132. extern struct IntuitionBase *IntuitionBase;
  133. extern struct GfxBase *GfxBase;
  134. #endif
  135. static struct Screen *Screen;
  136. static struct Window *Window;
  137. static struct Border Border;
  138. static short xy[4];
  139.  
  140. /* Open Borderless Full Screen Window for Drawing */
  141. void amiini()
  142. {
  143.    struct Library *OpenLibrary();
  144.    struct Screen *OpenScreen();
  145.    struct Window *OpenWindow();
  146.  
  147.    IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0L);
  148.    if(IntuitionBase == NULL) {
  149.       printf("Couldn't open intuition library");
  150.       exit(1);
  151.    }
  152.     
  153.    GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0L);
  154.    if(GfxBase == NULL) {
  155.       printf("Couldn't open graphics library");
  156.       exit(1);
  157.    }
  158.     
  159.    if((Screen = (struct Screen *)OpenScreen(&NewScreen)) == NULL) {
  160.       printf("Couldn't open custom screen");
  161.       exit(1);
  162.    }
  163.     
  164.    ShowTitle(Screen,FALSE);
  165.  
  166.    NewWindow.Screen = Screen;    /* Pointer to CustomScreen */
  167.     
  168.    if((Window = (struct Window *)OpenWindow(&NewWindow)) == NULL) {
  169.       printf("Couldn't open window.\n");
  170.       exit(1);
  171.    }
  172.     
  173.    Border.LeftEdge = 0;
  174.    Border.TopEdge = 0;
  175.    Border.FrontPen = 1;
  176.    Border.BackPen = 0;
  177.    Border.DrawMode = JAM1;
  178.    Border.Count = 2;
  179.    Border.NextBorder = NULL;
  180.    Border.XY = xy;
  181.     
  182.    SetMenuStrip(Window,Menu);
  183. }
  184.  
  185. void amitex()
  186. {
  187.    /* I don't have a text mode on the custom screen */
  188. }
  189.  
  190. void amigra()
  191. {
  192. }
  193.  
  194. void amicol(color)
  195. int color;
  196. {
  197.    /* No color support at present -- maybe in the next release */
  198. }
  199.  
  200. /* Clear the screen */
  201. void amiclr()
  202. {
  203.    SetRast(Window->RPort,0);
  204. }        
  205.  
  206. /* Draw the line.  Also check for interrupts. */
  207. void amilin(x1,y1,x2,y2)
  208. int x1, y1, x2, y2;
  209. {
  210.    int ItemNumber, MenuNumber;
  211.    ULONG class;
  212.    USHORT code, qualifier;
  213.    struct IntuiMessage *message;
  214.    struct MenuItem *Item, *ItemAddress();
  215.     struct Message *GetMsg();
  216.    void beepw();
  217.  
  218.    xy[0] = x1;
  219.    xy[1] = 399-y1;
  220.    xy[2] = x2;
  221.    xy[3] = 399-y2;
  222.     
  223.    if((xy[0] == xy[2]) && (xy[1] == xy[3]))
  224.       WritePixel(Window->RPort,xy[0],xy[1]);
  225.    else
  226.       DrawBorder(Window->RPort,&Border,0,0);
  227.     
  228.    /* Check for user abort via CTRL-C or menu ABORT selection */
  229.    /* and also Screen to Back Selection */
  230.    /* All other messages are replied to but ignored. */
  231.    while((message = (struct IntuiMessage *)
  232.                      GetMsg(Window->UserPort))!=NULL) {
  233.       class = message->Class;
  234.       code = message->Code;
  235.       qualifier = message->Qualifier;
  236.       ReplyMsg(message);
  237.       if(class == VANILLAKEY) {
  238.          if(code == 3)
  239.             beepw();
  240.       }
  241.       else if(class == MENUPICK) {
  242.          while (code != MENUNULL) {
  243.                Item = ItemAddress(Menu,code);
  244.             MenuNumber = MENUNUM(code);
  245.             ItemNumber = ITEMNUM(code);
  246.             if((MenuNumber == 0) && (ItemNumber == 0))
  247.                ScreenToBack(Screen);
  248.             else if((MenuNumber == 1) && (ItemNumber == 0))
  249.                beepw();
  250.             code = Item->NextSelect;
  251.          }
  252.       }
  253.    }
  254. }
  255.  
  256. void amitid()
  257. {
  258.    ClearMenuStrip(Window);
  259.    CloseWindow(Window);
  260.    CloseScreen(Screen);
  261. }
  262.  
  263. void beepw()
  264. {
  265.    int ItemNumber, MenuNumber;
  266.    ULONG class;
  267.    USHORT code, qualifier;
  268.    struct IntuiMessage *message;
  269.    struct MenuItem *Item, *ItemAddress();
  270.     struct Message *GetMsg();
  271.  
  272.    OnMenu(Window,SHIFTMENU(0)+SHIFTITEM(1));
  273.    OnMenu(Window,SHIFTMENU(0)+SHIFTITEM(2));
  274.    OnMenu(Window,SHIFTMENU(1)+SHIFTITEM(1));
  275.    OffMenu(Window,SHIFTMENU(1)+SHIFTITEM(0));
  276.    for(;;) {
  277.       Wait(1L << Window->UserPort->mp_SigBit);
  278.       while((message = (struct IntuiMessage *)
  279.                         GetMsg(Window->UserPort))!=NULL) {
  280.          class = message->Class;
  281.          code = message->Code;
  282.          qualifier = message->Qualifier;
  283.          ReplyMsg(message);
  284.          if(class == VANILLAKEY) {
  285.             if(code == 13) {
  286.                OffMenu(Window,SHIFTMENU(0)+SHIFTITEM(1));
  287.                OffMenu(Window,SHIFTMENU(0)+SHIFTITEM(2));
  288.                OffMenu(Window,SHIFTMENU(1)+SHIFTITEM(1));
  289.                OnMenu(Window,SHIFTMENU(1)+SHIFTITEM(0));
  290.                return;
  291.             }
  292.          }
  293.          else if(class == MENUPICK) {
  294.             while (code != MENUNULL) {
  295.                Item = ItemAddress(Menu,code);
  296.                MenuNumber = MENUNUM(code);
  297.                ItemNumber = ITEMNUM(code);
  298.                if(MenuNumber == 0) {
  299.                   if(ItemNumber == 0)
  300.                      ScreenToBack(Screen);
  301.                   else if(ItemNumber == 1)
  302.                      SetRast(Window->RPort,0);
  303.                   else if(ItemNumber == 2) {
  304.                      ClearMenuStrip(Window);
  305.                      CloseWindow(Window);
  306.                      CloseScreen(Screen);
  307.                      goto AllDone;
  308.                   }
  309.                }
  310.                else if(MenuNumber == 1) {
  311.                   if (ItemNumber == 1) {
  312.                      OffMenu(Window,SHIFTMENU(0)+SHIFTITEM(1));
  313.                      OffMenu(Window,SHIFTMENU(0)+SHIFTITEM(2));
  314.                      OffMenu(Window,SHIFTMENU(1)+SHIFTITEM(1));
  315.                      OnMenu(Window,SHIFTMENU(1)+SHIFTITEM(0));
  316.                      return;
  317.                   }
  318.                }
  319.                code = Item->NextSelect;
  320.             }
  321.          }
  322.       }
  323.    }
  324.  
  325. AllDone:
  326.    plend();
  327.    exit(1);
  328. }
  329.  
  330.  
  331.