Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Subclassing NSColor

Subclassing NSColor
Thread Tools
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Feb 2, 2003, 07:24 PM
 
Boy, this is poorly-documented. The documentation tells you to override colorSpaceName and set, but it doesn't give any information on how to make your color actually do anything. For instance, say I wanted to replicate the functionality of NSPatternColor--how would I go about this? What sort of thing would I need to put in my set implementation to make it go, "Hey, I need to tile this image?"

Anybody care to help?
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Rickster
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Feb 2, 2003, 09:15 PM
 
I can't offer much advice for NSColor subclassing, but if you're just wanting to use tiled patterns as colors, try +[NSColor colorWithPatternImage:].
Rick Roe
icons.cx | weblog
     
Chuckit  (op)
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Feb 2, 2003, 09:38 PM
 
Originally posted by Rickster:
I can't offer much advice for NSColor subclassing, but if you're just wanting to use tiled patterns as colors, try +[NSColor colorWithPatternImage:].
Yeah, I pretty much have that. I was just using it as an example. Thanks, though.

Basically what I wanted to do is have it so that the background of a box can be either a color or a gradient. The most logical way seemed to be to subclass NSColor so that I could just switch between subclasses. But I suppose I could just use separate drawing routines for the two modes.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Rickster
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Feb 3, 2003, 06:20 PM
 
Most of the built-in NSColor subclasses implement -set to call various NSGraphicsContext and CoreGraphics API to set up state on the current graphics context, I believe. It might be possible to, say, use GoreGraphics' new API for gradients to implement gradient colors this way. It's certainly possible to do things like implementing a new color space (like LAB or a Pantone list) via subclassing NSColor -- just perform your own translation to RGB and set that on the context -- in fact, that's probably what the class is designed around.
Rick Roe
icons.cx | weblog
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 06:21 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,