|
7
|
1 |
Rkns.Renderer = {} |
|
1
|
2 |
|
|
7
|
3 |
Rkns.Renderer.Utils = { |
|
5
|
4 |
_EDITOR_ARROW_LENGTH : 20, |
|
|
5 |
_EDITOR_ARROW_WIDTH : 40, |
|
|
6 |
_EDITOR_MARGIN : 15, |
|
|
7 |
_EDITOR_PADDING : 10, |
|
6
|
8 |
_EDITOR_GRADIENT : new paper.Gradient(['#f0f0f0', '#d0d0d0']), |
|
5
|
9 |
drawEditBox : function(_coords, _path, _width, _height) { |
|
|
10 |
var _isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
|
|
11 |
_left = _coords.x + _isLeft * ( this._EDITOR_MARGIN + this._EDITOR_ARROW_LENGTH ), |
|
|
12 |
_right = _coords.x + _isLeft * ( this._EDITOR_MARGIN + this._EDITOR_ARROW_LENGTH + _width ), |
|
|
13 |
_top = _coords.y - _height / 2; |
|
|
14 |
if (_top < this._EDITOR_MARGIN) { |
|
|
15 |
_top = Math.min( this._EDITOR_MARGIN, _coords.y - this._EDITOR_ARROW_WIDTH / 2 ); |
|
|
16 |
} |
|
|
17 |
var _bottom = _top + _height; |
|
|
18 |
if (_bottom > (paper.view.size.height - this._EDITOR_MARGIN)) { |
|
|
19 |
_bottom = Math.max( paper.view.size.height - this._EDITOR_MARGIN, _coords.y + this._EDITOR_ARROW_WIDTH / 2 ); |
|
|
20 |
_top = _bottom - _height; |
|
|
21 |
} |
|
|
22 |
_path.segments[0].point |
|
|
23 |
= _path.segments[7].point |
|
|
24 |
= _coords.add([_isLeft * this._EDITOR_MARGIN, 0]); |
|
|
25 |
_path.segments[1].point.x |
|
|
26 |
= _path.segments[2].point.x |
|
|
27 |
= _path.segments[5].point.x |
|
|
28 |
= _path.segments[6].point.x |
|
|
29 |
= _left; |
|
|
30 |
_path.segments[3].point.x |
|
|
31 |
= _path.segments[4].point.x |
|
|
32 |
= _right; |
|
|
33 |
_path.segments[2].point.y |
|
|
34 |
= _path.segments[3].point.y |
|
|
35 |
= _top; |
|
|
36 |
_path.segments[4].point.y |
|
|
37 |
= _path.segments[5].point.y |
|
|
38 |
= _bottom; |
|
|
39 |
_path.segments[1].point.y = _coords.y - this._EDITOR_ARROW_WIDTH / 2; |
|
|
40 |
_path.segments[6].point.y = _coords.y + this._EDITOR_ARROW_WIDTH / 2; |
|
6
|
41 |
_path.fillColor = new paper.GradientColor(this._EDITOR_GRADIENT, [0,_top], [0, _bottom]) |
|
5
|
42 |
return { |
|
|
43 |
left: (this._EDITOR_PADDING + Math.min(_left, _right)), |
|
|
44 |
top: (this._EDITOR_PADDING + _top) |
|
|
45 |
} |
|
7
|
46 |
}, |
|
18
|
47 |
sector : function(_ctrl, _inR, _outR, _startAngle, _endAngle, _padding, _imgsrc) { |
|
7
|
48 |
var _startRads = _startAngle * Math.PI / 180, |
|
|
49 |
_endRads = _endAngle * Math.PI / 180, |
|
|
50 |
_img = new Image(), |
|
|
51 |
_span = _endRads - _startRads, |
|
|
52 |
_k = .0879 * _span, |
|
|
53 |
_kin = _k * _inR, |
|
|
54 |
_kout = _k * _outR, |
|
|
55 |
_startdx = - Math.sin(_startRads), |
|
|
56 |
_startdy = Math.cos(_startRads), |
|
|
57 |
_startXIn = Math.cos(_startRads) * _inR + _padding * _startdx, |
|
|
58 |
_startYIn = Math.sin(_startRads) * _inR + _padding * _startdy, |
|
|
59 |
_startXOut = Math.cos(_startRads) * _outR + _padding * _startdx, |
|
|
60 |
_startYOut = Math.sin(_startRads) * _outR + _padding * _startdy, |
|
|
61 |
_enddx = - Math.sin(_endRads), |
|
|
62 |
_enddy = Math.cos(_endRads), |
|
|
63 |
_endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
|
|
64 |
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
|
|
65 |
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
|
|
66 |
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
|
|
67 |
_centerR = (_inR + _outR)/2, |
|
|
68 |
_centerRads = (_startRads + _endRads) / 2, |
|
|
69 |
_centerX = Math.cos(_centerRads) * _centerR, |
|
|
70 |
_centerY = Math.sin(_centerRads) * _centerR, |
|
|
71 |
_segments = []; |
|
|
72 |
_segments.push([[_startXIn, _startYIn], [0, 0], [ _kin * _startdx, _kin * _startdy ]]); |
|
|
73 |
for (var i = 1; i < 4; i++) { |
|
|
74 |
var _rads = i * _span / 4 + _startRads, |
|
|
75 |
_dx = - Math.sin(_rads), |
|
|
76 |
_dy = Math.cos(_rads), |
|
|
77 |
_x = Math.cos(_rads) * _inR, |
|
|
78 |
_y = Math.sin(_rads) * _inR; |
|
|
79 |
_segments.push([[_x, _y], [ - _kin * _dx, - _kin * _dy], [ _kin * _dx, _kin * _dy ]]); |
|
|
80 |
} |
|
|
81 |
_segments.push([[_endXIn, _endYIn], [ - _kin * _enddx, - _kin * _enddy ], [0,0]]); |
|
|
82 |
_segments.push([[_endXOut, _endYOut], [ 0,0 ], [ - _kout * _enddx, - _kout * _enddy ]]); |
|
|
83 |
for (var i = 3; i > 0; i--) { |
|
|
84 |
var _rads = i * _span / 4 + _startRads, |
|
|
85 |
_dx = - Math.sin(_rads), |
|
|
86 |
_dy = Math.cos(_rads), |
|
|
87 |
_x = Math.cos(_rads) * _outR, |
|
|
88 |
_y = Math.sin(_rads) * _outR; |
|
|
89 |
_segments.push([[_x, _y], [ _kout * _dx, _kout * _dy], [ - _kout * _dx, - _kout * _dy ]]); |
|
|
90 |
} |
|
|
91 |
_segments.push([[_startXOut, _startYOut], [ _kout * _startdx, _kout * _startdy ], [0, 0]]); |
|
18
|
92 |
var _path = new paper.Path(); |
|
7
|
93 |
_path.add.apply(_path, _segments); |
|
|
94 |
_path.fillColor = "#333333"; |
|
15
|
95 |
_path.opacity = .5; |
|
7
|
96 |
_path.closed = true; |
|
18
|
97 |
_path.__controller = _ctrl; |
|
|
98 |
var _visible = false, |
|
|
99 |
_restPos = new paper.Point(-200, -200), |
|
|
100 |
_grp = new paper.Group([_path]), |
|
|
101 |
_delta = _grp.position, |
|
|
102 |
_imgdelta = new paper.Point([_centerX, _centerY]), |
|
|
103 |
_currentPos = new paper.Point(0,0); |
|
|
104 |
_grp.visible = false; |
|
|
105 |
_grp.position = _restPos; |
|
|
106 |
var _res = { |
|
|
107 |
show: function() { |
|
|
108 |
_visible = true; |
|
|
109 |
_grp.position = _currentPos.add(_delta); |
|
|
110 |
_grp.visible = true; |
|
|
111 |
}, |
|
|
112 |
moveTo: function(_point) { |
|
|
113 |
_currentPos = _point; |
|
|
114 |
if (_visible) { |
|
|
115 |
_grp.position = _point.add(_delta); |
|
|
116 |
} |
|
|
117 |
}, |
|
|
118 |
hide: function() { |
|
|
119 |
_visible = false; |
|
|
120 |
_grp.visible = false; |
|
|
121 |
_grp.position = _restPos; |
|
|
122 |
}, |
|
|
123 |
select: function() { |
|
|
124 |
_path.opacity = .8; |
|
|
125 |
}, |
|
|
126 |
unselect: function() { |
|
|
127 |
_path.opacity = .5; |
|
|
128 |
}, |
|
|
129 |
destroy: function() { |
|
|
130 |
_grp.remove(); |
|
7
|
131 |
} |
|
18
|
132 |
} |
|
7
|
133 |
_img.onload = function() { |
|
|
134 |
var _w = _img.width, |
|
|
135 |
_h = _img.height; |
|
|
136 |
var _raster = new paper.Raster(_img); |
|
18
|
137 |
_raster.position = _imgdelta.add(_grp.position).subtract(_delta); |
|
7
|
138 |
_grp.addChild(_raster); |
|
|
139 |
} |
|
|
140 |
_img.src = _imgsrc; |
|
|
141 |
return _res |
|
5
|
142 |
} |
|
|
143 |
} |
|
|
144 |
|
|
7
|
145 |
Rkns.Renderer._BaseController = function(_renderer, _element) { |
|
1
|
146 |
if (typeof _renderer !== "undefined") { |
|
4
|
147 |
this.id = Rkns.Utils.getUID('controller'); |
|
1
|
148 |
this._renderer = _renderer; |
|
5
|
149 |
this._project = _renderer._project; |
|
1
|
150 |
this._element = _element; |
|
2
|
151 |
this._element.__controller = this; |
|
1
|
152 |
} |
|
|
153 |
} |
|
|
154 |
|
|
7
|
155 |
Rkns.Renderer._BaseController.prototype.select = function() {} |
|
4
|
156 |
|
|
7
|
157 |
Rkns.Renderer._BaseController.prototype.unselect = function() {} |
|
|
158 |
|
|
|
159 |
Rkns.Renderer._BaseController.prototype.mouseup = function() {} |
|
4
|
160 |
|
|
7
|
161 |
Rkns.Renderer._BaseController.prototype.destroy = function() {} |
|
5
|
162 |
|
|
7
|
163 |
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
1
|
164 |
|
|
7
|
165 |
Rkns.Renderer.Node.prototype._init = function() { |
|
2
|
166 |
this._renderer.node_layer.activate(); |
|
20
|
167 |
this.type = "Node"; |
|
7
|
168 |
this.circle = new paper.Path.Circle([0, 0], Rkns._NODE_RADIUS); |
|
|
169 |
this.circle.fillColor = '#ffffff'; |
|
|
170 |
this.circle.__controller = this; |
|
|
171 |
this.title = new paper.PointText([0,0]); |
|
|
172 |
this.title.characterStyle = { |
|
4
|
173 |
fontSize: Rkns._NODE_FONT_SIZE, |
|
2
|
174 |
fillColor: 'black' |
|
|
175 |
}; |
|
7
|
176 |
this.edit_button = new Rkns.Renderer.NodeEditButton(this._renderer, {}); |
|
|
177 |
this.edit_button.node_controller = this; |
|
|
178 |
this.remove_button = new Rkns.Renderer.NodeRemoveButton(this._renderer, {}); |
|
|
179 |
this.remove_button.node_controller = this; |
|
11
|
180 |
this.link_button = new Rkns.Renderer.NodeLinkButton(this._renderer, {}); |
|
|
181 |
this.link_button.node_controller = this; |
|
7
|
182 |
this.title.paragraphStyle.justification = 'center'; |
|
|
183 |
this.title.__controller = this; |
|
1
|
184 |
} |
|
|
185 |
|
|
7
|
186 |
Rkns.Renderer.Node.prototype.redraw = function() { |
|
|
187 |
var _model_coords = new paper.Point(this._element.position); |
|
|
188 |
this.paper_coords = this._renderer.toPaperCoords(_model_coords); |
|
|
189 |
this.circle.position = this.paper_coords; |
|
|
190 |
this.title.content = this._element.title; |
|
|
191 |
this.title.position = this.paper_coords.add([0, 2 * Rkns._NODE_RADIUS]); |
|
|
192 |
this.circle.strokeColor = this._element.created_by.color; |
|
|
193 |
this.edit_button.moveTo(this.paper_coords); |
|
|
194 |
this.remove_button.moveTo(this.paper_coords); |
|
11
|
195 |
this.link_button.moveTo(this.paper_coords); |
|
1
|
196 |
} |
|
|
197 |
|
|
7
|
198 |
Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
|
|
199 |
var _coords = this._renderer.toModelCoords(this.paper_coords.add(_delta)), |
|
5
|
200 |
_data = { |
|
|
201 |
position: { |
|
|
202 |
x: _coords.x, |
|
|
203 |
y: _coords.y |
|
|
204 |
} |
|
|
205 |
}; |
|
20
|
206 |
this._project.updateElement(this.type, this._element, _data, Rkns._SAVE); |
|
2
|
207 |
this._renderer.redraw(); |
|
|
208 |
} |
|
|
209 |
|
|
8
|
210 |
Rkns.Renderer.Node.prototype.openEditor = function() { |
|
|
211 |
this._renderer.removeControllersOfType("editor"); |
|
|
212 |
var _editor = this._renderer.addController("NodeEditor",{}); |
|
|
213 |
_editor.node_controller = this; |
|
|
214 |
_editor.redraw(); |
|
|
215 |
} |
|
|
216 |
|
|
7
|
217 |
Rkns.Renderer.Node.prototype.select = function() { |
|
|
218 |
this.circle.strokeWidth = 3; |
|
|
219 |
this.edit_button.show(); |
|
|
220 |
this.remove_button.show(); |
|
11
|
221 |
this.link_button.show(); |
|
7
|
222 |
} |
|
|
223 |
|
|
|
224 |
Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
|
11
|
225 |
if (!_newTarget || (_newTarget !== this.edit_button && _newTarget !== this.remove_button && _newTarget !== this.link_button)) { |
|
7
|
226 |
this.edit_button.hide(); |
|
|
227 |
this.remove_button.hide(); |
|
11
|
228 |
this.link_button.hide(); |
|
7
|
229 |
} |
|
|
230 |
this.circle.strokeWidth = 1; |
|
4
|
231 |
} |
|
|
232 |
|
|
7
|
233 |
Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
|
|
234 |
if (!this._renderer.is_dragging) { |
|
8
|
235 |
this.openEditor(); |
|
7
|
236 |
} |
|
|
237 |
} |
|
|
238 |
|
|
|
239 |
Rkns.Renderer.Node.prototype.destroy = function(_event) { |
|
|
240 |
this.edit_button.destroy(); |
|
|
241 |
this.remove_button.destroy(); |
|
|
242 |
this.circle.remove(); |
|
|
243 |
this.title.remove(); |
|
4
|
244 |
} |
|
|
245 |
|
|
2
|
246 |
/* */ |
|
|
247 |
|
|
7
|
248 |
Rkns.Renderer.Edge = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
2
|
249 |
|
|
7
|
250 |
Rkns.Renderer.Edge.prototype._init = function() { |
|
2
|
251 |
this._renderer.edge_layer.activate(); |
|
20
|
252 |
this.type = "Edge"; |
|
7
|
253 |
this.from_controller = this._element.from.__controller; |
|
2
|
254 |
this.to_node_controller = this._element.to.__controller; |
|
7
|
255 |
this.line = new paper.Path(); |
|
|
256 |
this.line.add([0,0],[0,0]); |
|
|
257 |
this.line.__controller = this; |
|
|
258 |
this.arrow = new paper.Path(); |
|
|
259 |
this.arrow.add([0,0],[Rkns._ARROW_LENGTH,Rkns._ARROW_WIDTH / 2],[0,Rkns._ARROW_WIDTH]); |
|
|
260 |
this.arrow.__controller = this; |
|
|
261 |
this.text = new paper.PointText(); |
|
|
262 |
this.text.characterStyle = { |
|
4
|
263 |
fontSize: Rkns._EDGE_FONT_SIZE, |
|
2
|
264 |
fillColor: 'black' |
|
|
265 |
}; |
|
7
|
266 |
this.text.paragraphStyle.justification = 'center'; |
|
|
267 |
this.text.__controller = this; |
|
|
268 |
this.text_angle = 0; |
|
|
269 |
this.arrow_angle = 0; |
|
15
|
270 |
this.edit_button = new Rkns.Renderer.EdgeEditButton(this._renderer, {}); |
|
|
271 |
this.edit_button.edge_controller = this; |
|
|
272 |
this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this._renderer, {}); |
|
|
273 |
this.remove_button.edge_controller = this; |
|
2
|
274 |
} |
|
|
275 |
|
|
7
|
276 |
Rkns.Renderer.Edge.prototype.redraw = function() { |
|
15
|
277 |
var _p0o = this.from_controller.paper_coords, |
|
|
278 |
_p1o = this.to_node_controller.paper_coords, |
|
|
279 |
_v = _p1o.subtract(_p0o), |
|
|
280 |
_r = _v.length, |
|
18
|
281 |
_u = _v.divide(_r), |
|
|
282 |
_delta = new paper.Point([- _u.y, _u.x]).multiply( 4 ), |
|
15
|
283 |
_p0 = _p0o.add(_delta), /* Adding a 4 px difference */ |
|
|
284 |
_p1 = _p1o.add(_delta), /* to differentiate inbound and outbound links */ |
|
|
285 |
_a = _v.angle, |
|
4
|
286 |
_color = this._element.created_by.color; |
|
15
|
287 |
this.paper_coords = _p0.add(_p1).divide(2); |
|
7
|
288 |
this.line.strokeColor = _color; |
|
|
289 |
this.line.segments[0].point = _p0; |
|
|
290 |
this.line.segments[1].point = _p1; |
|
|
291 |
this.arrow.rotate(_a - this.arrow_angle); |
|
|
292 |
this.arrow.fillColor = _color; |
|
18
|
293 |
this.arrow.position = this.paper_coords.subtract(_u.multiply(4)); |
|
7
|
294 |
this.arrow_angle = _a; |
|
2
|
295 |
if (_a > 90) { |
|
|
296 |
_a -= 180; |
|
|
297 |
} |
|
|
298 |
if (_a < -90) { |
|
|
299 |
_a += 180; |
|
|
300 |
} |
|
7
|
301 |
this.text.rotate(_a - this.text_angle); |
|
|
302 |
this.text.content = this._element.title; |
|
15
|
303 |
this.text.position = this.paper_coords; |
|
7
|
304 |
this.text_angle = _a; |
|
15
|
305 |
this.edit_button.moveTo(this.paper_coords); |
|
|
306 |
this.remove_button.moveTo(this.paper_coords); |
|
7
|
307 |
} |
|
|
308 |
|
|
18
|
309 |
Rkns.Renderer.Edge.prototype.openEditor = function() { |
|
|
310 |
this._renderer.removeControllersOfType("editor"); |
|
|
311 |
var _editor = this._renderer.addController("EdgeEditor",{}); |
|
|
312 |
_editor.edge_controller = this; |
|
|
313 |
_editor.redraw(); |
|
|
314 |
} |
|
|
315 |
|
|
7
|
316 |
Rkns.Renderer.Edge.prototype.select = function() { |
|
|
317 |
this.line.strokeWidth = 3; |
|
15
|
318 |
this.edit_button.show(); |
|
|
319 |
this.remove_button.show(); |
|
7
|
320 |
} |
|
|
321 |
|
|
|
322 |
Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { |
|
15
|
323 |
if (!_newTarget || (_newTarget !== this.edit_button && _newTarget !== this.remove_button)) { |
|
|
324 |
this.edit_button.hide(); |
|
|
325 |
this.remove_button.hide(); |
|
|
326 |
} |
|
7
|
327 |
this.line.strokeWidth = 1; |
|
4
|
328 |
} |
|
|
329 |
|
|
7
|
330 |
Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
|
|
331 |
if (!this._renderer.is_dragging) { |
|
18
|
332 |
this.openEditor(); |
|
7
|
333 |
} |
|
4
|
334 |
} |
|
|
335 |
|
|
7
|
336 |
Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
|
|
337 |
this.from_controller.paperShift(_delta); |
|
|
338 |
this.to_node_controller.paperShift(_delta); |
|
|
339 |
this._renderer.redraw(); |
|
2
|
340 |
} |
|
|
341 |
|
|
7
|
342 |
Rkns.Renderer.Edge.prototype.destroy = function() { |
|
|
343 |
this.line.remove(); |
|
|
344 |
this.arrow.remove(); |
|
|
345 |
this.text.remove(); |
|
15
|
346 |
this.edit_button.destroy(); |
|
|
347 |
this.remove_button.destroy(); |
|
2
|
348 |
} |
|
5
|
349 |
|
|
4
|
350 |
/* */ |
|
|
351 |
|
|
7
|
352 |
Rkns.Renderer.TempEdge = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
4
|
353 |
|
|
7
|
354 |
Rkns.Renderer.TempEdge.prototype._init = function() { |
|
4
|
355 |
this._renderer.edge_layer.activate(); |
|
|
356 |
this.type = "temp-edge"; |
|
5
|
357 |
var _color = this._project.current_user.color; |
|
7
|
358 |
this.line = new paper.Path(); |
|
|
359 |
this.line.strokeColor = _color; |
|
|
360 |
this.line.add([0,0],[0,0]); |
|
|
361 |
this.line.__controller = this; |
|
|
362 |
this.arrow = new paper.Path(); |
|
|
363 |
this.arrow.fillColor = _color; |
|
|
364 |
this.arrow.add([0,0],[Rkns._ARROW_LENGTH,Rkns._ARROW_WIDTH / 2],[0,Rkns._ARROW_WIDTH]); |
|
|
365 |
this.arrow.__controller = this; |
|
|
366 |
this.arrow_angle = 0; |
|
4
|
367 |
} |
|
|
368 |
|
|
7
|
369 |
Rkns.Renderer.TempEdge.prototype.redraw = function() { |
|
|
370 |
var _p0 = this.from_controller.paper_coords, |
|
4
|
371 |
_p1 = this.end_pos, |
|
|
372 |
_a = _p1.subtract(_p0).angle, |
|
|
373 |
_c = _p0.add(_p1).divide(2); |
|
7
|
374 |
this.line.segments[0].point = _p0; |
|
|
375 |
this.line.segments[1].point = _p1; |
|
|
376 |
this.arrow.rotate(_a - this.arrow_angle); |
|
|
377 |
this.arrow.position = _c; |
|
|
378 |
this.arrow_angle = _a; |
|
4
|
379 |
} |
|
|
380 |
|
|
7
|
381 |
Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) { |
|
4
|
382 |
this.end_pos = this.end_pos.add(_delta); |
|
21
|
383 |
var _hitResult = paper.project.hitTest(this.end_pos); |
|
|
384 |
this._renderer.findTarget(_hitResult); |
|
4
|
385 |
this.redraw(); |
|
|
386 |
} |
|
|
387 |
|
|
7
|
388 |
Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) { |
|
4
|
389 |
var _hitResult = paper.project.hitTest(_event.point); |
|
|
390 |
if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
|
|
391 |
var _target = _hitResult.item.__controller; |
|
20
|
392 |
if (_target.type === "Node" && this.from_controller._element.id !== _target._element.id) { |
|
5
|
393 |
this._project.addEdge({ |
|
7
|
394 |
from: this.from_controller._element.id, |
|
4
|
395 |
to: _target._element.id |
|
|
396 |
}, Rkns._RENDER_AND_SAVE) |
|
|
397 |
} |
|
|
398 |
} |
|
5
|
399 |
this._renderer.removeController(this); |
|
|
400 |
} |
|
|
401 |
|
|
7
|
402 |
Rkns.Renderer.TempEdge.prototype.destroy = function() { |
|
|
403 |
this.arrow.remove(); |
|
|
404 |
this.line.remove(); |
|
5
|
405 |
} |
|
|
406 |
|
|
|
407 |
/* */ |
|
|
408 |
|
|
7
|
409 |
Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
5
|
410 |
|
|
7
|
411 |
Rkns.Renderer.NodeEditor.prototype._init = function() { |
|
5
|
412 |
this._renderer.overlay_layer.activate(); |
|
|
413 |
this.type = "editor"; |
|
|
414 |
this.editor_block = new paper.Path(); |
|
|
415 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
|
416 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
|
417 |
this.editor_block.strokeWidth = 2; |
|
|
418 |
this.editor_block.strokeColor = "#999999"; |
|
|
419 |
this.editor_block.fillColor = "#e0e0e0"; |
|
|
420 |
this.editor_block.opacity = .8; |
|
|
421 |
this.editor_$ = Rkns.$('<div>') |
|
11
|
422 |
.appendTo(this._renderer.editor_$) |
|
5
|
423 |
.css({ |
|
|
424 |
position: "absolute", |
|
|
425 |
opacity: .8 |
|
|
426 |
}) |
|
|
427 |
.hide(); |
|
|
428 |
} |
|
|
429 |
|
|
7
|
430 |
Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
|
5
|
431 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_node%></span></h2>' |
|
|
432 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
|
|
433 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=node.uri%>"/></p>' |
|
|
434 |
+ '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
|
|
435 |
+ '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by.color%>;"></span> <%=node.created_by.title%></p>' |
|
|
436 |
); |
|
|
437 |
|
|
7
|
438 |
Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
|
|
439 |
var _coords = this.node_controller.paper_coords, |
|
5
|
440 |
_element = this.node_controller._element, |
|
7
|
441 |
_css = Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 300); |
|
5
|
442 |
this.editor_$ |
|
|
443 |
.html(this.template({ |
|
|
444 |
node: _element, |
|
|
445 |
l10n: this._project.l10n |
|
|
446 |
})) |
|
|
447 |
.show() |
|
|
448 |
.css(_css); |
|
|
449 |
var _this = this; |
|
|
450 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
|
451 |
_this._renderer.removeController(_this); |
|
|
452 |
paper.view.draw(); |
|
|
453 |
}); |
|
|
454 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
|
455 |
var _data = { |
|
|
456 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
|
457 |
description: _this.editor_$.find(".Rk-Edit-Description").val(), |
|
|
458 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
|
459 |
} |
|
20
|
460 |
_this._project.updateNode( |
|
5
|
461 |
_element, |
|
|
462 |
_data, |
|
|
463 |
Rkns._SAVE |
|
|
464 |
); |
|
|
465 |
_this.node_controller.redraw(); |
|
|
466 |
paper.view.draw(); |
|
|
467 |
}); |
|
8
|
468 |
this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
|
5
|
469 |
} |
|
|
470 |
|
|
7
|
471 |
Rkns.Renderer.NodeEditor.prototype.destroy = function() { |
|
5
|
472 |
this.editor_block.remove(); |
|
|
473 |
this.editor_$.detach(); |
|
|
474 |
} |
|
|
475 |
|
|
|
476 |
/* */ |
|
|
477 |
|
|
7
|
478 |
Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
5
|
479 |
|
|
7
|
480 |
Rkns.Renderer.EdgeEditor.prototype._init = function() { |
|
5
|
481 |
this._renderer.overlay_layer.activate(); |
|
|
482 |
this.type = "editor"; |
|
|
483 |
this.editor_block = new paper.Path(); |
|
|
484 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
|
485 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
|
486 |
this.editor_block.strokeWidth = 2; |
|
|
487 |
this.editor_block.strokeColor = "#999999"; |
|
|
488 |
this.editor_block.fillColor = "#e0e0e0"; |
|
|
489 |
this.editor_block.opacity = .8; |
|
|
490 |
this.editor_$ = Rkns.$('<div>') |
|
11
|
491 |
.appendTo(this._renderer.editor_$) |
|
5
|
492 |
.css({ |
|
|
493 |
position: "absolute", |
|
|
494 |
opacity: .8 |
|
|
495 |
}) |
|
|
496 |
.hide(); |
|
|
497 |
} |
|
|
498 |
|
|
7
|
499 |
Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template( |
|
5
|
500 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_edge%></span></h2>' |
|
|
501 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>' |
|
|
502 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=edge.uri%>"/></p>' |
|
|
503 |
+ '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from.created_by.color%>;"></span><%=edge.from.title%></p>' |
|
|
504 |
+ '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to.created_by.color%>;"></span><%=edge.to.title%></p>' |
|
|
505 |
+ '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by.color%>;"></span> <%=edge.created_by.title%></p>' |
|
|
506 |
); |
|
|
507 |
|
|
7
|
508 |
Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
|
15
|
509 |
var _coords = this.edge_controller.paper_coords, |
|
5
|
510 |
_element = this.edge_controller._element, |
|
7
|
511 |
_css = Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 200); |
|
5
|
512 |
this.editor_$ |
|
|
513 |
.html(this.template({ |
|
|
514 |
edge: _element, |
|
|
515 |
l10n: this._project.l10n |
|
|
516 |
})) |
|
|
517 |
.show() |
|
|
518 |
.css(_css); |
|
|
519 |
var _this = this; |
|
|
520 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
|
521 |
_this._renderer.removeController(_this); |
|
|
522 |
paper.view.draw(); |
|
|
523 |
}); |
|
|
524 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
|
525 |
var _data = { |
|
|
526 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
|
527 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
|
528 |
} |
|
20
|
529 |
_this._project.updateEdge( |
|
5
|
530 |
_element, |
|
|
531 |
_data, |
|
|
532 |
Rkns._SAVE |
|
|
533 |
); |
|
|
534 |
_this.edge_controller.redraw(); |
|
|
535 |
paper.view.draw(); |
|
|
536 |
}); |
|
|
537 |
} |
|
|
538 |
|
|
7
|
539 |
Rkns.Renderer.EdgeEditor.prototype.destroy = function() { |
|
5
|
540 |
this.editor_block.remove(); |
|
|
541 |
this.editor_$.detach(); |
|
4
|
542 |
} |
|
2
|
543 |
|
|
|
544 |
/* */ |
|
1
|
545 |
|
|
7
|
546 |
Rkns.Renderer.NodeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
|
547 |
|
|
|
548 |
Rkns.Renderer.NodeEditButton.prototype._init = function() { |
|
|
549 |
this._renderer.node_layer.activate(); |
|
20
|
550 |
this.type = "Node-edit-button"; |
|
18
|
551 |
this.sector = Rkns.Renderer.Utils.sector(this, 1 + Rkns._NODE_RADIUS, 3 * Rkns._NODE_RADIUS, - 90, 30, 2, 'img/edit.png'); |
|
7
|
552 |
} |
|
|
553 |
|
|
|
554 |
Rkns.Renderer.NodeEditButton.prototype.moveTo = function(_pos) { |
|
18
|
555 |
this.sector.moveTo(_pos); |
|
7
|
556 |
} |
|
|
557 |
|
|
|
558 |
Rkns.Renderer.NodeEditButton.prototype.show = function() { |
|
18
|
559 |
this.sector.show(); |
|
7
|
560 |
} |
|
|
561 |
|
|
|
562 |
Rkns.Renderer.NodeEditButton.prototype.hide = function() { |
|
18
|
563 |
this.sector.hide(); |
|
7
|
564 |
} |
|
|
565 |
|
|
|
566 |
Rkns.Renderer.NodeEditButton.prototype.select = function() { |
|
18
|
567 |
this.sector.select(); |
|
7
|
568 |
} |
|
|
569 |
|
|
|
570 |
Rkns.Renderer.NodeEditButton.prototype.unselect = function() { |
|
18
|
571 |
this.sector.unselect(); |
|
7
|
572 |
this.hide(); |
|
|
573 |
this.node_controller.remove_button.hide(); |
|
11
|
574 |
this.node_controller.link_button.hide(); |
|
7
|
575 |
} |
|
|
576 |
|
|
|
577 |
Rkns.Renderer.NodeEditButton.prototype.mouseup = function() { |
|
|
578 |
if (!this._renderer.is_dragging) { |
|
8
|
579 |
this.node_controller.openEditor(); |
|
7
|
580 |
} |
|
|
581 |
} |
|
|
582 |
|
|
|
583 |
Rkns.Renderer.NodeEditButton.prototype.destroy = function() { |
|
18
|
584 |
this.sector.destroy(); |
|
7
|
585 |
} |
|
|
586 |
|
|
|
587 |
/* */ |
|
|
588 |
|
|
|
589 |
Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
|
590 |
|
|
|
591 |
Rkns.Renderer.NodeRemoveButton.prototype._init = function() { |
|
|
592 |
this._renderer.node_layer.activate(); |
|
20
|
593 |
this.type = "Node-remove-button"; |
|
18
|
594 |
this.sector = Rkns.Renderer.Utils.sector(this, 1 + Rkns._NODE_RADIUS, 3 * Rkns._NODE_RADIUS, -210, -90, 2, 'img/remove.png'); |
|
7
|
595 |
} |
|
|
596 |
|
|
|
597 |
Rkns.Renderer.NodeRemoveButton.prototype.moveTo = function(_pos) { |
|
18
|
598 |
this.sector.moveTo(_pos); |
|
7
|
599 |
} |
|
|
600 |
|
|
|
601 |
Rkns.Renderer.NodeRemoveButton.prototype.show = function() { |
|
18
|
602 |
this.sector.show(); |
|
7
|
603 |
} |
|
|
604 |
|
|
|
605 |
Rkns.Renderer.NodeRemoveButton.prototype.hide = function() { |
|
18
|
606 |
this.sector.hide(); |
|
7
|
607 |
} |
|
|
608 |
|
|
|
609 |
Rkns.Renderer.NodeRemoveButton.prototype.select = function() { |
|
18
|
610 |
this.sector.select(); |
|
7
|
611 |
} |
|
|
612 |
|
|
|
613 |
Rkns.Renderer.NodeRemoveButton.prototype.unselect = function() { |
|
18
|
614 |
this.sector.unselect(); |
|
7
|
615 |
this.hide(); |
|
|
616 |
this.node_controller.edit_button.hide(); |
|
11
|
617 |
this.node_controller.link_button.hide(); |
|
7
|
618 |
} |
|
|
619 |
|
|
|
620 |
Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() { |
|
10
|
621 |
if (confirm('Do you really wish to remove node "' + this.node_controller._element.title + '"?')) { |
|
|
622 |
this._renderer._project.removeNode(this.node_controller._element, Rkns._RENDER_AND_SAVE); |
|
|
623 |
} |
|
7
|
624 |
} |
|
|
625 |
|
|
|
626 |
Rkns.Renderer.NodeRemoveButton.prototype.destroy = function() { |
|
18
|
627 |
this.sector.destroy(); |
|
7
|
628 |
} |
|
|
629 |
|
|
|
630 |
/* */ |
|
|
631 |
|
|
11
|
632 |
Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
|
633 |
|
|
|
634 |
Rkns.Renderer.NodeLinkButton.prototype._init = function() { |
|
|
635 |
this._renderer.node_layer.activate(); |
|
20
|
636 |
this.type = "Node-link-button"; |
|
18
|
637 |
this.sector = Rkns.Renderer.Utils.sector(this, 1 + Rkns._NODE_RADIUS , 3 * Rkns._NODE_RADIUS, 30, 150, 2, 'img/link.png'); |
|
11
|
638 |
} |
|
|
639 |
|
|
|
640 |
Rkns.Renderer.NodeLinkButton.prototype.moveTo = function(_pos) { |
|
18
|
641 |
this.sector.moveTo(_pos); |
|
11
|
642 |
} |
|
|
643 |
|
|
|
644 |
Rkns.Renderer.NodeLinkButton.prototype.show = function() { |
|
18
|
645 |
this.sector.show(); |
|
11
|
646 |
} |
|
|
647 |
|
|
|
648 |
Rkns.Renderer.NodeLinkButton.prototype.hide = function() { |
|
18
|
649 |
this.sector.hide(); |
|
11
|
650 |
} |
|
|
651 |
|
|
|
652 |
Rkns.Renderer.NodeLinkButton.prototype.select = function() { |
|
18
|
653 |
this.sector.select(); |
|
11
|
654 |
} |
|
|
655 |
|
|
|
656 |
Rkns.Renderer.NodeLinkButton.prototype.unselect = function() { |
|
18
|
657 |
this.sector.unselect(); |
|
11
|
658 |
this.hide(); |
|
|
659 |
this.node_controller.edit_button.hide(); |
|
|
660 |
this.node_controller.remove_button.hide(); |
|
|
661 |
} |
|
|
662 |
|
|
|
663 |
Rkns.Renderer.NodeLinkButton.prototype.destroy = function() { |
|
18
|
664 |
this.sector.destroy(); |
|
11
|
665 |
} |
|
|
666 |
|
|
|
667 |
/* */ |
|
|
668 |
|
|
15
|
669 |
Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
|
670 |
|
|
|
671 |
Rkns.Renderer.EdgeEditButton.prototype._init = function() { |
|
|
672 |
this._renderer.edge_layer.activate(); |
|
20
|
673 |
this.type = "Edge-edit-button"; |
|
18
|
674 |
this.sector = Rkns.Renderer.Utils.sector(this, 5 , 2 * Rkns._NODE_RADIUS, - 60, 60, 2, 'img/edit.png'); |
|
15
|
675 |
} |
|
|
676 |
|
|
|
677 |
Rkns.Renderer.EdgeEditButton.prototype.moveTo = function(_pos) { |
|
18
|
678 |
this.sector.moveTo(_pos); |
|
15
|
679 |
} |
|
|
680 |
|
|
|
681 |
Rkns.Renderer.EdgeEditButton.prototype.show = function() { |
|
18
|
682 |
this.sector.show(); |
|
15
|
683 |
} |
|
|
684 |
|
|
|
685 |
Rkns.Renderer.EdgeEditButton.prototype.hide = function() { |
|
18
|
686 |
this.sector.hide(); |
|
15
|
687 |
} |
|
|
688 |
|
|
|
689 |
Rkns.Renderer.EdgeEditButton.prototype.select = function() { |
|
18
|
690 |
this.sector.select(); |
|
15
|
691 |
} |
|
|
692 |
|
|
|
693 |
Rkns.Renderer.EdgeEditButton.prototype.unselect = function() { |
|
18
|
694 |
this.sector.unselect(); |
|
15
|
695 |
this.hide(); |
|
|
696 |
this.edge_controller.remove_button.hide(); |
|
|
697 |
} |
|
|
698 |
|
|
|
699 |
Rkns.Renderer.EdgeEditButton.prototype.mouseup = function() { |
|
|
700 |
if (!this._renderer.is_dragging) { |
|
|
701 |
this.edge_controller.openEditor(); |
|
|
702 |
} |
|
|
703 |
} |
|
|
704 |
|
|
|
705 |
Rkns.Renderer.EdgeEditButton.prototype.destroy = function() { |
|
18
|
706 |
this.sector.destroy(); |
|
15
|
707 |
} |
|
|
708 |
|
|
|
709 |
/* */ |
|
|
710 |
|
|
|
711 |
Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
|
712 |
|
|
|
713 |
Rkns.Renderer.EdgeRemoveButton.prototype._init = function() { |
|
|
714 |
this._renderer.edge_layer.activate(); |
|
20
|
715 |
this.type = "Edge-remove-button"; |
|
18
|
716 |
this.sector = Rkns.Renderer.Utils.sector(this, 5, 2 * Rkns._NODE_RADIUS, - 240, -120, 2, 'img/remove.png'); |
|
15
|
717 |
} |
|
|
718 |
Rkns.Renderer.EdgeRemoveButton.prototype.moveTo = function(_pos) { |
|
18
|
719 |
this.sector.moveTo(_pos); |
|
15
|
720 |
} |
|
|
721 |
|
|
|
722 |
Rkns.Renderer.EdgeRemoveButton.prototype.show = function() { |
|
18
|
723 |
this.sector.show(); |
|
15
|
724 |
} |
|
|
725 |
|
|
|
726 |
Rkns.Renderer.EdgeRemoveButton.prototype.hide = function() { |
|
18
|
727 |
this.sector.hide(); |
|
15
|
728 |
} |
|
|
729 |
|
|
|
730 |
Rkns.Renderer.EdgeRemoveButton.prototype.select = function() { |
|
18
|
731 |
this.sector.select(); |
|
15
|
732 |
} |
|
|
733 |
|
|
|
734 |
Rkns.Renderer.EdgeRemoveButton.prototype.unselect = function() { |
|
18
|
735 |
this.sector.unselect(); |
|
15
|
736 |
this.hide(); |
|
|
737 |
this.edge_controller.edit_button.hide(); |
|
|
738 |
} |
|
|
739 |
|
|
|
740 |
Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() { |
|
|
741 |
if (confirm('Do you really wish to remove edge "' + this.edge_controller._element.title + '"?')) { |
|
|
742 |
this._renderer._project.removeEdge(this.edge_controller._element, Rkns._RENDER_AND_SAVE); |
|
|
743 |
} |
|
|
744 |
} |
|
|
745 |
|
|
|
746 |
Rkns.Renderer.EdgeRemoveButton.prototype.destroy = function() { |
|
18
|
747 |
this.sector.destroy(); |
|
15
|
748 |
} |
|
|
749 |
|
|
|
750 |
/* */ |
|
|
751 |
|
|
7
|
752 |
Rkns.Renderer.Scene = function(_project) { |
|
|
753 |
this._project = _project; |
|
4
|
754 |
this._MARGIN_X = 80; |
|
|
755 |
this._MARGIN_Y = 50; |
|
20
|
756 |
this.$ = Rkns.$(".Rk-Render"); |
|
|
757 |
this.$.html(this.template({ |
|
11
|
758 |
l10n: this._project.l10n |
|
20
|
759 |
})) |
|
|
760 |
this.canvas_$ = this.$.find(".Rk-Canvas"); |
|
|
761 |
this.editor_$ = this.$.find(".Rk-Editor"); |
|
|
762 |
paper.setup(this.canvas_$[0]); |
|
2
|
763 |
this.scale = 1; |
|
|
764 |
this.offset = paper.view.center; |
|
|
765 |
this.totalScroll = 0; |
|
5
|
766 |
this.click_target = null; |
|
4
|
767 |
this.selected_target = null; |
|
2
|
768 |
this.edge_layer = new paper.Layer(); |
|
|
769 |
this.node_layer = new paper.Layer(); |
|
5
|
770 |
this.overlay_layer = new paper.Layer(); |
|
2
|
771 |
var _tool = new paper.Tool(), |
|
|
772 |
_this = this; |
|
5
|
773 |
_tool.minDistance = Rkns._MIN_DRAG_DISTANCE; |
|
4
|
774 |
_tool.onMouseMove = function(_event) { |
|
|
775 |
_this.onMouseMove(_event); |
|
|
776 |
} |
|
2
|
777 |
_tool.onMouseDown = function(_event) { |
|
|
778 |
_this.onMouseDown(_event); |
|
|
779 |
} |
|
|
780 |
_tool.onMouseDrag = function(_event) { |
|
|
781 |
_this.onMouseDrag(_event); |
|
|
782 |
} |
|
21
|
783 |
this.canvas_$.mouseup(function(_event) { |
|
4
|
784 |
_this.onMouseUp(_event); |
|
21
|
785 |
}); |
|
20
|
786 |
this.canvas_$.mousewheel(function(_event, _delta) { |
|
2
|
787 |
_this.onScroll(_event, _delta); |
|
21
|
788 |
}); |
|
20
|
789 |
this.canvas_$.dblclick(function(_event) { |
|
4
|
790 |
_this.onDoubleClick(_event); |
|
11
|
791 |
}); |
|
21
|
792 |
this.canvas_$.mouseenter(function(_event) { |
|
|
793 |
_this.onMouseEnter(_event); |
|
|
794 |
}); |
|
11
|
795 |
this.editor_$.find(".Rk-ZoomOut").click(function() { |
|
|
796 |
_this.offset = new paper.Point([ |
|
20
|
797 |
_this.canvas_$.width(), |
|
|
798 |
_this.canvas_$.height() |
|
11
|
799 |
]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(_this.offset.multiply( Math.SQRT1_2 )); |
|
|
800 |
_this.scale *= Math.SQRT1_2; |
|
|
801 |
_this.redraw(); |
|
|
802 |
}); |
|
|
803 |
this.editor_$.find(".Rk-ZoomIn").click(function() { |
|
|
804 |
_this.offset = new paper.Point([ |
|
20
|
805 |
_this.canvas_$.width(), |
|
|
806 |
_this.canvas_$.height() |
|
11
|
807 |
]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(_this.offset.multiply( Math.SQRT2 )); |
|
|
808 |
_this.scale *= Math.SQRT2; |
|
|
809 |
_this.redraw(); |
|
|
810 |
}); |
|
2
|
811 |
paper.view.onResize = function(_event) { |
|
|
812 |
_this.offset = _this.offset.add(_event.delta.divide(2)); |
|
|
813 |
_this.redraw(); |
|
|
814 |
} |
|
|
815 |
} |
|
|
816 |
|
|
20
|
817 |
Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
|
|
818 |
'<canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor">' |
|
|
819 |
+ '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>' |
|
|
820 |
+ '</div>' |
|
11
|
821 |
); |
|
|
822 |
|
|
7
|
823 |
Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
|
2
|
824 |
return _point.multiply(this.scale).add(this.offset); |
|
|
825 |
} |
|
|
826 |
|
|
|
827 |
|
|
7
|
828 |
Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
|
2
|
829 |
return _point.subtract(this.offset).divide(this.scale); |
|
1
|
830 |
} |
|
|
831 |
|
|
7
|
832 |
Rkns.Renderer.Scene.prototype.draw = function() { |
|
2
|
833 |
var _this = this, |
|
|
834 |
_xx = this._project.nodes.map(function(_node) { return _node.position.x }), |
|
|
835 |
_yy = this._project.nodes.map(function(_node) { return _node.position.y }), |
|
|
836 |
_minx = Math.min.apply(Math, _xx), |
|
|
837 |
_miny = Math.min.apply(Math, _yy), |
|
|
838 |
_maxx = Math.max.apply(Math, _xx), |
|
|
839 |
_maxy = Math.max.apply(Math, _yy); |
|
4
|
840 |
this.scale = Math.min((paper.view.size.width - 2 * this._MARGIN_X) / (_maxx - _minx), (paper.view.size.height - 2 * this._MARGIN_Y) / (_maxy - _miny)); |
|
2
|
841 |
this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(this.scale)); |
|
20
|
842 |
this.controllers = new Rkns.ViewModel.List(); |
|
4
|
843 |
this._project.nodes.forEach(function(_node) { |
|
5
|
844 |
_this.addController("Node", _node); |
|
1
|
845 |
}); |
|
4
|
846 |
this._project.edges.forEach(function(_edge) { |
|
5
|
847 |
_this.addController("Edge", _edge); |
|
2
|
848 |
}); |
|
|
849 |
|
|
|
850 |
this.redraw(); |
|
1
|
851 |
} |
|
|
852 |
|
|
7
|
853 |
Rkns.Renderer.Scene.prototype.addController = function(_type, _controller) { |
|
|
854 |
var _el = new Rkns.Renderer[_type](this, _controller); |
|
4
|
855 |
this.controllers.push(_el); |
|
|
856 |
return _el; |
|
|
857 |
} |
|
|
858 |
|
|
7
|
859 |
Rkns.Renderer.Scene.prototype.removeController = function(_controller) { |
|
5
|
860 |
_controller.destroy(); |
|
7
|
861 |
this.controllers.removeId(_controller.id); |
|
5
|
862 |
} |
|
|
863 |
|
|
7
|
864 |
Rkns.Renderer.Scene.prototype.removeControllersOfType = function(_type) { |
|
5
|
865 |
var _controllers = this.controllers.filter(function(_ctrl) { |
|
|
866 |
return _ctrl.type == _type; |
|
|
867 |
}), |
|
|
868 |
_this = this; |
|
|
869 |
_controllers.forEach(function(_ctrl) { |
|
|
870 |
_this.removeController(_ctrl); |
|
|
871 |
}); |
|
|
872 |
} |
|
|
873 |
|
|
7
|
874 |
Rkns.Renderer.Scene.prototype.redraw = function() { |
|
4
|
875 |
this.controllers.forEach(function(_controller) { |
|
|
876 |
_controller.redraw(); |
|
2
|
877 |
}); |
|
|
878 |
paper.view.draw(); |
|
|
879 |
} |
|
|
880 |
|
|
11
|
881 |
Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
|
|
882 |
var _tmpEdge = this.addController("TempEdge",{}); |
|
|
883 |
_tmpEdge.end_pos = _point; |
|
|
884 |
_tmpEdge.from_controller = _from; |
|
|
885 |
_tmpEdge.redraw(); |
|
|
886 |
this.click_target = _tmpEdge; |
|
|
887 |
} |
|
|
888 |
|
|
21
|
889 |
Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) { |
|
4
|
890 |
if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
|
7
|
891 |
var _newTarget = _hitResult.item.__controller; |
|
4
|
892 |
if (this.selected_target !== _hitResult.item.__controller) { |
|
|
893 |
if (this.selected_target) { |
|
7
|
894 |
this.selected_target.unselect(_newTarget); |
|
4
|
895 |
} |
|
7
|
896 |
_newTarget.select(this.selected_target); |
|
|
897 |
this.selected_target = _newTarget; |
|
4
|
898 |
} |
|
|
899 |
} else { |
|
|
900 |
if (this.selected_target) { |
|
7
|
901 |
this.selected_target.unselect(null); |
|
4
|
902 |
} |
|
|
903 |
this.selected_target = null; |
|
|
904 |
} |
|
|
905 |
} |
|
|
906 |
|
|
21
|
907 |
Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
|
|
908 |
var _hitResult = paper.project.hitTest(_event.point); |
|
|
909 |
if (this.is_dragging) { |
|
|
910 |
if (this.click_target && typeof this.click_target.paperShift === "function") { |
|
|
911 |
this.click_target.paperShift(_event.delta); |
|
|
912 |
} else { |
|
|
913 |
this.offset = this.offset.add(_event.delta); |
|
|
914 |
this.redraw(); |
|
|
915 |
} |
|
|
916 |
} else { |
|
|
917 |
this.findTarget(_hitResult); |
|
|
918 |
} |
|
|
919 |
} |
|
|
920 |
|
|
7
|
921 |
Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) { |
|
5
|
922 |
this.is_dragging = false; |
|
2
|
923 |
var _hitResult = paper.project.hitTest(_event.point); |
|
|
924 |
if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
|
5
|
925 |
this.click_target = _hitResult.item.__controller; |
|
20
|
926 |
if (this.click_target.type === "Node" && _hitResult.type === "stroke") { |
|
11
|
927 |
this.addTempEdge(this.click_target, _event.point); |
|
|
928 |
} |
|
20
|
929 |
if (this.click_target.type === "Node-link-button") { |
|
11
|
930 |
this.addTempEdge(this.click_target.node_controller, _event.point); |
|
4
|
931 |
} |
|
2
|
932 |
} else { |
|
5
|
933 |
this.click_target = null; |
|
2
|
934 |
} |
|
1
|
935 |
} |
|
2
|
936 |
|
|
7
|
937 |
Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) { |
|
5
|
938 |
this.is_dragging = true; |
|
21
|
939 |
this.onMouseMove(_event); |
|
2
|
940 |
} |
|
|
941 |
|
|
7
|
942 |
Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) { |
|
5
|
943 |
if (this.click_target) { |
|
21
|
944 |
var _off = this.canvas_$.offset(); |
|
|
945 |
this.click_target.mouseup( |
|
|
946 |
{ |
|
|
947 |
point: new paper.Point([ |
|
|
948 |
_event.pageX - _off.left, |
|
|
949 |
_event.pageY - _off.top |
|
|
950 |
]) |
|
|
951 |
} |
|
|
952 |
); |
|
4
|
953 |
} |
|
5
|
954 |
this.is_dragging = false; |
|
|
955 |
this.click_target = null; |
|
4
|
956 |
} |
|
|
957 |
|
|
7
|
958 |
Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) { |
|
3
|
959 |
this.totalScroll += _scrolldelta; |
|
2
|
960 |
if (Math.abs(this.totalScroll) >= 1) { |
|
20
|
961 |
var _off = this.canvas_$.offset(), |
|
3
|
962 |
_delta = new paper.Point([ |
|
|
963 |
_event.pageX - _off.left, |
|
|
964 |
_event.pageY - _off.top |
|
|
965 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
|
2
|
966 |
if (this.totalScroll > 0) { |
|
3
|
967 |
this.offset = this.offset.subtract(_delta); |
|
2
|
968 |
this.scale *= Math.SQRT2; |
|
|
969 |
} else { |
|
3
|
970 |
this.offset = this.offset.add(_delta.divide( Math.SQRT2 )); |
|
2
|
971 |
this.scale *= Math.SQRT1_2; |
|
|
972 |
} |
|
|
973 |
this.totalScroll = 0; |
|
|
974 |
this.redraw(); |
|
|
975 |
} |
|
|
976 |
} |
|
4
|
977 |
|
|
7
|
978 |
Rkns.Renderer.Scene.prototype.onDoubleClick = function(_event) { |
|
20
|
979 |
var _off = this.canvas_$.offset(), |
|
4
|
980 |
_point = new paper.Point([ |
|
|
981 |
_event.pageX - _off.left, |
|
|
982 |
_event.pageY - _off.top |
|
|
983 |
]); |
|
|
984 |
var _hitResult = paper.project.hitTest(_point); |
|
|
985 |
if (!_hitResult || typeof _hitResult.item.__controller === "undefined") { |
|
8
|
986 |
var _coords = this.toModelCoords(_point), |
|
|
987 |
_node = this._project.addNode({ |
|
|
988 |
position: { |
|
|
989 |
x: _coords.x, |
|
|
990 |
y: _coords.y |
|
|
991 |
} |
|
|
992 |
}, Rkns._RENDER_AND_SAVE); |
|
|
993 |
_node.__controller.openEditor(); |
|
4
|
994 |
} |
|
|
995 |
paper.view.draw(); |
|
|
996 |
} |
|
21
|
997 |
|
|
|
998 |
Rkns.Renderer.Scene.prototype.onMouseEnter = function(_event) { |
|
|
999 |
var _newEl = this.renkan.selected_bin_item; |
|
|
1000 |
if (_newEl) { |
|
|
1001 |
var _off = this.canvas_$.offset(), |
|
|
1002 |
_point = new paper.Point([ |
|
|
1003 |
_event.pageX - _off.left, |
|
|
1004 |
_event.pageY - _off.top |
|
|
1005 |
]), |
|
|
1006 |
_coords = this.toModelCoords(_point), |
|
|
1007 |
_node = this._project.addNode({ |
|
|
1008 |
uri: _newEl.uri, |
|
|
1009 |
title: _newEl.title, |
|
|
1010 |
description: _newEl.description, |
|
|
1011 |
position: { |
|
|
1012 |
x: _coords.x, |
|
|
1013 |
y: _coords.y |
|
|
1014 |
} |
|
|
1015 |
}, Rkns._RENDER_AND_SAVE); |
|
|
1016 |
this.is_dragging = true; |
|
|
1017 |
this.click_target = _node.__controller; |
|
|
1018 |
} |
|
|
1019 |
} |