[comp.sys.mac.programmer] ICONs as buttons in a dialog.

time@ice.com (02/15/91)

In article <1392@gertie.osc.edu>, spencer@cgrg.ohio-state.edu (Stephen N. Spencer) writes:
> I've created a dialog box which has the standard 'Cancel' and 'OK' buttons,
> and have five ICON resources that I'd like to use as buttons.  I can display
> them in the dialog box, and I get dialog events when I click on them (it's a
> modeless dialog box...) but they don't invert or anything like that.
> 
> Will I have to handle the inversion of the appropriate area of the screen
> (the clicked-upon ICON) myself or is there some other method for doing this?

You need to use ICN# resources, with the icon mask data.
Example:

DrawIcon(myWindow, myIcon)
WindowPtr	myWindow;
ICONCtl		*myIcon;
{
	/* Cut "hole" into gray (or other) background for icon transfer... */
	CopyBits(&myIcon->maskbits, &myWindow->portBits, &myIcon->maskbits.bounds,
				&myIcon->bounds, srcBic, NULL);
	/* Copyt the icon */
	CopyBits(&myIcon->iconbits, &myWindow->portBits, &myIcon->iconbits.bounds,
				&myIcon->bounds, srcOr, NULL);
	/* Check for "dim" icon. */
	if (icon_list->active == 0) {
		PenMode(patBic);
		PenPat(qd.gray);
		PaintRect(&icon_list->bounds);
		PenNormal();
		}
	}
	
HiliteICON(myWindow, theicon)
WindowPtr	myWindow;
ICONCtl		*theicon;
{
	if (theicon != NULL) {
		if (theicon->showing) {
			/* Invert the icon using it's mask. */
			CopyBits(&theicon->maskbits, &myWindow->portBits, &theicon->maskbits.bounds,
						&theicon->bounds, srcXor, NULL);
			}
		}
	}

Ignore my silly data structures. The iconbits are the first 128 bytes
of the ICN# resource and the maskbits are the second 128 bytes.

tim.

-------------------------------------------------------------
Tim Endres                |  time@ice.com
ICE Engineering           |  uupsi!ice.com!time
8840 Main Street          |  Voice            FAX
Whitmore Lake MI. 48189   |  (313) 449 8288   (313) 449 9208

spencer@cgrg.ohio-state.edu (Stephen N. Spencer) (02/16/91)

I've created a dialog box which has the standard 'Cancel' and 'OK' buttons,
and have five ICON resources that I'd like to use as buttons.  I can display
them in the dialog box, and I get dialog events when I click on them (it's a
modeless dialog box...) but they don't invert or anything like that.

Will I have to handle the inversion of the appropriate area of the screen
(the clicked-upon ICON) myself or is there some other method for doing this?

Stephen N. Spencer     |"Now you must dance the dance that you imply!
ACCAD   (614) 292-3416 | Your actions will follow you full circle round,
The Ohio State Univ.   | The higher the leap, I said, 
1224 Kinnear Road      | The harder the ground!"
Columbus, OH 43212-1163|		- Amy Ray, "Center Stage"
spencer@cgrg.ohio-state.edu||71160.3141@compuserve.com||stephen_spencer@osu.edu

dweisman@umiami.ir.miami.edu (Ordinary Man) (02/16/91)

In article <1CE00001.or5i24@tbomb.ice.com>, ** Sender Unknown ** writes:
> 
> In article <1392@gertie.osc.edu>, spencer@cgrg.ohio-state.edu (Stephen N. Spencer) writes:
>> I've created a dialog box which has the standard 'Cancel' and 'OK' buttons,
>> and have five ICON resources that I'd like to use as buttons.  I can display
>> them in the dialog box, and I get dialog events when I click on them (it's a
>> modeless dialog box...) but they don't invert or anything like that.
>> 
>> Will I have to handle the inversion of the appropriate area of the screen
>> (the clicked-upon ICON) myself or is there some other method for doing this?
> 
> You need to use ICN# resources, with the icon mask data.
> Example:

[Example deleted]

Another possible way seems a lot easier...

Why not just do an InvertRect on the icon's rect. After all, inverting a rect
works as a toggle. Wouldn't this be acceptable?

