Johann Dirdal
Johann Dirdal

Reputation: 1090

Clearing content of NSWindow

I have used the (void)drawRect:(NSRect)dirtyRect to draw triangles, which is displayed in a NSWindow. My triangles are drawn, but the problem is removing them from the window. I have to figure out how to remove/clear the lines that are drawn from the strokeLineFromPoint:toPoint using a simple method.

Thanks in advance!

Upvotes: 0

Views: 858

Answers (2)

Nicholas1024
Nicholas1024

Reputation: 890

You need to use the setNeedsDisplay method to redraw the view. So, you'd need something like this:

-(void) deleteStuff{
   removeTriangles = YES; //Boolean value
   [myView setNeedsDisplay];
}

Then, inside the drawRect function, simply put all your drawing code inside an if statement.

(void)drawRect:(NSRect)dirtyRect{
   if(!removeTriangles){
      //Rest of drawing code
   }
}

Don't forget to set removeTriangles to NO originally so you can draw the triangles!

Hope this helps.

Upvotes: 0

David
David

Reputation: 14404

You have to create a view and set it to the view property of the NSWindow. Then, draw using the view's drawRect method. The NSWindow does not have a drawRect method. Also, If you want to change the drawing, you have to redraw the part or the entire view.

Upvotes: 1

Related Questions