summaryrefslogtreecommitdiff
path: root/assets/javascripts/mx/primitives/mx.image.js
blob: 92a888211fcacb1209f4836f8f2e4679a2e05563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
MX.Image = MX.Object3D.extend({
  init: function (ops) {

	this.type = "Image"

    var layer = this
    layer.width = 0
    layer.height = 0

    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
    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.classList.add('image')
      layer.dirty = true
      layer.update()
      minimap.update()
    }
    image.src = ops.src;
  }
})