home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / iv-17 / extscreen.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  13KB  |  351 lines

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