summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/mx/primitives/mx.text.js
blob: 6b5681b818c6d69b7dc2e5fea3e2481ff9f972c4 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
MX.Text = MX.Object3D.extend({

  init: function (ops) {

		this.type = "Text"

  	this.type = "Image"
		this.media = ops.media
    this.width = 0
    this.height = 0
		this.x = ops.x || 0
		this.y = ops.y || 0
		this.z = ops.z || 0
		this.scale = ops.scale || 1
		this.backface = ops.backface || false

    this.scale = ops.scale || 1
    this.width = ops.media.width
    this.height = ops.media.height
    this.x = ops.x || 0
    this.y = ops.y || 0
    this.z = ops.z || 0
    this.rotationX = ops.rotationX || 0
    this.rotationY = ops.rotationY || 0
    this.rotationZ = ops.rotationZ || 0
		
		ops.className && this.el.classList.add(ops.className)
		this.backface && this.el.classList.add("backface-visible")
		this.el.classList.add("mx-text")
		this.el.classList.add("mx-scenery")
		
		this.inner = document.createElement("div")
		this.inner.classList.add("inner")
		this.el.appendChild(this.inner)
		
		this.load(ops)
  },
  
  load: function(ops){
    var media = ops.media
    if (media.font) this.setFont(media.font)

    this.setText( media.description )
  },
  
  setFont: function(font){
    if (! font.color || font.color[0] == "#") { font.color = [0,0,0] }

    this.inner.style.fontFamily = "'" + font.family + "',sans-serif"
    this.el.style.fontSize = (2 * font.size / devicePixelRatio) + "pt"
    this.el.style.textAlign = font.align
    this.el.style.color = rgb_string(font.color)
  },
  
  setText: function(text){
    this.inner.innerHTML = marked( text || "" )
  },

})