# Class: Style

## Style()

#### new Style()

Style represents in a generic way a style applied to canvas drawing. Some styles (e.g. gradients, patterns) required a context to be generated this provides a generic way to share styles between objects.

Source:
  - objects/style/Style.js, line 8

### Members

#### (static) types :Map.<string, function()>

List of available style types known by the application. Stores the object constructor by object type.

##### Type:

- Map.<string, function()>

Source:
  - objects/style/Style.js, line 57

#### cache :string|CanvasGradient|CanvasPattern

Cached style object pre-generated from previous calls. To avoid regenerating the same style object every cycle. Inherited classes should write their own get method that returns the style object and stores it in this property.

##### Type:

- string | CanvasGradient | CanvasPattern

Source:
  - objects/style/Style.js, line 17

#### needsUpdate :boolean

Indicates if the style object needs to be updated, should be used after applying changed to the style in order to generate a new object. Inherited classes should implement this functionality.

##### Type:

- boolean

Source:
  - objects/style/Style.js, line 26

### Methods

#### (static) parse(data) → {Style}

Parse style from JSON serialized data, created a style of the correct data type automatically and parses its data.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` |  | JSON serialized data.

Source:
  - objects/style/Style.js, line 76

##### Returns:

Parsed style from the provided data.

Type
  Style

#### (static) register(constructor, type)

Register a style type to be serializable. Associates the type string to the object constructor.

##### Parameters:

Name | Type | Description
--- | --- | ---
`constructor` | function | Style constructor.
`type` | string | Style type name.

Source:
  - objects/style/Style.js, line 65

#### get(context) → {string|CanvasGradient|CanvasPattern}

Get generated style object from style data and the drawing context.

##### Parameters:

Name | Type | Description
--- | --- | ---
`context` | CanvasRenderingContext2D | Context being used to draw the object.

Source:
  - objects/style/Style.js, line 35

##### Returns:

Return the canvas style object generated.

Type
  string | CanvasGradient | CanvasPattern

#### parse(data)

Parse the style attributes from JSON object data created with the serialize() method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | Serialized style data.

Source:
  - objects/style/Style.js, line 49

#### serialize() → {Object}

Serialize the style to JSON object, called by the objects using these styles.

Source:
  - objects/style/Style.js, line 42

##### Returns:

Serialized style data.

Type
  Object