diff options
| author | Julie Lala <jules@okfoc.us> | 2014-06-04 00:31:01 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-06-04 00:31:01 -0400 |
| commit | 80e1fcbc52870366f2e885fe82724960929765c9 (patch) | |
| tree | d380e04e8d784c40606bdaad82dcd37d0e260de5 /public/assets/javascripts/mx/primitives/mx.image.js | |
| parent | 5fb0ad045820de96848e1bde8e2dba8a6853dd4d (diff) | |
| parent | 90142bd07f926ef8a7f3ea86a563ec0ca648ca5d (diff) | |
Merge branch 'master' of github.com:okfocus/vvalls
Diffstat (limited to 'public/assets/javascripts/mx/primitives/mx.image.js')
| -rw-r--r-- | public/assets/javascripts/mx/primitives/mx.image.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/public/assets/javascripts/mx/primitives/mx.image.js b/public/assets/javascripts/mx/primitives/mx.image.js new file mode 100644 index 0000000..d1e292d --- /dev/null +++ b/public/assets/javascripts/mx/primitives/mx.image.js @@ -0,0 +1,69 @@ +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 + layer.backface = ops.backface || false + + if (layer.backface) { + layer.el.classList.add("backface-visible") + } + + if (ops.src) { + this.loadTexture(ops) + } + + if (ops.className) { + 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 + layer.ops = defaults(ops, layer.ops) + var image = new Image() + image.onload = function(){ + layer.scale = layer.ops.scale || 1 + layer.width = image.naturalWidth + layer.height = image.naturalHeight + layer.x = layer.ops.x || 0 + layer.y = (layer.ops.y || 0) + layer.scale * layer.height/2 + 1 + layer.z = layer.ops.z || 0 + layer.rotationX = layer.ops.rotationX || 0 + layer.rotationY = layer.ops.rotationY || 0 + layer.rotationZ = layer.ops.rotationZ || 0 + layer.el.style.backgroundImage = "url(" + image.src + ")" + layer.el.classList.add('image') + layer.dirty = true + layer.update() + } + image.src = ops.src; + }, + + move: function(ops){ + var layer = this + layer.ops = defaults(ops, layer.ops) + for (var i in ops) { + layer[i] = ops[i] + } + layer.dirty = true + layer.update() + }, + + toString: function(){ + var params = "id src width height depth x y z rotationX rotationY rotationZ scale".split(" ") + return this.__toString(params) + }, + +}) |
