|
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"; |
|
|
95 |
_path.closed = true; |
|
|
96 |
var _grp = new paper.Group([_path]), |
|
|
97 |
_res = { |
|
|
98 |
group: _grp, |
|
|
99 |
circle: _path, |
|
|
100 |
delta: new paper.Point(0,0), |
|
|
101 |
img: _img, |
|
|
102 |
imgdelta: new paper.Point([_centerX, _centerY]) |
|
|
103 |
} |
|
|
104 |
_img.onload = function() { |
|
|
105 |
var _w = _img.width, |
|
|
106 |
_h = _img.height; |
|
|
107 |
var _raster = new paper.Raster(_img); |
|
|
108 |
_raster.position = _res.imgdelta.add(_grp.position).subtract(_res.delta); |
|
|
109 |
_grp.addChild(_raster); |
|
|
110 |
} |
|
|
111 |
_img.src = _imgsrc; |
|
|
112 |
return _res |
|
5
|
113 |
} |
|
|
114 |
} |
|
|
115 |
|
|
7
|
116 |
Rkns.Renderer._BaseController = function(_renderer, _element) { |
|
1
|
117 |
if (typeof _renderer !== "undefined") { |
|
4
|
118 |
this.id = Rkns.Utils.getUID('controller'); |
|
1
|
119 |
this._renderer = _renderer; |
|
5
|
120 |
this._project = _renderer._project; |
|
1
|
121 |
this._element = _element; |
|
2
|
122 |
this._element.__controller = this; |
|
1
|
123 |
} |
|
|
124 |
} |
|
|
125 |
|
|
7
|
126 |
Rkns.Renderer._BaseController.prototype.select = function() {} |
|
4
|
127 |
|
|
7
|
128 |
Rkns.Renderer._BaseController.prototype.unselect = function() {} |
|
|
129 |
|
|
|
130 |
Rkns.Renderer._BaseController.prototype.mouseup = function() {} |
|
4
|
131 |
|
|
7
|
132 |
Rkns.Renderer._BaseController.prototype.destroy = function() {} |
|
5
|
133 |
|
|
7
|
134 |
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
1
|
135 |
|
|
7
|
136 |
Rkns.Renderer.Node.prototype._init = function() { |
|
2
|
137 |
this._renderer.node_layer.activate(); |
|
|
138 |
this.type = "node"; |
|
7
|
139 |
this.circle = new paper.Path.Circle([0, 0], Rkns._NODE_RADIUS); |
|
|
140 |
this.circle.fillColor = '#ffffff'; |
|
|
141 |
this.circle.opacity = .9; |
|
|
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; |
|
|
152 |
this.title.paragraphStyle.justification = 'center'; |
|
|
153 |
this.title.__controller = this; |
|
1
|
154 |
} |
|
|
155 |
|
|
7
|
156 |
Rkns.Renderer.Node.prototype.redraw = function() { |
|
|
157 |
var _model_coords = new paper.Point(this._element.position); |
|
|
158 |
this.paper_coords = this._renderer.toPaperCoords(_model_coords); |
|
|
159 |
this.circle.position = this.paper_coords; |
|
|
160 |
this.title.content = this._element.title; |
|
|
161 |
this.title.position = this.paper_coords.add([0, 2 * Rkns._NODE_RADIUS]); |
|
|
162 |
this.circle.strokeColor = this._element.created_by.color; |
|
|
163 |
this.edit_button.moveTo(this.paper_coords); |
|
|
164 |
this.remove_button.moveTo(this.paper_coords); |
|
1
|
165 |
} |
|
|
166 |
|
|
7
|
167 |
Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
|
|
168 |
var _coords = this._renderer.toModelCoords(this.paper_coords.add(_delta)), |
|
5
|
169 |
_data = { |
|
|
170 |
position: { |
|
|
171 |
x: _coords.x, |
|
|
172 |
y: _coords.y |
|
|
173 |
} |
|
|
174 |
}; |
|
|
175 |
this._project.updateElement(this._element, _data, Rkns._SAVE); |
|
2
|
176 |
this._renderer.redraw(); |
|
|
177 |
} |
|
|
178 |
|
|
7
|
179 |
Rkns.Renderer.Node.prototype.select = function() { |
|
|
180 |
this.circle.strokeWidth = 3; |
|
|
181 |
this.edit_button.show(); |
|
|
182 |
this.remove_button.show(); |
|
|
183 |
} |
|
|
184 |
|
|
|
185 |
Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
|
|
186 |
if (!_newTarget || (_newTarget !== this.edit_button && _newTarget !== this.remove_button)) { |
|
|
187 |
this.edit_button.hide(); |
|
|
188 |
this.remove_button.hide(); |
|
|
189 |
} |
|
|
190 |
this.circle.strokeWidth = 1; |
|
4
|
191 |
} |
|
|
192 |
|
|
7
|
193 |
Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
|
|
194 |
if (!this._renderer.is_dragging) { |
|
|
195 |
this._renderer.removeControllersOfType("editor"); |
|
|
196 |
var _editor = this._renderer.addController("NodeEditor",{}); |
|
|
197 |
_editor.node_controller = this; |
|
|
198 |
_editor.redraw(); |
|
|
199 |
} |
|
|
200 |
} |
|
|
201 |
|
|
|
202 |
Rkns.Renderer.Node.prototype.destroy = function(_event) { |
|
|
203 |
this.edit_button.destroy(); |
|
|
204 |
this.remove_button.destroy(); |
|
|
205 |
this.circle.remove(); |
|
|
206 |
this.title.remove(); |
|
4
|
207 |
} |
|
|
208 |
|
|
2
|
209 |
/* */ |
|
|
210 |
|
|
7
|
211 |
Rkns.Renderer.Edge = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
2
|
212 |
|
|
7
|
213 |
Rkns.Renderer.Edge.prototype._init = function() { |
|
2
|
214 |
this._renderer.edge_layer.activate(); |
|
|
215 |
this.type = "edge"; |
|
7
|
216 |
this.from_controller = this._element.from.__controller; |
|
2
|
217 |
this.to_node_controller = this._element.to.__controller; |
|
7
|
218 |
this.line = new paper.Path(); |
|
|
219 |
this.line.add([0,0],[0,0]); |
|
|
220 |
this.line.__controller = this; |
|
|
221 |
this.arrow = new paper.Path(); |
|
|
222 |
this.arrow.add([0,0],[Rkns._ARROW_LENGTH,Rkns._ARROW_WIDTH / 2],[0,Rkns._ARROW_WIDTH]); |
|
|
223 |
this.arrow.__controller = this; |
|
|
224 |
this.text = new paper.PointText(); |
|
|
225 |
this.text.characterStyle = { |
|
4
|
226 |
fontSize: Rkns._EDGE_FONT_SIZE, |
|
2
|
227 |
fillColor: 'black' |
|
|
228 |
}; |
|
7
|
229 |
this.text.paragraphStyle.justification = 'center'; |
|
|
230 |
this.text.__controller = this; |
|
|
231 |
this.text_angle = 0; |
|
|
232 |
this.arrow_angle = 0; |
|
2
|
233 |
} |
|
|
234 |
|
|
7
|
235 |
Rkns.Renderer.Edge.prototype.redraw = function() { |
|
|
236 |
var _p0 = this.from_controller.paper_coords, |
|
|
237 |
_p1 = this.to_node_controller.paper_coords, |
|
4
|
238 |
_a = _p1.subtract(_p0).angle, |
|
|
239 |
_color = this._element.created_by.color; |
|
5
|
240 |
this.edge_paper_coords = _p0.add(_p1).divide(2); |
|
7
|
241 |
this.line.strokeColor = _color; |
|
|
242 |
this.line.segments[0].point = _p0; |
|
|
243 |
this.line.segments[1].point = _p1; |
|
|
244 |
this.arrow.rotate(_a - this.arrow_angle); |
|
|
245 |
this.arrow.fillColor = _color; |
|
|
246 |
this.arrow.position = this.edge_paper_coords; |
|
|
247 |
this.arrow_angle = _a; |
|
2
|
248 |
if (_a > 90) { |
|
|
249 |
_a -= 180; |
|
|
250 |
} |
|
|
251 |
if (_a < -90) { |
|
|
252 |
_a += 180; |
|
|
253 |
} |
|
7
|
254 |
this.text.rotate(_a - this.text_angle); |
|
|
255 |
this.text.content = this._element.title; |
|
|
256 |
this.text.position = this.edge_paper_coords; |
|
|
257 |
this.text_angle = _a; |
|
|
258 |
} |
|
|
259 |
|
|
|
260 |
Rkns.Renderer.Edge.prototype.select = function() { |
|
|
261 |
this.line.strokeWidth = 3; |
|
|
262 |
} |
|
|
263 |
|
|
|
264 |
Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { |
|
|
265 |
this.line.strokeWidth = 1; |
|
4
|
266 |
} |
|
|
267 |
|
|
7
|
268 |
Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
|
|
269 |
if (!this._renderer.is_dragging) { |
|
|
270 |
this._renderer.removeControllersOfType("editor"); |
|
|
271 |
var _editor = this._renderer.addController("EdgeEditor",{}); |
|
|
272 |
_editor.edge_controller = this; |
|
|
273 |
_editor.redraw(); |
|
|
274 |
} |
|
4
|
275 |
} |
|
|
276 |
|
|
7
|
277 |
Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
|
|
278 |
this.from_controller.paperShift(_delta); |
|
|
279 |
this.to_node_controller.paperShift(_delta); |
|
|
280 |
this._renderer.redraw(); |
|
2
|
281 |
} |
|
|
282 |
|
|
7
|
283 |
Rkns.Renderer.Edge.prototype.destroy = function() { |
|
|
284 |
this.line.remove(); |
|
|
285 |
this.arrow.remove(); |
|
|
286 |
this.text.remove(); |
|
2
|
287 |
} |
|
5
|
288 |
|
|
4
|
289 |
/* */ |
|
|
290 |
|
|
7
|
291 |
Rkns.Renderer.TempEdge = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
4
|
292 |
|
|
7
|
293 |
Rkns.Renderer.TempEdge.prototype._init = function() { |
|
4
|
294 |
this._renderer.edge_layer.activate(); |
|
|
295 |
this.type = "temp-edge"; |
|
5
|
296 |
var _color = this._project.current_user.color; |
|
7
|
297 |
this.line = new paper.Path(); |
|
|
298 |
this.line.strokeColor = _color; |
|
|
299 |
this.line.add([0,0],[0,0]); |
|
|
300 |
this.line.__controller = this; |
|
|
301 |
this.arrow = new paper.Path(); |
|
|
302 |
this.arrow.fillColor = _color; |
|
|
303 |
this.arrow.add([0,0],[Rkns._ARROW_LENGTH,Rkns._ARROW_WIDTH / 2],[0,Rkns._ARROW_WIDTH]); |
|
|
304 |
this.arrow.__controller = this; |
|
|
305 |
this.arrow_angle = 0; |
|
4
|
306 |
} |
|
|
307 |
|
|
7
|
308 |
Rkns.Renderer.TempEdge.prototype.redraw = function() { |
|
|
309 |
var _p0 = this.from_controller.paper_coords, |
|
4
|
310 |
_p1 = this.end_pos, |
|
|
311 |
_a = _p1.subtract(_p0).angle, |
|
|
312 |
_c = _p0.add(_p1).divide(2); |
|
7
|
313 |
this.line.segments[0].point = _p0; |
|
|
314 |
this.line.segments[1].point = _p1; |
|
|
315 |
this.arrow.rotate(_a - this.arrow_angle); |
|
|
316 |
this.arrow.position = _c; |
|
|
317 |
this.arrow_angle = _a; |
|
4
|
318 |
} |
|
|
319 |
|
|
7
|
320 |
Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) { |
|
4
|
321 |
this.end_pos = this.end_pos.add(_delta); |
|
|
322 |
this._renderer.onMouseMove({point: this.end_pos}); |
|
|
323 |
this.redraw(); |
|
|
324 |
} |
|
|
325 |
|
|
7
|
326 |
Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) { |
|
4
|
327 |
var _hitResult = paper.project.hitTest(_event.point); |
|
|
328 |
if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
|
|
329 |
var _target = _hitResult.item.__controller; |
|
7
|
330 |
if (_target.type === "node" && this.from_controller._element.id !== _target._element.id) { |
|
5
|
331 |
this._project.addEdge({ |
|
7
|
332 |
from: this.from_controller._element.id, |
|
4
|
333 |
to: _target._element.id |
|
|
334 |
}, Rkns._RENDER_AND_SAVE) |
|
|
335 |
} |
|
|
336 |
} |
|
5
|
337 |
this._renderer.removeController(this); |
|
|
338 |
} |
|
|
339 |
|
|
7
|
340 |
Rkns.Renderer.TempEdge.prototype.destroy = function() { |
|
|
341 |
this.arrow.remove(); |
|
|
342 |
this.line.remove(); |
|
5
|
343 |
} |
|
|
344 |
|
|
|
345 |
/* */ |
|
|
346 |
|
|
7
|
347 |
Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
5
|
348 |
|
|
7
|
349 |
Rkns.Renderer.NodeEditor.prototype._init = function() { |
|
5
|
350 |
this._renderer.overlay_layer.activate(); |
|
|
351 |
this.type = "editor"; |
|
|
352 |
this.editor_block = new paper.Path(); |
|
|
353 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
|
354 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
|
355 |
this.editor_block.strokeWidth = 2; |
|
|
356 |
this.editor_block.strokeColor = "#999999"; |
|
|
357 |
this.editor_block.fillColor = "#e0e0e0"; |
|
|
358 |
this.editor_block.opacity = .8; |
|
|
359 |
this.editor_$ = Rkns.$('<div>') |
|
|
360 |
.appendTo('.Rk-Editor') |
|
|
361 |
.css({ |
|
|
362 |
position: "absolute", |
|
|
363 |
opacity: .8 |
|
|
364 |
}) |
|
|
365 |
.hide(); |
|
|
366 |
} |
|
|
367 |
|
|
7
|
368 |
Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
|
5
|
369 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_node%></span></h2>' |
|
|
370 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
|
|
371 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=node.uri%>"/></p>' |
|
|
372 |
+ '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
|
|
373 |
+ '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by.color%>;"></span> <%=node.created_by.title%></p>' |
|
|
374 |
); |
|
|
375 |
|
|
7
|
376 |
Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
|
|
377 |
var _coords = this.node_controller.paper_coords, |
|
5
|
378 |
_element = this.node_controller._element, |
|
7
|
379 |
_css = Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 300); |
|
5
|
380 |
this.editor_$ |
|
|
381 |
.html(this.template({ |
|
|
382 |
node: _element, |
|
|
383 |
l10n: this._project.l10n |
|
|
384 |
})) |
|
|
385 |
.show() |
|
|
386 |
.css(_css); |
|
|
387 |
var _this = this; |
|
|
388 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
|
389 |
_this._renderer.removeController(_this); |
|
|
390 |
paper.view.draw(); |
|
|
391 |
}); |
|
|
392 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
|
393 |
var _data = { |
|
|
394 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
|
395 |
description: _this.editor_$.find(".Rk-Edit-Description").val(), |
|
|
396 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
|
397 |
} |
|
|
398 |
_this._project.updateElement( |
|
|
399 |
_element, |
|
|
400 |
_data, |
|
|
401 |
Rkns._SAVE |
|
|
402 |
); |
|
|
403 |
_this.node_controller.redraw(); |
|
|
404 |
paper.view.draw(); |
|
|
405 |
}); |
|
|
406 |
} |
|
|
407 |
|
|
7
|
408 |
Rkns.Renderer.NodeEditor.prototype.destroy = function() { |
|
5
|
409 |
this.editor_block.remove(); |
|
|
410 |
this.editor_$.detach(); |
|
|
411 |
} |
|
|
412 |
|
|
|
413 |
/* */ |
|
|
414 |
|
|
7
|
415 |
Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
5
|
416 |
|
|
7
|
417 |
Rkns.Renderer.EdgeEditor.prototype._init = function() { |
|
5
|
418 |
this._renderer.overlay_layer.activate(); |
|
|
419 |
this.type = "editor"; |
|
|
420 |
this.editor_block = new paper.Path(); |
|
|
421 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
|
422 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
|
423 |
this.editor_block.strokeWidth = 2; |
|
|
424 |
this.editor_block.strokeColor = "#999999"; |
|
|
425 |
this.editor_block.fillColor = "#e0e0e0"; |
|
|
426 |
this.editor_block.opacity = .8; |
|
|
427 |
this.editor_$ = Rkns.$('<div>') |
|
|
428 |
.appendTo('.Rk-Editor') |
|
|
429 |
.css({ |
|
|
430 |
position: "absolute", |
|
|
431 |
opacity: .8 |
|
|
432 |
}) |
|
|
433 |
.hide(); |
|
|
434 |
} |
|
|
435 |
|
|
7
|
436 |
Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template( |
|
5
|
437 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_edge%></span></h2>' |
|
|
438 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>' |
|
|
439 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=edge.uri%>"/></p>' |
|
|
440 |
+ '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from.created_by.color%>;"></span><%=edge.from.title%></p>' |
|
|
441 |
+ '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to.created_by.color%>;"></span><%=edge.to.title%></p>' |
|
|
442 |
+ '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by.color%>;"></span> <%=edge.created_by.title%></p>' |
|
|
443 |
); |
|
|
444 |
|
|
7
|
445 |
Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
|
5
|
446 |
var _coords = this.edge_controller.edge_paper_coords, |
|
|
447 |
_element = this.edge_controller._element, |
|
7
|
448 |
_css = Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 200); |
|
5
|
449 |
this.editor_$ |
|
|
450 |
.html(this.template({ |
|
|
451 |
edge: _element, |
|
|
452 |
l10n: this._project.l10n |
|
|
453 |
})) |
|
|
454 |
.show() |
|
|
455 |
.css(_css); |
|
|
456 |
var _this = this; |
|
|
457 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
|
458 |
_this._renderer.removeController(_this); |
|
|
459 |
paper.view.draw(); |
|
|
460 |
}); |
|
|
461 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
|
462 |
var _data = { |
|
|
463 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
|
464 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
|
465 |
} |
|
|
466 |
_this._project.updateElement( |
|
|
467 |
_element, |
|
|
468 |
_data, |
|
|
469 |
Rkns._SAVE |
|
|
470 |
); |
|
|
471 |
_this.edge_controller.redraw(); |
|
|
472 |
paper.view.draw(); |
|
|
473 |
}); |
|
|
474 |
} |
|
|
475 |
|
|
7
|
476 |
Rkns.Renderer.EdgeEditor.prototype.destroy = function() { |
|
5
|
477 |
this.editor_block.remove(); |
|
|
478 |
this.editor_$.detach(); |
|
4
|
479 |
} |
|
2
|
480 |
|
|
|
481 |
/* */ |
|
1
|
482 |
|
|
7
|
483 |
Rkns.Renderer.NodeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
|
484 |
|
|
|
485 |
Rkns.Renderer.NodeEditButton.prototype._init = function() { |
|
|
486 |
this._renderer.node_layer.activate(); |
|
|
487 |
this.type = "node-edit-button"; |
|
|
488 |
this.sector = Rkns.Renderer.Utils.sector(1 + Rkns._NODE_RADIUS, 3 * Rkns._NODE_RADIUS, - 90, 30, 2, 'img/edit.png'); |
|
|
489 |
this.sector.group.visible = false; |
|
|
490 |
this.sector.group.opacity = .5; |
|
|
491 |
this.sector.circle.__controller = this; |
|
|
492 |
this.sector.delta = this.sector.group.position; |
|
|
493 |
} |
|
|
494 |
|
|
|
495 |
Rkns.Renderer.NodeEditButton.prototype.moveTo = function(_pos) { |
|
|
496 |
this.sector.group.position = this.sector.delta.add(_pos); |
|
|
497 |
} |
|
|
498 |
|
|
|
499 |
Rkns.Renderer.NodeEditButton.prototype.show = function() { |
|
|
500 |
this.sector.group.visible = true; |
|
|
501 |
} |
|
|
502 |
|
|
|
503 |
Rkns.Renderer.NodeEditButton.prototype.hide = function() { |
|
|
504 |
this.sector.group.visible = false; |
|
|
505 |
} |
|
|
506 |
|
|
|
507 |
Rkns.Renderer.NodeEditButton.prototype.select = function() { |
|
|
508 |
this.sector.group.opacity = .8; |
|
|
509 |
} |
|
|
510 |
|
|
|
511 |
Rkns.Renderer.NodeEditButton.prototype.unselect = function() { |
|
|
512 |
this.sector.group.opacity = .5; |
|
|
513 |
this.hide(); |
|
|
514 |
this.node_controller.remove_button.hide(); |
|
|
515 |
} |
|
|
516 |
|
|
|
517 |
Rkns.Renderer.NodeEditButton.prototype.mouseup = function() { |
|
|
518 |
if (!this._renderer.is_dragging) { |
|
|
519 |
this.node_controller.mouseup(); |
|
|
520 |
} |
|
|
521 |
} |
|
|
522 |
|
|
|
523 |
Rkns.Renderer.NodeEditButton.prototype.destroy = function() { |
|
|
524 |
this.sector.group.remove(); |
|
|
525 |
} |
|
|
526 |
|
|
|
527 |
/* */ |
|
|
528 |
|
|
|
529 |
Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
|
530 |
|
|
|
531 |
Rkns.Renderer.NodeRemoveButton.prototype._init = function() { |
|
|
532 |
this._renderer.node_layer.activate(); |
|
|
533 |
this.type = "node-remove-button"; |
|
|
534 |
this.sector = Rkns.Renderer.Utils.sector(1 + Rkns._NODE_RADIUS, 3 * Rkns._NODE_RADIUS, -210, -90, 2, 'img/remove.png'); |
|
|
535 |
this.sector.group.visible = false; |
|
|
536 |
this.sector.group.opacity = .5; |
|
|
537 |
this.sector.circle.__controller = this; |
|
|
538 |
this.sector.delta = this.sector.group.position; |
|
|
539 |
} |
|
|
540 |
|
|
|
541 |
Rkns.Renderer.NodeRemoveButton.prototype.moveTo = function(_pos) { |
|
|
542 |
this.sector.group.position = this.sector.delta.add(_pos); |
|
|
543 |
} |
|
|
544 |
|
|
|
545 |
Rkns.Renderer.NodeRemoveButton.prototype.show = function() { |
|
|
546 |
this.sector.group.visible = true; |
|
|
547 |
} |
|
|
548 |
|
|
|
549 |
Rkns.Renderer.NodeRemoveButton.prototype.hide = function() { |
|
|
550 |
this.sector.group.visible = false; |
|
|
551 |
} |
|
|
552 |
|
|
|
553 |
Rkns.Renderer.NodeRemoveButton.prototype.select = function() { |
|
|
554 |
this.sector.group.opacity = .8; |
|
|
555 |
} |
|
|
556 |
|
|
|
557 |
Rkns.Renderer.NodeRemoveButton.prototype.unselect = function() { |
|
|
558 |
this.sector.group.opacity = .5; |
|
|
559 |
this.hide(); |
|
|
560 |
this.node_controller.edit_button.hide(); |
|
|
561 |
} |
|
|
562 |
|
|
|
563 |
Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() { |
|
|
564 |
this._renderer._project.removeNode(this.node_controller._element, Rkns._RENDER_AND_SAVE) |
|
|
565 |
} |
|
|
566 |
|
|
|
567 |
Rkns.Renderer.NodeRemoveButton.prototype.destroy = function() { |
|
|
568 |
this.sector.group.remove(); |
|
|
569 |
} |
|
|
570 |
|
|
|
571 |
/* */ |
|
|
572 |
|
|
|
573 |
Rkns.Renderer.Scene = function(_project) { |
|
|
574 |
this._project = _project; |
|
4
|
575 |
this._MARGIN_X = 80; |
|
|
576 |
this._MARGIN_Y = 50; |
|
|
577 |
var _canvas_id = this._project._opts.canvas_id; |
|
|
578 |
this.$ = Rkns.$("#"+_canvas_id) |
|
|
579 |
paper.setup(document.getElementById(_canvas_id)); |
|
2
|
580 |
this.scale = 1; |
|
|
581 |
this.offset = paper.view.center; |
|
|
582 |
this.totalScroll = 0; |
|
5
|
583 |
this.click_target = null; |
|
4
|
584 |
this.selected_target = null; |
|
2
|
585 |
this.edge_layer = new paper.Layer(); |
|
|
586 |
this.node_layer = new paper.Layer(); |
|
5
|
587 |
this.overlay_layer = new paper.Layer(); |
|
2
|
588 |
var _tool = new paper.Tool(), |
|
|
589 |
_this = this; |
|
5
|
590 |
_tool.minDistance = Rkns._MIN_DRAG_DISTANCE; |
|
4
|
591 |
_tool.onMouseMove = function(_event) { |
|
|
592 |
_this.onMouseMove(_event); |
|
|
593 |
} |
|
2
|
594 |
_tool.onMouseDown = function(_event) { |
|
|
595 |
_this.onMouseDown(_event); |
|
|
596 |
} |
|
|
597 |
_tool.onMouseDrag = function(_event) { |
|
|
598 |
_this.onMouseDrag(_event); |
|
|
599 |
} |
|
4
|
600 |
_tool.onMouseUp = function(_event) { |
|
|
601 |
_this.onMouseUp(_event); |
|
|
602 |
} |
|
|
603 |
this.$.mousewheel(function(_event, _delta) { |
|
2
|
604 |
_this.onScroll(_event, _delta); |
|
|
605 |
}) |
|
4
|
606 |
this.$.dblclick(function(_event) { |
|
|
607 |
_this.onDoubleClick(_event); |
|
|
608 |
}) |
|
2
|
609 |
paper.view.onResize = function(_event) { |
|
|
610 |
_this.offset = _this.offset.add(_event.delta.divide(2)); |
|
|
611 |
_this.redraw(); |
|
|
612 |
} |
|
|
613 |
} |
|
|
614 |
|
|
7
|
615 |
Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
|
2
|
616 |
return _point.multiply(this.scale).add(this.offset); |
|
|
617 |
} |
|
|
618 |
|
|
|
619 |
|
|
7
|
620 |
Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
|
2
|
621 |
return _point.subtract(this.offset).divide(this.scale); |
|
1
|
622 |
} |
|
|
623 |
|
|
7
|
624 |
Rkns.Renderer.Scene.prototype.draw = function() { |
|
2
|
625 |
var _this = this, |
|
|
626 |
_xx = this._project.nodes.map(function(_node) { return _node.position.x }), |
|
|
627 |
_yy = this._project.nodes.map(function(_node) { return _node.position.y }), |
|
|
628 |
_minx = Math.min.apply(Math, _xx), |
|
|
629 |
_miny = Math.min.apply(Math, _yy), |
|
|
630 |
_maxx = Math.max.apply(Math, _xx), |
|
|
631 |
_maxy = Math.max.apply(Math, _yy); |
|
4
|
632 |
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
|
633 |
this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(this.scale)); |
|
4
|
634 |
this.controllers = new Rkns.Model.List(); |
|
|
635 |
this._project.nodes.forEach(function(_node) { |
|
5
|
636 |
_this.addController("Node", _node); |
|
1
|
637 |
}); |
|
4
|
638 |
this._project.edges.forEach(function(_edge) { |
|
5
|
639 |
_this.addController("Edge", _edge); |
|
2
|
640 |
}); |
|
|
641 |
|
|
|
642 |
this.redraw(); |
|
1
|
643 |
} |
|
|
644 |
|
|
7
|
645 |
Rkns.Renderer.Scene.prototype.addController = function(_type, _controller) { |
|
|
646 |
var _el = new Rkns.Renderer[_type](this, _controller); |
|
4
|
647 |
this.controllers.push(_el); |
|
|
648 |
return _el; |
|
|
649 |
} |
|
|
650 |
|
|
7
|
651 |
Rkns.Renderer.Scene.prototype.removeController = function(_controller) { |
|
5
|
652 |
_controller.destroy(); |
|
7
|
653 |
this.controllers.removeId(_controller.id); |
|
5
|
654 |
} |
|
|
655 |
|
|
7
|
656 |
Rkns.Renderer.Scene.prototype.removeControllersOfType = function(_type) { |
|
5
|
657 |
var _controllers = this.controllers.filter(function(_ctrl) { |
|
|
658 |
return _ctrl.type == _type; |
|
|
659 |
}), |
|
|
660 |
_this = this; |
|
|
661 |
_controllers.forEach(function(_ctrl) { |
|
|
662 |
_this.removeController(_ctrl); |
|
|
663 |
}); |
|
|
664 |
} |
|
|
665 |
|
|
7
|
666 |
Rkns.Renderer.Scene.prototype.redraw = function() { |
|
4
|
667 |
this.controllers.forEach(function(_controller) { |
|
|
668 |
_controller.redraw(); |
|
2
|
669 |
}); |
|
|
670 |
paper.view.draw(); |
|
|
671 |
} |
|
|
672 |
|
|
7
|
673 |
Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
|
4
|
674 |
var _hitResult = paper.project.hitTest(_event.point); |
|
|
675 |
if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
|
7
|
676 |
var _newTarget = _hitResult.item.__controller; |
|
4
|
677 |
if (this.selected_target !== _hitResult.item.__controller) { |
|
|
678 |
if (this.selected_target) { |
|
7
|
679 |
this.selected_target.unselect(_newTarget); |
|
4
|
680 |
} |
|
7
|
681 |
_newTarget.select(this.selected_target); |
|
|
682 |
this.selected_target = _newTarget; |
|
4
|
683 |
} |
|
|
684 |
} else { |
|
|
685 |
if (this.selected_target) { |
|
7
|
686 |
this.selected_target.unselect(null); |
|
4
|
687 |
} |
|
|
688 |
this.selected_target = null; |
|
|
689 |
} |
|
|
690 |
} |
|
|
691 |
|
|
7
|
692 |
Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) { |
|
5
|
693 |
this.is_dragging = false; |
|
2
|
694 |
var _hitResult = paper.project.hitTest(_event.point); |
|
|
695 |
if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
|
5
|
696 |
this.click_target = _hitResult.item.__controller; |
|
|
697 |
if (this.click_target.type === "node" && _hitResult.type === "stroke") { |
|
|
698 |
var _tmpEdge = this.addController("TempEdge",{}); |
|
4
|
699 |
_tmpEdge.end_pos = _event.point; |
|
7
|
700 |
_tmpEdge.from_controller = this.click_target; |
|
4
|
701 |
_tmpEdge.redraw(); |
|
5
|
702 |
this.click_target = _tmpEdge; |
|
4
|
703 |
} |
|
2
|
704 |
} else { |
|
5
|
705 |
this.click_target = null; |
|
2
|
706 |
} |
|
1
|
707 |
} |
|
2
|
708 |
|
|
7
|
709 |
Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) { |
|
5
|
710 |
this.is_dragging = true; |
|
|
711 |
if (this.click_target && typeof this.click_target.paperShift === "function") { |
|
|
712 |
this.click_target.paperShift(_event.delta); |
|
2
|
713 |
} else { |
|
|
714 |
this.offset = this.offset.add(_event.delta); |
|
|
715 |
this.redraw(); |
|
|
716 |
} |
|
|
717 |
} |
|
|
718 |
|
|
7
|
719 |
Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) { |
|
5
|
720 |
if (this.click_target) { |
|
7
|
721 |
this.click_target.mouseup(_event); |
|
4
|
722 |
} |
|
5
|
723 |
this.is_dragging = false; |
|
|
724 |
this.click_target = null; |
|
4
|
725 |
} |
|
|
726 |
|
|
7
|
727 |
Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) { |
|
3
|
728 |
this.totalScroll += _scrolldelta; |
|
2
|
729 |
if (Math.abs(this.totalScroll) >= 1) { |
|
4
|
730 |
var _off = this.$.offset(), |
|
3
|
731 |
_delta = new paper.Point([ |
|
|
732 |
_event.pageX - _off.left, |
|
|
733 |
_event.pageY - _off.top |
|
|
734 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
|
2
|
735 |
if (this.totalScroll > 0) { |
|
3
|
736 |
this.offset = this.offset.subtract(_delta); |
|
2
|
737 |
this.scale *= Math.SQRT2; |
|
|
738 |
} else { |
|
3
|
739 |
this.offset = this.offset.add(_delta.divide( Math.SQRT2 )); |
|
2
|
740 |
this.scale *= Math.SQRT1_2; |
|
|
741 |
} |
|
|
742 |
this.totalScroll = 0; |
|
|
743 |
this.redraw(); |
|
|
744 |
} |
|
|
745 |
} |
|
4
|
746 |
|
|
7
|
747 |
Rkns.Renderer.Scene.prototype.onDoubleClick = function(_event) { |
|
4
|
748 |
var _off = this.$.offset(), |
|
|
749 |
_point = new paper.Point([ |
|
|
750 |
_event.pageX - _off.left, |
|
|
751 |
_event.pageY - _off.top |
|
|
752 |
]); |
|
|
753 |
var _hitResult = paper.project.hitTest(_point); |
|
|
754 |
if (!_hitResult || typeof _hitResult.item.__controller === "undefined") { |
|
|
755 |
var _coords = this.toModelCoords(_point); |
|
|
756 |
this._project.addNode({ |
|
|
757 |
position: { |
|
|
758 |
x: _coords.x, |
|
|
759 |
y: _coords.y |
|
|
760 |
} |
|
|
761 |
}, Rkns._RENDER_AND_SAVE); |
|
|
762 |
} |
|
|
763 |
paper.view.draw(); |
|
|
764 |
} |