Table of Contents

Class ColorDef

Namespace
CADability.Attribute
Assembly
CADability.dll

Summary description for ColorDef.

public class ColorDef : ISerializable, INamedAttribute, IJsonSerialize
Inheritance
ColorDef
Implements
Inherited Members

Constructors

ColorDef()

Creates a ColorDef without a name, with source fromName and the colour black. Needed by the JSON deserialization; otherwise use ColorDef(string, Color) or CreateOrFind(string, Color).

public ColorDef()

ColorDef(SerializationInfo, StreamingContext)

Constructor required by deserialization

public ColorDef(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

ColorDef(string, Color)

Creates an ordinary named colour (fromName). The ColorDef does not belong to a list yet; add it with Add(ColorDef), or use CreateOrFind(string, Color) instead.

public ColorDef(string pName, Color pColor)

Parameters

pName string

the name, unique within the ColorList it is added to

pColor Color

the RGB value

ColorDef(string, Color, ColorSource)

Creates a ColorDef with the given name, colour value and ColorDef.ColorSource. When pName is null and the source is fromParent or fromStyle, the name of the corresponding placeholder (CDfromParent, CDfromStyle) is used.

public ColorDef(string pName, Color pColor, ColorDef.ColorSource cs)

Parameters

pName string

the name, unique within the ColorList it is added to

pColor Color

the RGB value

cs ColorDef.ColorSource

where the colour comes from

Fields

CDfromParent

The placeholder colour "of the block" (fromParent): an object with this ColorDef is painted in the colour of the Block it belongs to. When such an object is added to a block, the block replaces it by its own clone, which carries the block's actual colour value. The name comes from the string resource "ColorDef.fromParent".

public static ColorDef CDfromParent

Field Value

ColorDef

CDfromStyle

The placeholder colour "of the style" (fromStyle): it stands for a colour that is determined by the Style of the object rather than by this ColorDef. The name comes from the string resource "ColorDef.fromStyle".

public static ColorDef CDfromStyle

Field Value

ColorDef

Properties

Color

The RGB (or ARGB) value of the colour. For the placeholders CDfromParent and CDfromStyle the value is not meaningful. Setting a different value raises ColorWillChangeEvent before and ColorDidChangeEvent after the change, and forwards the change to the owner of the list (undoable); all objects referring to this ColorDef are displayed in the new colour.

public Color Color { get; set; }

Property Value

Color

Name

The name of the colour, unique within its ColorList and shown in the colour selection of the control center. Setting a name that is already used by another entry of the list throws a NameAlreadyExistsException; otherwise the change is forwarded to the owner of the list (the project), which records it for undo.

public string Name { get; set; }

Property Value

string

Source

Says where the colour of an object with this ColorDef comes from (see ColorDef.ColorSource); normally fromName. Setting a different value raises the colour change events; unlike Color the change is not forwarded to the list and is not undoable.

public ColorDef.ColorSource Source { get; set; }

Property Value

ColorDef.ColorSource

Methods

Clone()

Creates a copy with the same name, colour value and Source. The copy does not belong to a ColorList and has no event subscribers.

public ColorDef Clone()

Returns

ColorDef

the copy

Dimm(double)

Returns a darkened version of the colour value: the red, green and blue components are multiplied by percent, the alpha component is kept. This ColorDef itself is not changed.

public Color Dimm(double percent)

Parameters

percent double

factor between 0.0 (black) and 1.0 (the unchanged colour); greater values are treated as 1.0

Returns

Color

the darkened colour

GetDefault()

Returns the first colour of a freshly created default ColorList (red, see the string resource "ColorList.Default"). The returned ColorDef belongs to that temporary list and not to a project; it serves as a fallback where a colour is needed before a project is available, e.g. for a new DimensionStyle.

public static ColorDef GetDefault()

Returns

ColorDef

the default colour

GetObjectData(IJsonWriteData)

Writes the name, source and colour value of this ColorDef for the JSON serialization (IJsonSerialize).

public void GetObjectData(IJsonWriteData data)

Parameters

data IJsonWriteData

receives the data

GetObjectData(SerializationInfo, StreamingContext)

Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.

public void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

receives the data

context StreamingContext

the destination of the serialization

Read(SerializationInfo, StreamingContext)

Reads the ColorDef stored under the name "ColorDef" from the legacy binary serialization data; same as Read(string, SerializationInfo, StreamingContext) with that name.

public static ColorDef Read(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

the serialization data

context StreamingContext

the source of the serialization

Returns

ColorDef

the ColorDef, or null when the data contains no such entry

Read(string, SerializationInfo, StreamingContext)

Reads the ColorDef stored under the given name from the legacy binary serialization data (ISerializable). For use in the deserialization constructors of objects that have a colour; missing or incompatible entries yield null instead of an exception, so that older files can be read.

public static ColorDef Read(string name, SerializationInfo info, StreamingContext context)

Parameters

name string

the name the ColorDef was stored under

info SerializationInfo

the serialization data

context StreamingContext

the source of the serialization

Returns

ColorDef

the ColorDef, or null when there is no entry with that name or it is not a ColorDef

SetObjectData(IJsonReadData)

Restores this ColorDef from the JSON data written by GetObjectData(IJsonWriteData) (IJsonSerialize).

public void SetObjectData(IJsonReadData dict)

Parameters

dict IJsonReadData

the data to read from

Events

ColorDidChangeEvent

ColorWillChangeEvent is raised before and ColorDidChangeEvent after the Color (or the Source) of this ColorDef changes; the arguments name the property and carry its old resp. new value. Objects that derive their colour from this ColorDef (e.g. a Block whose children are coloured "from parent") subscribe to update themselves.

public event AttributeChangeDelegate ColorDidChangeEvent

Event Type

AttributeChangeDelegate

ColorWillChangeEvent

ColorWillChangeEvent is raised before and ColorDidChangeEvent after the Color (or the Source) of this ColorDef changes; the arguments name the property and carry its old resp. new value. Objects that derive their colour from this ColorDef (e.g. a Block whose children are coloured "from parent") subscribe to update themselves.

public event AttributeChangeDelegate ColorWillChangeEvent

Event Type

AttributeChangeDelegate