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