1 /** 2 * A wrapper for canvas element. This should only used to save / store canvas' properties 3 * 4 * @constructor 5 * @this {Builder} 6 * @param {Number} width - the width of the {Canvas} 7 * @param {Number} height - the height of the {Canvas} 8 * @author Zack Newsham <zack_newsham@yahoo.co.uk> 9 * @author Alex Gheorghiu <alex@scriptoid.com> 10 */ 11 function CanvasProps(width, height){ 12 /**Canvas width*/ 13 this.width = width; 14 /**Canvas height*/ 15 this.height = height; 16 /**Canvas id. Used in main.js:updateFigure() to see what object we have*/ 17 this.id = "canvasProps"; // 18 /**Serialization type*/ 19 this.oType = 'CanvasProps'; 20 } 21 22 /**default height for canvas*/ 23 CanvasProps.DEFAULT_HEIGHT = 600; 24 25 /**default width for canvas*/ 26 CanvasProps.DEFAULT_WIDTH = 800; 27 28 /** 29 *We only ever have one instance of this class (like stack) 30 *but we need the creation of the Canvas to appear AFTER the page exists, 31 *otherwise we would not be able to add it dinamically to the document. 32 *@param {JSONObject} o 33 *@return new {Canvas} 34 *@author Zack Newsham <zack_newsham@yahoo.co.uk> 35 *@author Alex Gheorghiu <alex@scriptoid.com> 36 */ 37 CanvasProps.load = function(o){ 38 var canvasprops = new CanvasProps(); 39 40 canvasprops.height = o.height; 41 canvasprops.width = o.width; 42 43 return canvasprops; 44 } 45 46 47 CanvasProps.prototype = { 48 49 /**Get width of the canvas*/ 50 getWidth:function(){ 51 return this.width; 52 }, 53 54 55 /** 56 * Set the width of the canvas. Also force a canvas resize 57 * @param {Numeric} width - the new width 58 */ 59 setWidth:function(width){//required for undo 60 this.width = width; 61 this.sync(); 62 }, 63 64 /**Return the height of the canvas*/ 65 getHeight:function(){ 66 return this.height; 67 }, 68 69 70 /** 71 * Set the height of the canvas. Also force a Canvas resize 72 * @param {Numeric} height - the new height 73 */ 74 setHeight:function(height){//required for undo 75 this.height = height; 76 this.sync(); 77 }, 78 79 80 /** 81 *Resize the Canvas to current values 82 *@author alex@scriptoid.com 83 **/ 84 sync:function() { 85 var canvas = getCanvas(); 86 87 canvas.height = this.height; 88 canvas.width = this.width; 89 90 //whenever we change a detail of the width of the canvas, we need to update the map 91 minimap.initMinimap(); 92 }, 93 94 /**Returns a representation of the object 95 *@return {String} 96 **/ 97 toString: function(){ 98 return "CanvasProp [width: " + this.width + " height: " + this.height + ' ]'; 99 } 100 } 101 102