Skip to content

Commit 6e4f089

Browse files
JacksonJacksonRG
authored andcommitted
Coppied changes from playhead-bug branch
1 parent d755af2 commit 6e4f089

File tree

4 files changed

+207
-57
lines changed

4 files changed

+207
-57
lines changed

src/timeline/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@
5151
<div class="playhead-line-small"></div>
5252
</div>
5353
<!-- Ruler extends beyond tracks area at least for a width of vertical scroll bar (or more, like 50px here) -->
54-
<canvas tl-ruler id="ruler" width="{{canvasMaxWidth(getTimelineWidth(0) + 6)}}px" height="39"></canvas>
54+
<div tl-ruler id="ruler" style="width: {{project.duration * pixelsPerSecond}}px;">
55+
</div>
5556

5657
<!-- MARKERS -->
58+
5759
<span class="ruler_marker" id="marker_for_{{marker.id}}">
5860
<img ng-repeat="marker in project.markers" id="marker_{{marker.id}}_{{$index}}" ng-right-click="showMarkerMenu(marker.id)" style="position: absolute; bottom: 0px; left: {{(marker.position * pixelsPerSecond) - 6 }}px;" class="marker_icon" ng-src="media/images/markers/{{ marker.icon }}" draggable="false"/>
5961
</span>

src/timeline/js/directives/ruler.js

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ var scroll_left_pixels = 0;
4242
App.directive("tlScrollableTracks", function () {
4343
return {
4444
restrict: "A",
45-
4645
link: function (scope, element, attrs) {
4746

4847
// Sync ruler to track scrolling
@@ -61,14 +60,18 @@ App.directive("tlScrollableTracks", function () {
6160
// Send scrollbar position to Qt
6261
if (scope.Qt) {
6362
// Calculate scrollbar positions (left and right edge of scrollbar)
64-
var timeline_length = Math.min(32767, scope.getTimelineWidth(0));
63+
var timeline_length = scope.getTimelineWidth(0);
6564
var left_scrollbar_edge = scroll_left_pixels / timeline_length;
6665
var right_scrollbar_edge = (scroll_left_pixels + element.width()) / timeline_length;
6766

6867
// Send normalized scrollbar positions to Qt
6968
timeline.ScrollbarChanged([left_scrollbar_edge, right_scrollbar_edge, timeline_length, element.width()]);
7069
}
7170

71+
scope.$apply( () => {
72+
scope.scrollLeft = element[0].scrollLeft;
73+
})
74+
7275
});
7376

7477
// Initialize panning when middle mouse is clicked
@@ -99,7 +102,6 @@ App.directive("tlScrollableTracks", function () {
99102
element.removeClass("drag_cursor");
100103
});
101104

102-
103105
}
104106
};
105107
});
@@ -115,7 +117,6 @@ App.directive("tlBody", function () {
115117
}
116118
});
117119

118-
119120
}
120121
};
121122
});
@@ -147,7 +148,6 @@ App.directive("tlRuler", function ($timeout) {
147148
scope.playhead_animating = false;
148149
});
149150
});
150-
151151
});
152152

153153
// Move playhead to new position (if it's not currently being animated)
@@ -160,60 +160,63 @@ App.directive("tlRuler", function ($timeout) {
160160
}
161161
});
162162

