• 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
Drawing into myView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing into myView


  • Subject: Drawing into myView
  • From: R T <email@hidden>
  • Date: Wed, 16 Dec 2009 22:21:36 -0800 (PST)

I have a subclass of NSView and I want to draw into it after I retrieve an Image in an NSImageView.

I'm trying to set 2 instance variables in the drawRect block of code...

@property(readwrite) NSRect tRect;
@property (retain, readwrite) NSGraphicsContext*savedContext;
_______________________________________________

- (void)drawRect:(NSRect)rect
{
[selfsetSavedContext:[NSGraphicsContext currentContext]];
[selfsetTRect:rect];
}

...and then in a block of code called when the NSImageView has an image dragged into it,
I try to draw a black background into the view. Nothing is drawn and I don't seem to have any context.

- (void) process{
[NSGraphicsContext setCurrentContext:savedContext];
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
CGRect aRect = NSRectToCGRect(tRect);
CGLayerRefbkgndLayer = CGLayerCreateWithContext (context, aRect.size, NULL);
CGContextRefbkgndContext = CGLayerGetContext (bkgndLayer);
CGContextSetRGBFillColor (bkgndContext, 0, 0, 0, 1);
CGContextFillRect (bkgndContext, aRect);
CGContextSaveGState(context);
CGContextDrawLayerInRect (context, aRect, bkgndLayer);
CGContextRestoreGState(context);
CGLayerRelease(bkgndLayer);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Any help greatly appreciated,
Thanks, Rick




_______________________________________________

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

  • Prev by Date: Re: App works when launched from Xcode, not from Finder
  • Next by Date: core data: Entity vs Class mode
  • Previous by thread: Re: NSPredicate Matches
  • Next by thread: Re: Drawing into myView
  • Index(es):
    • Date
    • Thread