@@ -42,7 +42,6 @@ var scroll_left_pixels = 0;
42
42
App . directive ( "tlScrollableTracks" , function ( ) {
43
43
return {
44
44
restrict : "A" ,
45
-
46
45
link : function ( scope , element , attrs ) {
47
46
48
47
// Sync ruler to track scrolling
@@ -61,14 +60,18 @@ App.directive("tlScrollableTracks", function () {
61
60
// Send scrollbar position to Qt
62
61
if ( scope . Qt ) {
63
62
// 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 ) ;
65
64
var left_scrollbar_edge = scroll_left_pixels / timeline_length ;
66
65
var right_scrollbar_edge = ( scroll_left_pixels + element . width ( ) ) / timeline_length ;
67
66
68
67
// Send normalized scrollbar positions to Qt
69
68
timeline . ScrollbarChanged ( [ left_scrollbar_edge , right_scrollbar_edge , timeline_length , element . width ( ) ] ) ;
70
69
}
71
70
71
+ scope . $apply ( ( ) => {
72
+ scope . scrollLeft = element [ 0 ] . scrollLeft ;
73
+ } )
74
+
72
75
} ) ;
73
76
74
77
// Initialize panning when middle mouse is clicked
@@ -99,7 +102,6 @@ App.directive("tlScrollableTracks", function () {
99
102
element . removeClass ( "drag_cursor" ) ;
100
103
} ) ;
101
104
102
-
103
105
}
104
106
} ;
105
107
} ) ;
@@ -115,7 +117,6 @@ App.directive("tlBody", function () {
115
117
}
116
118
} ) ;
117
119
118
-
119
120
}
120
121
} ;
121
122
} ) ;
@@ -147,7 +148,6 @@ App.directive("tlRuler", function ($timeout) {
147
148
scope . playhead_animating = false ;
148
149
} ) ;
149
150
} ) ;
150
-
151
151
} ) ;
152
152
153
153
// Move playhead to new position (if it's not currently being animated)
@@ -160,60 +160,63 @@ App.directive("tlRuler", function ($timeout) {
160
160
}
161
161
} ) ;
162
162
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
+
163
197
//watch the scale value so it will be able to draw the ruler after changes,
164
198
//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 ) {
166
200
if ( val ) {
167
-
168
201
$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 ;
214
205
}
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 ) ;
217
220
}
218
221
} ) ;
219
222
0 commit comments