Skip to content

Commit

Permalink
Added support for rotation transform to the bounding-box and to the t…
Browse files Browse the repository at this point in the history
…ransform handler for the tracker effect
  • Loading branch information
BrennoCaldato committed Dec 14, 2020
1 parent 0d348bb commit 4179022
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/windows/video_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,20 @@ def changed(self, action):


def drawTransformHandler(self, painter, sx, sy, source_width, source_height, origin_x, origin_y,
x1=None, y1=None, x2=None, y2=None):
x1=None, y1=None, x2=None, y2=None, rotation = None):
# Draw transform corners and center origin circle
# Corner size
cs = 14.0
os = 12.0

# Rotate the transform handler
if rotation:
bbox_center_x = (((x1*source_width + x2*source_width) / 2.0) ) - ( (os/2) /sx)
bbox_center_y = (((y1*source_height + y2*source_height) / 2.0) ) - ( (os/2) /sy)
painter.translate(bbox_center_x, bbox_center_y)
painter.rotate(rotation)
painter.translate(-bbox_center_x, -bbox_center_y)

if(x1 and y1 and x2 and y2):
# Calculate bounds of clip
self.clipBounds = QRectF(QPointF(x1*source_width, y1*source_height), QPointF(x2*source_width, y2*source_height))
Expand Down Expand Up @@ -300,8 +308,9 @@ def paintEvent(self, event, *args):
y1 = raw_properties_effect.get('y1').get('value')
x2 = raw_properties_effect.get('x2').get('value')
y2 = raw_properties_effect.get('y2').get('value')
rotation_effect = raw_properties_effect.get('rotation').get('value')
self.drawTransformHandler(painter, sx, sy, source_width, source_height, origin_x, origin_y,
x1, y1, x2, y2)
x1, y1, x2, y2, rotation_effect)
else:
self.drawTransformHandler(painter, sx, sy, source_width, source_height, origin_x, origin_y)

Expand Down Expand Up @@ -605,7 +614,6 @@ def mouseMoveEvent(self, event):
origin_y = 0.0
if origin_y > 1.0:
origin_y = 1.0

# Update keyframe value (or create new one)
self.updateClipProperty(self.transforming_clip.id, clip_frame_number, 'origin_x', origin_x, refresh=False)
self.updateClipProperty(self.transforming_clip.id, clip_frame_number, 'origin_y', origin_y)
Expand Down Expand Up @@ -951,7 +959,7 @@ def mouseMoveEvent(self, event):
elif self.transform_mode == 'scale_bottom':
scale_y += (event.pos().y() - self.mouse_position.y()) / (self.clipBounds.height() / 2.0)
elif self.transform_mode == 'scale_left':
scale_x -= (event.pos().x() - self.mouse_position.x()) / (self.clipBounds.width() / 2.0)
scale_x -= (event.pos().x() - self.mouse_position.x()) / (self.clipBounds.width() / 2.0)
elif self.transform_mode == 'scale_right':
scale_x += (event.pos().x() - self.mouse_position.x()) / (self.clipBounds.width() / 2.0)

Expand Down Expand Up @@ -1040,14 +1048,17 @@ def updateEffectProperty(self, effect_id, frame_number, property_key, new_value,

# Reduce # of clip properties we are saving (performance boost)
# raw_properties = {property_key: raw_properties.get(property_key)}

raw_properties_string = json.dumps(raw_properties)

self.transforming_effect_object.SetJson(frame_number, raw_properties_string)

if refresh:
if effect_updated:
c.save()
# Update the preview
get_app().window.refreshFrameSignal.emit()
if refresh:
get_app().window.refreshFrameSignal.emit()

self.transforming_effect_object.SetJson(frame_number, raw_properties_string)

def refreshTriggered(self):
"""Signal to refresh viewport (i.e. a property might have changed that effects the preview)"""
Expand Down

0 comments on commit 4179022

Please sign in to comment.