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