• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to get rid of blinking?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: How to get rid of blinking?
      • From: Mike Abdullah <email@hidden>
    • Re: How to get rid of blinking?
      • From: Fritz Anderson <email@hidden>
  • Prev by Date: Re: ARC + return of autoreleased CFType
  • Next by Date: Re: How to get rid of blinking?
  • Previous by thread: Re: ARC + return of autoreleased CFType
  • Next by thread: Re: How to get rid of blinking?
  • Index(es):
    • Date
    • Thread