summaryrefslogtreecommitdiff
path: root/js/image.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/image.js')
-rw-r--r--js/image.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/js/image.js b/js/image.js
new file mode 100644
index 0000000..a09e71c
--- /dev/null
+++ b/js/image.js
@@ -0,0 +1,49 @@
+MX.Image = MX.Object3D.extend({
+ init: function (ops) {
+
+ ops = $.extend({}, {
+ src: undefined,
+ }, ops || {})
+
+ var layer = this.layer = new MX.Object3D()
+ layer.width = 0
+ layer.height = 0
+
+ this.add(layer)
+
+ if (ops.src) this.loadTexture(ops)
+
+ this.children.forEach(function (c, i) {
+ if (ops.texture) {
+ }
+ else if (ops.classname) {
+ c.el.classList.add(ops.classname)
+ }
+ else {
+ }
+ c.el.style.backgroundRepeat = 'no-repeat'
+ })
+
+ this.dirty = true
+ this.updateChildren = true
+ this.update()
+ },
+
+ loadTexture: function(ops){
+ var layer = this.children[0]
+ var image = new Image()
+ image.onload = function(){
+ layer.width = image.naturalWidth
+ layer.height = image.naturalHeight
+ layer.x = ops.x || 0
+ layer.y = ops.y || 0
+ layer.z = ops.z || 0
+ layer.scale = ops.scale || 1
+ layer.el.style.backgroundImage = "url(" + image.src + ")"
+ $(layer.el).addClass('image')
+ layer.dirty = true
+ layer.update()
+ }
+ image.src = ops.src;
+ }
+})