27
27
*/
28
28
29
29
30
+ /*global setSelections, setBoundingBox, moveBoundingBox, bounding_box */
30
31
// Init variables
31
32
var dragging = false ;
32
33
var resize_disabled = false ;
@@ -55,6 +56,12 @@ App.directive("tlClip", function ($timeout) {
55
56
start : function ( e , ui ) {
56
57
dragging = true ;
57
58
59
+ // Set selections
60
+ setSelections ( scope , element , $ ( this ) . attr ( "id" ) ) ;
61
+
62
+ // Set bounding box
63
+ setBoundingBox ( scope , $ ( this ) , "trimming" ) ;
64
+
58
65
//determine which side is being changed
59
66
var parentOffset = element . offset ( ) ;
60
67
var mouseLoc = e . pageX - parentOffset . left ;
@@ -92,6 +99,9 @@ App.directive("tlClip", function ($timeout) {
92
99
return ;
93
100
}
94
101
102
+ // Hide snapline (if any)
103
+ scope . hideSnapline ( ) ;
104
+
95
105
// Hide keyframe points
96
106
if ( dragLoc === "right" ) {
97
107
// Make the keyframe points visible again
@@ -100,7 +110,7 @@ App.directive("tlClip", function ($timeout) {
100
110
}
101
111
102
112
//get amount changed in width
103
- var delta_x = ui . originalSize . width - ui . size . width ;
113
+ var delta_x = ui . originalSize . width - ui . element . width ( ) ;
104
114
var delta_time = delta_x / scope . pixelsPerSecond ;
105
115
106
116
//change the clip end/start based on which side was dragged
@@ -131,12 +141,7 @@ App.directive("tlClip", function ($timeout) {
131
141
132
142
//apply the new start, end and length to the clip's scope
133
143
scope . $apply ( function ( ) {
134
- // Get the nearest starting frame position to the clip position (this helps to prevent cutting
135
- // in-between frames, and thus less likely to repeat or skip a frame).
136
- new_position = ( Math . round ( ( new_position * scope . project . fps . num ) / scope . project . fps . den ) * scope . project . fps . den ) / scope . project . fps . num ;
137
- new_right = ( Math . round ( ( new_right * scope . project . fps . num ) / scope . project . fps . den ) * scope . project . fps . den ) / scope . project . fps . num ;
138
- new_left = ( Math . round ( ( new_left * scope . project . fps . num ) / scope . project . fps . den ) * scope . project . fps . den ) / scope . project . fps . num ;
139
-
144
+ // Apply clip scope changes
140
145
if ( scope . clip . end !== new_right ) {
141
146
scope . clip . end = new_right ;
142
147
}
@@ -168,36 +173,51 @@ App.directive("tlClip", function ($timeout) {
168
173
return ;
169
174
}
170
175
171
- // get amount changed in width
172
- var delta_x = parseFloat ( ui . originalSize . width ) - ui . size . width ;
173
- var delta_time = delta_x / scope . pixelsPerSecond ;
176
+ // Calculate the clip bounding box movement and apply snapping rules
177
+ let cursor_position = e . pageX - $ ( "#ruler" ) . offset ( ) . left ;
178
+ let results = moveBoundingBox ( scope , bounding_box . left , bounding_box . top ,
179
+ cursor_position - bounding_box . left , cursor_position - bounding_box . top ,
180
+ cursor_position , cursor_position , "trimming" ) ;
174
181
175
- // change the clip end/start based on which side was dragged
176
- var new_left = scope . clip . start ;
177
- var new_right = scope . clip . end ;
182
+ // Calculate delta from current mouse position
183
+ let new_position = cursor_position ;
184
+ new_position = results . position . left ;
185
+ let delta_x = 0 ;
186
+ if ( dragLoc === "left" ) {
187
+ delta_x = ( parseFloat ( ui . originalPosition . left ) ) - new_position ;
188
+ } else if ( dragLoc === "right" ) {
189
+ delta_x = ( parseFloat ( ui . originalPosition . left ) + parseFloat ( ui . originalSize . width ) ) - new_position ;
190
+ }
191
+
192
+ // Calculate the pixel locations of the left and right side
193
+ var new_left = scope . clip . start * scope . pixelsPerSecond ;
194
+ var new_right = scope . clip . end * scope . pixelsPerSecond ;
178
195
179
196
if ( dragLoc === "left" ) {
180
- // changing the start of the clip
181
- new_left += delta_time ;
182
- if ( new_left < 0 ) {
183
- ui . element . width ( ui . size . width + ( new_left * scope . pixelsPerSecond ) ) ;
184
- ui . element . css ( "left" , ui . position . left - ( new_left * scope . pixelsPerSecond ) ) ;
185
- }
186
- else {
187
- ui . element . width ( ui . size . width ) ;
197
+ // Adjust left side of clip
198
+ // Don't allow less than 0.0 start
199
+ let zero_left_x = ( scope . clip . position - scope . clip . start ) * scope . pixelsPerSecond ;
200
+ let proposed_left_x = ui . originalPosition . left - delta_x ;
201
+ if ( proposed_left_x < zero_left_x ) {
202
+ // prevent less than 0.0
203
+ delta_x = ui . originalPosition . left - zero_left_x ;
188
204
}
205
+
206
+ // Position and size clip
207
+ ui . element . css ( "left" , ui . originalPosition . left - delta_x ) ;
208
+ ui . element . width ( new_right - ( new_left - delta_x ) ) ;
189
209
}
190
210
else {
191
- // changing the end of the clips
192
- new_right -= delta_time ;
193
- if ( new_right > scope . clip . duration ) {
194
-
211
+ // Adjust right side of clip
212
+ new_right -= delta_x ;
213
+ let duration_pixels = scope . clip . duration * scope . pixelsPerSecond ;
214
+ if ( new_right > duration_pixels ) {
195
215
// change back to actual duration (for the preview below)
196
- new_right = scope . clip . duration ;
197
- ui . element . width ( new_right * scope . pixelsPerSecond ) ;
216
+ new_right = duration_pixels ;
217
+ ui . element . width ( new_right ) ;
198
218
}
199
219
else {
200
- ui . element . width ( ui . size . width ) ;
220
+ ui . element . width ( ( new_right - new_left ) ) ;
201
221
}
202
222
}
203
223
@@ -237,31 +257,9 @@ App.directive("tlClip", function ($timeout) {
237
257
start : function ( event , ui ) {
238
258
previous_drag_position = null ;
239
259
dragging = true ;
240
- if ( ! element . hasClass ( "ui-selected" ) ) {
241
- // Clear previous selections?
242
- var clear_selections = false ;
243
- if ( $ ( ".ui-selected" ) . length > 0 ) {
244
- clear_selections = true ;
245
- }
246
260
247
- // selectClip, selectTransition
248
- var id = $ ( this ) . attr ( "id" ) ;
249
- if ( element . hasClass ( "clip" ) ) {
250
- // Select this clip, unselect all others
251
- scope . selectTransition ( "" , clear_selections ) ;
252
- scope . selectClip ( id , clear_selections ) ;
253
-
254
- }
255
- else if ( element . hasClass ( "transition" ) ) {
256
- // Select this transition, unselect all others
257
- scope . selectClip ( "" , clear_selections ) ;
258
- scope . selectTransition ( id , clear_selections ) ;
259
- }
260
- }
261
-
262
- // Apply scope up to this point
263
- scope . $apply ( function ( ) {
264
- } ) ;
261
+ // Set selections
262
+ setSelections ( scope , element , $ ( this ) . attr ( "id" ) ) ;
265
263
266
264
var scrolling_tracks = $ ( "#scrolling_tracks" ) ;
267
265
var vert_scroll_offset = scrolling_tracks . scrollTop ( ) ;
@@ -271,7 +269,8 @@ App.directive("tlClip", function ($timeout) {
271
269
bounding_box = { } ;
272
270
273
271
// Init all other selected clips (prepare to drag them)
274
- $ ( ".ui-selected" ) . each ( function ( ) {
272
+ // This creates a bounding box which contains all selected clips
273
+ $ ( ".ui-selected, #" + $ ( this ) . attr ( "id" ) ) . each ( function ( ) {
275
274
// Init all clips whether selected or not
276
275
start_clips [ $ ( this ) . attr ( "id" ) ] = {
277
276
"top" : $ ( this ) . position ( ) . top + vert_scroll_offset ,
0 commit comments