From 5b430285a10714557b0ffd59dc07aa1fb9f5221f Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 7 Aug 2013 22:39:23 -0700 Subject: [PATCH] Added a scale method to Graphics. - Some graphics may not have a scale method. #63 --- EndGate/EndGate.Core.JS/Graphics/Graphic2d.js | 8 ++++++++ EndGate/EndGate.Core.JS/Graphics/Graphic2d.ts | 8 ++++++++ EndGate/EndGate.Core.JS/Graphics/Grid/Grid.js | 8 ++++++++ EndGate/EndGate.Core.JS/Graphics/Grid/Grid.ts | 8 ++++++++ EndGate/EndGate.Core.JS/Graphics/Line2d.js | 9 +++++++++ EndGate/EndGate.Core.JS/Graphics/Line2d.ts | 9 +++++++++ EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.js | 8 ++++++++ EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.ts | 8 ++++++++ EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.js | 9 +++++++++ EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.ts | 9 +++++++++ EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.js | 9 +++++++++ EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.ts | 9 +++++++++ EndGate/EndGate.Core.JS/Graphics/Text/Text2d.js | 10 ++++++++++ EndGate/EndGate.Core.JS/Graphics/Text/Text2d.ts | 10 ++++++++++ EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.js | 6 ++++++ EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.ts | 7 +++++++ 16 files changed, 135 insertions(+) diff --git a/EndGate/EndGate.Core.JS/Graphics/Graphic2d.js b/EndGate/EndGate.Core.JS/Graphics/Graphic2d.js index 86114d9d..50070f77 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Graphic2d.js +++ b/EndGate/EndGate.Core.JS/Graphics/Graphic2d.js @@ -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. */ diff --git a/EndGate/EndGate.Core.JS/Graphics/Graphic2d.ts b/EndGate/EndGate.Core.JS/Graphics/Graphic2d.ts index 7e3828ed..d93f39af 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Graphic2d.ts +++ b/EndGate/EndGate.Core.JS/Graphics/Graphic2d.ts @@ -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. */ diff --git a/EndGate/EndGate.Core.JS/Graphics/Grid/Grid.js b/EndGate/EndGate.Core.JS/Graphics/Grid/Grid.js index 66d50285..69d1b7ec 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Grid/Grid.js +++ b/EndGate/EndGate.Core.JS/Graphics/Grid/Grid.js @@ -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. diff --git a/EndGate/EndGate.Core.JS/Graphics/Grid/Grid.ts b/EndGate/EndGate.Core.JS/Graphics/Grid/Grid.ts index 7f14e6d0..4df388ae 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Grid/Grid.ts +++ b/EndGate/EndGate.Core.JS/Graphics/Grid/Grid.ts @@ -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. diff --git a/EndGate/EndGate.Core.JS/Graphics/Line2d.js b/EndGate/EndGate.Core.JS/Graphics/Line2d.js index ce6652dc..747ad933 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Line2d.js +++ b/EndGate/EndGate.Core.JS/Graphics/Line2d.js @@ -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); diff --git a/EndGate/EndGate.Core.JS/Graphics/Line2d.ts b/EndGate/EndGate.Core.JS/Graphics/Line2d.ts index 2a311c4c..5c3fd2c7 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Line2d.ts +++ b/EndGate/EndGate.Core.JS/Graphics/Line2d.ts @@ -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); diff --git a/EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.js b/EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.js index 7cb4baa8..1be75c86 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.js +++ b/EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.js @@ -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); }; diff --git a/EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.ts b/EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.ts index 56e5c46e..b3b003d6 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.ts +++ b/EndGate/EndGate.Core.JS/Graphics/Shapes/Circle.ts @@ -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, (Math).twoPI); } diff --git a/EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.js b/EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.js index a52c0fab..d59061e3 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.js +++ b/EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.js @@ -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); }; diff --git a/EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.ts b/EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.ts index c541c64a..674039de 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.ts +++ b/EndGate/EndGate.Core.JS/Graphics/Shapes/Rectangle.ts @@ -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); } diff --git a/EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.js b/EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.js index 5db9dad2..0ad0369f 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.js +++ b/EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.js @@ -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; diff --git a/EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.ts b/EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.ts index 86aaa648..bfc49155 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.ts +++ b/EndGate/EndGate.Core.JS/Graphics/Sprites/Sprite2d.ts @@ -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; + } } } \ No newline at end of file diff --git a/EndGate/EndGate.Core.JS/Graphics/Text/Text2d.js b/EndGate/EndGate.Core.JS/Graphics/Text/Text2d.js index 2336f873..358b67c9 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Text/Text2d.js +++ b/EndGate/EndGate.Core.JS/Graphics/Text/Text2d.js @@ -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; diff --git a/EndGate/EndGate.Core.JS/Graphics/Text/Text2d.ts b/EndGate/EndGate.Core.JS/Graphics/Text/Text2d.ts index 9c2a5003..a8d4df48 100644 --- a/EndGate/EndGate.Core.JS/Graphics/Text/Text2d.ts +++ b/EndGate/EndGate.Core.JS/Graphics/Text/Text2d.ts @@ -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()); + } } } \ No newline at end of file diff --git a/EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.js b/EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.js index 0362f0fe..f648610b 100644 --- a/EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.js +++ b/EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.js @@ -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; diff --git a/EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.ts b/EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.ts index 8bf381af..29f1dd90 100644 --- a/EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.ts +++ b/EndGate/EndGate.Core.JS/Map/TileMaps/TileMap.ts @@ -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."); + } } } \ No newline at end of file