davism@csgrad.cs.vt.edu (06/27/91)
I'm trying to get "bouncing" buttons working using color icons. I'm using two icons per button, a "normal" image and a "pressed" image. Because I can't predict what color background they'll be drawn on, I need to compute bitmaps that are the difference of the two images (one normal-to-pressed and the other pressed-to-normal) so that I can use CopyMask to clean up the background after a press or a release. The code was working fine with THINK C 4.0.x and the TCL, but now I've converted it to MPW C++ and MacApp and it is no longer working. From inserting debugging code, it appears that I can't reliably use the colorIcon.iconMask bitmap anymore. I discovered in THINK C that the icon mask doesn't appear to be valid until *after* the cicn is drawn the first time (with PlotCIcon), but I'm not trying to use it until after the first draw. If anyone can provide any suggestions, I'd greatly appreciate it. -------------------------------------------------------------------------- Mat Davis Virginia Tech -------------------------------------------------------------------------- *** Problem code *** /*----------------------------------------------------------------------*/ static void createDiffBitmap (CIconHandle beforeIcon, CIconHandle afterIcon, BitMap *diffMap, Ptr bits) { // createDiffBitmap static Rect iconRect = { 0, 0, 32, 32 }; // Initialize 'diffMap' if (!bits) diffMap -> baseAddr = NewPtr (128); else { diffMap -> baseAddr = bits; memset (bits, 0, 128); } // else diffMap -> rowBytes = 4; diffMap -> bounds = iconRect; // Make sure we don't "colorize" the CopyBits RGBForeColor (&SysBlack); RGBBackColor (&SysWhite); // Make sure everything's locked down HLock ((Handle) beforeIcon); HLock ((Handle) afterIcon); #if 0 // This CopyBits to the screen doesn't *always* show the // correct bitmap (it does sometimes, though). CopyBits (&(**beforeIcon).iconMask, &qd.thePort -> portBits, &iconRect, &rect1, srcCopy, NULL); #endif // Straight copy of 'beforeIcon' to 'diffMap' CopyBits (&(**beforeIcon).iconMask, diffMap, &iconRect, &iconRect, srcCopy, NULL); // Now erase the bits of 'diffMap' that are in 'afterIcon' CopyBits (&(**afterIcon).iconMask, diffMap, &iconRect, &iconRect, srcBic, NULL); // Unlock both icons HUnlock ((Handle) beforeIcon); HUnlock ((Handle) afterIcon); } // createDiffBitmap
davism@csgrad.cs.vt.edu (06/28/91)
In article <1326@creatures.cs.vt.edu> davism@vtopus.cs.vt.edu (me) writes: >I'm trying to get "bouncing" buttons working using color icons. >... >I discovered in THINK C that the icon mask doesn't appear to be valid >until *after* the cicn is drawn the first time (with PlotCIcon), but >I'm not trying to use it until after the first draw. I tracked down the problem: apparently the mask is only valid just after a call to PlotCIcon and is subject to some kind of trashing later. I finally reorganized the code so that the mask is never used except just *after* it's been drawn. That isn't the most logical way to structure it, but it appears to be the only way that works. I'd suggest one or more of the following changes: 1. Make the internal structures valid at all times 2. Document the times that they *are* valid 3. Don't document the internals. Anyway, another bug bites the dust!! -------------------------------------------------------------------------- Mat Davis Virginia Tech --------------------------------------------------------------------------