[Drawkit] DKKnob color and layers
Graham Cox
graham.cox at bigpond.com
Fri Aug 15 21:43:28 PDT 2008
Hi Brad,
On 16 Aug 2008, at 7:23 am, Brad Larson wrote:
> I added layer support to our drawing program and was wondering the
> correct way to go about customizing the coloring of DKKnobs and
> objects within the layer. What I want to do is have each layer
> represent a different solution that we'd print on a surface, so I'd
> like for the color of the objects within a layer to reflect the
> layer's color. I can do this by setting a layer-wide DKStyle that
> is changed when the layer's color is changed. Subclassing DKLayer
> is the best way I can think of doing this, unless DKLayers can store
> metadata like DKDrawings and DKDrawableObjects and I'm not seeing it.
DKLayer doesn't have metadata in B4, but will have from B5, because I
also found I needed this (and DKDrawing will inherit it anyway). But
for now, subclassing is necessary for adding data to a layer. I think
your approach of using a layer-wide style sounds entirely reasonable.
> The part that I'm not sure about is how to set all the control knobs
> and selection borders to a neutral color, like light blue or black,
> so that they don't become lost in the drawable objects that are now
> the same color as the layer. I'm a little lost as to where to do
> this.
Selection borders and knobs get their colour from DKLayer's -
selectionColour method, which you can set using -setSelectionColour:
You can also get finer control over customising a knob's appearance on
a per-layer basis by attaching a subclassed instance of DKKnob to a
layer using -setKnobs: This would allow you to set the knob's colours
per layer and independently of the layer's -selectionColour if you
wished. The knobs used by an object are the most local it can find, so
if there are no knobs attached to a layer (which there aren't by
default) it searches up to the next highest grouping which is the
layer group or drawing.
>> Also, for a more general case, I noticed that the
>> controlOnPointColour property of DKKnob is never set, so line
>> beginning and end knobs are always orange. That can make it
>> difficult to tell what layer a DKDrawablePath belongs to because
>> the orange knobs are more prominent than the thin selection line
>> running down the middle of the path. Again, I couldn't figure out
>> where the best place would be to set the controlOnPointColour
>> property so that it would match the layer's selection color.
Right now, DKKnob uses class-wide settings for colours and things, so
you'll need to subclass DKKnob to override these. For some time I've
been meaning to alter this to be more useful and use instance
variables, so I'll finally get that sorted out.
If you subclass, you can override:
- (NSColor*) fillColourForKnobType:(DKKnobType) knobType;
- (NSColor*) strokeColourForKnobType:(DKKnobType) knobType;
to return whatever colours you like for each knob type.
>
cheers, Graham
More information about the Drawkit
mailing list