diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-04-09 17:45:32 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-04-09 17:45:32 -0400 |
| commit | cbd5e2411cd4df39dda75723da9c5e0153ad3331 (patch) | |
| tree | 61090416889211be2b0d2a37cf5fe0fd545a77e7 /assets/javascripts/mx/primitives/mx.image.js | |
| parent | 12d7bd4b9dba1c9e51b80059af650ff3fbfda0ca (diff) | |
box-drawing example
Diffstat (limited to 'assets/javascripts/mx/primitives/mx.image.js')
| -rw-r--r-- | assets/javascripts/mx/primitives/mx.image.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/assets/javascripts/mx/primitives/mx.image.js b/assets/javascripts/mx/primitives/mx.image.js new file mode 100644 index 0000000..cf4446e --- /dev/null +++ b/assets/javascripts/mx/primitives/mx.image.js @@ -0,0 +1,49 @@ +MX.Image = MX.Object3D.extend({ + init: function (ops) { + + this.type = "Image" + + var layer = this + layer.width = 0 + layer.height = 0 + layer.x = ops.x || 0 + layer.y = ops.y || 0 + layer.z = ops.z || 0 + + if (ops.src) this.loadTexture(ops) + + layer.el.classList.add(ops.className) + layer.el.style.backgroundRepeat = 'no-repeat' + + this.dirty = true + this.updateChildren = true + this.update() + }, + + loadTexture: function(ops){ + var layer = this + var image = new Image() + image.onload = function(){ + layer.scale = ops.scale || 1 + layer.width = image.naturalWidth + layer.height = image.naturalHeight + layer.x = ops.x || 0 + layer.y = (ops.y || 0) + layer.scale * layer.height/2 + 1 + layer.z = ops.z || 0 + layer.rotationX = ops.rotationX || 0 + layer.rotationY = ops.rotationY || 0 + layer.rotationZ = ops.rotationZ || 0 + layer.el.style.backgroundImage = "url(" + image.src + ")" + layer.el.classList.add('image') + layer.dirty = true + layer.update() + } + image.src = ops.src; + }, + + toString: function(){ + var params = "id src width height depth x y z rotationX rotationY rotationZ scale".split(" ") + return this.__toString(params) + }, + +}) |
