Skip to content

Commit 67b415a

Browse files
committed
Adding snapping logic to ruler dragging (similar to playhead movement). Also fixing a few Codacy issues.
1 parent 1babaea commit 67b415a

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

src/timeline/js/directives/playhead.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,26 @@ App.directive("tlPlayhead", function () {
3939

4040
element.on("mousedown", function (e) {
4141
// Set bounding box for the playhead
42-
bounding_box = {};
4342
setBoundingBox(scope, $(this), true);
4443
});
4544

4645
// Move playhead to new position (if it's not currently being animated)
4746
element.on("mousemove", function (e) {
4847
if (e.which === 1 && !scope.playhead_animating) { // left button
4948
// Calculate the playhead bounding box movement and apply snapping rules
50-
var cursor_position = e.pageX - $("#ruler").offset().left;
51-
var results = moveBoundingBox(scope, bounding_box.left, bounding_box.top,
49+
let cursor_position = e.pageX - $("#ruler").offset().left;
50+
let results = moveBoundingBox(scope, bounding_box.left, bounding_box.top,
5251
cursor_position - bounding_box.left, cursor_position - bounding_box.top,
5352
cursor_position, cursor_position, true);
5453

5554
// Only apply snapping when SHIFT is pressed
55+
let new_position = cursor_position;
5656
if (e.shiftKey) {
5757
new_position = results.position.left;
58-
} else {
59-
new_position = cursor_position;
6058
}
6159

6260
// Move playhead
63-
var playhead_seconds = new_position / scope.pixelsPerSecond;
61+
let playhead_seconds = new_position / scope.pixelsPerSecond;
6462
scope.movePlayhead(playhead_seconds);
6563
scope.previewFrame(playhead_seconds);
6664
}

src/timeline/js/directives/ruler.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ App.directive("tlBody", function () {
111111
}
112112
});
113113

114-
115114
}
116115
};
117116
});
@@ -146,11 +145,28 @@ App.directive("tlRuler", function ($timeout) {
146145

147146
});
148147

148+
element.on("mousedown", function (e) {
149+
// Set bounding box for the playhead position
150+
setBoundingBox(scope, $(this), true);
151+
});
152+
149153
// Move playhead to new position (if it's not currently being animated)
150154
element.on("mousemove", function (e) {
151155
if (e.which === 1 && !scope.playhead_animating) { // left button
152-
var playhead_seconds = (e.pageX - element.offset().left) / scope.pixelsPerSecond;
153-
// Update playhead
156+
// Calculate the playhead bounding box movement and apply snapping rules
157+
let cursor_position = e.pageX - $("#ruler").offset().left;
158+
let results = moveBoundingBox(scope, bounding_box.left, bounding_box.top,
159+
cursor_position - bounding_box.left, cursor_position - bounding_box.top,
160+
cursor_position, cursor_position, true);
161+
162+
// Only apply snapping when SHIFT is pressed
163+
let new_position = cursor_position;
164+
if (e.shiftKey) {
165+
new_position = results.position.left;
166+
}
167+
168+
// Move playhead
169+
let playhead_seconds = new_position / scope.pixelsPerSecond;
154170
scope.movePlayhead(playhead_seconds);
155171
scope.previewFrame(playhead_seconds);
156172
}

src/timeline/media/css/main.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ img {
6363
.track { height: 62px; background-color: #000; margin-bottom: 8px; background: -webkit-gradient(linear, left bottom, left top, color-stop(0%,rgba(50,50,50,1)), color-stop(100%,rgba(6,6,6,1))); border-top: 1px solid #4b92ad; border-bottom: 1px solid #4b92ad; border-right: 1px solid #4B92AD; border-top-right-radius: 8px; border-bottom-right-radius: 8px; box-shadow: 0px 0px 10px #000; }
6464

6565
/* Playhead */
66-
.playhead-line { z-index: 9999; position: absolute; height:316px; top:0px; width:1px; background-color:#ff0024; opacity:1;}
66+
.playhead-line { z-index: 9999; position: absolute; height: 316px; top: 0; width: 1px; background-color: #ff0024; opacity: 1; }
6767
.playhead-line-small { z-index: 9999; position: absolute; height:20px; top:32px;; margin-left: 12px; width:1px; background-color:#ff0024; opacity:1;}
6868
.playhead-top { cursor:move; z-index: 9999; position: absolute; margin-left: -12px; margin-top: 12px; width:25px; height:32px; background-image: url(../images/play_head.png); opacity:1;}
6969
.marker {position:absolute; top:30px;}

0 commit comments

Comments
 (0)