home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!nih-csl.dcrt.nih.gov!FAXCSL!FIXER
- From: fixer@faxcsl.dcrt.nih.gov (Chris Feelin' Groovy Tate)
- Subject: Re: Displaying a picture. Question.
- Message-ID: <1992Dec28.153342.24774@alw.nih.gov>
- Sender: postman@alw.nih.gov (AMDS Postmaster)
- Reply-To: fixer@faxcsl.dcrt.nih.gov
- Organization: Computer Systems Laboratory, DCRT, NIH
- References: <1992Dec22.223722.6239@bnr.ca>
- Date: Mon, 28 Dec 1992 15:33:42 GMT
- Lines: 93
-
- In article <1992Dec22.223722.6239@bnr.ca>, brunner@crchh447.bnr.ca (James Brunner) writes:
- >Greetings, I wish to display a small picture in a dialog box. I have an
- >8-bit grayscale pict. How do I display this if the monitor is set to 1-bit?
- >I know that QuickTime can do this, but I can't always be sure that QuickTime
- >is installed. Do I need two PICTs in the resource fork and then I have to
- >pick the PICT based on bit depth? I guess I need a user-item in my dialog
- >box for this? How do I get the screen depth of the screen where my dialog
- >is displayed? Is there a better way?
-
- The easiest way, I think, is to have two PICT resources - one 8-bit, one
- 1-bit. At run-time, fetch the appropriate one into a PicHandle, and draw
- whatever picture it holds via a userItem procedure. The easiest way to do
- this involves using a global variable, so you don't have to read the picture
- more than once (i.e. so that the userItem procedure can assume that the
- PicHandle has been initialized). Example (in C):
-
- PicHandle globalPict;
-
- // here's the userItem procedure for drawing the PICT
-
- pascal void pictItem(DialogPtr theDialog, short theItem)
- {
- Rect itemRect;
- short iType;
- Handle iHand;
-
- // look up the rectangle for drawing the PICT
-
- GetDItem(theDialog, theItem, &iType, &iHand, &itemRect);
-
- // draw the PICT
-
- DrawPicture(globalPict, &itemRect);
- }
-
- // now, here's a skeleton of code you'd use to set up the dialog
-
- void DoDialog()
- {
- short iType;
- Handle iHand;
- Rect iRect;
- DialogPtr theDlog;
-
- // get the dialog from the resource file
-
- theDlog = GetNewDialog(DLOG_ID, (Ptr) 0L, (WindowPtr) -1L);
-
- // configure the userItem
-
- GetDItem(theDlog, PICT_ITEM, &iType, &iHand, &iRect);
- SetDItem(theDlog, PICT_ITEM, &iType, (Handle) pictItem, &iRect);
-
- // look up the appropriate picture
-
- if (gRunningInColor)
- globalPict = (PicHandle) GetResource('PICT', COLOR_PICT);
- else globalPict = (PicHandle) GetResource('PICT', BW_PICT);
-
- // now do the dialog stuff
-
- ShowWindow(theDlog);
-
- do { ModalDialog(0L, &itemHit); } while (itemHit != ok);
-
- DisposeDialog(theDlog);
- ReleaseResource((Handle) globalPict);
- }
-
- Things in all caps (COLOR_PICT, etc.) need to be appropriately #define'd (or
- declared const, or whatever your preference, depending on your Language Of
- Choice).
-
- To figure out whether you're running in 8-bit or 1-bit mode, you can use the
- GetDepth() function (assuming it's available). Or, you could examine thePort
- as follows:
-
- if (((CGrafPort) thePort)->portVersion & 0xC000)
- gRunningInColor = TRUE;
- else gRunningInColor = FALSE;
-
- This will tell you whether or not the current port is a color GrafPort (I think
- - no guarantees; this is untested :-). You have a variety of mechanisms
- available to you. SysEnvirons() will tell you whether or not you have color
- QuickDraw available; you can go from there.
-
- Hope this isn't too confusing (and is correct!)...
-
- ------------------------------------------------------------------------------
- Christopher Tate | Return of the CryptoSig (tm):
- Management Systems Designers | LR KMBVALMH ZKM HD CNDMH, LV CLYY. LR
- | MDVALMH AKT HDMU CNDMH, BDX'QU DQUNYDDEUJ
- fixer@faxcsl.dcrt.nih.gov | TDIUVALMH.
-