home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / publicscreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  3.1 KB  |  105 lines

  1. /* publicscreen.c
  2. ** open a screen with the pens from a public screen.
  3. **
  4. ** SAS/C 5.10a
  5. ** lc -b1 -cfist -v -y publicscreen
  6. ** blink FROM LIB:c.o publicscreen.o TO publicscreen LIB LIB:lc.lib LIB:amiga.lib
  7. */
  8. #define INTUI_V36_NAMES_ONLY
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/screens.h>
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <clib/intuition_protos.h>
  17.  
  18. #ifdef LATTICE
  19. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  20. int chkabort(void) { return(0); }  /* really */
  21. #endif
  22.  
  23. VOID usePubScreenPens(void);
  24.  
  25. struct Library *IntuitionBase;
  26.  
  27. /* main(): open libraries, clean up when done.
  28. */
  29. VOID main(int argc, char **argv)
  30. {
  31. IntuitionBase = OpenLibrary("intuition.library",0);
  32. if ( IntuitionBase != NULL )
  33.     {
  34.     /* Check the version number; Release 2 is */
  35.     /* required for public screen functions   */
  36.     if (IntuitionBase->lib_Version >= 37)
  37.         {
  38.         usePubScreenPens();
  39.         }
  40.     CloseLibrary(IntuitionBase);
  41.     }
  42. }
  43.  
  44. /* Open a screen that uses the pens of an existing public screen
  45. ** (the Workbench screen in this case).
  46. */
  47. VOID usePubScreenPens(void)
  48. {
  49. struct Screen *my_screen;
  50. struct TagItem screen_tags[2];
  51. UBYTE *pubScreenName = "Workbench";
  52.  
  53. struct Screen *pub_screen = NULL;
  54. struct DrawInfo *screen_drawinfo = NULL;
  55.  
  56. /* Get a lock on the Workbench screen */
  57. pub_screen = LockPubScreen(pubScreenName);
  58. if ( pub_screen != NULL )
  59.     {
  60.     /* get the DrawInfo structure from the locked screen */
  61.     screen_drawinfo = GetScreenDrawInfo(pub_screen);
  62.     if ( screen_drawinfo != NULL)
  63.         {
  64.         /* the pens are copied in the OpenScreenTagList() call,
  65.         ** so we can simply use a pointer to the pens in the tag list.
  66.         **
  67.         ** This works better if the depth and colors of the new screen
  68.         ** matches that of the public screen.  Here we are forcing the
  69.         ** workbench screen pens on a monochrome screen (which may not
  70.         ** be a good idea).  You could add the tag:
  71.         **      (SA_Depth, screen_drawinfo->dri_Depth)
  72.         */
  73.         screen_tags[0].ti_Tag  = SA_Pens;
  74.         screen_tags[0].ti_Data = (ULONG)(screen_drawinfo->dri_Pens);
  75.         screen_tags[0].ti_Tag  = TAG_END;
  76.         screen_tags[0].ti_Data = NULL;
  77.  
  78.         my_screen = OpenScreenTagList(NULL, screen_tags);
  79.         if (my_screen != NULL)
  80.             {
  81.             /* We no longer need to hold the lock on the public screen
  82.             ** or a copy of its DrawInfo structure as we now have our
  83.             ** own screen.  Release the screen.
  84.             */
  85.             FreeScreenDrawInfo(pub_screen,screen_drawinfo);
  86.             screen_drawinfo = NULL;
  87.             UnlockPubScreen(pubScreenName,pub_screen);
  88.             pub_screen = NULL;
  89.  
  90.             Delay(90);   /* should be rest_of_program */
  91.  
  92.             CloseScreen(my_screen);
  93.             }
  94.         }
  95.     }
  96.  
  97. /* These are freed in the main loop if OpenScreenTagList() does
  98. ** not fail.  If something goes wrong, free them here.
  99. */
  100. if ( screen_drawinfo != NULL )
  101.     FreeScreenDrawInfo(pub_screen,screen_drawinfo);
  102. if ( pub_screen!= NULL )
  103.     UnlockPubScreen(pubScreenName,pub_screen);
  104. }
  105.