@@ -160,34 +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
+
163
181
drawTimes = ( ) => {
182
+ console . log ( scope . scrollLeft ) ;
164
183
ruler = $ ( "#ruler" ) ;
165
184
width = $ ( "body" ) . width ( ) ;
166
185
$ ( "#ruler span" ) . remove ( ) ;
167
- start = Math . max ( scope . scrollLeft - width , 100 ) ;
186
+ start = Math . max ( scope . scrollLeft - width , 0 ) ;
168
187
end = Math . min ( scope . scrollLeft + ( 2 * width ) , $ ( '#ruler' ) . width ( ) ) ;
169
-
170
- scale = scope . project . scale ;
171
- for ( var i = start - ( start % 100 ) ; i < end ; i += 100 ) {
172
- /* create and format span */
173
- s = $ ( '<span style="left: ' + i + 'px;">' ) ;
174
- s . addClass ( "ruler_time" ) ;
175
-
176
- /* Calculate Time */
177
- var time = i / scope . pixelsPerSecond ;
178
- var text_time = secondsToTime ( time , scope . project . fps . num , scope . project . fps . den ) ;
179
- s [ 0 ] . innerText = text_time [ "hour" ] + ":" + text_time [ "min" ] + ":" + text_time [ "sec" ] ;
180
-
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;" ;
181
193
ruler . append ( s ) ;
182
194
}
183
195
}
184
196
185
- scope . $watch ( "project.scale + project.duration + scrollLeft" , function ( val ) {
197
+ //watch the scale value so it will be able to draw the ruler after changes,
198
+ //otherwise the canvas is just reset to blank
199
+ scope . $watch ( "project.scale + project.duration" , function ( val ) {
200
+ if ( val ) {
201
+ $timeout ( function ( ) {
202
+ $ ( '#ruler' ) . scrollLeft = $ ( '#scrolling_tracks' ) . scrollLeft ;
203
+ drawTimes ( ) ;
204
+ return ;
205
+ }
206
+ , 0 ) ;
207
+ }
208
+ } ) ;
209
+
210
+ scope . $watch ( "scrollLeft" , function ( val ) {
186
211
if ( val ) {
187
212
$timeout ( function ( ) {
213
+ // $('#ruler').scrollLeft = $('#scrolling_tracks').scrollLeft;
188
214
drawTimes ( ) ;
215
+ //reposition the spans at every visible multiple of 50 pixels
216
+ //Plus a screen width before and after for scrolling
189
217
return ;
190
- } , 0 ) ;
218
+ }
219
+ , 0 ) ;
191
220
}
192
221
} ) ;
193
222
0 commit comments