Le 15 mars 09 à 13:00, Graham Cox a écrit :


On 14/03/2009, at 7:42 PM, Philip Kime wrote:

I am trying to work out how to flash two rects in a frame. I have it
working with one rect using the view cacheImageInRect method but this
only works on one rect. I tried putting two such calls in serial but
the second one doesn't work for some (optimisation?) reason. Then I
tried copying and modifying the code from the GNUstep implementation
of the method but this is too hard for me since I'm not a serious ObjC
or Cocoa programmer - the method is designed to be run as an instance
method and the code wasn't suitable for just calling directly in a
routine. I never got it to work. So, I subclassed  NSWindow and tried
adding a "cacheImagesInRects" method but again, I couldn't get this to
work - the "restoreImagesInRects" never seemed to restore anything.

I also tried just colouring the rects with
NSRectFillListWithColorsUsingOperation, hoping to be able to use
NSCompositeLighter and then NSCompositeDarker to reverse the change.
Again, no luck - it almost looked right with a simple DeviceWhite 50%
alpha fill and then Lighter/Darker change but not quite. Any other
colour (which I needed) just failed to reverse and the rects stayed in
the "on" flash state.

I've spent far, far too much time on this now and I realise I'm just
not knowledgeable enough in ObjC or Cocoa. So, any hints on how to
approach flashing two rectangles at the same time? This was so easy in
Carbon - InvRect().


It's not precisely clear what you want here - what do you mean by "flash".

I'll assume you want to draw two rects in a view for a short period then erase them again. In response to what though?

Quartz graphics aren't comparable to QuickDraw graphics because a) they are not pixel-based and b) they support alpha channels which makes simply "inverting" a rect have little meaning. However, if my assumption above is reasonable, doing this is straightforward.


Note that if you want to get a revert effect, you can obtains it drawing white rect with the Quart "Difference Blend Mode".

http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_images/dq_images.html

CGContextRef ctxt = [[NSGraphicsContext currentContext] graphicsPort];
  CGContextSetBlendMode(ctxt, kCGBlendModeDifference);

  CGContextSetGrayFillColor(ctxt, 1, 1);
  CGContextFillRect(ctxt, NSRectToCGRect(aRect));


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to