advertisement

Article:
  Building a Scratch Pad with Cocoa
Subject:   small steps on my own to three color padview
Date:   2001-12-05 08:52:23
From:   psheldon
I made a red green and blue color button and connected them to actions that chose currentPath amongst 3 different colored Bezierpaths.


Here is the relevant code I added to PadView.m (obvious variables and headers in PadView.h) :


- (IBAction)SetColorPath:(NSString *)NSstr //wouldn't allow me (void *) for return type, not connected to button
{
BOOL test;
test=[NSstr isEqualToString:@"red"];
if (test) pathCurrent=pathRed;
test=[NSstr isEqualToString:@"green"];
if (test) pathCurrent=pathGreen;
test=[NSstr isEqualToString:@"blue"];
if (test) pathCurrent=pathBlue;
}


- (IBAction)ChooseBlue:(id)sender
{
[self SetColorPath:@"blue"];
}


- (IBAction)ChooseGreen:(id)sender
{
[self SetColorPath:@"green"];
}


- (IBAction)ChooseRed:(id)sender
{
[self SetColorPath:@"red"];
}


I don't know whether my code was that tight for further generalization . That tightness might emerge on attempting to generalize.
I could imagine each mouse down could generate a new path and put in an NSMutableArray that could be inspired by canibalizing sketch project for relevant methods. Once that tested out without bugs,
one might have a new colored path button asking for a color well to attach a color to a new path in the array.
Somehow, as the code got more complex, it should have helper methods to make it more surveyable. I don't know what the warning in response to my putting (void *) output to SetColorPath meant, so my confidence at making things surveyable has gotten bitten.
;-)


1 to 1 of 1
  1. Michael Beam photo small steps on my own to three color padview
    2001-12-05 21:49:03  Michael Beam | O'Reilly Author [View]

    • NSBezier subclass for ColoredPath
      2001-12-08 23:48:12  psheldon [View]

      • NSBezier subclass creation set with no get accessor
        2001-12-09 07:06:48  psheldon [View]

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

          • got rid of warning with accessor and less self
            2001-12-11 10:15:44  psheldon [View]

    • structs for ColorPath in padview
      2001-12-08 16:02:05  psheldon [View]

1 to 1 of 1