Skip to content

Commit 5d704fc

Browse files
committed
Fixed rotation transform logic to correctly adjust around the origin point (in viewport coordinates).
Fixed shear transform logic to correctly scale 1 to 1, as user moves mouse
1 parent ec0428b commit 5d704fc

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/windows/video_widget.py

+20-16
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ def paintEvent(self, event, *args):
198198
shear_y = raw_properties.get('shear_y').get('value')
199199
origin_x = raw_properties.get('origin_x').get('value')
200200
origin_y = raw_properties.get('origin_y').get('value')
201+
origin_x_value = scaled_source_width * origin_x
202+
origin_y_value = scaled_source_height * origin_y
203+
self.originHandle = QPointF(x + origin_x_value, y + origin_y_value)
201204
if rotation or shear_x or shear_y:
202-
origin_x_value = scaled_source_width * origin_x
203-
origin_y_value = scaled_source_height * origin_y
204205
self.transform.translate(origin_x_value, origin_y_value)
205206
self.transform.rotate(rotation)
206207
self.transform.shear(shear_x, shear_y)
@@ -516,8 +517,8 @@ def mouseMoveEvent(self, event):
516517
scale_x = raw_properties.get('scale_x').get('value')
517518

518519
# Calculate new location coordinates
519-
clip_aspect_ratio = self.clipBounds.width() / self.clipBounds.height()
520-
shear_x -= (event.pos().x() - self.mouse_position.x()) / ((self.clipBounds.width() * scale_x) / clip_aspect_ratio)
520+
aspect_ratio = (self.clipBounds.width() / self.clipBounds.height()) * 2.0
521+
shear_x -= (event.pos().x() - self.mouse_position.x()) / ((self.clipBounds.width() * scale_x) / aspect_ratio)
521522

522523
# Update keyframe value (or create new one)
523524
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'shear_x', shear_x)
@@ -528,8 +529,8 @@ def mouseMoveEvent(self, event):
528529
shear_x = raw_properties.get('shear_x').get('value')
529530

530531
# Calculate new location coordinates
531-
clip_aspect_ratio = self.clipBounds.width() / self.clipBounds.height()
532-
shear_x += (event.pos().x() - self.mouse_position.x()) / ((self.clipBounds.width() * scale_x) / clip_aspect_ratio)
532+
aspect_ratio = (self.clipBounds.width() / self.clipBounds.height()) * 2.0
533+
shear_x += (event.pos().x() - self.mouse_position.x()) / ((self.clipBounds.width() * scale_x) / aspect_ratio)
533534

534535
# Update keyframe value (or create new one)
535536
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'shear_x', shear_x)
@@ -540,41 +541,43 @@ def mouseMoveEvent(self, event):
540541
scale_y = raw_properties.get('scale_y').get('value')
541542

542543
# Calculate new location coordinates
543-
clip_aspect_ratio = self.clipBounds.height() / self.clipBounds.width()
544-
shear_y -= (event.pos().y() - self.mouse_position.y()) / ((self.clipBounds.height() * scale_y) / clip_aspect_ratio)
544+
aspect_ratio = (self.clipBounds.height() / self.clipBounds.width()) * 2.0
545+
shear_y -= (event.pos().y() - self.mouse_position.y()) / (self.clipBounds.height() * scale_y / aspect_ratio)
545546

546547
# Update keyframe value (or create new one)
547548
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'shear_y', shear_y)
548549

549550
elif self.transform_mode == 'shear_right':
550551
# Get current keyframe shear value
551-
clip_aspect_ratio = self.clipBounds.height() / self.clipBounds.width()
552552
scale_y = raw_properties.get('scale_y').get('value')
553553
shear_y = raw_properties.get('shear_y').get('value')
554554

555555
# Calculate new location coordinates
556-
shear_y += (event.pos().y() - self.mouse_position.y()) / ((self.clipBounds.height() * scale_y) / clip_aspect_ratio)
556+
aspect_ratio = (self.clipBounds.height() / self.clipBounds.width()) * 2.0
557+
shear_y += (event.pos().y() - self.mouse_position.y()) / (self.clipBounds.height() * scale_y / aspect_ratio)
557558

558559
# Update keyframe value (or create new one)
559560
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'shear_y', shear_y)
560561

561562
elif self.transform_mode == 'rotation':
562563
# Get current rotation keyframe value
563564
rotation = raw_properties.get('rotation').get('value')
565+
scale_x = max(float(raw_properties.get('scale_x').get('value')), 0.001)
566+
scale_y = max(float(raw_properties.get('scale_y').get('value')), 0.001)
564567

565568
# Calculate new location coordinates
566-
is_on_left = event.pos().x() < (viewport_rect.width() / 2.0)
567-
is_on_top = event.pos().y() < (viewport_rect.height() / 2.0)
569+
is_on_left = event.pos().x() < self.originHandle.x()
570+
is_on_top = event.pos().y() < self.originHandle.y()
568571

569572
if is_on_top:
570-
rotation += (event.pos().x() - self.mouse_position.x()) / (self.clipBounds.width() / 90)
573+
rotation += (event.pos().x() - self.mouse_position.x()) / ((self.clipBounds.width() * scale_x) / 90)
571574
else:
572-
rotation -= (event.pos().x() - self.mouse_position.x()) / (self.clipBounds.width() / 90)
575+
rotation -= (event.pos().x() - self.mouse_position.x()) / ((self.clipBounds.width() * scale_x) / 90)
573576

574577
if is_on_left:
575-
rotation -= (event.pos().y() - self.mouse_position.y()) / (self.clipBounds.height() / 90)
578+
rotation -= (event.pos().y() - self.mouse_position.y()) / ((self.clipBounds.height() * scale_y) / 90)
576579
else:
577-
rotation += (event.pos().y() - self.mouse_position.y()) / (self.clipBounds.height() / 90)
580+
rotation += (event.pos().y() - self.mouse_position.y()) / ((self.clipBounds.height() * scale_y) / 90)
578581

579582
# Update keyframe value (or create new one)
580583
self.updateProperty(self.transforming_clip.id, clip_frame_number, 'rotation', rotation)
@@ -786,6 +789,7 @@ def __init__(self, *args):
786789
self.rightHandle = None
787790
self.centerHandle = None
788791
self.clipBounds = None
792+
self.originHandle = None
789793
self.mouse_pressed = False
790794
self.mouse_dragging = False
791795
self.mouse_position = None

0 commit comments

Comments
 (0)