home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.4 / Migrating / ScreenExample / ExtScreen.c next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  11.5 KB  |  291 lines

  1. /* ExtScreen - An example of opening a Screen and a Window in an
  2.  *             operating system version independent manner.
  3.  * SAS/C compile and link with: LC -b1 -cfist -L -v -y ExtScreen.c
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/screens.h>
  9. #include <graphics/gfxbase.h>
  10. #include <graphics/displayinfo.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/graphics_protos.h>
  17.  
  18. struct IntuitionBase *IntuitionBase;
  19. struct GfxBase *GfxBase;
  20. extern struct ExecBase *SysBase;
  21.  
  22. UBYTE vers[] = "$VER: ExtScreen 1.1 (07.08.91)";
  23.  
  24. /* Define the name of Intuition's library if it hasn't itself. */
  25. #ifndef INTUITIONNAME
  26. #define INTUITIONNAME "intuition.library"
  27. #endif
  28.  
  29. /* To get that New Look we'll use Workbench compatible pen numbers.
  30.  * The end of the pen array is indicated with ~0.
  31.  * Note that the screen depth should comply with the pen numbers used.
  32.  * I.e. specifying pen number 3 on a one bitplane screen will obviously
  33.  * not give the desired effect.
  34.  * A description of the pen array can be found in intuition/screens.h.
  35.  */
  36.  
  37. static UWORD    dri_Pens[] =
  38. {0, 1, 1, 2, 1, 3, 1, 0, 3, ~0};
  39.  
  40. /* zoom/zip/zap/zop array to illustrate NW_EXTENDED */
  41. static UWORD    zoomdata[] =
  42. {30, 30, 200, 100};
  43.  
  44. /* Old style requester to be compatible with < V36 */
  45. struct IntuiText reqtext[] = {
  46.     {0,1, JAM1, 10,10, NULL, NULL, NULL},
  47.     {0,1, JAM1, 6,3, NULL, "Continue", NULL},
  48. };
  49.  
  50.  
  51. /* local protos */
  52. void            main(void);
  53. BOOL CheckPAL(STRPTR screenname);
  54.  
  55. void main(void)
  56. {
  57.     struct ExtNewScreen xnewscreen;
  58.     struct ExtNewWindow xnewwindow;
  59.     struct Screen  *screen;
  60.     struct Window  *window;
  61.     struct IntuiMessage *msg;
  62.     struct DisplayInfo displayinfo;
  63.     struct TagItem  taglist[3];
  64.     BOOL OpenA2024 = FALSE;
  65.     BOOL IsV36 = FALSE;
  66.     BOOL IsPAL;
  67.  
  68.     if (IntuitionBase = OpenLibrary(INTUITIONNAME, LIBRARY_MINIMUM)) {
  69.     if (GfxBase = (struct GfxBase *) OpenLibrary(GRAPHICSNAME, LIBRARY_MINIMUM)) {
  70.  
  71.             /* V36 check if a 10 Hz A2024 screen can be opened. If this has to be
  72.              * done in V35 (Jumpstart), start by checking the library version
  73.              * ofcourse. Next simply open the screen with A2024 parameters. If this
  74.              * fails there are a couple of possibilities. The system may have run
  75.              * out of memory or even though the user is running V35 s/he hasn't set
  76.              * up Hedley mode. Logical step in case of failure is to try again with
  77.              * regular parameters. Depending on the nature of the program, this could
  78.              * be done everytime the program starts, or according to some kind of
  79.              * user preferences setting.
  80.              */
  81.  
  82.             /* Check library version. If >= 36 check Hedley availability */
  83.             if (GfxBase->LibNode.lib_Version >= 36) {
  84.                 IsV36 = TRUE;
  85.                 /* Use GetDisplayInfoData() with the DTAG_DISP to get the display info,
  86.                  * containing availability. Note that availability means that the user
  87.                  * admonitor'ed A2024, not necessarily that there is a physical A2024
  88.                  * out there.
  89.                  */
  90.                 if(GetDisplayInfoData(NULL, (UBYTE *)&displayinfo,
  91.                     sizeof(struct DisplayInfo), DTAG_DISP, A2024TENHERTZ_KEY))
  92.                     if (displayinfo.NotAvailable == 0)
  93.                         OpenA2024 = TRUE;
  94.             } else {
  95.                 /* Check if V35. If it is indicate I want the  tags added to open a
  96.                  * A2024 screen. Note that this still doesn't mean I can actually open
  97.                  * in Hedley mode.
  98.                  */
  99.                 if (GfxBase->LibNode.lib_Version == 35)
  100.                     OpenA2024 = TRUE;
  101.             }
  102.  
  103.             /* Use a separate CheckPAL() function to see if how the use has set up
  104.              * the system.
  105.              */
  106.             IsPAL = CheckPAL("Workbench");
  107.  
  108.             /* Build taglist, this is completely ignored in V33/V34 and V35 doesn't
  109.              * recognize tags other than those A2024 ones.
  110.              */
  111.  
  112.             /* Pass the A2024 tags. Note that with V36 it is easy to pass the
  113.              * displaymodeid as a tag (SA_DisplayID) that that is not V35 compatible.
  114.              * Also for V35 compatability this must be the first tag. */
  115.  
  116.             if (OpenA2024) {
  117.             taglist[0].ti_Tag = NSTAG_EXT_VPMODE;
  118.             taglist[0].ti_Data = VPF_A2024 | VPF_TENHZ;
  119.             } else {
  120.                 /* With V36 Intuition fully supports overscan. We'll pass the Overscantype
  121.                  * used by Workbench as a tag, and specify STDSCREENWIDTH/HEIGHT in the
  122.                  * Width and Height fields of the ExtNewScreen structure.
  123.                  */
  124.                 taglist[0].ti_Tag = SA_Overscan;
  125.                 taglist[0].ti_Data = OSCAN_TEXT;
  126.             }
  127.  
  128.             /* Indicate we want the New Look if this system is running V36 by
  129.              * specifying the SA_Pens tag and passing the pen array as data.
  130.              */
  131.             taglist[1].ti_Tag = SA_Pens;
  132.             taglist[1].ti_Data = (ULONG) dri_Pens;
  133.  
  134.  
  135.             /* End the taglist with TAG_DONE */
  136.             taglist[2].ti_Tag = TAG_DONE;
  137.  
  138.  
  139.             /* If V36, the overscan mode will give us the right offsets */
  140.         xnewscreen.LeftEdge = 0;
  141.         xnewscreen.TopEdge = 0;
  142.  
  143.             /* Width = 1008 if A2024, 640 if < V35, STDSCREENWIDTH if V36> */
  144.         xnewscreen.Width = (OpenA2024) ? 1008 : (IsV36) ? STDSCREENWIDTH : 640;
  145.  
  146.             /* Height = 1024 if A2024 & PAL, 800 if A2024 & NTSC, else STDSCREENHEIGHT */
  147.         xnewscreen.Height = (OpenA2024) ? ((IsPAL) ? 1024 : 800) : STDSCREENHEIGHT;
  148.  
  149.         xnewscreen.Depth = 2;
  150.         xnewscreen.DetailPen = 0;
  151.         xnewscreen.BlockPen = 1;
  152.  
  153.             /* Set viewmodes to 0 if going to attempt to open in Hedley mode */
  154.         xnewscreen.ViewModes = (OpenA2024) ? 0 : HIRES | LACE;
  155.  
  156.             /* Use NS_EXTENDED to tell V35 tags are on their way */
  157.         xnewscreen.Type = CUSTOMSCREEN | NS_EXTENDED;
  158.  
  159.             /* Default font */
  160.         xnewscreen.Font = NULL;
  161.  
  162.         xnewscreen.DefaultTitle = (OpenA2024) ? "VPF_A2024|VPF_TENHZ" : "HIRES|LACE";
  163.         xnewscreen.Gadgets = NULL;
  164.  
  165.             /* Pass the taglist as a V35 compatible extension. V34 will ignore this */
  166.         xnewscreen.Extension = taglist;
  167.  
  168.             if ((screen = OpenScreen(&xnewscreen)) == NULL) {
  169.                 /* Can't open screen. Might be V35 A2024 failure. Try with something
  170.                  * simpler.
  171.                  */
  172.                 xnewscreen.Width = (IsV36) ? STDSCREENWIDTH : 640;
  173.                 xnewscreen.Height = STDSCREENHEIGHT;
  174.                 xnewscreen.ViewModes = HIRES | LACE;
  175.                 xnewscreen.DefaultTitle = "HIRES|LACE";
  176.                 /* Get rid of A2024 tags, keep the others. */
  177.                 taglist[0].ti_Tag = SA_Overscan;
  178.                 taglist[0].ti_Data = OSCAN_TEXT;
  179.                 OpenA2024 = FALSE;
  180.             screen = OpenScreen(&xnewscreen);
  181.                 /* If it still fails, give up */
  182.             }
  183.  
  184.             /* If screen opened, open a simple ExtNewWindow on it and wait */
  185.             if (screen) {
  186.                 /* Give me a zoom gadget on my window. */
  187.         taglist[0].ti_Tag = WA_Zoom,
  188.                 taglist[0].ti_Data = (ULONG) zoomdata;
  189.         taglist[1].ti_Tag = TAG_DONE;
  190.  
  191.         xnewwindow.LeftEdge = 0;
  192.         xnewwindow.TopEdge = screen->BarHeight + 1;
  193.         xnewwindow.Width = screen->Width;
  194.         xnewwindow.Height = screen->Height - xnewwindow.TopEdge;
  195.         xnewwindow.DetailPen = 0;
  196.         xnewwindow.BlockPen = 1;
  197.         xnewwindow.IDCMPFlags = CLOSEWINDOW;
  198.         xnewwindow.Flags =
  199.             WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | NW_EXTENDED |
  200.             SMART_REFRESH | NOCAREREFRESH | ACTIVATE;
  201.         xnewwindow.FirstGadget = NULL;
  202.         xnewwindow.CheckMark = NULL;
  203.         xnewwindow.Title = "Close to exit.";
  204.         xnewwindow.Screen = screen;
  205.         xnewwindow.BitMap = NULL;
  206.         xnewwindow.MinWidth = 100;
  207.         xnewwindow.MinHeight = 50;
  208.         xnewwindow.MaxWidth = ~0;
  209.         xnewwindow.MaxHeight = ~0;
  210.         xnewwindow.Type = CUSTOMSCREEN;
  211.                 /* The window extension is completely ignored if not V36 */
  212.         xnewwindow.Extension = taglist;
  213.  
  214.         if (window = OpenWindow(&xnewwindow)) {
  215.             WaitPort(window->UserPort);
  216.             while (msg = (struct IntuiMessage *)GetMsg(window->UserPort))
  217.                         ReplyMsg((struct Message *)msg);
  218.             CloseWindow(window);
  219.         } else {
  220.                     reqtext[0].IText = "Can't open window";
  221.                     AutoRequest(NULL, &reqtext[0], NULL, &reqtext[1], NULL, GADGETUP, 320, 60);
  222.                 }
  223.         CloseScreen(screen);
  224.         } else {
  225.                 reqtext[0].IText = "Can't open screen";
  226.                 AutoRequest(NULL, &reqtext[0], NULL, &reqtext[1], NULL, GADGETUP, 320, 60);
  227.             }
  228.         CloseLibrary((struct Library *) GfxBase);
  229.     }
  230.     CloseLibrary((struct Library *) IntuitionBase);
  231.     }
  232. }
  233.  
  234. /* CheckPAL returns TRUE, if the the videomode of the specified public screen (or default videmode)
  235.  * is PAL.
  236.  * If the screenname is NULL, the default public screen will be used.
  237.  */
  238.  
  239. BOOL CheckPAL(STRPTR screenname)
  240. {
  241.     struct Screen *screen;
  242.     ULONG modeID = LORES_KEY;
  243.     struct DisplayInfo displayinfo;
  244.     BOOL IsPAL;
  245.  
  246.     if (GfxBase->LibNode.lib_Version >= 36) {
  247.     /*
  248.      * We got V36, so lets use the new calls to find out what
  249.      * kind of videomode the user (hopefully) prefers.
  250.      */
  251.  
  252.         if (screen = LockPubScreen(screenname)) {
  253.             /*
  254.              * Use graphics.library/GetVPModeID() to get the ModeID of the specified screen.
  255.              * Will use the default public screen (Workbench most of the time) if NULL It is
  256.              * _very_ unlikely that this would be invalid, heck it's impossible.
  257.              */
  258.             if ((modeID = GetVPModeID(&(screen->ViewPort))) != INVALID_ID) {
  259.                 /*
  260.                  * If the screen is in VGA mode, we can't tell whether the system is PAL or NTSC. So
  261.                  * to be fullproof we fall back to the displayinfo of the default.monitor by
  262.                  * inquiring about just the LORES_KEY displaymode if we don't know. The
  263.                  * default.monitor reflects the initial video setup of the system, thus is an alias
  264.                  * for either ntsc.monitor or pal.monitor. We only use the displaymode of the
  265.                  * specified public screen if it's display mode is PAL or NTSC and NOT the default.
  266.                  */
  267.  
  268.                 if (!((modeID & MONITOR_ID_MASK) == NTSC_MONITOR_ID ||
  269.                       (modeID & MONITOR_ID_MASK) == PAL_MONITOR_ID))
  270.                     modeID = LORES_KEY;
  271.             }
  272.             UnlockPubScreen(NULL, screen);
  273.         } /* if fails modeID = LORES_KEY. Can't lock screen, so fall back on default monitor. */
  274.  
  275.         if (GetDisplayInfoData(NULL, (UBYTE *) & displayinfo,
  276.             sizeof(struct DisplayInfo), DTAG_DISP, modeID)) {
  277.             if (displayinfo.PropertyFlags & DIPF_IS_PAL)
  278.                 IsPAL = TRUE;
  279.             else
  280.                 IsPAL = FALSE;  /* Currently the default monitor is always either
  281.                                  * PAL or NTSC.
  282.                                  */
  283.         }
  284.     } else /* < V36. The enhancements to the videosystem in V36 cannot be better expressed than
  285.             * with the simple way to determine PAL in V34.
  286.             */
  287.         IsPAL= (GfxBase->DisplayFlags & PAL) ? TRUE : FALSE;
  288.  
  289.     return(IsPAL);
  290. }
  291.