As you said, you can evaluate which icon was clicked in; probably with
PtInRect. Then just invert the rect that the point was in, and invert it 
again when the button is released, just like TrackControl does. I've never
tried this but I imagine it would work fine, but maybe it would be slow,
flickery, etc...

	==Dan

--

/-------------------------------------------------------------------------\
|   Dan Weisman -  University of Miami - Florida   |  ||   ||   ||   ||   |
|--------------------------------------------------|  ||   ||   ||\ /||   |
|   INTERNET  -----> dweisman@umiami.IR.Miami.edu  |  ||   ||   || | ||   |
|     BITNET  -----> dweisman@umiami               |  |||||||   || | ||   |
|-------------------------------------------------------------------------|
|       "The more I get to see, the less I understand..."    - Triumph    |
\_________________________________________________________________________/

time@ice.com (02/16/91)

In article <1991Feb16.002121.7836@umiami.ir.miami.edu>, dweisman@umiami.ir.miami.edu (Ordinary Man) writes:
> Why not just do an InvertRect on the icon's rect. After all, inverting a rect
> works as a toggle. Wouldn't this be acceptable?
> 

Try inverting the rectangle of an icon using only an area of 8x8 pixels!
Looks like shit don't it! The icon mask is used by most Macintosh
applications specifically to make the inversion "look right".

Besides, with the code right there, why do anything less?

Everyhing depends on how well you want your interface to look. I do
not advocate less-than-Mac standards in Macintosh programs.

tim.

-------------------------------------------------------------
Tim Endres                |  time@ice.com
ICE Engineering           |  uupsi!ice.com!time
8840 Main Street          |  Voice            FAX
Whitmore Lake MI. 48189   |  (313) 449 8288   (313) 449 9208

time@ice.com (02/16/91)

In article <3931@uakari.primate.wisc.edu>, bin@primate.wisc.edu (Brain in Neutral) writes:
[>From article <1CE00001.0876hq@tbomb.ice.com>, by <somebody>:
[> Try inverting the rectangle of an icon using only an area of 8x8 pixels!
[> Looks like shit don't it!

> I imagine it would, since icons are bigger than 8x8...

I meant that if this were my icon (two 8x8 pixel items in the icon's
32x32 pixel area and a line), and I were to highlight this by inverting
the icon's entire 32x32 area, the result would not look very good. If
you look at an ICN# resource in ResEdit you will discover the
importance of the icon mask.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . X X . . . . . . . . . . .
. . . . . . X X . . . . . . . . . . X X X . . . . . . . . . . .
. . . . . . X X X . . . . . . . . X X X . . . . . . . . . . . .
. . . X X X X X X X . . . . . . X X X . . . . . . . . . . . . .
. . . X . X X X . X X . . . . X X X . . . . . . . . . . . . . .
. . . X X X X X X X . . . . X X X . . . . . . . . . . . . . . .
. . . . . . X X X . . . . X X X . . . . . X X . . . . . . . . .
. . . . . . X X . . . . X X X . . . . . X X X . . . . . . . . .
. . . . . . . . . . . X X X . . . . . X X X X X X X . . . . . .
. . . . . . . . . . X X X . . . . . X X . X X X . X . . . . . .
. . . . . . . . . X X X . . . . . . . X X X X X X X . . . . . .
. . . . . . . . X X X . . . . . . . . . X X X . . . . . . . . .
. . . . . . . . X X . . . . . . . . . . . X X . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

-------------------------------------------------------------
Tim Endres                |  time@ice.com
ICE Engineering           |  uupsi!ice.com!time
8840 Main Street          |  Voice            FAX
Whitmore Lake MI. 48189   |  (313) 449 8288   (313) 449 9208

bin@primate.wisc.edu (Brain in Neutral) (02/17/91)

From article <1CE00001.0876hq@tbomb.ice.com>, by <somebody>:
> Try inverting the rectangle of an icon using only an area of 8x8 pixels!
> Looks like shit don't it!

I imagine it would, since icons are bigger than 8x8...

--
Paul DuBois
dubois@primate.wisc.edu