mouse - Cocoa's NSView getting insane mouseDown events? -
hullo - i've got nsview subclass move programmatically on mousedown. works, has odd side effect:
- i click subview. subview moves away [good]
- i wait while. not move mouse. since subview has moved it's no longer under cursor.
- i click mouse again.
- i expect underlying window mousedown event (since subview no longer under cursor), subview somehow gets event [odd]
- the mousedown event shows click outside bounds of subclass [odd]
- the mousedown event shows click count has incremented, though i've waited several seconds between mouse clicks [odd]
... there's gotta explanation i'm seeing. here's code - create new cocoa application project called "oddmouse", , copy following oddmouseappdelegate.h file:
#import <cocoa/cocoa.h> @interface oddmouseappdelegate : nsobject <nsapplicationdelegate> { nswindow *window; } @property (assign) iboutlet nswindow *window; @end @interface oddview : nsview { } @end
... , following oddmouseappdelegate.m file:
#import "oddmouseappdelegate.h" @implementation oddmouseappdelegate @synthesize window; - (void)applicationdidfinishlaunching:(nsnotification *)anotification {
[[window contentview] addsubview:[[oddview alloc] init]]; } @end
@implementation oddview - (id)init { self = [super initwithframe:nsmakerect(100, 100, 100, 100)]; return self; } - (void)drawrect:(nsrect)dirtyrect { nsbezierpath *bz = [nsbezierpath bezierpathwithroundedrect:[self bounds] xradius:9 yradius:9]; [[nscolor bluecolor] set]; [bz fill]; } - (void)mousedown:(nsevent *)event { nspoint locationinmyself = [self convertpoint: [event locationinwindow] fromview: nil]; nslog(@"mouse down coords: x=%f y=%f, count=%i", locationinmyself.x, locationinmyself.y, [event clickcount]); float newx = [self frame].origin.x+100; float newy = [self frame].origin.y+100; [self setframe:nsmakerect(newx, newy, 100, 100)]; } @end
... build, run, witness ! fwiw, here's see in console:
10-01-15 11:38:24 pm oddmouse[4583] mouse down coords: x=48.000000 y=56.000000, count=1 10-01-15 11:38:37 pm oddmouse[4583] mouse down coords: x=-52.000000 y=-44.000000, count=2 10-01-15 11:38:44 pm oddmouse[4583] mouse down coords: x=-152.000000 y=-144.000000, count=3 10-01-15 11:38:52 pm oddmouse[4583] mouse down coords: x=-252.000000 y=-244.000000, count=4 10-01-15 11:39:03 pm oddmouse[4583] mouse down coords: x=-352.000000 y=-344.000000, count=5
freaking heck - turns out misbehaving double-click speed - changing prefs did sfa, reboot resolved ...
Comments
Post a Comment