home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol1 / intuition-wb / openfullsize < prev    next >
Text File  |  1990-01-26  |  11KB  |  362 lines

  1. (c)  Copyright 1989 Commodore-Amiga, Inc.   All rights reserved.
  2. The information contained herein is subject to change without notice, and 
  3. is provided "as is" without warranty of any kind, either expressed or implied.  
  4. The entire risk as to the use of this information is assumed by the user.
  5.  
  6.  
  7.  
  8.              OPENING FULL SIZE SCREENS AND WINDOWS ON ANY SYSTEM
  9.  
  10.                         Carolyn Scheppner - CATS
  11.  
  12.  
  13.         When writing international software, it is important that your
  14.      screen and window code adapt to both NTSC and PAL screen dimensions.
  15.      In addition to conforming with NTSC (200 line) and PAL (256) line
  16.      displays, you may also wish to adapt to interlace Workbench or any
  17.      additional rows and columns enabled by Morerows (Fish Disk #54).
  18.      
  19.         The 1.2 system software supports both PAL and NTSC, and provides
  20.      several methods for application software to do the same.  The GfxBase
  21.      member DisplayFlags contains flag bits for PAL and NTSC.  Two other
  22.      members, NormalDisplayColumns and NormalDisplayRows, contain the
  23.      default width and height for a non-interlace Workbench screen.  A 
  24.      new Intuition function GetScreenData can provide you with a copy of
  25.      the system's Workbench (or CLI) Screen structure.  In addition, the
  26.      new 1.2 Intuition constant STDSCREENHEIGHT can be specified for
  27.      NewScreen.Height, causing OpenScreen to supply the correct screen
  28.      height for the system you are running on and the ViewMode you
  29.      have requested.  Proper use of these system features should also
  30.      insure compatibility with any future Amiga screen resolutions.
  31.         
  32.         The example program FullScreen.c takes advantage of these new
  33.      features to open a full-screen Workbench window, and two full-size
  34.      custom screens and windows, one lo-res, the other hi-res interlace.
  35.      The display sizes are automatically adjusted for NTSC, PAL, Morerows,
  36.      and interlace Workbench.  Please note that when using any new 1.2
  37.      features or functions, version number 33 should be specified when
  38.      opening system libraries.  In addition, programs which use sprites
  39.      may wish to refuse to run in a Morerows environment because the
  40.      additional DMA cycles needed for the Morerows display can interfere
  41.      with the proper display of sprites.  
  42.           
  43.  
  44.  
  45. /*
  46.  *  FullScreen.c --- Opens full-size screens/windows on any
  47.  *                     NTSC/PAL/Interlace/Morerows system
  48.  *                           C. Scheppner  CBM  06/87 
  49.  */
  50.  
  51. #include <exec/types.h>
  52. #include <graphics/gfxbase.h>
  53. #include <intuition/intuition.h>
  54. #include <libraries/dos.h>
  55.  
  56.  
  57. struct   IntuitionBase  *IntuitionBase;
  58. struct   GfxBase        *GfxBase;
  59.  
  60. #define IS_PAL  (((struct GfxBase *)GfxBase)->DisplayFlags & PAL)
  61. #define IS_NTSC (((struct GfxBase *)GfxBase)->DisplayFlags & NTSC)
  62.  
  63.  
  64. #define NOTYET (0)
  65. #define DEPTH  (2)
  66.  
  67. struct   Screen         *loScreen, *hiScreen;
  68. struct   Window         *loWindow, *hiWindow, *wbWindow;
  69.  
  70. ULONG    signals, waitMask, wbSig, loSig, hiSig;
  71. BOOL     FromWB, Done;
  72.  
  73.  
  74. struct   TextAttr       MyFont = {
  75.    "topaz.font",                    /* Font Name   */
  76.    TOPAZ_EIGHTY,                    /* Font Height */
  77.    FS_NORMAL,                       /* Style       */
  78.    FPF_ROMFONT,                     /* Preferences */
  79.    };
  80.  
  81.  
  82. struct   NewScreen      ns = {
  83.    0, 0,                                  /* LeftEdge and TopEdge   */
  84.    NOTYET,NOTYET,                         /* Width and Height       */
  85.    DEPTH,                                 /* Depth                  */
  86.    0, 1,                                  /* DetailPen and BlockPen */
  87.    NOTYET,                                /* Special display modes  */
  88.    CUSTOMSCREEN,                          /* Screen Type            */
  89.    &MyFont,                               /* Use my font            */
  90.    "==== Screen Title ====",              /* Title                  */
  91.    NULL,                                  /* No gadgets             */
  92.    NULL,                                  /* No bitmap supplied     */
  93.    };
  94.  
  95. struct   NewWindow      nw = {
  96.    0, 0,                                  /* LeftEdge and TopEdge */
  97.    NOTYET, NOTYET,                        /* Width and Height */
  98.    -1, -1,                                /* DetailPen and BlockPen */
  99.    CLOSEWINDOW,                           /* IDCMP Flags */
  100.    WINDOWDEPTH|WINDOWSIZING|              /* Flags */
  101.    WINDOWDRAG|WINDOWCLOSE|
  102.    SMART_REFRESH|ACTIVATE,
  103.    NULL, NULL,                            /* Gadget and Image pointers */
  104.    NOTYET,                                /* Title string */
  105.    NULL,                                  /* Ptr to window's Screen */
  106.    NULL,                                  /* BitMap pointer */
  107.    40, 20,                                /* MinWidth and MinHeight */
  108.    -1, -1,                                /* MaxWidth and MaxHeight */
  109.    NOTYET                                 /* Type of window */
  110.    };
  111.  
  112.  
  113.  
  114. main(argc,argv)
  115. int argc;
  116. char** argv;
  117.    {
  118.    struct Screen wbScrData;
  119.  
  120.    FromWB = (argc==0) ? TRUE : FALSE;
  121.  
  122.    /* Open Libraries - Need at least 1.2 for PAL and NTSC support */
  123.  
  124.    if(!(IntuitionBase =
  125.       (struct IntuitionBase *)OpenLibrary("intuition.library", 33)))
  126.          cleanexit("At least V1.2 intuition required\n");
  127.  
  128.    if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",33)))
  129.       cleanexit("At least V1.2 graphics required\n");
  130.  
  131.  
  132.    /* OPEN FULL-SIZE WINDOW ON WORKBENCH SCREEN */
  133. B
  134.    /* Get parameters of the existing Workbench screen */
  135.    if(!(GetScreenData(&wbScrData,sizeof(struct Screen),WBENCHSCREEN,NULL)))
  136.       cleanexit("Can't get default screen info\n");
  137.  
  138.    /* Set NewWindow sizes to match */
  139.    nw.Width  = wbScrData.Width;
  140.    nw.Height = wbScrData.Height;
  141.    nw.Type   = WBENCHSCREEN;
  142.    nw.Title  = ">>>> Workbench Window <<<<";
  143.  
  144.    /* Open the window */
  145.    if(!(wbWindow = (struct Window *)OpenWindow(&nw)))
  146.       cleanexit("Can't open wbWindow\n");
  147.  
  148.    /* Output info about this window */
  149.    showInfo(wbWindow);
  150.  
  151.  
  152.    /* OPEN A FULL-SIZE LO-RES CUSTOM SCREEN AND WINDOW */
  153.  
  154.    /* Set NewScreen sizes */
  155.    ns.ViewModes   = NULL;                 /* Lo-res non-interlace screen */
  156.    ns.Width       = wbScrData.Width >> 1;     /* Lo-res is half WB width */
  157.    ns.Height      = STDSCREENHEIGHT;             /* From 1.2 intuition.h */
  158.  
  159.    /* Open the screen */
  160.    if(!(loScreen = (struct Screen *)OpenScreen(&ns)))
  161.       cleanexit("Can't open loScreen\n");
  162.  
  163.    /* Set NewWindow sizes to match */
  164.    nw.Screen = loScreen;
  165.    nw.Width  = loScreen->Width;
  166.    nw.Height = loScreen->Height;
  167.    nw.Type   = CUSTOMSCREEN;
  168.    nw.Title  = ">>>> Lo-res <<<<";
  169.  
  170.    /* Open the window */
  171.    if(!(loWindow = (struct Window *)OpenWindow(&nw)))
  172.       cleanexit("Can't open loWindow\n");
  173.  
  174.    /* Output info about this window */
  175.    showInfo(loWindow);
  176.  
  177.  
  178.    /* OPEN A FULL-SIZE HI-RES LACE CUSTOM SCREEN AND WINDOW */
  179.  
  180.    /* Set NewScreen sizes */
  181.    ns.ViewModes = HIRES|LACE;                 /* Hi-res interlace screen */
  182.    ns.Width     = wbScrData.Width;            /* Same width as Workbench */
  183.    ns.Height    = STDSCREENHEIGHT;               /* From 1.2 intuition.h */
  184.  
  185.    /* Open the screen */
  186.    if(!(hiScreen = (struct Screen *)OpenScreen(&ns)))
  187.       cleanexit("Can't open hiScreen\n");
  188.  
  189.    /* Set NewWindow sizes to match */
  190.    nw.Screen = hiScreen;
  191.    nw.Width  = hiScreen->Width;
  192.    nw.Height = hiScreen->Height;
  193.    nw.Type   = CUSTOMSCREEN;
  194.    nw.Title  = ">>>> Hi-res Lace <<<<";
  195.  
  196.    /* Open the window */
  197.    if(!(hiWindow = (struct Window *)OpenWindow(&nw)))
  198.       cleanexit("Can't open hiWindow\n");
  199.  
  200.    /* Output info about this window */
  201.    showInfo(hiWindow);
  202.  
  203.  
  204.    /* Set up signal mask for each window */
  205.    wbSig = 1 << wbWindow->UserPort->mp_SigBit;
  206.    loSig = 1 << loWindow->UserPort->mp_SigBit;
  207.    hiSig = 1 << hiWindow->UserPort->mp_SigBit;
  208.    waitMask = wbSig|loSig|hiSig;    /* Will knock out each as closed */
  209.  
  210.    /* Wait for signals, Done when all windows are closed */
  211.    Done = FALSE;
  212.    while(!Done)
  213.       {
  214.       signals = Wait(waitMask);
  215.  
  216.       /* chkmsg will set Done = TRUE when all windows are closed */
  217.       if(signals & wbSig)  chkmsg(wbWindow);
  218.       if(signals & loSig)  chkmsg(loWindow);
  219.       if(signals & hiSig)  chkmsg(hiWindow);
  220.       }
  221.  
  222.    /* All closed - keep cleanup from re-closing */
  223.    loWindow = hiWindow = wbWindow = NULL;
  224.    loScreen = hiScreen = NULL;
  225.    cleanup();
  226.    }
  227.  
  228.  
  229. showInfo(win)
  230. struct Window *win;
  231.    {
  232.    struct RastPort *rp;
  233.    char sbuf[80], *s;
  234.  
  235.    rp = win->RPort;
  236.    SetAPen(rp,1);
  237.  
  238.    Move(rp,20,40);
  239.    if(IS_PAL)        s = "Running on a PAL system";
  240.    else if(IS_NTSC)  s = "Running on an NTSC system";
  241.    Text(rp,s,strlen(s));
  242.  
  243.    Move(rp,20,80);
  244.    sprintf(sbuf,"Screen Size: %ld by %ld",
  245.               win->WScreen->Width, win->WScreen->Height);
  246.    Text(rp,sbuf,strlen(sbuf));
  247.  
  248.    Move(rp,20,120);
  249.    sprintf(sbuf,"( Close all windows to end demo )");
  250.    Text(rp,sbuf,strlen(sbuf));
  251.  
  252.    Delay(100);
  253.    }
  254.  
  255.  
  256. chkmsg(win)
  257. struct Window *win;
  258.    {
  259.    struct IntuiMessage *msg;
  260.    ULONG  class, code;
  261.    BOOL   CloseIt = FALSE;
  262.  
  263.    while(msg = (struct IntuiMessage *)GetMsg(win->UserPort))
  264.       {
  265.       class = msg->Class;
  266.       code  = msg->Code;
  267.  
  268.       ReplyMsg(msg);
  269.       switch(class)
  270.          {
  271.          case CLOSEWINDOW:
  272.             CloseIt = TRUE;
  273.             break;
  274.          default:
  275.             break;
  276.          }
  277.       }
  278.  
  279.    /* Handle Close after out of the GetMsg loop! */
  280.    if(CloseIt)
  281.       {
  282.       /* Stop waiting on this one - Set Done = TRUE if none left */
  283.       waitMask &= ~(1 << win->UserPort->mp_SigBit);
  284.       if(!waitMask)  Done = TRUE;
  285.  
  286.       /* Close this display */
  287.       closeDisplay(win, win->WScreen);
  288.       }
  289.    }
  290.  
  291. cleanexit(s)
  292. char *s;
  293.    {
  294.    LONG wh;
  295.  
  296.    cleanup();
  297.    if(*s)
  298.       {
  299.       if(FromWB)
  300.          {
  301.          if(wh = (Open("CON:40/40/600/100/>>>> Error <<<<",MODE_OLDFILE)))
  302.             {
  303.             Write(wh,s,strlen(s));
  304.             Delay(200);
  305.             Close(wh);
  306.             }
  307.           }
  308.        else  printf(s);
  309.        }
  310.    exit(0);
  311.    }
  312.  
  313.  
  314. cleanup()
  315.    {
  316.    closeDisplay(hiWindow, hiScreen);
  317.    closeDisplay(loWindow, loScreen);
  318.    closeDisplay(wbWindow, NULL);
  319.  
  320.    if (GfxBase) CloseLibrary(GfxBase);
  321.    if (IntuitionBase) CloseLibrary(IntuitionBase);
  322.    }
  323.  
  324.  
  325. closeDisplay(win,scr)
  326. struct Window *win;
  327. struct Screen *scr;
  328.    {
  329.    struct IntuiMessage *msg;
  330.  
  331.    /* Close the window */
  332.    if(win)
  333.       {
  334.       while(msg = (struct IntuiMessage *)GetMsg(win->UserPort))
  335.          {
  336.          ReplyMsg(msg);
  337.          }
  338.       CloseWindow(win);
  339.       }
  340.  
  341.    /* If not on WorkBench screen, close screen also */
  342.    if((scr)&&((scr->Flags & SCREENTYPE)!=WBENCHSCREEN))  CloseScreen(scr);
  343.    }
  344.  
  345.  
  346. strlen(s)
  347. char *s;
  348.    {
  349.    int i = 0;
  350.    while(*s++) i++;
  351.    return(i);
  352.    }
  353.  
  354. /* end */
  355.       
  356.      
  357.  
  358.  
  359.  
  360.  
  361.  
  362.