-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.js
More file actions
109 lines (74 loc) · 2.81 KB
/
views.js
File metadata and controls
109 lines (74 loc) · 2.81 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var WorldWindow = Point.extend4000({
initialize: function(opt) {
this.set(vectorize(this,'size',[100,100]))
this.paper = opt.paper
},
translate: function(v) {
return v.add(this).idiv(this.get('size'))
}
})
var WorldChunk = Quad.extend4000({
initialize: function() {
}
})
var ThingView = Backbone.View.extend( {
initialize: function(opt) {
var self = this;
this.paper = opt.paper
console.log(toArray(arguments))
var size = this.model.get('size');
if (!this.repr) {
this.repr = this.paper.rect(this.model.get('x') - (size / 2), this.model.get('y')- (size / 2), size, size);
this.repr.attr("fill", "#ffffff");
this.repr.attr("stroke", "#000000");
}
this.model.on('change:x', function(model,value) { self.repr.attr("x",value - (size / 2)) })
this.model.on('change:y', function(model,value) { self.repr.attr("y",value - (size / 2)) })
}
})
var VectViewArrow = Backbone.View.extend({
initialize: function(opt) {
this.paper = opt.paper
if (opt.color) { this.color = opt.color } else { this.color = "red" }
var self = this;
var host = this.model.get('host')
this.render()
host.on('change:x', function() { self.render() })
host.on('change:y', function() { self.render() })
this.model.on('change:x', function() { self.render() })
this.model.on('change:y', function() { self.render() })
},
render: function() {
var host = this.model.get('host')
var cto = host.add(this.model).mul(1.5)
var pathdata = { x1: host.x(), y1: host.y(), x2: cto.x(), y2: cto.y(), color: this.color}
if (!this.repr) {
this.repr = paper.arrow(pathdata)
} else {
this.repr.repos(pathdata)
}
}
})
var VectView = Backbone.View.extend({
initialize: function(opt) {
this.paper = opt.paper
if (opt.color) { this.color = opt.color } else { this.color = "red" }
var self = this;
var host = this.model.get('host')
this.render()
host.on('change:x', function() { self.render() })
host.on('change:y', function() { self.render() })
this.model.on('change:x', function() { self.render() })
this.model.on('change:y', function() { self.render() })
},
render: function() {
var host = this.model.get('host')
var cto = host.add(this.model)
var pathdata = [ [ "M", host.x(), host.y() ], [ "L" , cto.x(), cto.y() ] ]
if (!this.repr) {
this.repr = paper.path()
}
var pathParams = { stroke: this.color, "stroke-width": 2 }
this.repr.attr(_.extend({path: pathdata }, pathParams))
}
})