163+
drawTicks = () => {
164+
/* Remove all divs in ruler and readraw along the full length
165+
* Only needed when timeline length changes.
166+
*/
167+
168+
ruler = $("#ruler");
169+
$('#ruler div').remove();
170+
width = ruler.width();
171+
for (var x = 0; x < width; x+=50) {
172+
d = $('<div>');
173+
d.addClass('on_ruler');
174+
d.addClass( (x % 100 == 0) ? 'ruler_tick_long' : 'ruler_tick');
175+
d[0].style = "left: " + x + 'px;';
176+
console.log(d[0]);
177+
ruler.append(d);
178+
}
179+
}
180+
181+
drawTimes = () => {
182+
console.log(scope.scrollLeft);
183+
ruler = $("#ruler");
184+
width = $("body").width();
185+
$("#ruler span").remove();
186+
start = Math.max(scope.scrollLeft - width, 0);
187+
end = Math.min(scope.scrollLeft + (2*width), $('#ruler').width());
188+
for (var i = start - (start % 50) ; i < end; i += 100) {
189+
s = $('<span>');
190+
s.addClass("tick_time");
191+
s[0].innerText= "00:00";
192+
s[0].style = "left: " + i + "px;";
193+
ruler.append(s);
194+
}
195+
}
196+
163197
//watch the scale value so it will be able to draw the ruler after changes,
164198
//otherwise the canvas is just reset to blank
165-
scope.$watch("project.scale + markers.length + project.duration", function (val) {
199+
scope.$watch("project.scale + project.duration", function(val) {
166200
if (val) {
167-
168201
$timeout(function () {
169-
//get all scope variables we need for the ruler
170-
var scale = scope.project.scale;
171-
var tick_pixels = scope.project.tick_pixels;
172-
var each_tick = tick_pixels / 2;
173-
// Don't go over the max supported canvas size
174-
var pixel_length = Math.min(32767,scope.getTimelineWidth(1024));
175-
176-
//draw the ruler
177-
var ctx = element[0].getContext("2d");
178-
//clear the canvas first
179-
ctx.clearRect(0, 0, element.width(), element.height());
180-
//set number of ticks based 2 for each pixel_length
181-
var num_ticks = pixel_length / 50;
182-
183-
ctx.lineWidth = 1;
184-
ctx.strokeStyle = "#c8c8c8";
185-
ctx.lineCap = "round";
186-
187-
//loop em and draw em
188-
for (var x = 0; x < num_ticks + 1; x++) {
189-
ctx.beginPath();
190-
191-
//if it's even, make the line longer
192-
var line_top = 0;
193-
if (x % 2 === 0) {
194-
line_top = 18;
195-
//if it's not the first line, set the time text
196-
if (x !== 0) {
197-
//get time for this tick
198-
var time = (scale * x) / 2;
199-
var time_text = secondsToTime(time, scope.project.fps.num, scope.project.fps.den);
200-
201-
//write time on the canvas, centered above long tick
202-
ctx.fillStyle = "#c8c8c8";
203-
ctx.font = "0.9em";
204-
ctx.fillText(time_text["hour"] + ":" + time_text["min"] + ":" + time_text["sec"], x * each_tick - 22, 11);
205-
}
206-
} else {
207-
//shorter line
208-
line_top = 28;
209-
}
210-
211-
ctx.moveTo(x * each_tick, 39);
212-
ctx.lineTo(x * each_tick, line_top);
213-
ctx.stroke();
202+
$('#ruler').scrollLeft = $('#scrolling_tracks').scrollLeft;
203+
drawTimes();
204+
return;
214205
}
215-
}, 0);
216-
206+
, 0);
207+
}
208+
});
209+
210+
scope.$watch("scrollLeft", function (val) {
211+
if (val) {
212+
$timeout(function () {
213+
// $('#ruler').scrollLeft = $('#scrolling_tracks').scrollLeft;
214+
drawTimes();
215+
//reposition the spans at every visible multiple of 50 pixels
216+
//Plus a screen width before and after for scrolling
217+
return;
218+
}
219+
, 0);
217220
}
218221
});
219222

src/timeline/media/css/main.css

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,44 @@ img {
4343
}
4444

4545
/* Ruler */
46-
#scrolling_ruler { overflow: hidden; position: relative;line-height: 4px; }
46+
#scrolling_ruler { overflow: hidden; position: relative;line-height: 4px; height:43px;}
4747
#scrolling_tracks { height: 316px; overflow: scroll; position: relative; }
4848
#ruler_label { height: 39px; width: 140px; float: left; margin-bottom: 4px; }
49-
#ruler_ticks { background-color:#000; }
5049
#ruler_time { font-size: 13pt; color: #c8c8c8; padding-top: 14px; padding-left: 17px; }
5150
#progress_container {margin-left:140px; overflow: hidden; height: 13px;}
5251
.drag_cursor { cursor: move; }
52+
#ruler {
53+
position: relative;
54+
height: 100%;
55+
background-image: url(../images/ruler-tick.svg);
56+
}
57+
.on_ruler{
58+
position: absolute;
59+
color: white;
60+
font-size: 0.8em;
61+
}
62+
.ruler_tick_long {
63+
background-color: white;
64+
width: 5px;
65+
height: 20px;
66+
bottom: 0px;
67+
position: absolute;
68+
border-radius: 2px;
69+
}
70+
.ruler_tick {
71+
background-color: white;
72+
width: 5px;
73+
height: 10px;
74+
bottom: 0px;
75+
position: absolute;
76+
border-radius: 2px;
77+
}
78+
.tick_time {
79+
color: white;
80+
top: 5px;
81+
position: absolute;
82+
transform: translate(-50%,0);
83+
}
5384

5485
/* Tracks */
5586
#track_controls { width: 140px; position: relative; float: left; height: 316px; overflow: hidden;}
Lines changed: 114 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)