How to get rid of blinking?
How to get rid of blinking?
- Subject: How to get rid of blinking?
- From: Nick <email@hidden>
- Date: Wed, 19 Oct 2011 20:41:56 +0300
Hello
Could you advice me how to get rid of blinking in the following code?
This is an NSView's subclass, I am trying to draw a rectangle for zooming
(theoretically a user is supposed to be able to zoom in a piece of a view,
by selecting a rectangle area to zoom.
The problem is that when the mouse is being dragged, the rectangle that's
being drawn is blinking.
What would be the write approach to make it behave like other software where
a user can select things with a rectangle?
Thank you!
-(void)mouseDown:(NSEvent *)theEvent {
NSPoint locationOnCanvas = [self convertPoint:[theEvent locationInWindow]
fromView:nil];
if(currentMouseMode == MMFree) {
currentMouseMode = MMZooming;
lastMouseDownPos = locationOnCanvas;
}
NSLog(@"mouse down: (%f; %f)", locationOnCanvas.x, locationOnCanvas.y);
}
-(void)drawRectUsingTwoPoints:(NSPoint)first:(NSPoint)second {
NSPoint leftBottomPoint = NSMakePoint(MIN(first.x, second.x),
MIN(first.y, second.y));
GLfloat width = ABS(first.x-second.x);
GLfloat height = ABS(first.y-second.y);
NSFrameRect(NSMakeRect(leftBottomPoint.x, leftBottomPoint.y, width,
height));
}
-(void)mouseDragged:(NSEvent *)theEvent {
NSPoint locationOnCanvas = [self convertPoint:[theEvent
locationInWindow] fromView:nil];
if(currentMouseMode == MMZooming) {
* [self display]; //clear the previous "rectangle"
[self lockFocus];
[self drawRectUsingTwoPoints:lastMouseDownPos:locationOnCanvas];
[self unlockFocus];
[self displayIfNeeded]; //show the currect "rectangle"*
}
}
-(void)mouseUp:(NSEvent *)theEvent {
if(currentMouseMode == MMZooming) {
currentMouseMode = MMFree;
NSLog(@"performing zoom");
[self setNeedsDisplay:YES]; //clear the "rectangle"
}
}
_______________________________________________
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