Transparent background for controls - some problems
Transparent background for controls - some problems
- Subject: Transparent background for controls - some problems
- From: Alexander Bokovikov <email@hidden>
- Date: Mon, 8 Mar 2010 10:12:48 +0500
Hi, All,
I'm trying to create a NSView descendent which could draw a custom
bitmap background and which could contain other subviews (like labels
and buttons) . The problem that all goes perfectly unless controls
will change their state or any another event will cause my view
redrawing.
When any control changes its state (e.g. label changes its caption)
its background is drawn in some incorrect way, which you can see here:
http://68.178.246.102/etc/cocoa/test.png
Here an empty label is shown after its caption was changed to "". I've
created a special striped background with holes, randomly set to
visualize this effect.
Please note, that initially (on startup) all looks just perfectly.
Here is my code (its essential part) of my custom view, drawing the
background:
Here "buf" is a temporary NSImage, where rectangular piece is created,
and "bg" is the original background of the whole NSView in size.
- (void)drawRect:(NSRect)rect {
..............
rep = [[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:nil ............
reps = [buf representations];
if (reps != nil && [reps count] > 0)
[buf removeRepresentation:[reps objectAtIndex:0]];
[buf setSize:NSZeroSize];
[buf addRepresentation:rep];
r = rect;
r.origin.x = 0;
r.origin.y = 0;
[buf lockFocus];
[bg drawInRect:r
fromRect:rect
operation:NSCompositeCopy
fraction:1.0];
[buf unlockFocus];
ctx = [NSGraphicsContext currentContext];
[ctx saveGraphicsState];
[ctx setShouldAntialias:YES];
[ctx setPatternPhase:NSMakePoint(0, 0)];
[[NSColor colorWithPatternImage:buf] set];
NSRectFill(rect);
[ctx restoreGraphicsState];
}
I've tried to save both buf and bg as TIFF's and apply buf on bg in
PhotoShop with appropriate shift - all looks exactly, as it should be.
The problem is that some controls, like labels, checkboxes and
buttons, are drawn somehow outside of this procedure. At least I could
not find their rectangles, when I logged rect parameter.
Any help would be appreciated.
Thanks
-Alexander
_______________________________________________
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