aboutsummaryrefslogtreecommitdiff
path: root/js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js
diff options
context:
space:
mode:
authorJon Reid2012-06-18 16:12:49 -0700
committerJon Reid2012-06-18 16:12:49 -0700
commit730389f72b1f2949e74b4ce8f8625bfd8bc4fa39 (patch)
tree5613be2e03a88cf76d80602b4210801a107fa895 /js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js
parentb51c9448bc187f9bfa3ab39c366657ec2bb9e2fb (diff)
downloadninja-730389f72b1f2949e74b4ce8f8625bfd8bc4fa39.tar.gz
Timeline: Bug Fixes
- Splitting tweens now works again for shift-click interaction - Fixed visual "jump" in keyframes and spans when splitting tweens - Set default easing to "none" to match CSS standard.
Diffstat (limited to 'js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js')
-rw-r--r--js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js101
1 files changed, 95 insertions, 6 deletions
diff --git a/js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js b/js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js
index 3db57a3a..74dd1ca1 100644
--- a/js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js
+++ b/js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js
@@ -687,7 +687,7 @@ var TimelineTrack = exports.TimelineTrack = Montage.create(Component, {
687 if (ev.target.className === "tracklane") { 687 if (ev.target.className === "tracklane") {
688 this.handleNewTween(ev); 688 this.handleNewTween(ev);
689 this.updateKeyframeRule(); 689 this.updateKeyframeRule();
690 } else if (ev.target.className === "tween_span" && ev.target.parentElement.parentElement.className === "tracklane") { 690 } else if (ev.target.className === "tween_span_bar" && ev.target.parentElement.parentElement.parentElement.className === "tracklane") {
691 this.handleNewTween(ev); 691 this.handleNewTween(ev);
692 this.updateKeyframeRule(); 692 this.updateKeyframeRule();
693 } 693 }
@@ -703,6 +703,8 @@ var TimelineTrack = exports.TimelineTrack = Montage.create(Component, {
703 this.addAnimationRuleToElement(ev); 703 this.addAnimationRuleToElement(ev);
704 this.updateKeyframeRule(); 704 this.updateKeyframeRule();
705 } else { 705 } else {
706
707
706 this.handleNewTween(ev); 708 this.handleNewTween(ev);
707 this.updateKeyframeRule(); 709 this.updateKeyframeRule();
708 } 710 }
@@ -716,7 +718,24 @@ var TimelineTrack = exports.TimelineTrack = Montage.create(Component, {
716 this.application.ninja.timeline.selectLayer(selectedIndex, false); 718 this.application.ninja.timeline.selectLayer(selectedIndex, false);
717 this.insertTween(ev.offsetX); 719 this.insertTween(ev.offsetX);
718 } else { 720 } else {
719 this.splitTween(ev); 721 // We will be splitting a tween. Get the x-coordinate of the mouse click within the target element.
722 // You'd think you could use the event.x info for that, right? NO. We must use page values, calculating offsets and scrolling.
723
724 // Here's an easy function that adds up offsets and scrolls and returns the page x value of an element
725 var findXOffset = function(obj) {
726 var curleft = 0;
727 if (obj.offsetParent) {
728 do {
729 curleft += (obj.offsetLeft-obj.scrollLeft);
730
731 } while (obj = obj.offsetParent);
732 }
733 return curleft;
734 }
735 var targetElementOffset = findXOffset(ev.currentTarget),
736 position = event.pageX - targetElementOffset;
737
738 this.splitTweenAt(position-18);
720 } 739 }
721 } 740 }
722 }, 741 },
@@ -771,10 +790,12 @@ var TimelineTrack = exports.TimelineTrack = Montage.create(Component, {
771 790
772 splitTween:{ 791 splitTween:{
773 value:function (ev) { 792 value:function (ev) {
774 var clickPos = ev.target.parentElement.offsetLeft + ev.offsetX; 793 var clickPos = ev.target.parentElement.offsetLeft + ev.offsetX,
775 var i; 794 i,
776 var tweensLength = this.tweens.length-1; 795 tweensLength = this.tweens.length-1,
777 var prevTween, nextTween, splitTweenIndex; 796 prevTween, nextTween, splitTweenIndex;
797
798 consol.log(ev.target.className)
778 for(i=0; i<tweensLength; i++){ 799 for(i=0; i<tweensLength; i++){
779 prevTween = this.tweens[i].tweenData.keyFramePosition; 800 prevTween = this.tweens[i].tweenData.keyFramePosition;
780 nextTween = this.tweens[i+1].tweenData.keyFramePosition; 801 nextTween = this.tweens[i+1].tweenData.keyFramePosition;
@@ -810,6 +831,71 @@ var TimelineTrack = exports.TimelineTrack = Montage.create(Component, {
810 } 831 }
811 }, 832 },
812 833
834 // splitTweenAt: Split a tween at a particular position (x coordinate)
835 splitTweenAt: {
836 value:function (position) {
837 var i, j, nextComponentIndex,
838 tweensLength = this.tweens.length-1,
839 prevTween,
840 nextTween,
841 splitTweenIndex;
842
843 // Search through the tweens and find the pair whose keyframes bracket position.
844 for(i=0; i<tweensLength; i++){
845 prevTween = this.tweens[i].tweenData.keyFramePosition;
846 nextTween = this.tweens[i+1].tweenData.keyFramePosition;
847 if(position > prevTween && position < nextTween) {
848
849 // We will insert a new tween at this index
850 splitTweenIndex = i+1;
851
852 // Update the next tween to have new span position and width.
853 this.tweens[i+1].tweenData.spanPosition = position;
854 this.tweens[i+1].spanPosition = position;
855 this.tweens[i+1].tweenData.spanWidth = this.tweens[i+1].tweenData.keyFramePosition - position;
856 this.tweens[i+1].spanWidth = this.tweens[i+1].keyFramePosition - position;
857
858 // You'd think that would be enough to make the component associated with that part of the array redraw, wouldn't you?
859 // Turns out we have to manually poke the desired childComponent in the repetition to register its new changes.
860 // So we have to get the index of the actual componentin the repetition, which may not match our iteration index.
861 for (j = 0; j < tweensLength +1; j++) {
862 if (this.tweenRepetition.childComponents[j].keyFramePosition === nextTween) {
863 nextComponentIndex = j;
864 }
865 }
866 this.tweenRepetition.childComponents[nextComponentIndex].setData();
867
868 // Create the new tween and splice it into the model
869 var newTweenToInsert = {};
870 newTweenToInsert.tweenData = {};
871 newTweenToInsert.tweenData.spanWidth = position - prevTween;
872 newTweenToInsert.tweenData.keyFramePosition = position;
873 newTweenToInsert.tweenData.keyFrameMillisec = Math.floor(this.application.ninja.timeline.millisecondsOffset / 80) * position;
874 newTweenToInsert.tweenData.tweenID = this.tweens.length;
875 newTweenToInsert.tweenData.spanPosition = position - newTweenToInsert.tweenData.spanWidth;
876 newTweenToInsert.tweenData.tweenedProperties = [];
877 newTweenToInsert.tweenData.tweenedProperties["top"] = this.animatedElement.offsetTop + "px";
878 newTweenToInsert.tweenData.tweenedProperties["left"] = this.animatedElement.offsetLeft + "px";
879 newTweenToInsert.tweenData.tweenedProperties["width"] = this.animatedElement.offsetWidth + "px";
880 newTweenToInsert.tweenData.tweenedProperties["height"] = this.animatedElement.offsetHeight + "px";
881 this.tweens.splice(splitTweenIndex, 0, newTweenToInsert);
882
883 // We are done, so end the loop.
884 i = tweensLength;
885 }
886 }
887
888 // We've made a change, so set the needsSave flag
889 this.application.ninja.currentDocument.model.needsSave = true;
890
891 // Our tween IDs are now all messed up. Fix them.
892 for (i = 0; i <= tweensLength+1; i++) {
893 this.tweens[i].tweenID = i;
894 this.tweens[i].tweenData.tweenID = i;
895 }
896 }
897 },
898
813 retrieveStoredTweens:{ 899 retrieveStoredTweens:{
814 value:function () { 900 value:function () {
815 var percentValue, fraction, splitValue,offsetAttribute,topOffSetAttribute,leftOffsetAttribute,widthOffsetAttribute,heightOffsetAttribute; 901 var percentValue, fraction, splitValue,offsetAttribute,topOffSetAttribute,leftOffsetAttribute,widthOffsetAttribute,heightOffsetAttribute;
@@ -885,6 +971,9 @@ var TimelineTrack = exports.TimelineTrack = Montage.create(Component, {
885 newTween.tweenData.tweenID = this.nextKeyframe; 971 newTween.tweenData.tweenID = this.nextKeyframe;
886 newTween.tweenData.spanPosition =clickPosition - newTween.tweenData.spanWidth; 972 newTween.tweenData.spanPosition =clickPosition - newTween.tweenData.spanWidth;
887 newTween.tweenData.easing = this.currentKeyframeRule[i].style.webkitAnimationName; 973 newTween.tweenData.easing = this.currentKeyframeRule[i].style.webkitAnimationName;
974 if (newTween.tweenData.easing == "") {
975 newTween.tweenData.easing = "none";
976 }
888 this.tweens.push(newTween); 977 this.tweens.push(newTween);
889 } 978 }
890 this.nextKeyframe += 1; 979 this.nextKeyframe += 1;