Skip to content

Commit

Permalink
Added a scale method to Graphics.
Browse files Browse the repository at this point in the history
- Some graphics may not have a scale method.

#63
  • Loading branch information
NTaylorMullen committed Aug 8, 2013
1 parent 6e819e5 commit 5b43028
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 0 deletions.
8 changes: 8 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Graphic2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ var EndGate;
throw new Error("GetDrawBounds is abstract, it must be implemented.");
};

/**
* Abstract: Should be overridden to scale the size of the Graphic2d.
* @param scale The value to multiply the graphic's size by.
*/
Graphic2d.prototype.Scale = function (scale) {
throw new Error("Scale is abstract, it must be implemented.");
};

/**
* Triggers the OnDisposed event. If this Graphic2d is used with a Scene2d it will be removed from the scene when disposed.
*/
Expand Down
8 changes: 8 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Graphic2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ module EndGate.Graphics {
throw new Error("GetDrawBounds is abstract, it must be implemented.");
}

/**
* Abstract: Should be overridden to scale the size of the Graphic2d.
* @param scale The value to multiply the graphic's size by.
*/
public Scale(scale: number): void{
throw new Error("Scale is abstract, it must be implemented.");
}

/**
* Triggers the OnDisposed event. If this Graphic2d is used with a Scene2d it will be removed from the scene when disposed.
*/
Expand Down
8 changes: 8 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ var EndGate;
return bounds;
};

/**
* Scale is not implemented.
* @param scale The value to multiply the graphic's size by.
*/
Grid.prototype.Scale = function (scale) {
throw new Error("Scale is not implemented for the Grid class.");
};

/**
* Converts the provided vertical coordinate to a row number that is based on the current grid.
* @param y The vertical coordinate to convert to a row.
Expand Down
8 changes: 8 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Grid/Grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ module EndGate.Graphics {
return bounds;
}

/**
* Scale is not implemented.
* @param scale The value to multiply the graphic's size by.
*/
public Scale(scale: number): void {
throw new Error("Scale is not implemented for the Grid class.");
}

/**
* Converts the provided vertical coordinate to a row number that is based on the current grid.
* @param y The vertical coordinate to convert to a row.
Expand Down
9 changes: 9 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Line2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ var EndGate;
return bounds;
};

/**
* Scale's the Line2d graphic.
* @param scale The value to multiply the graphic's size by.
*/
Line2d.prototype.Scale = function (scale) {
this.From = this.Position.Add(this.From.Subtract(this.Position).Multiply(scale));
this.To = this.Position.Add(this.To.Subtract(this.Position).Multiply(scale));
};

Line2d.prototype.UpdatePosition = function () {
this.Position = ((this._from.Add(this._to)).Divide(2));
this._difference = this._to.Subtract(this._from);
Expand Down
9 changes: 9 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Line2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ module EndGate.Graphics {
return bounds;
}

/**
* Scale's the Line2d graphic.
* @param scale The value to multiply the graphic's size by.
*/
public Scale(scale: number): void {
this.From = this.Position.Add(this.From.Subtract(this.Position).Multiply(scale));
this.To = this.Position.Add(this.To.Subtract(this.Position).Multiply(scale));
}

private UpdatePosition(): void {
this.Position = ((this._from.Add(this._to)).Divide(2));
this._difference = this._to.Subtract(this._from);
Expand Down
8 changes: 8 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ var EndGate;
return bounds;
};

/**
* Scale's the circle graphic.
* @param scale The value to multiply the graphic's size by.
*/
Circle.prototype.Scale = function (scale) {
this.Radius *= scale;
};

Circle.prototype._BuildPath = function (context) {
context.arc(0, 0, this.Radius, 0, (Math).twoPI);
};
Expand Down
8 changes: 8 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ module EndGate.Graphics {
return bounds;
}

/**
* Scale's the circle graphic.
* @param scale The value to multiply the graphic's size by.
*/
public Scale(scale: number): void {
this.Radius *= scale;
}

public _BuildPath(context: CanvasRenderingContext2D): void {
context.arc(0, 0, this.Radius, 0, (<any>Math).twoPI);
}
Expand Down
9 changes: 9 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ var EndGate;
return bounds;
};

/**
* Scale's the rectangle graphic.
* @param scale The value to multiply the graphic's size by.
*/
Rectangle.prototype.Scale = function (scale) {
this.Size.Width *= scale;
this.Size.Height *= scale;
};

Rectangle.prototype._BuildPath = function (context) {
context.rect(-this.Size.HalfWidth, -this.Size.HalfHeight, this.Size.Width, this.Size.Height);
};
Expand Down
9 changes: 9 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ module EndGate.Graphics {
return bounds;
}

/**
* Scale's the rectangle graphic.
* @param scale The value to multiply the graphic's size by.
*/
public Scale(scale: number): void {
this.Size.Width *= scale;
this.Size.Height *= scale;
}

public _BuildPath(context: CanvasRenderingContext2D): void {
context.rect(-this.Size.HalfWidth, -this.Size.HalfHeight, this.Size.Width, this.Size.Height);
}
Expand Down
9 changes: 9 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ var EndGate;

return bounds;
};

/**
* Scale's the Sprite2d graphic.
* @param scale The value to multiply the graphic's size by.
*/
Sprite2d.prototype.Scale = function (scale) {
this.Size.Width *= scale;
this.Size.Height *= scale;
};
return Sprite2d;
})(Graphics.Graphic2d);
Graphics.Sprite2d = Sprite2d;
Expand Down
9 changes: 9 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ module EndGate.Graphics {

return bounds;
}

/**
* Scale's the Sprite2d graphic.
* @param scale The value to multiply the graphic's size by.
*/
public Scale(scale: number): void {
this.Size.Width *= scale;
this.Size.Height *= scale;
}
}

}
10 changes: 10 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Text/Text2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ var EndGate;

return this._drawBounds;
};

/**
* Scale's the fonts FontSize.
* @param scale The value to multiply the graphic's size by.
*/
Text2d.prototype.Scale = function (scale) {
var size = parseInt(this.FontSettings.FontSize);

this.FontSettings.FontSize = this.FontSettings.FontSize.replace(size.toString(), (size * scale).toString());
};
return Text2d;
})(Graphics.Graphic2d);
Graphics.Text2d = Text2d;
Expand Down
10 changes: 10 additions & 0 deletions EndGate/EndGate.Core.JS/Graphics/Text/Text2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,15 @@ module EndGate.Graphics {

return this._drawBounds;
}

/**
* Scale's the fonts FontSize.
* @param scale The value to multiply the graphic's size by.
*/
public Scale(scale: number): void {
var size = parseInt(this.FontSettings.FontSize);

this.FontSettings.FontSize = this.FontSettings.FontSize.replace(size.toString(), (size * scale).toString());
}
}
}
6 changes: 6 additions & 0 deletions EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ var EndGate;

this._Resources = resources;
}
/**
* Scale is not implemented.
*/
TileMap.prototype.Scale = function (scale) {
throw new Error("Scale is not implemented for TileMaps.");
};
return TileMap;
})(EndGate.Graphics.Graphic2d);
Map.TileMap = TileMap;
Expand Down
7 changes: 7 additions & 0 deletions EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ module EndGate.Map {

this._Resources = resources;
}

/**
* Scale is not implemented.
*/
public Scale(scale: number): void {
throw new Error("Scale is not implemented for TileMaps.");
}
}

}

0 comments on commit 5b43028

Please sign in to comment.