147 }; |
147 }; |
148 this.edit_button = new Rkns.Renderer.NodeEditButton(this._renderer, {}); |
148 this.edit_button = new Rkns.Renderer.NodeEditButton(this._renderer, {}); |
149 this.edit_button.node_controller = this; |
149 this.edit_button.node_controller = this; |
150 this.remove_button = new Rkns.Renderer.NodeRemoveButton(this._renderer, {}); |
150 this.remove_button = new Rkns.Renderer.NodeRemoveButton(this._renderer, {}); |
151 this.remove_button.node_controller = this; |
151 this.remove_button.node_controller = this; |
|
152 this.link_button = new Rkns.Renderer.NodeLinkButton(this._renderer, {}); |
|
153 this.link_button.node_controller = this; |
152 this.title.paragraphStyle.justification = 'center'; |
154 this.title.paragraphStyle.justification = 'center'; |
153 this.title.__controller = this; |
155 this.title.__controller = this; |
154 } |
156 } |
155 |
157 |
156 Rkns.Renderer.Node.prototype.redraw = function() { |
158 Rkns.Renderer.Node.prototype.redraw = function() { |
160 this.title.content = this._element.title; |
162 this.title.content = this._element.title; |
161 this.title.position = this.paper_coords.add([0, 2 * Rkns._NODE_RADIUS]); |
163 this.title.position = this.paper_coords.add([0, 2 * Rkns._NODE_RADIUS]); |
162 this.circle.strokeColor = this._element.created_by.color; |
164 this.circle.strokeColor = this._element.created_by.color; |
163 this.edit_button.moveTo(this.paper_coords); |
165 this.edit_button.moveTo(this.paper_coords); |
164 this.remove_button.moveTo(this.paper_coords); |
166 this.remove_button.moveTo(this.paper_coords); |
|
167 this.link_button.moveTo(this.paper_coords); |
165 } |
168 } |
166 |
169 |
167 Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
170 Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
168 var _coords = this._renderer.toModelCoords(this.paper_coords.add(_delta)), |
171 var _coords = this._renderer.toModelCoords(this.paper_coords.add(_delta)), |
169 _data = { |
172 _data = { |
185 |
188 |
186 Rkns.Renderer.Node.prototype.select = function() { |
189 Rkns.Renderer.Node.prototype.select = function() { |
187 this.circle.strokeWidth = 3; |
190 this.circle.strokeWidth = 3; |
188 this.edit_button.show(); |
191 this.edit_button.show(); |
189 this.remove_button.show(); |
192 this.remove_button.show(); |
|
193 this.link_button.show(); |
190 } |
194 } |
191 |
195 |
192 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
196 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
193 if (!_newTarget || (_newTarget !== this.edit_button && _newTarget !== this.remove_button)) { |
197 if (!_newTarget || (_newTarget !== this.edit_button && _newTarget !== this.remove_button && _newTarget !== this.link_button)) { |
194 this.edit_button.hide(); |
198 this.edit_button.hide(); |
195 this.remove_button.hide(); |
199 this.remove_button.hide(); |
|
200 this.link_button.hide(); |
196 } |
201 } |
197 this.circle.strokeWidth = 1; |
202 this.circle.strokeWidth = 1; |
198 } |
203 } |
199 |
204 |
200 Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
205 Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
359 this.editor_block.strokeWidth = 2; |
364 this.editor_block.strokeWidth = 2; |
360 this.editor_block.strokeColor = "#999999"; |
365 this.editor_block.strokeColor = "#999999"; |
361 this.editor_block.fillColor = "#e0e0e0"; |
366 this.editor_block.fillColor = "#e0e0e0"; |
362 this.editor_block.opacity = .8; |
367 this.editor_block.opacity = .8; |
363 this.editor_$ = Rkns.$('<div>') |
368 this.editor_$ = Rkns.$('<div>') |
364 .appendTo('.Rk-Editor') |
369 .appendTo(this._renderer.editor_$) |
365 .css({ |
370 .css({ |
366 position: "absolute", |
371 position: "absolute", |
367 opacity: .8 |
372 opacity: .8 |
368 }) |
373 }) |
369 .hide(); |
374 .hide(); |
428 this.editor_block.strokeWidth = 2; |
433 this.editor_block.strokeWidth = 2; |
429 this.editor_block.strokeColor = "#999999"; |
434 this.editor_block.strokeColor = "#999999"; |
430 this.editor_block.fillColor = "#e0e0e0"; |
435 this.editor_block.fillColor = "#e0e0e0"; |
431 this.editor_block.opacity = .8; |
436 this.editor_block.opacity = .8; |
432 this.editor_$ = Rkns.$('<div>') |
437 this.editor_$ = Rkns.$('<div>') |
433 .appendTo('.Rk-Editor') |
438 .appendTo(this._renderer.editor_$) |
434 .css({ |
439 .css({ |
435 position: "absolute", |
440 position: "absolute", |
436 opacity: .8 |
441 opacity: .8 |
437 }) |
442 }) |
438 .hide(); |
443 .hide(); |
515 |
520 |
516 Rkns.Renderer.NodeEditButton.prototype.unselect = function() { |
521 Rkns.Renderer.NodeEditButton.prototype.unselect = function() { |
517 this.sector.group.opacity = .5; |
522 this.sector.group.opacity = .5; |
518 this.hide(); |
523 this.hide(); |
519 this.node_controller.remove_button.hide(); |
524 this.node_controller.remove_button.hide(); |
|
525 this.node_controller.link_button.hide(); |
520 } |
526 } |
521 |
527 |
522 Rkns.Renderer.NodeEditButton.prototype.mouseup = function() { |
528 Rkns.Renderer.NodeEditButton.prototype.mouseup = function() { |
523 if (!this._renderer.is_dragging) { |
529 if (!this._renderer.is_dragging) { |
524 this.node_controller.openEditor(); |
530 this.node_controller.openEditor(); |
561 |
567 |
562 Rkns.Renderer.NodeRemoveButton.prototype.unselect = function() { |
568 Rkns.Renderer.NodeRemoveButton.prototype.unselect = function() { |
563 this.sector.group.opacity = .5; |
569 this.sector.group.opacity = .5; |
564 this.hide(); |
570 this.hide(); |
565 this.node_controller.edit_button.hide(); |
571 this.node_controller.edit_button.hide(); |
|
572 this.node_controller.link_button.hide(); |
566 } |
573 } |
567 |
574 |
568 Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() { |
575 Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() { |
569 if (confirm('Do you really wish to remove node "' + this.node_controller._element.title + '"?')) { |
576 if (confirm('Do you really wish to remove node "' + this.node_controller._element.title + '"?')) { |
570 this._renderer._project.removeNode(this.node_controller._element, Rkns._RENDER_AND_SAVE); |
577 this._renderer._project.removeNode(this.node_controller._element, Rkns._RENDER_AND_SAVE); |
571 } |
578 } |
572 } |
579 } |
573 |
580 |
574 Rkns.Renderer.NodeRemoveButton.prototype.destroy = function() { |
581 Rkns.Renderer.NodeRemoveButton.prototype.destroy = function() { |
|
582 this.sector.group.remove(); |
|
583 } |
|
584 |
|
585 /* */ |
|
586 |
|
587 Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._BaseController); |
|
588 |
|
589 Rkns.Renderer.NodeLinkButton.prototype._init = function() { |
|
590 this._renderer.node_layer.activate(); |
|
591 this.type = "node-link-button"; |
|
592 this.sector = Rkns.Renderer.Utils.sector(1 + Rkns._NODE_RADIUS, 3 * Rkns._NODE_RADIUS, 30, 150, 2, 'img/link.png'); |
|
593 this.sector.group.visible = false; |
|
594 this.sector.group.opacity = .5; |
|
595 this.sector.circle.__controller = this; |
|
596 this.sector.delta = this.sector.group.position; |
|
597 } |
|
598 |
|
599 Rkns.Renderer.NodeLinkButton.prototype.moveTo = function(_pos) { |
|
600 this.sector.group.position = this.sector.delta.add(_pos); |
|
601 } |
|
602 |
|
603 Rkns.Renderer.NodeLinkButton.prototype.show = function() { |
|
604 this.sector.group.visible = true; |
|
605 } |
|
606 |
|
607 Rkns.Renderer.NodeLinkButton.prototype.hide = function() { |
|
608 this.sector.group.visible = false; |
|
609 } |
|
610 |
|
611 Rkns.Renderer.NodeLinkButton.prototype.select = function() { |
|
612 this.sector.group.opacity = .8; |
|
613 } |
|
614 |
|
615 Rkns.Renderer.NodeLinkButton.prototype.unselect = function() { |
|
616 this.sector.group.opacity = .5; |
|
617 this.hide(); |
|
618 this.node_controller.edit_button.hide(); |
|
619 this.node_controller.remove_button.hide(); |
|
620 } |
|
621 |
|
622 Rkns.Renderer.NodeLinkButton.prototype.destroy = function() { |
575 this.sector.group.remove(); |
623 this.sector.group.remove(); |
576 } |
624 } |
577 |
625 |
578 /* */ |
626 /* */ |
579 |
627 |
580 Rkns.Renderer.Scene = function(_project) { |
628 Rkns.Renderer.Scene = function(_project) { |
581 this._project = _project; |
629 this._project = _project; |
582 this._MARGIN_X = 80; |
630 this._MARGIN_X = 80; |
583 this._MARGIN_Y = 50; |
631 this._MARGIN_Y = 50; |
584 var _canvas_id = this._project._opts.canvas_id; |
632 var _canvas_id = this._project._opts.canvas_id; |
585 this.$ = Rkns.$("#"+_canvas_id) |
633 this.$ = Rkns.$("#"+_canvas_id); |
|
634 this.editor_$ = Rkns.$(".Rk-Editor"); |
|
635 this.editor_$.html(this.editorTemplate({ |
|
636 l10n: this._project.l10n |
|
637 })); |
586 paper.setup(document.getElementById(_canvas_id)); |
638 paper.setup(document.getElementById(_canvas_id)); |
587 this.scale = 1; |
639 this.scale = 1; |
588 this.offset = paper.view.center; |
640 this.offset = paper.view.center; |
589 this.totalScroll = 0; |
641 this.totalScroll = 0; |
590 this.click_target = null; |
642 this.click_target = null; |
610 this.$.mousewheel(function(_event, _delta) { |
662 this.$.mousewheel(function(_event, _delta) { |
611 _this.onScroll(_event, _delta); |
663 _this.onScroll(_event, _delta); |
612 }) |
664 }) |
613 this.$.dblclick(function(_event) { |
665 this.$.dblclick(function(_event) { |
614 _this.onDoubleClick(_event); |
666 _this.onDoubleClick(_event); |
615 }) |
667 }); |
|
668 this.editor_$.find(".Rk-ZoomOut").click(function() { |
|
669 _this.offset = new paper.Point([ |
|
670 _this.$.width(), |
|
671 _this.$.height() |
|
672 ]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(_this.offset.multiply( Math.SQRT1_2 )); |
|
673 _this.scale *= Math.SQRT1_2; |
|
674 _this.redraw(); |
|
675 }); |
|
676 this.editor_$.find(".Rk-ZoomIn").click(function() { |
|
677 _this.offset = new paper.Point([ |
|
678 _this.$.width(), |
|
679 _this.$.height() |
|
680 ]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(_this.offset.multiply( Math.SQRT2 )); |
|
681 _this.scale *= Math.SQRT2; |
|
682 _this.redraw(); |
|
683 }); |
616 paper.view.onResize = function(_event) { |
684 paper.view.onResize = function(_event) { |
617 _this.offset = _this.offset.add(_event.delta.divide(2)); |
685 _this.offset = _this.offset.add(_event.delta.divide(2)); |
618 _this.redraw(); |
686 _this.redraw(); |
619 } |
687 } |
620 } |
688 } |
|
689 |
|
690 Rkns.Renderer.Scene.prototype.editorTemplate = Rkns._.template( |
|
691 '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>' |
|
692 ); |
621 |
693 |
622 Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
694 Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
623 return _point.multiply(this.scale).add(this.offset); |
695 return _point.multiply(this.scale).add(this.offset); |
624 } |
696 } |
625 |
697 |
675 _controller.redraw(); |
747 _controller.redraw(); |
676 }); |
748 }); |
677 paper.view.draw(); |
749 paper.view.draw(); |
678 } |
750 } |
679 |
751 |
|
752 Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
|
753 var _tmpEdge = this.addController("TempEdge",{}); |
|
754 _tmpEdge.end_pos = _point; |
|
755 _tmpEdge.from_controller = _from; |
|
756 _tmpEdge.redraw(); |
|
757 this.click_target = _tmpEdge; |
|
758 } |
|
759 |
680 Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
760 Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
681 var _hitResult = paper.project.hitTest(_event.point); |
761 var _hitResult = paper.project.hitTest(_event.point); |
682 if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
762 if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
683 var _newTarget = _hitResult.item.__controller; |
763 var _newTarget = _hitResult.item.__controller; |
684 if (this.selected_target !== _hitResult.item.__controller) { |
764 if (this.selected_target !== _hitResult.item.__controller) { |
700 this.is_dragging = false; |
780 this.is_dragging = false; |
701 var _hitResult = paper.project.hitTest(_event.point); |
781 var _hitResult = paper.project.hitTest(_event.point); |
702 if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
782 if (_hitResult && typeof _hitResult.item.__controller !== "undefined") { |
703 this.click_target = _hitResult.item.__controller; |
783 this.click_target = _hitResult.item.__controller; |
704 if (this.click_target.type === "node" && _hitResult.type === "stroke") { |
784 if (this.click_target.type === "node" && _hitResult.type === "stroke") { |
705 var _tmpEdge = this.addController("TempEdge",{}); |
785 this.addTempEdge(this.click_target, _event.point); |
706 _tmpEdge.end_pos = _event.point; |
786 } |
707 _tmpEdge.from_controller = this.click_target; |
787 if (this.click_target.type === "node-link-button") { |
708 _tmpEdge.redraw(); |
788 this.addTempEdge(this.click_target.node_controller, _event.point); |
709 this.click_target = _tmpEdge; |
|
710 } |
789 } |
711 } else { |
790 } else { |
712 this.click_target = null; |
791 this.click_target = null; |
713 } |
792 } |
714 } |
793 } |