Re: Getting mouse moved events on overlay windows
Re: Getting mouse moved events on overlay windows
- Subject: Re: Getting mouse moved events on overlay windows
- From: Markus Spoettl <email@hidden>
- Date: Tue, 1 Jul 2008 22:03:18 -0700
On Jul 1, 2008, at 3:54 PM, Brett Powley wrote:
If you get any further, I'd be keen to hear what you find out.
As a matter of fact, I seem to have found something that is much
simpler than overlaying:
Add a subview to the WebView that doesn't clear its content before
drawing. When I first tried this months ago I never tried not clearing
the view's background and always ended up with a completely black
content area where the WebView content should be drawing, so I though
WebView just doesn't like subviews (IB doesn't allow you to put one
there either).
Just minutes ago I retried this and to my complete surprise it works
perfectly (see code example below). The only thing I fear is that
redrawing works by pure coincidence. Does anyone think this is a
doable solution?
I'm using Xcode 3.0 on Mac OS 10.5.4, I have no idea if it works on
previous systems but I'd be most interested in hearing whether or not
it does.
Regards
Markus
In the controller (responsible for the WebView) -awakeFromNib I added
a subview:
- (void)awakeFromNib
{
NSViewTest *sub = [[NSViewTest alloc] initWithFrame:[webview
bounds]];
[webview addSubview:sub];
[sub setHidden:NO];
[sub setAutoresizingMask:[webview autoresizingMask]];
}
And this is my super-simplistic NSView:
@interface NSViewTest : NSView {
NSTrackingArea *ta;
NSPoint mp;
}
@end
@implementation NSViewTest
- (id)initWithFrame:(NSRect)rect
{
self = [super initWithFrame:rect];
if (self) {
ta = [[NSTrackingArea alloc] initWithRect:[self bounds]
options:(NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
NSTrackingActiveInKeyWindow) owner:self userInfo:nil];
[self addTrackingArea:ta];
}
return self;
}
- (void)dealloc
{
[self removeTrackingArea:ta];
[ta release];
[super dealloc];
}
- (void)updateTrackingAreas
{
if (ta) {
[self removeTrackingArea:ta];
[ta release];
}
ta = [[NSTrackingArea alloc] initWithRect:[self bounds] options:
(NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved |
NSTrackingActiveInKeyWindow) owner:self userInfo:nil];
[self addTrackingArea:ta];
}
- (void)drawRect:(NSRect)rect
{
[[NSColor redColor] set];
NSFrameRect([self bounds]);
if (!NSEqualPoints(mp, NSZeroPoint)) {
NSBezierPath *pt = [NSBezierPath
bezierPathWithOvalInRect:NSMakeRect(mp.x-5, mp.y-5, 10, 10)];
[[NSColor blueColor] set];
[pt setLineWidth:2.0];
[pt stroke];
}
}
- (void)mouseEntered:(NSEvent *)theEvent
{
}
- (void)mouseExited:(NSEvent *)theEvent
{
mp = NSZeroPoint;
[self setNeedsDisplay:YES];
}
- (void)mouseMoved:(NSEvent *)theEvent
{
mp = [self convertPoint:[theEvent locationInWindow] fromView:nil];
[self setNeedsDisplay:YES];
}
@end
--
__________________________________________
Markus Spoettl
_______________________________________________
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