| author | veltr |
| Wed, 05 Sep 2012 14:49:33 +0200 | |
| changeset 36 | d249d36ecc37 |
| parent 35 | 10e0c23c849e |
| child 37 | db991a757015 |
| permissions | -rw-r--r-- |
| 28 | 1 |
Rkns.Renderer = { |
2 |
_MARGIN_X: 80, |
|
3 |
_MARGIN_Y: 50, |
|
4 |
_MIN_DRAG_DISTANCE: 2, |
|
5 |
_NODE_RADIUS: 15, |
|
| 31 | 6 |
_NODE_BUTTON_INNER: 16, |
7 |
_NODE_BUTTON_OUTER: 50, |
|
| 35 | 8 |
_EDGE_BUTTON_INNER: 1, |
| 31 | 9 |
_EDGE_BUTTON_OUTER: 40, |
| 28 | 10 |
_NODE_FONT_SIZE: 10, |
11 |
_EDGE_FONT_SIZE: 9, |
|
12 |
_NODE_MAX_CHAR: 50, |
|
13 |
_EDGE_MAX_CHAR: 40, |
|
14 |
_ARROW_LENGTH: 16, |
|
15 |
_ARROW_WIDTH: 8, |
|
| 5 | 16 |
_EDITOR_ARROW_LENGTH : 20, |
17 |
_EDITOR_ARROW_WIDTH : 40, |
|
18 |
_EDITOR_MARGIN : 15, |
|
19 |
_EDITOR_PADDING : 10, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
20 |
_EDITOR_GRADIENT : new paper.Gradient(['#f0f0f0', '#d0d0d0']), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
21 |
_CLICKMODE_ADDNODE : 1, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
22 |
_CLICKMODE_STARTEDGE : 2, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
23 |
_CLICKMODE_ENDEDGE : 3 |
| 28 | 24 |
} |
25 |
||
26 |
Rkns.Renderer.Utils = { |
|
27 |
drawEditBox : function(_coords, _path, _width, _xmargin, _selector) { |
|
28 |
_selector.css({ |
|
29 |
width: (_width - 2* Rkns.Renderer._EDITOR_PADDING), |
|
30 |
}) |
|
31 |
var _height = _selector.outerHeight() + 2* Rkns.Renderer._EDITOR_PADDING, |
|
32 |
_isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
|
33 |
_left = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH ), |
|
34 |
_right = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH + _width ), |
|
| 5 | 35 |
_top = _coords.y - _height / 2; |
| 28 | 36 |
if (_top < Rkns.Renderer._EDITOR_MARGIN) { |
37 |
_top = Math.min( Rkns.Renderer._EDITOR_MARGIN, _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 38 |
} |
39 |
var _bottom = _top + _height; |
|
| 28 | 40 |
if (_bottom > (paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN)) { |
41 |
_bottom = Math.max( paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN, _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 42 |
_top = _bottom - _height; |
43 |
} |
|
44 |
_path.segments[0].point |
|
45 |
= _path.segments[7].point |
|
| 28 | 46 |
= _coords.add([_isLeft * _xmargin, 0]); |
| 5 | 47 |
_path.segments[1].point.x |
48 |
= _path.segments[2].point.x |
|
49 |
= _path.segments[5].point.x |
|
50 |
= _path.segments[6].point.x |
|
51 |
= _left; |
|
52 |
_path.segments[3].point.x |
|
53 |
= _path.segments[4].point.x |
|
54 |
= _right; |
|
55 |
_path.segments[2].point.y |
|
56 |
= _path.segments[3].point.y |
|
57 |
= _top; |
|
58 |
_path.segments[4].point.y |
|
59 |
= _path.segments[5].point.y |
|
60 |
= _bottom; |
|
| 28 | 61 |
_path.segments[1].point.y = _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
62 |
_path.segments[6].point.y = _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
|
63 |
_path.closed = true; |
|
64 |
_path.fillColor = new paper.GradientColor(Rkns.Renderer._EDITOR_GRADIENT, [0,_top], [0, _bottom]); |
|
65 |
_selector.css({ |
|
66 |
left: (Rkns.Renderer._EDITOR_PADDING + Math.min(_left, _right)), |
|
67 |
top: (Rkns.Renderer._EDITOR_PADDING + _top) |
|
68 |
}); |
|
| 7 | 69 |
}, |
| 23 | 70 |
sector : function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgsrc) { |
| 7 | 71 |
var _startRads = _startAngle * Math.PI / 180, |
72 |
_endRads = _endAngle * Math.PI / 180, |
|
73 |
_img = new Image(), |
|
74 |
_span = _endRads - _startRads, |
|
75 |
_k = .0879 * _span, |
|
76 |
_kin = _k * _inR, |
|
77 |
_kout = _k * _outR, |
|
78 |
_startdx = - Math.sin(_startRads), |
|
79 |
_startdy = Math.cos(_startRads), |
|
80 |
_startXIn = Math.cos(_startRads) * _inR + _padding * _startdx, |
|
81 |
_startYIn = Math.sin(_startRads) * _inR + _padding * _startdy, |
|
82 |
_startXOut = Math.cos(_startRads) * _outR + _padding * _startdx, |
|
83 |
_startYOut = Math.sin(_startRads) * _outR + _padding * _startdy, |
|
84 |
_enddx = - Math.sin(_endRads), |
|
85 |
_enddy = Math.cos(_endRads), |
|
86 |
_endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
|
87 |
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
|
88 |
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
|
89 |
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
|
90 |
_centerR = (_inR + _outR)/2, |
|
91 |
_centerRads = (_startRads + _endRads) / 2, |
|
92 |
_centerX = Math.cos(_centerRads) * _centerR, |
|
93 |
_centerY = Math.sin(_centerRads) * _centerR, |
|
94 |
_segments = []; |
|
95 |
_segments.push([[_startXIn, _startYIn], [0, 0], [ _kin * _startdx, _kin * _startdy ]]); |
|
96 |
for (var i = 1; i < 4; i++) { |
|
97 |
var _rads = i * _span / 4 + _startRads, |
|
98 |
_dx = - Math.sin(_rads), |
|
99 |
_dy = Math.cos(_rads), |
|
100 |
_x = Math.cos(_rads) * _inR, |
|
101 |
_y = Math.sin(_rads) * _inR; |
|
102 |
_segments.push([[_x, _y], [ - _kin * _dx, - _kin * _dy], [ _kin * _dx, _kin * _dy ]]); |
|
103 |
} |
|
104 |
_segments.push([[_endXIn, _endYIn], [ - _kin * _enddx, - _kin * _enddy ], [0,0]]); |
|
105 |
_segments.push([[_endXOut, _endYOut], [ 0,0 ], [ - _kout * _enddx, - _kout * _enddy ]]); |
|
106 |
for (var i = 3; i > 0; i--) { |
|
107 |
var _rads = i * _span / 4 + _startRads, |
|
108 |
_dx = - Math.sin(_rads), |
|
109 |
_dy = Math.cos(_rads), |
|
110 |
_x = Math.cos(_rads) * _outR, |
|
111 |
_y = Math.sin(_rads) * _outR; |
|
112 |
_segments.push([[_x, _y], [ _kout * _dx, _kout * _dy], [ - _kout * _dx, - _kout * _dy ]]); |
|
113 |
} |
|
114 |
_segments.push([[_startXOut, _startYOut], [ _kout * _startdx, _kout * _startdy ], [0, 0]]); |
|
| 18 | 115 |
var _path = new paper.Path(); |
| 7 | 116 |
_path.add.apply(_path, _segments); |
117 |
_path.fillColor = "#333333"; |
|
| 15 | 118 |
_path.opacity = .5; |
| 7 | 119 |
_path.closed = true; |
| 23 | 120 |
_path.__representation = _repr; |
| 18 | 121 |
var _visible = false, |
122 |
_restPos = new paper.Point(-200, -200), |
|
123 |
_grp = new paper.Group([_path]), |
|
124 |
_delta = _grp.position, |
|
125 |
_imgdelta = new paper.Point([_centerX, _centerY]), |
|
126 |
_currentPos = new paper.Point(0,0); |
|
127 |
_grp.visible = false; |
|
128 |
_grp.position = _restPos; |
|
129 |
var _res = { |
|
130 |
show: function() { |
|
131 |
_visible = true; |
|
132 |
_grp.position = _currentPos.add(_delta); |
|
133 |
_grp.visible = true; |
|
134 |
}, |
|
135 |
moveTo: function(_point) { |
|
136 |
_currentPos = _point; |
|
137 |
if (_visible) { |
|
138 |
_grp.position = _point.add(_delta); |
|
139 |
} |
|
140 |
}, |
|
141 |
hide: function() { |
|
142 |
_visible = false; |
|
143 |
_grp.visible = false; |
|
144 |
_grp.position = _restPos; |
|
145 |
}, |
|
146 |
select: function() { |
|
147 |
_path.opacity = .8; |
|
148 |
}, |
|
149 |
unselect: function() { |
|
150 |
_path.opacity = .5; |
|
151 |
}, |
|
152 |
destroy: function() { |
|
153 |
_grp.remove(); |
|
| 7 | 154 |
} |
| 18 | 155 |
} |
| 7 | 156 |
_img.onload = function() { |
157 |
var _w = _img.width, |
|
158 |
_h = _img.height; |
|
159 |
var _raster = new paper.Raster(_img); |
|
| 18 | 160 |
_raster.position = _imgdelta.add(_grp.position).subtract(_delta); |
| 7 | 161 |
_grp.addChild(_raster); |
162 |
} |
|
163 |
_img.src = _imgsrc; |
|
164 |
return _res |
|
| 5 | 165 |
} |
166 |
} |
|
167 |
||
| 23 | 168 |
Rkns.Renderer._BaseRepresentation = function(_renderer, _model) { |
| 1 | 169 |
if (typeof _renderer !== "undefined") { |
| 23 | 170 |
this.renderer = _renderer; |
171 |
this.project = _renderer.renkan.project; |
|
172 |
this.model = _model; |
|
| 1 | 173 |
} |
174 |
} |
|
175 |
||
| 23 | 176 |
Rkns.Renderer._BaseRepresentation.prototype.select = function() {} |
| 4 | 177 |
|
| 23 | 178 |
Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {} |
| 7 | 179 |
|
| 26 | 180 |
Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {} |
181 |
||
182 |
Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {} |
|
183 |
||
| 23 | 184 |
Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {} |
| 4 | 185 |
|
| 23 | 186 |
Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {} |
| 5 | 187 |
|
| 23 | 188 |
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 1 | 189 |
|
| 7 | 190 |
Rkns.Renderer.Node.prototype._init = function() { |
| 23 | 191 |
this.renderer.node_layer.activate(); |
| 20 | 192 |
this.type = "Node"; |
| 28 | 193 |
this.circle = new paper.Path.Circle([0, 0], Rkns.Renderer._NODE_RADIUS); |
| 7 | 194 |
this.circle.fillColor = '#ffffff'; |
| 23 | 195 |
this.circle.__representation = this; |
| 7 | 196 |
this.title = new paper.PointText([0,0]); |
197 |
this.title.characterStyle = { |
|
| 28 | 198 |
fontSize: Rkns.Renderer._NODE_FONT_SIZE, |
| 2 | 199 |
fillColor: 'black' |
200 |
}; |
|
| 23 | 201 |
this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, {}); |
202 |
this.edit_button.node_representation = this; |
|
203 |
this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, {}); |
|
204 |
this.remove_button.node_representation = this; |
|
205 |
this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, {}); |
|
206 |
this.link_button.node_representation = this; |
|
| 7 | 207 |
this.title.paragraphStyle.justification = 'center'; |
| 23 | 208 |
this.title.__representation = this; |
| 1 | 209 |
} |
210 |
||
| 7 | 211 |
Rkns.Renderer.Node.prototype.redraw = function() { |
| 23 | 212 |
var _model_coords = new paper.Point(this.model.get("position")); |
213 |
this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
|
| 7 | 214 |
this.circle.position = this.paper_coords; |
| 23 | 215 |
this.title.content = this.model.get("title"); |
| 28 | 216 |
this.title.position = this.paper_coords.add([0, 2 * Rkns.Renderer._NODE_RADIUS]); |
| 23 | 217 |
this.circle.strokeColor = this.model.get("created_by").get("color"); |
| 7 | 218 |
this.edit_button.moveTo(this.paper_coords); |
219 |
this.remove_button.moveTo(this.paper_coords); |
|
| 11 | 220 |
this.link_button.moveTo(this.paper_coords); |
| 1 | 221 |
} |
222 |
||
| 7 | 223 |
Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
| 23 | 224 |
var _coords = this.renderer.toModelCoords(this.paper_coords.add(_delta)), |
| 5 | 225 |
_data = { |
226 |
position: { |
|
227 |
x: _coords.x, |
|
228 |
y: _coords.y |
|
229 |
} |
|
230 |
}; |
|
| 23 | 231 |
this.model.set(_data); |
232 |
this.renderer.redraw(); |
|
| 2 | 233 |
} |
234 |
||
| 8 | 235 |
Rkns.Renderer.Node.prototype.openEditor = function() { |
| 23 | 236 |
this.renderer.removeRepresentationsOfType("editor"); |
237 |
var _editor = this.renderer.addRepresentation("NodeEditor",null); |
|
238 |
_editor.node_representation = this; |
|
| 8 | 239 |
_editor.redraw(); |
240 |
} |
|
241 |
||
| 7 | 242 |
Rkns.Renderer.Node.prototype.select = function() { |
243 |
this.circle.strokeWidth = 3; |
|
244 |
this.edit_button.show(); |
|
245 |
this.remove_button.show(); |
|
| 11 | 246 |
this.link_button.show(); |
| 26 | 247 |
var _uri = this.model.get("uri"); |
248 |
Rkns.$('.Rk-Bin-Item').each(function() { |
|
249 |
var _el = Rkns.$(this); |
|
250 |
if (_el.attr("data-uri") == _uri) { |
|
251 |
_el.addClass("selected"); |
|
252 |
} |
|
253 |
}); |
|
| 7 | 254 |
} |
255 |
||
256 |
Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
|
| 35 | 257 |
if (!_newTarget || _newTarget.node_representation !== this) { |
| 7 | 258 |
this.edit_button.hide(); |
259 |
this.remove_button.hide(); |
|
| 11 | 260 |
this.link_button.hide(); |
| 35 | 261 |
this.circle.strokeWidth = 1; |
262 |
Rkns.$('.Rk-Bin-Item').removeClass("selected"); |
|
| 7 | 263 |
} |
| 26 | 264 |
} |
265 |
||
266 |
Rkns.Renderer.Node.prototype.highlight = function() { |
|
267 |
this.circle.fillColor = "#ffffc0"; |
|
268 |
} |
|
269 |
||
270 |
Rkns.Renderer.Node.prototype.unhighlight = function(_newTarget) { |
|
271 |
this.circle.fillColor = "#ffffff"; |
|
| 4 | 272 |
} |
273 |
||
| 7 | 274 |
Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
| 23 | 275 |
if (!this.renderer.is_dragging) { |
| 8 | 276 |
this.openEditor(); |
| 7 | 277 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
278 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
279 |
this.renderer.is_dragging = false; |
| 7 | 280 |
} |
281 |
||
282 |
Rkns.Renderer.Node.prototype.destroy = function(_event) { |
|
283 |
this.edit_button.destroy(); |
|
284 |
this.remove_button.destroy(); |
|
| 26 | 285 |
this.link_button.destroy(); |
| 7 | 286 |
this.circle.remove(); |
287 |
this.title.remove(); |
|
| 4 | 288 |
} |
289 |
||
| 2 | 290 |
/* */ |
291 |
||
| 23 | 292 |
Rkns.Renderer.Edge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 2 | 293 |
|
| 7 | 294 |
Rkns.Renderer.Edge.prototype._init = function() { |
| 23 | 295 |
this.renderer.edge_layer.activate(); |
| 20 | 296 |
this.type = "Edge"; |
| 23 | 297 |
this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
298 |
this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
|
| 31 | 299 |
this.bundle = this.renderer.addToBundles(this); |
| 7 | 300 |
this.line = new paper.Path(); |
| 31 | 301 |
this.line.add([0,0],[0,0],[0,0]); |
| 23 | 302 |
this.line.__representation = this; |
| 7 | 303 |
this.arrow = new paper.Path(); |
| 28 | 304 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 305 |
this.arrow.__representation = this; |
| 7 | 306 |
this.text = new paper.PointText(); |
307 |
this.text.characterStyle = { |
|
| 28 | 308 |
fontSize: Rkns.Renderer._EDGE_FONT_SIZE, |
| 2 | 309 |
fillColor: 'black' |
310 |
}; |
|
| 7 | 311 |
this.text.paragraphStyle.justification = 'center'; |
| 23 | 312 |
this.text.__representation = this; |
| 7 | 313 |
this.text_angle = 0; |
314 |
this.arrow_angle = 0; |
|
| 23 | 315 |
this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, {}); |
316 |
this.edit_button.edge_representation = this; |
|
317 |
this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, {}); |
|
318 |
this.remove_button.edge_representation = this; |
|
| 2 | 319 |
} |
320 |
||
| 7 | 321 |
Rkns.Renderer.Edge.prototype.redraw = function() { |
| 31 | 322 |
var _p0a = this.from_representation.paper_coords, |
323 |
_p1a = this.to_representation.paper_coords, |
|
324 |
_v = _p1a.subtract(_p0a), |
|
| 15 | 325 |
_r = _v.length, |
| 18 | 326 |
_u = _v.divide(_r), |
| 31 | 327 |
_group_pos = this.bundle.getPosition(this), |
328 |
_delta = new paper.Point([- _u.y, _u.x]).multiply( 12 * _group_pos ), |
|
329 |
_p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
|
330 |
_p1b = _p1a.add(_delta), /* to differentiate inbound and outbound links */ |
|
| 15 | 331 |
_a = _v.angle, |
| 31 | 332 |
_handle = _v.divide(3), |
| 23 | 333 |
_color = this.model.get("created_by").get("color"); |
| 31 | 334 |
this.paper_coords = _p0b.add(_p1b).divide(2); |
| 7 | 335 |
this.line.strokeColor = _color; |
| 31 | 336 |
this.line.segments[0].point = _p0a; |
337 |
this.line.segments[1].point = this.paper_coords; |
|
338 |
this.line.segments[1].handleIn = _handle.multiply(-1); |
|
339 |
this.line.segments[1].handleOut = _handle; |
|
340 |
this.line.segments[2].point = _p1a; |
|
| 7 | 341 |
this.arrow.rotate(_a - this.arrow_angle); |
342 |
this.arrow.fillColor = _color; |
|
| 18 | 343 |
this.arrow.position = this.paper_coords.subtract(_u.multiply(4)); |
| 7 | 344 |
this.arrow_angle = _a; |
| 2 | 345 |
if (_a > 90) { |
346 |
_a -= 180; |
|
347 |
} |
|
348 |
if (_a < -90) { |
|
349 |
_a += 180; |
|
350 |
} |
|
| 7 | 351 |
this.text.rotate(_a - this.text_angle); |
| 23 | 352 |
this.text.content = this.model.get("title"); |
| 15 | 353 |
this.text.position = this.paper_coords; |
| 7 | 354 |
this.text_angle = _a; |
| 15 | 355 |
this.edit_button.moveTo(this.paper_coords); |
356 |
this.remove_button.moveTo(this.paper_coords); |
|
| 7 | 357 |
} |
358 |
||
| 18 | 359 |
Rkns.Renderer.Edge.prototype.openEditor = function() { |
| 23 | 360 |
this.renderer.removeRepresentationsOfType("editor"); |
361 |
var _editor = this.renderer.addRepresentation("EdgeEditor",null); |
|
362 |
_editor.edge_representation = this; |
|
| 18 | 363 |
_editor.redraw(); |
364 |
} |
|
365 |
||
| 7 | 366 |
Rkns.Renderer.Edge.prototype.select = function() { |
367 |
this.line.strokeWidth = 3; |
|
| 15 | 368 |
this.edit_button.show(); |
369 |
this.remove_button.show(); |
|
| 7 | 370 |
} |
371 |
||
372 |
Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { |
|
| 35 | 373 |
if (!_newTarget || _newTarget.edge_representation !== this) { |
| 15 | 374 |
this.edit_button.hide(); |
375 |
this.remove_button.hide(); |
|
| 35 | 376 |
this.line.strokeWidth = 1; |
| 15 | 377 |
} |
| 4 | 378 |
} |
379 |
||
| 7 | 380 |
Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
| 23 | 381 |
if (!this.renderer.is_dragging) { |
| 18 | 382 |
this.openEditor(); |
| 7 | 383 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
384 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
385 |
this.renderer.is_dragging = false; |
| 4 | 386 |
} |
387 |
||
| 7 | 388 |
Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
| 23 | 389 |
this.from_representation.paperShift(_delta); |
390 |
this.to_representation.paperShift(_delta); |
|
391 |
this.renderer.redraw(); |
|
| 2 | 392 |
} |
393 |
||
| 7 | 394 |
Rkns.Renderer.Edge.prototype.destroy = function() { |
395 |
this.line.remove(); |
|
396 |
this.arrow.remove(); |
|
397 |
this.text.remove(); |
|
| 15 | 398 |
this.edit_button.destroy(); |
399 |
this.remove_button.destroy(); |
|
| 31 | 400 |
var _this = this; |
401 |
this.bundle.edges = Rkns._(this.bundle.edges).reject(function(_edge) { |
|
402 |
return _edge === _this; |
|
403 |
}); |
|
| 2 | 404 |
} |
| 5 | 405 |
|
| 4 | 406 |
/* */ |
407 |
||
| 23 | 408 |
Rkns.Renderer.TempEdge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 4 | 409 |
|
| 7 | 410 |
Rkns.Renderer.TempEdge.prototype._init = function() { |
| 23 | 411 |
this.renderer.edge_layer.activate(); |
| 4 | 412 |
this.type = "temp-edge"; |
| 23 | 413 |
|
414 |
var _color = this.project.get("users").get(this.renderer.renkan.current_user).get("color"); |
|
| 7 | 415 |
this.line = new paper.Path(); |
416 |
this.line.strokeColor = _color; |
|
417 |
this.line.add([0,0],[0,0]); |
|
| 23 | 418 |
this.line.__representation = this; |
| 7 | 419 |
this.arrow = new paper.Path(); |
420 |
this.arrow.fillColor = _color; |
|
| 28 | 421 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 422 |
this.arrow.__representation = this; |
| 7 | 423 |
this.arrow_angle = 0; |
| 4 | 424 |
} |
425 |
||
| 7 | 426 |
Rkns.Renderer.TempEdge.prototype.redraw = function() { |
| 23 | 427 |
var _p0 = this.from_representation.paper_coords, |
| 4 | 428 |
_p1 = this.end_pos, |
429 |
_a = _p1.subtract(_p0).angle, |
|
430 |
_c = _p0.add(_p1).divide(2); |
|
| 7 | 431 |
this.line.segments[0].point = _p0; |
432 |
this.line.segments[1].point = _p1; |
|
433 |
this.arrow.rotate(_a - this.arrow_angle); |
|
434 |
this.arrow.position = _c; |
|
435 |
this.arrow_angle = _a; |
|
| 4 | 436 |
} |
437 |
||
| 7 | 438 |
Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) { |
| 4 | 439 |
this.end_pos = this.end_pos.add(_delta); |
| 21 | 440 |
var _hitResult = paper.project.hitTest(this.end_pos); |
| 23 | 441 |
this.renderer.findTarget(_hitResult); |
| 4 | 442 |
this.redraw(); |
443 |
} |
|
444 |
||
| 7 | 445 |
Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
446 |
var _hitResult = paper.project.hitTest(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
447 |
_model = this.from_representation.model, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
448 |
_endDrag = true; |
| 23 | 449 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
450 |
var _target = _hitResult.item.__representation; |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
451 |
if (_target.type === "Node" && _model !== _target.model) { |
| 23 | 452 |
var _data = { |
453 |
id: Rkns.Utils.getUID('edge'), |
|
454 |
created_by: this.renderer.renkan.current_user, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
455 |
from: _model.get("_id"), |
| 30 | 456 |
to: _target.model.get("_id") |
| 23 | 457 |
}; |
458 |
this.project.addEdge(_data); |
|
| 4 | 459 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
460 |
if (_model === _target.model || (_target.node_representation && _target.node_representation.model === _model)) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
461 |
_endDrag = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
462 |
this.renderer.is_dragging = true; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
463 |
} |
| 4 | 464 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
465 |
if (_endDrag) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
466 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
467 |
this.renderer.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
468 |
this.renderer.removeRepresentation(this); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
469 |
paper.view.draw(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
470 |
} |
| 5 | 471 |
} |
472 |
||
| 7 | 473 |
Rkns.Renderer.TempEdge.prototype.destroy = function() { |
474 |
this.arrow.remove(); |
|
475 |
this.line.remove(); |
|
| 5 | 476 |
} |
477 |
||
478 |
/* */ |
|
479 |
||
| 23 | 480 |
Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 481 |
|
| 7 | 482 |
Rkns.Renderer.NodeEditor.prototype._init = function() { |
| 23 | 483 |
this.renderer.overlay_layer.activate(); |
| 5 | 484 |
this.type = "editor"; |
485 |
this.editor_block = new paper.Path(); |
|
486 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
487 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
488 |
this.editor_block.strokeWidth = 2; |
|
489 |
this.editor_block.strokeColor = "#999999"; |
|
490 |
this.editor_block.fillColor = "#e0e0e0"; |
|
491 |
this.editor_block.opacity = .8; |
|
492 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 493 |
.appendTo(this.renderer.editor_$) |
| 5 | 494 |
.css({ |
495 |
position: "absolute", |
|
496 |
opacity: .8 |
|
497 |
}) |
|
498 |
.hide(); |
|
499 |
} |
|
500 |
||
| 7 | 501 |
Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
| 5 | 502 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_node%></span></h2>' |
503 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
|
| 26 | 504 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=node.uri%>"/><a class="Rk-Edit-Goto" href="<%=node.uri%>" target="_blank"></a></p>' |
| 5 | 505 |
+ '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
| 25 | 506 |
+ '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>' |
| 5 | 507 |
); |
508 |
||
| 7 | 509 |
Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
| 23 | 510 |
var _coords = this.node_representation.paper_coords, |
| 28 | 511 |
_model = this.node_representation.model; |
| 5 | 512 |
this.editor_$ |
513 |
.html(this.template({ |
|
| 23 | 514 |
node: { |
515 |
title: _model.get("title"), |
|
516 |
uri: _model.get("uri"), |
|
517 |
description: _model.get("description"), |
|
| 25 | 518 |
created_by_color: _model.get("created_by").get("color"), |
519 |
created_by_title: _model.get("created_by").get("title") |
|
| 23 | 520 |
}, |
521 |
l10n: this.renderer.renkan.l10n |
|
| 5 | 522 |
})) |
| 28 | 523 |
.show(); |
524 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 20, this.editor_$); |
|
| 5 | 525 |
var _this = this; |
526 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 527 |
_this.renderer.removeRepresentation(_this); |
| 5 | 528 |
paper.view.draw(); |
529 |
}); |
|
530 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
| 26 | 531 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val()); |
| 5 | 532 |
var _data = { |
533 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
534 |
description: _this.editor_$.find(".Rk-Edit-Description").val(), |
|
535 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
536 |
} |
|
| 23 | 537 |
_model.set(_data); |
| 5 | 538 |
paper.view.draw(); |
539 |
}); |
|
| 8 | 540 |
this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
| 23 | 541 |
paper.view.draw(); |
| 5 | 542 |
} |
543 |
||
| 7 | 544 |
Rkns.Renderer.NodeEditor.prototype.destroy = function() { |
| 5 | 545 |
this.editor_block.remove(); |
546 |
this.editor_$.detach(); |
|
547 |
} |
|
548 |
||
549 |
/* */ |
|
550 |
||
| 23 | 551 |
Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 552 |
|
| 7 | 553 |
Rkns.Renderer.EdgeEditor.prototype._init = function() { |
| 23 | 554 |
this.renderer.overlay_layer.activate(); |
| 5 | 555 |
this.type = "editor"; |
556 |
this.editor_block = new paper.Path(); |
|
557 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
558 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
559 |
this.editor_block.strokeWidth = 2; |
|
560 |
this.editor_block.strokeColor = "#999999"; |
|
561 |
this.editor_block.fillColor = "#e0e0e0"; |
|
562 |
this.editor_block.opacity = .8; |
|
563 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 564 |
.appendTo(this.renderer.editor_$) |
| 5 | 565 |
.css({ |
566 |
position: "absolute", |
|
567 |
opacity: .8 |
|
568 |
}) |
|
569 |
.hide(); |
|
570 |
} |
|
571 |
||
| 7 | 572 |
Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template( |
| 5 | 573 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_edge%></span></h2>' |
574 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>' |
|
| 26 | 575 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=edge.uri%>"/><a class="Rk-Edit-Goto" href="<%=edge.uri%>" target="_blank"></a></p>' |
| 25 | 576 |
+ '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from_created_by_color%>;"></span><%=edge.from_title%></p>' |
577 |
+ '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to_created_by_color%>;"></span><%=edge.to_title%></p>' |
|
578 |
+ '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>' |
|
| 5 | 579 |
); |
580 |
||
| 7 | 581 |
Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
| 23 | 582 |
var _coords = this.edge_representation.paper_coords, |
| 28 | 583 |
_model = this.edge_representation.model; |
| 5 | 584 |
this.editor_$ |
585 |
.html(this.template({ |
|
| 25 | 586 |
edge: { |
587 |
title: _model.get("title"), |
|
588 |
uri: _model.get("uri"), |
|
589 |
description: _model.get("description"), |
|
590 |
from_title: _model.get("from").get("title"), |
|
591 |
to_title: _model.get("to").get("title"), |
|
592 |
from_created_by_color: _model.get("from").get("created_by").get("color"), |
|
593 |
to_created_by_color: _model.get("to").get("created_by").get("color"), |
|
594 |
created_by_color: _model.get("created_by").get("color"), |
|
595 |
created_by_title: _model.get("created_by").get("title") |
|
596 |
}, |
|
| 23 | 597 |
l10n: this.renderer.renkan.l10n |
| 5 | 598 |
})) |
| 28 | 599 |
.show(); |
600 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 5, this.editor_$); |
|
| 5 | 601 |
var _this = this; |
602 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 603 |
_this.renderer.removeRepresentation(_this); |
| 5 | 604 |
paper.view.draw(); |
605 |
}); |
|
606 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
| 28 | 607 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val()); |
| 5 | 608 |
var _data = { |
609 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
610 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
611 |
} |
|
| 23 | 612 |
_model.set(_data); |
| 5 | 613 |
paper.view.draw(); |
614 |
}); |
|
| 23 | 615 |
paper.view.draw(); |
| 5 | 616 |
} |
617 |
||
| 7 | 618 |
Rkns.Renderer.EdgeEditor.prototype.destroy = function() { |
| 5 | 619 |
this.editor_block.remove(); |
620 |
this.editor_$.detach(); |
|
| 4 | 621 |
} |
| 2 | 622 |
|
623 |
/* */ |
|
| 1 | 624 |
|
| 23 | 625 |
Rkns.Renderer.NodeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 626 |
|
627 |
Rkns.Renderer.NodeEditButton.prototype._init = function() { |
|
| 35 | 628 |
this.renderer.overlay_layer.activate(); |
| 20 | 629 |
this.type = "Node-edit-button"; |
| 35 | 630 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._NODE_BUTTON_INNER, Rkns.Renderer._NODE_BUTTON_OUTER, - 90, 30, 1, 'img/edit.png'); |
| 7 | 631 |
} |
632 |
||
633 |
Rkns.Renderer.NodeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 634 |
this.sector.moveTo(_pos); |
| 7 | 635 |
} |
636 |
||
637 |
Rkns.Renderer.NodeEditButton.prototype.show = function() { |
|
| 18 | 638 |
this.sector.show(); |
| 7 | 639 |
} |
640 |
||
641 |
Rkns.Renderer.NodeEditButton.prototype.hide = function() { |
|
| 18 | 642 |
this.sector.hide(); |
| 7 | 643 |
} |
644 |
||
645 |
Rkns.Renderer.NodeEditButton.prototype.select = function() { |
|
| 18 | 646 |
this.sector.select(); |
| 7 | 647 |
} |
648 |
||
| 35 | 649 |
Rkns.Renderer.NodeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 650 |
this.sector.unselect(); |
| 35 | 651 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
652 |
this.node_representation.unselect(); |
|
653 |
} |
|
| 7 | 654 |
} |
655 |
||
656 |
Rkns.Renderer.NodeEditButton.prototype.mouseup = function() { |
|
| 23 | 657 |
if (!this.renderer.is_dragging) { |
658 |
this.node_representation.openEditor(); |
|
| 7 | 659 |
} |
660 |
} |
|
661 |
||
662 |
Rkns.Renderer.NodeEditButton.prototype.destroy = function() { |
|
| 18 | 663 |
this.sector.destroy(); |
| 7 | 664 |
} |
665 |
||
666 |
/* */ |
|
667 |
||
| 23 | 668 |
Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 669 |
|
670 |
Rkns.Renderer.NodeRemoveButton.prototype._init = function() { |
|
| 35 | 671 |
this.renderer.overlay_layer.activate(); |
| 20 | 672 |
this.type = "Node-remove-button"; |
| 35 | 673 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._NODE_BUTTON_INNER, Rkns.Renderer._NODE_BUTTON_OUTER, -210, -90, 1, 'img/remove.png'); |
| 7 | 674 |
} |
675 |
||
676 |
Rkns.Renderer.NodeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 677 |
this.sector.moveTo(_pos); |
| 7 | 678 |
} |
679 |
||
680 |
Rkns.Renderer.NodeRemoveButton.prototype.show = function() { |
|
| 18 | 681 |
this.sector.show(); |
| 7 | 682 |
} |
683 |
||
684 |
Rkns.Renderer.NodeRemoveButton.prototype.hide = function() { |
|
| 18 | 685 |
this.sector.hide(); |
| 7 | 686 |
} |
687 |
||
688 |
Rkns.Renderer.NodeRemoveButton.prototype.select = function() { |
|
| 18 | 689 |
this.sector.select(); |
| 7 | 690 |
} |
691 |
||
| 35 | 692 |
Rkns.Renderer.NodeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 693 |
this.sector.unselect(); |
| 35 | 694 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
695 |
this.node_representation.unselect(); |
|
696 |
} |
|
| 7 | 697 |
} |
698 |
||
699 |
Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
700 |
this.renderer.removeRepresentationsOfType("editor"); |
| 23 | 701 |
if (confirm('Do you really wish to remove node "' + this.node_representation.model.get("title") + '"?')) { |
702 |
this.project.removeNode(this.node_representation.model); |
|
| 10 | 703 |
} |
| 7 | 704 |
} |
705 |
||
706 |
Rkns.Renderer.NodeRemoveButton.prototype.destroy = function() { |
|
| 18 | 707 |
this.sector.destroy(); |
| 7 | 708 |
} |
709 |
||
710 |
/* */ |
|
711 |
||
| 23 | 712 |
Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 11 | 713 |
|
714 |
Rkns.Renderer.NodeLinkButton.prototype._init = function() { |
|
| 35 | 715 |
this.renderer.overlay_layer.activate(); |
| 20 | 716 |
this.type = "Node-link-button"; |
| 35 | 717 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._NODE_BUTTON_INNER, Rkns.Renderer._NODE_BUTTON_OUTER, 30, 150, 1, 'img/link.png'); |
| 11 | 718 |
} |
719 |
||
720 |
Rkns.Renderer.NodeLinkButton.prototype.moveTo = function(_pos) { |
|
| 18 | 721 |
this.sector.moveTo(_pos); |
| 11 | 722 |
} |
723 |
||
724 |
Rkns.Renderer.NodeLinkButton.prototype.show = function() { |
|
| 18 | 725 |
this.sector.show(); |
| 11 | 726 |
} |
727 |
||
728 |
Rkns.Renderer.NodeLinkButton.prototype.hide = function() { |
|
| 18 | 729 |
this.sector.hide(); |
| 11 | 730 |
} |
731 |
||
732 |
Rkns.Renderer.NodeLinkButton.prototype.select = function() { |
|
| 18 | 733 |
this.sector.select(); |
| 11 | 734 |
} |
735 |
||
| 35 | 736 |
Rkns.Renderer.NodeLinkButton.prototype.unselect = function(_newTarget) { |
| 18 | 737 |
this.sector.unselect(); |
| 35 | 738 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
739 |
this.node_representation.unselect(); |
|
740 |
} |
|
| 11 | 741 |
} |
742 |
||
743 |
Rkns.Renderer.NodeLinkButton.prototype.destroy = function() { |
|
| 18 | 744 |
this.sector.destroy(); |
| 11 | 745 |
} |
746 |
||
747 |
/* */ |
|
748 |
||
| 23 | 749 |
Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 750 |
|
751 |
Rkns.Renderer.EdgeEditButton.prototype._init = function() { |
|
| 35 | 752 |
this.renderer.overlay_layer.activate(); |
| 20 | 753 |
this.type = "Edge-edit-button"; |
| 35 | 754 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 90, 90, 1, 'img/edit.png'); |
| 15 | 755 |
} |
756 |
||
757 |
Rkns.Renderer.EdgeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 758 |
this.sector.moveTo(_pos); |
| 15 | 759 |
} |
760 |
||
761 |
Rkns.Renderer.EdgeEditButton.prototype.show = function() { |
|
| 18 | 762 |
this.sector.show(); |
| 15 | 763 |
} |
764 |
||
765 |
Rkns.Renderer.EdgeEditButton.prototype.hide = function() { |
|
| 18 | 766 |
this.sector.hide(); |
| 15 | 767 |
} |
768 |
||
769 |
Rkns.Renderer.EdgeEditButton.prototype.select = function() { |
|
| 18 | 770 |
this.sector.select(); |
| 15 | 771 |
} |
772 |
||
| 35 | 773 |
Rkns.Renderer.EdgeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 774 |
this.sector.unselect(); |
| 35 | 775 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
776 |
this.edge_representation.unselect(); |
|
777 |
} |
|
| 15 | 778 |
} |
779 |
||
780 |
Rkns.Renderer.EdgeEditButton.prototype.mouseup = function() { |
|
| 23 | 781 |
if (!this.renderer.is_dragging) { |
782 |
this.edge_representation.openEditor(); |
|
| 15 | 783 |
} |
784 |
} |
|
785 |
||
786 |
Rkns.Renderer.EdgeEditButton.prototype.destroy = function() { |
|
| 18 | 787 |
this.sector.destroy(); |
| 15 | 788 |
} |
789 |
||
790 |
/* */ |
|
791 |
||
| 23 | 792 |
Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 793 |
|
794 |
Rkns.Renderer.EdgeRemoveButton.prototype._init = function() { |
|
| 35 | 795 |
this.renderer.overlay_layer.activate(); |
| 20 | 796 |
this.type = "Edge-remove-button"; |
| 35 | 797 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 270, -90, 1, 'img/remove.png'); |
| 15 | 798 |
} |
799 |
Rkns.Renderer.EdgeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 800 |
this.sector.moveTo(_pos); |
| 15 | 801 |
} |
802 |
||
803 |
Rkns.Renderer.EdgeRemoveButton.prototype.show = function() { |
|
| 18 | 804 |
this.sector.show(); |
| 15 | 805 |
} |
806 |
||
807 |
Rkns.Renderer.EdgeRemoveButton.prototype.hide = function() { |
|
| 18 | 808 |
this.sector.hide(); |
| 15 | 809 |
} |
810 |
||
811 |
Rkns.Renderer.EdgeRemoveButton.prototype.select = function() { |
|
| 18 | 812 |
this.sector.select(); |
| 15 | 813 |
} |
814 |
||
| 35 | 815 |
Rkns.Renderer.EdgeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 816 |
this.sector.unselect(); |
| 35 | 817 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
818 |
this.edge_representation.unselect(); |
|
819 |
} |
|
| 15 | 820 |
} |
821 |
||
822 |
Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
823 |
this.renderer.removeRepresentationsOfType("editor"); |
| 23 | 824 |
if (confirm('Do you really wish to remove edge "' + this.edge_representation.model.get("title") + '"?')) { |
825 |
this.project.removeEdge(this.edge_representation.model); |
|
| 15 | 826 |
} |
827 |
} |
|
828 |
||
829 |
Rkns.Renderer.EdgeRemoveButton.prototype.destroy = function() { |
|
| 18 | 830 |
this.sector.destroy(); |
| 15 | 831 |
} |
832 |
||
833 |
/* */ |
|
834 |
||
| 23 | 835 |
Rkns.Renderer.Scene = function(_renkan) { |
836 |
this.renkan = _renkan; |
|
| 20 | 837 |
this.$ = Rkns.$(".Rk-Render"); |
| 23 | 838 |
this.representations = []; |
| 20 | 839 |
this.$.html(this.template({ |
| 23 | 840 |
l10n: _renkan.l10n |
| 20 | 841 |
})) |
842 |
this.canvas_$ = this.$.find(".Rk-Canvas"); |
|
843 |
this.editor_$ = this.$.find(".Rk-Editor"); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
844 |
this.notif_$ = this.$.find(".Rk-Notifications"); |
| 20 | 845 |
paper.setup(this.canvas_$[0]); |
| 2 | 846 |
this.scale = 1; |
847 |
this.offset = paper.view.center; |
|
848 |
this.totalScroll = 0; |
|
| 5 | 849 |
this.click_target = null; |
| 4 | 850 |
this.selected_target = null; |
| 2 | 851 |
this.edge_layer = new paper.Layer(); |
852 |
this.node_layer = new paper.Layer(); |
|
| 5 | 853 |
this.overlay_layer = new paper.Layer(); |
| 31 | 854 |
this.bundles = []; |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
855 |
this.click_mode = false; |
| 2 | 856 |
var _tool = new paper.Tool(), |
857 |
_this = this; |
|
| 28 | 858 |
_tool.minDistance = Rkns.Renderer._MIN_DRAG_DISTANCE; |
| 4 | 859 |
_tool.onMouseMove = function(_event) { |
860 |
_this.onMouseMove(_event); |
|
861 |
} |
|
| 2 | 862 |
_tool.onMouseDown = function(_event) { |
863 |
_this.onMouseDown(_event); |
|
864 |
} |
|
865 |
_tool.onMouseDrag = function(_event) { |
|
866 |
_this.onMouseDrag(_event); |
|
867 |
} |
|
| 21 | 868 |
this.canvas_$.mouseup(function(_event) { |
| 4 | 869 |
_this.onMouseUp(_event); |
| 21 | 870 |
}); |
| 20 | 871 |
this.canvas_$.mousewheel(function(_event, _delta) { |
| 2 | 872 |
_this.onScroll(_event, _delta); |
| 21 | 873 |
}); |
| 20 | 874 |
this.canvas_$.dblclick(function(_event) { |
| 4 | 875 |
_this.onDoubleClick(_event); |
| 11 | 876 |
}); |
| 21 | 877 |
this.canvas_$.mouseenter(function(_event) { |
878 |
_this.onMouseEnter(_event); |
|
879 |
}); |
|
| 11 | 880 |
this.editor_$.find(".Rk-ZoomOut").click(function() { |
881 |
_this.offset = new paper.Point([ |
|
| 20 | 882 |
_this.canvas_$.width(), |
883 |
_this.canvas_$.height() |
|
| 11 | 884 |
]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(_this.offset.multiply( Math.SQRT1_2 )); |
| 28 | 885 |
_this.setScale( _this.scale * Math.SQRT1_2 ); |
| 11 | 886 |
_this.redraw(); |
887 |
}); |
|
888 |
this.editor_$.find(".Rk-ZoomIn").click(function() { |
|
889 |
_this.offset = new paper.Point([ |
|
| 20 | 890 |
_this.canvas_$.width(), |
891 |
_this.canvas_$.height() |
|
| 11 | 892 |
]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(_this.offset.multiply( Math.SQRT2 )); |
| 28 | 893 |
_this.setScale( _this.scale * Math.SQRT2 ); |
| 11 | 894 |
_this.redraw(); |
895 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
896 |
this.$.find(".Rk-CurrentUser").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
897 |
function() { _this.$.find(".Rk-UserList").slideDown() } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
898 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
899 |
this.$.find(".Rk-Users").mouseleave( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
900 |
function() { _this.$.find(".Rk-UserList").slideUp(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
901 |
); |
| 34 | 902 |
this.$.find(".Rk-FullScreen-Button").click(function() { |
903 |
var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen, |
|
904 |
_el = _this.renkan.$[0], |
|
905 |
_requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"], |
|
906 |
_cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"]; |
|
907 |
if (_isFull) { |
|
908 |
for (var i = 0; i < _cancelMethods.length; i++) { |
|
909 |
if (typeof document[_cancelMethods[i]] === "function") { |
|
910 |
document[_cancelMethods[i]](); |
|
911 |
break; |
|
912 |
} |
|
913 |
} |
|
914 |
} else { |
|
915 |
for (var i = 0; i < _requestMethods.length; i++) { |
|
916 |
if (typeof _el[_requestMethods[i]] === "function") { |
|
917 |
_el[_requestMethods[i]](); |
|
918 |
break; |
|
919 |
} |
|
920 |
} |
|
921 |
} |
|
922 |
}); |
|
923 |
this.$.find(".Rk-AddNode-Button").click(function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
924 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
925 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
926 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
927 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
928 |
_this.click_mode = Rkns.Renderer._CLICKMODE_ADDNODE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
929 |
_this.notif_$.html(_renkan.l10n.notif_add_node).fadeIn(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
930 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
931 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
932 |
this.$.find(".Rk-AddEdge-Button").click(function() { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
933 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE || _this.click_mode === Rkns.Renderer._CLICKMODE_ENDEDGE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
934 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
935 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
936 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
937 |
_this.click_mode = Rkns.Renderer._CLICKMODE_STARTEDGE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
938 |
_this.notif_$.html(_renkan.l10n.notif_start_edge).fadeIn(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
939 |
} |
| 34 | 940 |
}); |
941 |
this.$.find(".Rk-TopBar-Button").mouseover(function() { |
|
942 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").show(); |
|
943 |
}).mouseout(function() { |
|
944 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").hide(); |
|
945 |
}); |
|
946 |
|
|
| 2 | 947 |
paper.view.onResize = function(_event) { |
948 |
_this.offset = _this.offset.add(_event.delta.divide(2)); |
|
949 |
_this.redraw(); |
|
950 |
} |
|
| 23 | 951 |
|
952 |
var _thRedraw = Rkns._.throttle(function() { |
|
953 |
_this.redraw(); |
|
954 |
},50); |
|
955 |
|
|
956 |
this.addRepresentations("Node", this.renkan.project.get("nodes")); |
|
957 |
this.addRepresentations("Edge", this.renkan.project.get("edges")); |
|
| 34 | 958 |
this.renkan.project.get("users").each(function(_user) { |
959 |
_this.addUser(_user); |
|
960 |
}) |
|
| 23 | 961 |
|
| 34 | 962 |
this.renkan.project.on("add:users", function(_user) { |
963 |
_this.addUser(_user); |
|
964 |
}); |
|
| 23 | 965 |
this.renkan.project.on("add:nodes", function(_node) { |
966 |
_this.addRepresentation("Node", _node); |
|
967 |
_thRedraw(); |
|
968 |
}); |
|
969 |
this.renkan.project.on("add:edges", function(_edge) { |
|
970 |
_this.addRepresentation("Edge", _edge); |
|
971 |
_thRedraw(); |
|
972 |
}); |
|
973 |
|
|
974 |
this.redraw(); |
|
| 2 | 975 |
} |
976 |
||
| 20 | 977 |
Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
978 |
'<div class="Rk-TopBar"><h3 class="Rk-PadTitle"><%=l10n.untitled_project%></h3>' |
| 34 | 979 |
+ '<div class="Rk-Users"><div class="Rk-CurrentUser"><span class="Rk-CurrentUser-Color"></span><span class="Rk-CurrentUser-Name"><unknown user></span></div><ul class="Rk-UserList"></ul></div>' |
980 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-FullScreen-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.full_screen%></div></div></div>' |
|
981 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddNode-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.add_node%></div></div></div>' |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
982 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddEdge-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.add_edge%></div></div></div>' |
| 34 | 983 |
+ '<div class="Rk-TopBar-Separator"></div></div>' |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
984 |
+ '<canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>' |
| 20 | 985 |
+ '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>' |
986 |
+ '</div>' |
|
| 11 | 987 |
); |
988 |
||
| 31 | 989 |
Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) { |
990 |
var _bundle = Rkns._(this.bundles).find(function(_bundle) { |
|
991 |
return ( |
|
992 |
( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) |
|
993 |
|| ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
|
994 |
); |
|
995 |
}); |
|
996 |
if (typeof _bundle !== "undefined") { |
|
997 |
_bundle.edges.push(_edgeRepr) |
|
998 |
} else { |
|
999 |
_bundle = { |
|
1000 |
from: _edgeRepr.from_representation, |
|
1001 |
to: _edgeRepr.to_representation, |
|
1002 |
edges: [ _edgeRepr ], |
|
1003 |
getPosition: function(_er) { |
|
1004 |
var _dir = (_er.from_representation === this.from) ? 1 : -1; |
|
1005 |
return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
|
1006 |
} |
|
1007 |
} |
|
1008 |
this.bundles.push(_bundle); |
|
1009 |
} |
|
1010 |
return _bundle; |
|
1011 |
} |
|
1012 |
||
| 28 | 1013 |
Rkns.Renderer.Scene.prototype.setScale = function(_newScale) { |
1014 |
this.scale = _newScale; |
|
1015 |
this.redraw(); |
|
1016 |
} |
|
1017 |
||
| 25 | 1018 |
Rkns.Renderer.Scene.prototype.autoScale = function() { |
| 26 | 1019 |
if (this.renkan.project.get("nodes").length) { |
1020 |
var _xx = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").x }), |
|
1021 |
_yy = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").y }), |
|
1022 |
_minx = Math.min.apply(Math, _xx), |
|
1023 |
_miny = Math.min.apply(Math, _yy), |
|
1024 |
_maxx = Math.max.apply(Math, _xx), |
|
1025 |
_maxy = Math.max.apply(Math, _yy); |
|
| 28 | 1026 |
var _scale = Math.min((paper.view.size.width - 2 * Rkns.Renderer._MARGIN_X) / (_maxx - _minx), (paper.view.size.height - 2 * Rkns.Renderer._MARGIN_Y) / (_maxy - _miny)); |
1027 |
this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
|
1028 |
this.setScale(_scale); |
|
| 26 | 1029 |
} |
| 25 | 1030 |
} |
1031 |
||
| 7 | 1032 |
Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
| 2 | 1033 |
return _point.multiply(this.scale).add(this.offset); |
1034 |
} |
|
1035 |
||
1036 |
||
| 7 | 1037 |
Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
| 2 | 1038 |
return _point.subtract(this.offset).divide(this.scale); |
| 1 | 1039 |
} |
1040 |
||
| 23 | 1041 |
Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) { |
1042 |
var _repr = new Rkns.Renderer[_type](this, _model); |
|
1043 |
this.representations.push(_repr); |
|
1044 |
if (_model) { |
|
1045 |
var _this = this; |
|
1046 |
_model.on("change", function() { |
|
1047 |
_repr.redraw(); |
|
1048 |
}); |
|
1049 |
_model.on("remove", function() { |
|
1050 |
_this.removeRepresentation(_repr); |
|
1051 |
_this.redraw(); |
|
1052 |
}); |
|
1053 |
} |
|
1054 |
return _repr; |
|
1055 |
} |
|
1056 |
||
1057 |
Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) { |
|
1058 |
var _this = this; |
|
1059 |
_collection.forEach(function(_model) { |
|
1060 |
_this.addRepresentation(_type, _model); |
|
| 1 | 1061 |
}); |
1062 |
} |
|
1063 |
||
| 34 | 1064 |
Rkns.Renderer.Scene.prototype.userTemplate = Rkns._.template( |
1065 |
'<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>' |
|
1066 |
); |
|
1067 |
||
1068 |
Rkns.Renderer.Scene.prototype.addUser = function(_user) { |
|
1069 |
if (_user.get("_id") === this.renkan.current_user) { |
|
1070 |
this.$.find(".Rk-CurrentUser-Name").text(_user.get("title")); |
|
1071 |
this.$.find(".Rk-CurrentUser-Color").css("background", _user.get("color")); |
|
1072 |
} else { |
|
1073 |
this.$.find(".Rk-UserList").append( |
|
1074 |
Rkns.$( |
|
1075 |
this.userTemplate({ |
|
1076 |
name: _user.get("title"), |
|
1077 |
background: _user.get("color") |
|
1078 |
}) |
|
1079 |
) |
|
1080 |
); |
|
1081 |
} |
|
1082 |
} |
|
1083 |
||
| 23 | 1084 |
Rkns.Renderer.Scene.prototype.removeRepresentation = function(_representation) { |
1085 |
_representation.destroy(); |
|
1086 |
this.representations = Rkns._(this.representations).reject( |
|
1087 |
function(_repr) { |
|
1088 |
return _repr == _representation |
|
1089 |
} |
|
1090 |
); |
|
| 4 | 1091 |
} |
1092 |
||
| 23 | 1093 |
Rkns.Renderer.Scene.prototype.getRepresentationByModel = function(_model) { |
1094 |
return Rkns._(this.representations).find(function(_repr) { |
|
1095 |
return _repr.model === _model; |
|
1096 |
}); |
|
| 5 | 1097 |
} |
1098 |
||
| 23 | 1099 |
Rkns.Renderer.Scene.prototype.removeRepresentationsOfType = function(_type) { |
1100 |
var _representations = Rkns._(this.representations).filter(function(_repr) { |
|
1101 |
return _repr.type == _type; |
|
| 5 | 1102 |
}), |
1103 |
_this = this; |
|
| 23 | 1104 |
Rkns._(_representations).each(function(_repr) { |
1105 |
_this.removeRepresentation(_repr); |
|
| 5 | 1106 |
}); |
1107 |
} |
|
1108 |
||
| 26 | 1109 |
Rkns.Renderer.Scene.prototype.highlightModel = function(_model) { |
1110 |
var _repr = this.getRepresentationByModel(_model); |
|
1111 |
if (_repr) { |
|
1112 |
_repr.highlight(); |
|
1113 |
} |
|
1114 |
} |
|
1115 |
||
1116 |
Rkns.Renderer.Scene.prototype.unhighlightAll = function(_model) { |
|
1117 |
Rkns._(this.representations).each(function(_repr) { |
|
1118 |
_repr.unhighlight(); |
|
1119 |
}); |
|
1120 |
} |
|
1121 |
||
| 7 | 1122 |
Rkns.Renderer.Scene.prototype.redraw = function() { |
| 23 | 1123 |
Rkns._(this.representations).each(function(_representation) { |
1124 |
_representation.redraw(); |
|
| 2 | 1125 |
}); |
1126 |
paper.view.draw(); |
|
1127 |
} |
|
1128 |
||
| 11 | 1129 |
Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
| 23 | 1130 |
var _tmpEdge = this.addRepresentation("TempEdge",null); |
| 11 | 1131 |
_tmpEdge.end_pos = _point; |
| 23 | 1132 |
_tmpEdge.from_representation = _from; |
| 11 | 1133 |
_tmpEdge.redraw(); |
1134 |
this.click_target = _tmpEdge; |
|
1135 |
} |
|
1136 |
||
| 21 | 1137 |
Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) { |
| 23 | 1138 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
1139 |
var _newTarget = _hitResult.item.__representation; |
|
1140 |
if (this.selected_target !== _hitResult.item.__representation) { |
|
| 4 | 1141 |
if (this.selected_target) { |
| 7 | 1142 |
this.selected_target.unselect(_newTarget); |
| 4 | 1143 |
} |
| 7 | 1144 |
_newTarget.select(this.selected_target); |
1145 |
this.selected_target = _newTarget; |
|
| 4 | 1146 |
} |
1147 |
} else { |
|
1148 |
if (this.selected_target) { |
|
| 7 | 1149 |
this.selected_target.unselect(null); |
| 4 | 1150 |
} |
1151 |
this.selected_target = null; |
|
1152 |
} |
|
1153 |
} |
|
1154 |
||
| 21 | 1155 |
Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
1156 |
var _hitResult = paper.project.hitTest(_event.point); |
|
1157 |
if (this.is_dragging) { |
|
1158 |
if (this.click_target && typeof this.click_target.paperShift === "function") { |
|
1159 |
this.click_target.paperShift(_event.delta); |
|
1160 |
} else { |
|
1161 |
this.offset = this.offset.add(_event.delta); |
|
1162 |
this.redraw(); |
|
1163 |
} |
|
1164 |
} else { |
|
1165 |
this.findTarget(_hitResult); |
|
1166 |
} |
|
1167 |
} |
|
1168 |
||
| 7 | 1169 |
Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1170 |
if (!this.click_target || this.click_target.type !== "temp-edge") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1171 |
this.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1172 |
var _hitResult = paper.project.hitTest(_event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1173 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1174 |
this.click_target = _hitResult.item.__representation; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1175 |
if (this.click_target.type === "Node-link-button") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1176 |
this.removeRepresentationsOfType("editor"); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1177 |
this.addTempEdge(this.click_target.node_representation, _event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1178 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1179 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1180 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1181 |
if (this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1182 |
var _coords = this.toModelCoords(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1183 |
_data = { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1184 |
id: Rkns.Utils.getUID('node'), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1185 |
created_by: this.renkan.current_user, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1186 |
position: { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1187 |
x: _coords.x, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1188 |
y: _coords.y |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1189 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1190 |
}; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1191 |
_node = this.renkan.project.addNode(_data); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1192 |
this.getRepresentationByModel(_node).openEditor(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1193 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1194 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1195 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1196 |
if (this.click_mode) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1197 |
if (this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1198 |
this.removeRepresentationsOfType("editor"); |
| 11 | 1199 |
this.addTempEdge(this.click_target, _event.point); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1200 |
this.click_mode = Rkns.Renderer._CLICKMODE_ENDEDGE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1201 |
this.notif_$.fadeOut(function() { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1202 |
Rkns.$(this).html(_renkan.l10n.notif_end_edge).fadeIn(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1203 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1204 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1205 |
this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1206 |
this.click_mode = false; |
| 11 | 1207 |
} |
| 2 | 1208 |
} |
| 1 | 1209 |
} |
| 2 | 1210 |
|
| 7 | 1211 |
Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) { |
| 5 | 1212 |
this.is_dragging = true; |
| 21 | 1213 |
this.onMouseMove(_event); |
| 2 | 1214 |
} |
1215 |
||
| 7 | 1216 |
Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) { |
| 5 | 1217 |
if (this.click_target) { |
| 21 | 1218 |
var _off = this.canvas_$.offset(); |
1219 |
this.click_target.mouseup( |
|
1220 |
{ |
|
1221 |
point: new paper.Point([ |
|
1222 |
_event.pageX - _off.left, |
|
1223 |
_event.pageY - _off.top |
|
1224 |
]) |
|
1225 |
} |
|
1226 |
); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1227 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1228 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1229 |
this.is_dragging = false; |
| 4 | 1230 |
} |
1231 |
} |
|
1232 |
||
| 7 | 1233 |
Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) { |
| 3 | 1234 |
this.totalScroll += _scrolldelta; |
| 2 | 1235 |
if (Math.abs(this.totalScroll) >= 1) { |
| 20 | 1236 |
var _off = this.canvas_$.offset(), |
| 3 | 1237 |
_delta = new paper.Point([ |
1238 |
_event.pageX - _off.left, |
|
1239 |
_event.pageY - _off.top |
|
1240 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
|
| 2 | 1241 |
if (this.totalScroll > 0) { |
| 3 | 1242 |
this.offset = this.offset.subtract(_delta); |
| 28 | 1243 |
this.setScale( this.scale * Math.SQRT2 ); |
| 2 | 1244 |
} else { |
| 3 | 1245 |
this.offset = this.offset.add(_delta.divide( Math.SQRT2 )); |
| 28 | 1246 |
this.setScale( this.scale * Math.SQRT1_2); |
| 2 | 1247 |
} |
1248 |
this.totalScroll = 0; |
|
1249 |
this.redraw(); |
|
1250 |
} |
|
1251 |
} |
|
| 4 | 1252 |
|
| 7 | 1253 |
Rkns.Renderer.Scene.prototype.onDoubleClick = function(_event) { |
| 20 | 1254 |
var _off = this.canvas_$.offset(), |
| 4 | 1255 |
_point = new paper.Point([ |
1256 |
_event.pageX - _off.left, |
|
1257 |
_event.pageY - _off.top |
|
1258 |
]); |
|
1259 |
var _hitResult = paper.project.hitTest(_point); |
|
| 23 | 1260 |
if (!_hitResult || typeof _hitResult.item.__representation === "undefined") { |
| 8 | 1261 |
var _coords = this.toModelCoords(_point), |
| 23 | 1262 |
_data = { |
1263 |
id: Rkns.Utils.getUID('node'), |
|
1264 |
created_by: this.renkan.current_user, |
|
| 8 | 1265 |
position: { |
1266 |
x: _coords.x, |
|
1267 |
y: _coords.y |
|
1268 |
} |
|
| 23 | 1269 |
}; |
1270 |
_node = this.renkan.project.addNode(_data); |
|
1271 |
this.getRepresentationByModel(_node).openEditor(); |
|
| 4 | 1272 |
} |
1273 |
paper.view.draw(); |
|
1274 |
} |
|
| 21 | 1275 |
|
1276 |
Rkns.Renderer.Scene.prototype.onMouseEnter = function(_event) { |
|
1277 |
var _newEl = this.renkan.selected_bin_item; |
|
1278 |
if (_newEl) { |
|
1279 |
var _off = this.canvas_$.offset(), |
|
1280 |
_point = new paper.Point([ |
|
1281 |
_event.pageX - _off.left, |
|
1282 |
_event.pageY - _off.top |
|
1283 |
]), |
|
1284 |
_coords = this.toModelCoords(_point), |
|
| 23 | 1285 |
_data = { |
1286 |
id: Rkns.Utils.getUID('node'), |
|
1287 |
created_by: this.renkan.current_user, |
|
| 21 | 1288 |
uri: _newEl.uri, |
1289 |
title: _newEl.title, |
|
1290 |
description: _newEl.description, |
|
1291 |
position: { |
|
1292 |
x: _coords.x, |
|
1293 |
y: _coords.y |
|
1294 |
} |
|
| 23 | 1295 |
}; |
1296 |
var _node = this.renkan.project.addNode(_data); |
|
1297 |
this.renkan.selected_bin_item = null; |
|
| 21 | 1298 |
this.is_dragging = true; |
| 23 | 1299 |
this.click_target = this.getRepresentationByModel(_node); |
| 21 | 1300 |
} |
1301 |
} |