Re: erase then draw image?
Re: erase then draw image?
- Subject: Re: erase then draw image?
- From: matt neuburg <email@hidden>
- Date: Thu, 24 Oct 2002 07:57:50 -0700
>
You need to make sure that you override the isOpaque: method properly in
>
your view. This is the source of the problem
No - I was doing that. And this is otiose in any case, since NO is the default.
>
Another thing to watch out for is overlapping views. If your views are not
>
completely contained within one another in the coordinate system, the view
>
hierarchy gets confused and drawing doesn't occur properly
The watermark view is the same size as the contentview of the window, so overlapping is complete. So I don't think this can be the problem either.
I think the problem is related to the rotation of the coordinate system, but I'm not sure how.
I append some sample code. (Remember, I'm no longer using anything like this code, but I'm just curious as to how to fix it to make it work, if this is possible.)
To see the problem, make a window, put into it a custom NSView the same size as the window, and over that put a button and a couple of non-editable textfields (the watermark must be drawn behind everything, so this layering order is important). If I comment out both line 1 and line 2 the problem does not immediately show itself, but we don't get any rotation either. If I comment out line 2, the textfields are rotated, which is wrong; thus it is important to include line 2. If I include line 1 and line 2, the original problem with darkening of the text appears - press the button several times to see it happen.
This is the NSView code. image is an NSImage ivar.
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
NSString* text = @"HOWDY";
NSFont* geneva100 = [NSFont fontWithName: @"Geneva" size: 100];
NSColor* blue = [NSColor blueColor];
NSDictionary* attrs = [NSDictionary dictionaryWithObjectsAndKeys:
geneva100, NSFontAttributeName,
blue, NSForegroundColorAttributeName, nil];
image = [[[NSImage alloc] init] retain];
[image setSize: NSMakeSize(frame.size.width/2, frame.size.height/2)];
[image lockFocus];
[text drawAtPoint:NSMakePoint(0,0) withAttributes:attrs];
[image unlockFocus];
}
return self;
}
- (BOOL) isOpaque {
return NO;
}
- (void)drawRect:(NSRect)rect {
[self setBoundsRotation: 10]; // line 1
[image drawAtPoint:NSMakePoint(50,25)
fromRect:NSMakeRect(0,0,[image size].width,[image size].height)
operation:NSCompositeSourceOver fraction:0.2];
[self setBoundsRotation: 0]; // line 2
}
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.