• 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
A hillegass challenge
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A hillegass challenge


  • Subject: A hillegass challenge
  • From: Michael de Haan <email@hidden>
  • Date: Thu, 3 Dec 2009 23:39:46 -0800

I would like to ask the group if  this is "good practice"   ( I am almost certain it is not "best practice" :-)  )

My question pertains to knowingly setting an object to NULL and then knowingly sending it a message as an acceptable technique. (If this is not done, drawRect will simply show the oval as if it was still being actively drawn).

The challenge was to design a doc based app that allowed a user to draw arbitrary ovals.

Very briefly, I used the outline of "Cocoa design patterns" by using an NSArray of objects in a "controller" object ( in this case "MyDocument") which defined a bezierpath, and in the "drawRect" method of the view, used this code.

- (void)drawRect:(NSRect)dirtyRect {

    ....code to fill background of viewObject....

        /* now load the stored ovals from the array */

for (NSBezierPath * oval in [[ self delegate] ovals])
{
    ....code to set saved color....
    [oval fill];
}

 /*paint the currently drawn user path (where currentPath is an ivar in the NSView Object) */

    ..code to change color to  "working"  color ....
    [[self currentPath] fill];
}




Now...In order to provide visual feedback on the mouseUp event ( the oval changes color to show that it is now saved) I set the current path to NULL thus.

- (void)mouseUp:(NSEvent *)theEvent
{
    ....code that sets the current mouseDown point and creates the current bezier path.....

    ...code that adds the current bezierpath to ovals list .....


    [self setCurrentPath:NULL]; /*sets the current bezierPath to nil */
    [self setNeedsDisplay:YES];


As mentioned above, this does work, but seems ?sloppy?.
Thanks.


_______________________________________________

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: A hillegass challenge
      • From: Seth Willits <email@hidden>
  • Prev by Date: How to get an italic font
  • Next by Date: Re: How to get an italic font
  • Previous by thread: Re: How to get an italic font
  • Next by thread: Re: A hillegass challenge
  • Index(es):
    • Date
    • Thread