Women in Technology

Hear us Roar



Article:
  Building a Scratch Pad with Cocoa
Subject:   NSBezier subclass creation set with no get accessor
Date:   2001-12-09 07:06:48
From:   psheldon
Response to: NSBezier subclass for ColoredPath

I would make a method to create a ColorPath with an NSColor value which would assign an internal NSColor value and retain it within the object instantiation initialization which would also perform the inherited function. Then, I would override the stroke function to include the NSColor set for the current environment.
I am not clear with the "fuzzy typing" whether I could make a subclass of ColorPath be ColorPaths because of my narrow focus on the methods of NSBezierclass. Apple didn't do this in sketch, so I think it would be too much of a stretch for me to try to do.
Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • works but with warning (short code eg.)
    2001-12-10 09:24:48  psheldon [View]

    ColorBezier.m:20: warning: instance variable `theColor' accessed in class method

    + (ColorBezier*)initWithColor:(NSColor*)color {
    self = [[super bezierPath] retain];

    if (self) {
    theColor = color;
    }
    return self;
    }
    • got rid of warning with accessor and less self
      2001-12-11 10:15:44  psheldon [View]

      I really don't know the meaning of "self" in newtonscript and objective C and need some years of pain, probably, to teach me the intuition and, beyond, perhaps to formalize into words. I think it is the left argument in the square brackets at first, be it class or instance.
      When I tried to make a new version that used a ColorWell, all my plans went haywire, as I doubted I had understood memory managment deep in my bones. I threw in retains and releases and perhaps too many retains knowing that when I quit, it would clean house, maybe. Still no change of color. I think the click in the color well ran the mousedown method and I got messages about not having a point for a line as soon as I tried to draw. I got rid of those error messages, without understanding them really, by insuring that I last clicked on a button I called "Well" by putting code assigning a new path in the action associated with that button in padView.
      So, having gotten rid of an error message, I went on to see that my color didn't change because my ColorBezier subclass of NSBezierpath didn't change. So, perhaps I don't know how to think in assigning currentPath because of this pointer retain and release stuff not having sunk in.
      Perhaps the button and colorwell actions may illustrate my confusion rather than all my code :

      - (IBAction)ChooseWell:(id)sender
      {
      [pathCurrent release];
      pathCurrent = [ColorBezier initWithColor: colorCurrent];
      [pathCurrent retain];
      [ColorPaths addObject: pathCurrent];
      }


      - (IBAction)colorWellAction:(id)sender
      {
      float *locRed,*locGreen,*locBlue,*locAlpha;
      [colorCurrent release];
      colorCurrent = [sender color];
      [colorCurrent retain];
      //[colorCurrent getRed:locRed green:locGreen blue:locBlue alpha:locAlpha];
      [colorCurrent set];
      //[colorCurrent getRed:locRed green:locGreen blue:locBlue alpha:locAlpha];
      }