home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / programm / 20355 < prev    next >
Encoding:
Text File  |  1992-12-28  |  3.6 KB  |  106 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!nih-csl.dcrt.nih.gov!FAXCSL!FIXER
  3. From: fixer@faxcsl.dcrt.nih.gov (Chris Feelin' Groovy Tate)
  4. Subject: Re: Displaying a picture.  Question.
  5. Message-ID: <1992Dec28.153342.24774@alw.nih.gov>
  6. Sender: postman@alw.nih.gov (AMDS Postmaster)
  7. Reply-To: fixer@faxcsl.dcrt.nih.gov
  8. Organization: Computer Systems Laboratory, DCRT, NIH
  9. References: <1992Dec22.223722.6239@bnr.ca>
  10. Date: Mon, 28 Dec 1992 15:33:42 GMT
  11. Lines: 93
  12.  
  13. In article <1992Dec22.223722.6239@bnr.ca>, brunner@crchh447.bnr.ca (James Brunner) writes:
  14. >Greetings, I wish to display a small picture in a dialog box.  I have an
  15. >8-bit grayscale pict.  How do I display this if the monitor is set to 1-bit?
  16. >I know that QuickTime can do this, but I can't always be sure that QuickTime
  17. >is installed.  Do I need two PICTs in the resource fork and then I have to
  18. >pick the PICT based on bit depth?  I guess I need a user-item in my dialog
  19. >box for this?  How do I get the screen depth of the screen where my dialog
  20. >is displayed?  Is there a better way?
  21.  
  22. The easiest way, I think, is to have two PICT resources - one 8-bit, one
  23. 1-bit.  At run-time, fetch the appropriate one into a PicHandle, and draw
  24. whatever picture it holds via a userItem procedure.  The easiest way to do
  25. this involves using a global variable, so you don't have to read the picture
  26. more than once (i.e. so that the userItem procedure can assume that the
  27. PicHandle has been initialized).  Example (in C):
  28.  
  29. PicHandle    globalPict;
  30.  
  31. // here's the userItem procedure for drawing the PICT
  32.  
  33. pascal void pictItem(DialogPtr theDialog, short theItem)
  34. {
  35.     Rect    itemRect;
  36.     short    iType;
  37.     Handle    iHand;
  38.  
  39. // look up the rectangle for drawing the PICT
  40.  
  41.     GetDItem(theDialog, theItem, &iType, &iHand, &itemRect);
  42.  
  43. // draw the PICT
  44.  
  45.     DrawPicture(globalPict, &itemRect);
  46. }
  47.  
  48. // now, here's a skeleton of code you'd use to set up the dialog
  49.  
  50. void DoDialog()
  51. {
  52.     short         iType;
  53.     Handle        iHand;
  54.     Rect           iRect;
  55.     DialogPtr    theDlog;
  56.  
  57. // get the dialog from the resource file
  58.  
  59.     theDlog = GetNewDialog(DLOG_ID, (Ptr) 0L, (WindowPtr) -1L);
  60.  
  61. // configure the userItem
  62.  
  63.     GetDItem(theDlog, PICT_ITEM, &iType, &iHand, &iRect);
  64.     SetDItem(theDlog, PICT_ITEM, &iType, (Handle) pictItem, &iRect);
  65.  
  66. // look up the appropriate picture
  67.  
  68.     if (gRunningInColor)
  69.         globalPict = (PicHandle) GetResource('PICT', COLOR_PICT);
  70.     else globalPict = (PicHandle) GetResource('PICT', BW_PICT);
  71.  
  72. // now do the dialog stuff
  73.  
  74.     ShowWindow(theDlog);
  75.  
  76.     do { ModalDialog(0L, &itemHit); } while (itemHit != ok);
  77.  
  78.     DisposeDialog(theDlog);
  79.     ReleaseResource((Handle) globalPict);
  80. }
  81.  
  82. Things in all caps (COLOR_PICT, etc.) need to be appropriately #define'd (or
  83. declared const, or whatever your preference, depending on your Language Of
  84. Choice).
  85.  
  86. To figure out whether you're running in 8-bit or 1-bit mode, you can use the
  87. GetDepth() function (assuming it's available).  Or, you could examine thePort
  88. as follows:
  89.  
  90.     if (((CGrafPort) thePort)->portVersion & 0xC000)
  91.         gRunningInColor = TRUE;
  92.     else gRunningInColor = FALSE;
  93.  
  94. This will tell you whether or not the current port is a color GrafPort (I think
  95. - no guarantees; this is untested :-).  You have a variety of mechanisms
  96. available to you.  SysEnvirons() will tell you whether or not you have color
  97. QuickDraw available; you can go from there.
  98.  
  99. Hope this isn't too confusing (and is correct!)...
  100.  
  101. ------------------------------------------------------------------------------
  102. Christopher Tate             | Return of the CryptoSig (tm):
  103. Management Systems Designers |    LR KMBVALMH ZKM HD CNDMH, LV CLYY.  LR
  104.                              |    MDVALMH AKT HDMU CNDMH, BDX'QU DQUNYDDEUJ
  105. fixer@faxcsl.dcrt.nih.gov    |    TDIUVALMH.
  106.