Creating a Color Meter Using Cocoa
Subject:   Color wheel...
Date:   2001-06-20 07:46:12
From:   rainwadj
Response to: Color wheel...

I finally noticed that this was an extra credit assignment (Doh!). Here's what I came up with:

- (IBAction)updateControls:(id)sender
NSColor *theColor = [sender color];

redValue = [theColor redComponent];
[redField setFloatValue:redValue];
[redSlider setFloatValue:redValue];

greenValue = [theColor greenComponent];
[greenField setFloatValue:greenValue];
[greenSlider setFloatValue:greenValue];

blueValue = [theColor blueComponent];
[blueField setFloatValue:blueValue];
[blueSlider setFloatValue:blueValue];

alphaValue = [theColor alphaComponent];
[alphaField setFloatValue:alphaValue];
[alphaSlider setFloatValue:alphaValue];

Looking at the class defs for NSColor helped a lot. It seems like it would have been cleaner to use getRed:green:blue:alpha, since I wanted them all anyway, but compiling with [theColor getRed:redValue...] complained that redValue... was an incompatible type. The method wants float * for the parameters, and the someValue variables are floats. (I feel like I'm forgetting something very basic here...)

1 to 1 of 1
  1. Color wheel...
    2001-06-20 08:26:02  davidmasters [View]

    • Color wheel...
      2001-06-20 10:40:23  rainwadj [View]

      • Color wheel...
        2001-06-20 11:39:04  johnts [View]

        • Color wheel...
          2001-06-20 12:50:22  davidmasters [View]

          • Color wheel...
            2001-06-22 09:17:54  donarb [View]

          • Color wheel...
            2001-06-20 19:54:29  johnts [View]

          • Color wheel...
            2001-06-20 19:39:24  johnts [View]

          • Color wheel...
            2001-06-20 19:28:20  johnts [View]

1 to 1 of 1