Re: I need a milder application badge (solution)
Re: I need a milder application badge (solution)
- Subject: Re: I need a milder application badge (solution)
- From: Jay Reynolds Freeman <email@hidden>
- Date: Fri, 24 Jul 2009 23:17:13 -0700
> I have cause to display something like an application badge on
> the docktile of my app, but [the regular one won't do] ...
Solution (I think ...):
I ended up finding a basically sane way to do this -- just
one method, and I did not have to subclass NSView -- but
with a large hack for one feature:
I was using a pre-existing image for the docktile. That was
what I wanted to put the badge on.
I created an offscreen window, added an NSImageView the same
size as my image to its view hierarchy, then added an instance
of NSText as a subview thereof, at an appropriate location.
By loading my image into the image view and then drawing the
text with a suitable background color, I was able to get a
decent "badge".
Before doing the drawing, I saved the graphics context and
set up a new one with the view, and locked focus on the view;
I unlocked and restored later. That setup allowed me to use
NSBitmapImageRep:initWithFocusedViewRect: to grab the bits
as drawn. I loaded the bitmap into a new instance of NSImage,
which I could then assign to my docktile.
Now the hack: My original image had some transparent areas,
and I could not figure out a reasonable technique for capturing
the bitmap drawn by the above procedure without also getting the
bits for whatever background lay *behind* the transparent areas
of my original image. I don't do a lot of graphics work, so if
I am overlooking something obvious I will be very grateful if
someone will tell me.
My hack took advantage of the fact that my badged image did
not have any of a certain color. I ended up setting the window
background color to that color, then going through the captured
bitmap one pixel at a time, changing all pixels that were
approximately that color to transparent. (Actually, I had to
make a whole new bitmap and copy or make-transparent; the
captured bitmap did not have an alpha plane.) That did work,
but it is not a very graceful technique or a very general one.
-- Jay Reynolds Freeman
---------------------
email@hidden
http://web.mac.com/jay_reynolds_freeman (personal web site)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden