• 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
Redrawing in a custom NSView.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Redrawing in a custom NSView.


  • Subject: Redrawing in a custom NSView.
  • From: "Manuel C." <email@hidden>
  • Date: Sat, 20 Jan 2007 11:49:11 -0600

Hi.

I am learning cocoa, and I trying to redraw a fancy shape in a custom NSView. this shape you can find in Cocoa Programming book from Anguish Buck.

This is the code:

#import <Cocoa/Cocoa.h>

@interface Cocoa2 : NSView
{
}

// Dibujo.
- (void)drawRect:(NSRect)rect;

// Control del dibujo.
- (void)dibujar:(int)num;

@end


#import <Cocoa/Cocoa.h>

#import "Cocoa2.h"

int numeroDeLados = 12;

@implementation Cocoa2

#define X(t) (sin(t) + 1) * width * 0.5		// Macro para X(t)
#define Y(t) (cos(t) + 1) * height * 0.5	// Macro para Y(t)

-(void)drawRect:(NSRect)rect
{

	double		 f, g;
	double const pi = 2 * acos(0.0);

	// Obtiene el tamanio de la ventana
	float width = [self bounds].size.width;
	float height = [self bounds].size.height;

	[[NSColor whiteColor] set];
	NSRectFill([self bounds]);

	// Lo siguiente pinta el poligono
	[[NSColor blackColor] set];

	for (f = 0; f<2*pi; f+=2*pi/numeroDeLados){
		for (g = 0; g<2*pi; g+=2*pi/numeroDeLados){
			NSPoint p1 = NSMakePoint(X(f), Y(f));
			NSPoint p2 = NSMakePoint(X(g), Y(g));
			[NSBezierPath strokeLineFromPoint:p1 toPoint:p2];
		}
	}

}   // Fin del metodo sobreescrito drawRect

-(void)dibujar:(int)num
{
	numeroDeLados = num;
	[self setNeedsDisplay: YES];
}


@end

All works fine and have the window with the fancy chape in my screen, but when I change the number of sides and enter to the method dibujar:num, and set [self setNeedsDisplay: YES]; the fancy draw not change.

What need to do for the event loop calls the drawRect: method.

Thanks.

Manuel C.
www.manuelcsolis.com.mx
http://mac-manuelito.blogspot.com


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: Redrawing in a custom NSView.
      • From: j o a r <email@hidden>
  • Prev by Date: Image not updated
  • Next by Date: Re: Redrawing in a custom NSView.
  • Previous by thread: Re: Image not updated
  • Next by thread: Re: Redrawing in a custom NSView.
  • Index(es):
    • Date
    • Thread