Skip to content

Commit a3b35c0

Browse files
committed
Fix middle click drag, and ruler jitter
1 parent cde191a commit a3b35c0

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/timeline/js/directives/ruler.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ App.directive("tlScrollableTracks", function () {
8080
if (is_scrolling) {
8181
// Calculate difference from last position
8282
var difference = {x: starting_mouse_position.x - e.pageX, y: starting_mouse_position.y - e.pageY};
83+
var newPos = { x: starting_scrollbar.x + difference.x, y: starting_scrollbar.y + difference.y};
8384

8485
// Scroll the tracks div
85-
element.scrollLeft(starting_scrollbar.x + difference.x);
86-
element.scrollTop(starting_scrollbar.y + difference.y);
86+
element.scrollLeft(newPos.x);
87+
element.scrollTop(newPos.y);
8788
}
8889
});
8990

@@ -119,7 +120,7 @@ App.directive("tlBody", function () {
119120
if (e.which === 2) { // middle button
120121
e.preventDefault();
121122
is_scrolling = true;
122-
starting_scrollbar = {x: element.scrollLeft(), y: element.scrollTop()};
123+
starting_scrollbar = {x: $('#scrolling_tracks').scrollLeft(), y: $('#scrolling_tracks').scrollTop()};
123124
starting_mouse_position = {x: e.pageX, y: e.pageY};
124125
element.addClass("drag_cursor");
125126
}
@@ -198,24 +199,30 @@ App.directive("tlRuler", function ($timeout) {
198199

199200
startPos = scope.scrollLeft;
200201
endPos = scope.scrollLeft + $("body").width();
201-
202+
fpt = framesPerTick(scope.pixelsPerSecond, scope.project.fps.num ,scope.project.fps.den);
202203
fps = scope.project.fps.num / scope.project.fps.den;
203204
time = [ startPos / scope.pixelsPerSecond, endPos / scope.pixelsPerSecond];
204-
time[0] -= time[0]%2;
205+
206+
if (fpt > fps) {
207+
// Make sure seconds don't change when scrolling right and left
208+
time[0] -= time[0]%(fpt/Math.round(fps));
209+
}
210+
else {
211+
time[0] -= time[0]%2;
212+
}
205213
time[1] -= time[1]%1 - 1;
206214

207215
startFrame = time[0] * Math.round(fps);
208216
endFrame = time[1] * Math.round(fps);
209217

210-
fpt = framesPerTick(scope.pixelsPerSecond, scope.project.fps.num ,scope.project.fps.den);
211218
frame = startFrame;
212219
while ( frame <= endFrame){
213220
t = frame / fps;
214221
pos = t * scope.pixelsPerSecond;
215222
tickSpan = $('<span style="left:'+pos+'px;"></span>');
216223
tickSpan.addClass("tick_mark");
217224

218-
if ((frame - startFrame) % (fpt * 2) == 0) {
225+
if ((frame) % (fpt * 2) == 0) {
219226
// Alternating long marks with times marked
220227
timeSpan = $('<span style="left:'+pos+'px;"></span>');
221228
timeSpan.addClass("ruler_time");

0 commit comments

Comments
 (0)