Skip to content

Commit

Permalink
Clean up material properties and specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mramato committed Feb 18, 2014
1 parent 34b04d1 commit cead80d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 202 deletions.
23 changes: 4 additions & 19 deletions Source/DynamicScene/ColorMaterialProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define(['../Core/Color',
'../Core/defineProperties',
'../Core/DeveloperError',
'../Core/Event',
'./createDynamicPropertyDescriptor',
'./ConstantProperty',
'./Property'
], function(
Expand All @@ -14,6 +15,7 @@ define(['../Core/Color',
defineProperties,
DeveloperError,
Event,
createDynamicPropertyDescriptor,
ConstantProperty,
Property) {
"use strict";
Expand All @@ -30,7 +32,7 @@ define(['../Core/Color',
this._definitionChanged = new Event();
this._color = undefined;
this._colorSubscription = undefined;
this.color = colorProperty;
this.color = defaultValue(colorProperty, new ConstantProperty(Color.WHITE));
};

/**
Expand Down Expand Up @@ -77,24 +79,7 @@ define(['../Core/Color',
* @memberof ColorMaterialProperty.prototype
* @type {Property}
*/
color : {
get : function() {
return this._color;
},
set : function(value) {
if (this._color !== value) {
if (defined(this._colorSubscription)) {
this._colorSubscription();
this._colorSubscription = undefined;
}
this._color = value;
if (defined(value)) {
this._colorSubscription = value.definitionChanged.addEventListener(ColorMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
}
color : createDynamicPropertyDescriptor('color')
});

/**
Expand Down
78 changes: 6 additions & 72 deletions Source/DynamicScene/GridMaterialProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ define(['../Core/Cartesian2',
'../Core/defined',
'../Core/defineProperties',
'../Core/Event',
'./createDynamicPropertyDescriptor',
'./ConstantProperty',
'./Property'
], function(
Expand All @@ -12,6 +13,7 @@ define(['../Core/Cartesian2',
defined,
defineProperties,
Event,
createDynamicPropertyDescriptor,
ConstantProperty,
Property) {
"use strict";
Expand Down Expand Up @@ -71,93 +73,25 @@ define(['../Core/Cartesian2',
* @type {Property}
* @default new ConstantProperty(Color.WHITE)
*/
color : {
get : function() {
return this._color;
},
set : function(value) {
if (this._color !== value) {
if (defined(this._colorSubscription)) {
this._colorSubscription();
this._colorSubscription = undefined;
}
this._color = value;
if (defined(value)) {
this._colorSubscription = value.definitionChanged.addEventListener(GridMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
},
color : createDynamicPropertyDescriptor('color'),
/**
* Gets or sets the numeric property which determines the grid cells alpha value, when combined with the color alpha.
* @type {Property}
* @default new ConstantProperty(0.1)
*/
cellAlpha : {
get : function() {
return this._cellAlpha;
},
set : function(value) {
if (this._cellAlpha !== value) {
if (this._cellAlphaSubscription) {
this._cellAlphaSubscription();
this._cellAlphaSubscription = undefined;
}
this._cellAlpha = value;
if (defined(value)) {
this._cellAlphaSubscription = value.definitionChanged.addEventListener(GridMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
},
cellAlpha : createDynamicPropertyDescriptor('cellAlpha'),
/**
* Gets or sets the {@link Cartesian2} property which determines the number of rows and columns in the grid.
* @type {Property}
* @default new ConstantProperty(new Cartesian2(8, 8))
*/
lineCount : {
get : function() {
return this._lineCount;
},
set : function(value) {
if (this._lineCount !== value) {
if (this._lineCountSubscription) {
this._lineCountSubscription();
this._lineCountSubscription = undefined;
}
this._lineCount = value;
if (defined(value)) {
this._lineCountSubscription = value.definitionChanged.addEventListener(GridMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
},
lineCount : createDynamicPropertyDescriptor('lineCount'),
/**
* Gets or sets the {@link Cartesian2} property which determines the thickness of rows and columns in the grid.
* @type {Property}
* @default new ConstantProperty(new Cartesian2(1.0, 1.0))
*/
lineThickness : {
get : function() {
return this._lineThickness;
},
set : function(value) {
if (this._lineThickness !== value) {
if (this._lineThicknessSubscription) {
this._lineThicknessSubscription();
this._lineThicknessSubscription = undefined;
}
this._lineThickness = value;
if (defined(value)) {
this._lineThicknessSubscription = value.definitionChanged.addEventListener(GridMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
}
lineThickness : createDynamicPropertyDescriptor('lineThickness')
});

/**
Expand Down
40 changes: 4 additions & 36 deletions Source/DynamicScene/ImageMaterialProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ define([
'../Core/defined',
'../Core/defineProperties',
'../Core/Event',
'./createDynamicPropertyDescriptor',
'./ConstantProperty',
'./Property'
], function(
Cartesian2,
defined,
defineProperties,
Event,
createDynamicPropertyDescriptor,
ConstantProperty,
Property) {
"use strict";
Expand Down Expand Up @@ -58,48 +60,14 @@ define([
* @memberof ImageMaterialProperty.prototype
* @type {Property}
*/
image : {
get : function() {
return this._image;
},
set : function(value) {
if (this._image !== value) {
if (this._imageSubscription) {
this._imageSubscription();
this._imageSubscription = undefined;
}
this._image = value;
if (defined(value)) {
this._imageSubscription = value.definitionChanged.addEventListener(ImageMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
},
image : createDynamicPropertyDescriptor('image'),
/**
* Gets or sets the {@link Cartesian2} property which determines the number of times the image repeats in each direction.
* @memberof ImageMaterialProperty.prototype
* @type {Property}
* @default new ConstantProperty(new Cartesian2(1, 1))
*/
repeat : {
get : function() {
return this._repeat;
},
set : function(value) {
if (this._repeat !== value) {
if (this._repeatSubscription) {
this._repeatSubscription();
this._repeatSubscription = undefined;
}
this._repeat = value;
if (defined(value)) {
this._repeatSubscription = value.definitionChanged.addEventListener(ImageMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
}
repeat : createDynamicPropertyDescriptor('repeat')
});

/**
Expand Down
59 changes: 5 additions & 54 deletions Source/DynamicScene/PolylineOutlineMaterialProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ define(['../Core/Color',
'../Core/defined',
'../Core/defineProperties',
'../Core/Event',
'./createDynamicPropertyDescriptor',
'./ConstantProperty',
'./Property'
], function(
Color,
defined,
defineProperties,
Event,
createDynamicPropertyDescriptor,
ConstantProperty,
Property) {
"use strict";
Expand Down Expand Up @@ -64,71 +66,20 @@ define(['../Core/Color',
* @type {Property}
* @default new ConstantProperty(Color.WHITE)
*/
color : {
get : function() {
return this._color;
},
set : function(value) {
if (this._color !== value) {
if (defined(this._colorSubscription)) {
this._colorSubscription();
this._colorSubscription = undefined;
}
this._color = value;
if (defined(value)) {
this._colorSubscription = value.definitionChanged.addEventListener(PolylineOutlineMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
},
color : createDynamicPropertyDescriptor('color'),
/**
* Gets or sets the {@link Color} property which determines the polyline's outline color.
* @memberof PolylineOutlineMaterialProperty.prototype
* @type {Property}
* @default new ConstantProperty(Color.BLACK)
*/
outlineColor : {
get : function() {
return this._outlineColor;
},
set : function(value) {
if (this._outlineColor !== value) {
if (this._outlineColorSubscription) {
this._outlineColorSubscription();
this._outlineColorSubscription = undefined;
}
this._outlineColor = value;
if (defined(value)) {
this._outlineColorSubscription = value.definitionChanged.addEventListener(PolylineOutlineMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
},
outlineColor : createDynamicPropertyDescriptor('outlineColor'),
/**
* Gets or sets the numberic property which determines the polyline's outline width.
* @type {Property}
* @default new ConstantProperty(0)
*/
outlineWidth : {
get : function() {
return this._outlineWidth;
},
set : function(value) {
if (this._outlineWidth !== value) {
if (this._outlineWidthSubscription) {
this._outlineWidthSubscription();
this._outlineWidthSubscription = undefined;
}
this._outlineWidth = value;
if (defined(value)) {
this._outlineWidthSubscription = value.definitionChanged.addEventListener(PolylineOutlineMaterialProperty.prototype._raiseDefinitionChanged, this);
}
this._raiseDefinitionChanged(this);
}
}
}
outlineWidth : createDynamicPropertyDescriptor('outlineWidth')
});

/**
Expand Down
7 changes: 4 additions & 3 deletions Specs/DynamicScene/ColorMaterialPropertySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defineSuite(['DynamicScene/ColorMaterialProperty',

it('constructor provides the expected defaults', function() {
var property = new ColorMaterialProperty();
expect(property.color).toBeUndefined();
expect(property.color).toEqual(new ConstantProperty(Color.WHITE));
expect(property.getType()).toEqual('Color');
expect(property.isConstant).toBe(true);

Expand Down Expand Up @@ -92,12 +92,13 @@ defineSuite(['DynamicScene/ColorMaterialProperty',
var listener = jasmine.createSpy('listener');
property.definitionChanged.addEventListener(listener);

var oldValue = property.color;
property.color = new ConstantProperty(Color.WHITE);
expect(listener).toHaveBeenCalledWith(property);
expect(listener).toHaveBeenCalledWith(property, 'color', property.color, oldValue);
listener.reset();

property.color.setValue(Color.BLACK);
expect(listener).toHaveBeenCalledWith(property);
expect(listener).toHaveBeenCalledWith(property, 'color', property.color, property.color);
listener.reset();

property.color = property.color;
Expand Down
Loading

0 comments on commit cead80d

Please sign in to comment.