[pitivi] transformation: remove old code. add comments
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] transformation: remove old code. add comments
- Date: Wed, 16 Sep 2015 15:50:57 +0000 (UTC)
commit 35324b07e2bc1c7f216c364c7161d6f094713385
Author: Lubosz Sarnecki <lubosz gmail com>
Date: Thu Nov 13 12:42:13 2014 +0100
transformation: remove old code. add comments
Summary: Depends on D266
Reviewers: Mathieu_Du, aleb
Differential Revision: https://phabricator.freedesktop.org/D267
pitivi/clipproperties.py | 3 +
pitivi/viewer.py | 468 ----------------------------------------------
2 files changed, 3 insertions(+), 468 deletions(-)
---
diff --git a/pitivi/clipproperties.py b/pitivi/clipproperties.py
index 345a343..d33ffbf 100644
--- a/pitivi/clipproperties.py
+++ b/pitivi/clipproperties.py
@@ -688,6 +688,8 @@ class TransformationProperties(Gtk.Expander):
def _selectionChangedCb(self, timeline):
if self.timeline and len(self.timeline.selection.selected) > 0:
+ # choose last selected clip
+ # TODO: hide effects properties when multiple clips are selected
for clip in self.timeline.selection.selected:
pass
@@ -701,6 +703,7 @@ class TransformationProperties(Gtk.Expander):
"frei0r-filter-scale0tilt")
self._updateSpinButtons()
else:
+ # Deselect
if self._selected_clip:
self._selected_clip = None
self.zoom_scale.set_value(1.0)
diff --git a/pitivi/viewer.py b/pitivi/viewer.py
index d79fff5..0efca82 100644
--- a/pitivi/viewer.py
+++ b/pitivi/viewer.py
@@ -480,328 +480,6 @@ class ViewerContainer(Gtk.Box, Loggable):
self.system.uninhibitScreensaver(self.INHIBIT_REASON)
-class Point():
-
- """
- Draw a point, used as a handle for the transformation box
- """
-
- def __init__(self, x, y, settings):
- self.x = x
- self.y = y
- self.color = hex_to_rgb(settings.pointColor)
- self.clickedColor = hex_to_rgb(settings.clickedPointColor)
- self.set_width(settings.pointSize)
- self.clicked = False
-
- def set_position(self, x, y):
- self.x = x
- self.y = y
-
- def set_width(self, width):
- self.width = width
- self.radius = width / 2
-
- def is_clicked(self, event):
- is_right_of_left = event.x > self.x - self.radius
- is_left_of_right = event.x < self.x + self.radius
- is_below_top = event.y > self.y - self.radius
- is_above_bottom = event.y < self.y + self.radius
-
- if is_right_of_left and is_left_of_right and is_below_top and is_above_bottom:
- self.clicked = True
- return True
-
- def draw(self, cr):
- linear = cairo.LinearGradient(self.x, self.y - self.radius,
- self.x, self.y + self.radius)
- linear.add_color_stop_rgba(0.00, .6, .6, .6, 1)
- linear.add_color_stop_rgba(0.50, .4, .4, .4, .1)
- linear.add_color_stop_rgba(0.60, .4, .4, .4, .1)
- linear.add_color_stop_rgba(1.00, .6, .6, .6, 1)
-
- radial = cairo.RadialGradient(self.x + self.radius / 2,
- self.y - self.radius / 2, 1,
- self.x, self.y,
- self.radius)
- if self.clicked:
- radial.add_color_stop_rgb(0, *self.clickedColor)
- else:
- radial.add_color_stop_rgb(0, *self.color)
- radial.add_color_stop_rgb(1, 0.1, 0.1, 0.1)
- radial_glow = cairo.RadialGradient(self.x, self.y,
- self.radius * .9,
- self.x, self.y,
- self.radius * 1.2)
- radial_glow.add_color_stop_rgba(0, 0.9, 0.9, 0.9, 1)
- radial_glow.add_color_stop_rgba(1, 0.9, 0.9, 0.9, 0)
-
- cr.set_source(radial_glow)
- cr.arc(self.x, self.y, self.radius * 1.2, 0, 2 * pi)
- cr.fill()
- cr.arc(self.x, self.y, self.radius * .9, 0, 2 * pi)
- cr.set_source(radial)
- cr.fill()
- cr.arc(self.x, self.y, self.radius * .9, 0, 2 * pi)
- cr.set_source(linear)
- cr.fill()
-
-(NO_POINT,
- AREA,
- TOP_LEFT,
- BOTTOM_LEFT,
- TOP_RIGHT,
- BOTTOM_RIGHT,
- LEFT,
- RIGHT,
- TOP,
- BOTTOM) = list(range(10))
-
-
-class TransformationBox():
-
- """
- Box for transforming the video on the ViewerWidget
- """
-
- def __init__(self, settings):
- self.clicked_point = NO_POINT
- self.left_factor = 0
- self.settings = settings
- self.right_factor = 1
- self.top_factor = 0
- self.bottom_factor = 1
- self.center_factor = Point(0.5, 0.5, settings)
- self.transformation_properties = None
- self.points = {}
-
- def is_clicked(self, event):
- is_right_of_left = event.x > self.left
- is_left_of_right = event.x < self.right
- is_below_top = event.y > self.top
- is_above_bottom = event.y < self.bottom
-
- if is_right_of_left and is_left_of_right and is_below_top and is_above_bottom:
- return True
-
- def update_scale(self):
- self.scale_x = (self.right_factor - self.left_factor) / 2.0
- self.scale_y = (self.bottom_factor - self.top_factor) / 2.0
-
- def update_center(self):
- self.center_factor.x = (self.left_factor + self.right_factor) / 2.0
- self.center_factor.y = (self.top_factor + self.bottom_factor) / 2.0
-
- self.center.x = self.area.width * self.center_factor.x
- self.center.y = self.area.height * self.center_factor.y
-
- def set_transformation_properties(self, transformation_properties):
- self.transformation_properties = transformation_properties
- self.update_from_effect(transformation_properties.effect)
-
- def update_from_effect(self, effect):
- self.scale_x = effect.get_property("scale-x")
- self.scale_y = effect.get_property("scale-y")
- self.center_factor.x = 2 * \
- (effect.get_property("tilt-x") - 0.5) + self.scale_x
- self.center_factor.y = 2 * \
- (effect.get_property("tilt-y") - 0.5) + self.scale_y
- self.left_factor = self.center_factor.x - self.scale_x
- self.right_factor = self.center_factor.x + self.scale_x
- self.top_factor = self.center_factor.y - self.scale_y
- self.bottom_factor = self.center_factor.y + self.scale_y
- self.update_absolute()
- self.update_factors()
- self.update_center()
- self.update_scale()
- self.update_points()
-
- def move(self, event):
- rel_x = self.last_x - event.x
- rel_y = self.last_y - event.y
-
- self.center.x -= rel_x
- self.center.y -= rel_y
-
- self.left -= rel_x
- self.right -= rel_x
- self.top -= rel_y
- self.bottom -= rel_y
-
- self.last_x = event.x
- self.last_y = event.y
-
- def init_points(self):
- # Corner boxes
- self.points[TOP_LEFT] = Point(self.left, self.top, self.settings)
- self.points[TOP_RIGHT] = Point(self.right, self.top, self.settings)
- self.points[BOTTOM_LEFT] = Point(self.left, self.bottom, self.settings)
- self.points[BOTTOM_RIGHT] = Point(
- self.right, self.bottom, self.settings)
- # Edge boxes
- self.points[TOP] = Point(self.center.x, self.top, self.settings)
- self.points[BOTTOM] = Point(self.center.x, self.bottom, self.settings)
- self.points[LEFT] = Point(self.left, self.center.y, self.settings)
- self.points[RIGHT] = Point(self.right, self.center.y, self.settings)
-
- def update_points(self):
- self._update_measure()
-
- # Corner boxes
- self.points[TOP_LEFT].set_position(self.left, self.top)
- self.points[TOP_RIGHT].set_position(self.right, self.top)
- self.points[BOTTOM_LEFT].set_position(self.left, self.bottom)
- self.points[BOTTOM_RIGHT].set_position(self.right, self.bottom)
- # Edge boxes
- self.points[TOP].set_position(self.center.x, self.top)
- self.points[BOTTOM].set_position(self.center.x, self.bottom)
- self.points[LEFT].set_position(self.left, self.center.y)
- self.points[RIGHT].set_position(self.right, self.center.y)
-
- if self.width < 100 or self.height < 100:
- if self.width < self.height:
- point_width = self.width / 4.0
- else:
- point_width = self.height / 4.0
-
- # gradient is not rendered below width 7
- if point_width < 7:
- point_width = 7
- else:
- point_width = self.settings.pointSize
-
- for point in list(self.points.values()):
- point.set_width(point_width)
-
- def draw(self, cr):
- self.update_points()
- # main box
- cr.set_source_rgba(0.5, 0.5, 0.5, 0.7)
- cr.rectangle(
- self.left, self.top, self.right - self.left, self.bottom - self.top)
- cr.stroke()
-
- for point in list(self.points.values()):
- point.draw(cr)
-
- def select_point(self, event):
- # translate when zoomed out
- event.x -= self.area.x
- event.y -= self.area.y
- for type, point in list(self.points.items()):
- if point.is_clicked(event):
- self.clicked_point = type
- return
-
- if self.is_clicked(event):
- self.clicked_point = AREA
- self.last_x = event.x
- self.last_y = event.y
- else:
- self.clicked_point = NO_POINT
-
- def _update_measure(self):
- self.width = self.right - self.left
- self.height = self.bottom - self.top
-
- def transform(self, event):
- # translate when zoomed out
- event.x -= self.area.x
- event.y -= self.area.y
- aspect = float(self.area.width) / float(self.area.height)
- self._update_measure()
-
- if self.clicked_point == NO_POINT:
- return False
- elif self.clicked_point == AREA:
- self.move(event)
- elif self.clicked_point == TOP_LEFT:
- self.left = event.x
- self.top = self.bottom - self.width / aspect
- elif self.clicked_point == BOTTOM_LEFT:
- self.left = event.x
- self.bottom = self.top + self.width / aspect
- elif self.clicked_point == TOP_RIGHT:
- self.right = event.x
- self.top = self.bottom - self.width / aspect
- elif self.clicked_point == BOTTOM_RIGHT:
- self.right = event.x
- self.bottom = self.top + self.width / aspect
- elif self.clicked_point == LEFT:
- self.left = event.x
- elif self.clicked_point == RIGHT:
- self.right = event.x
- elif self.clicked_point == TOP:
- self.top = event.y
- elif self.clicked_point == BOTTOM:
- self.bottom = event.y
- self._check_negative_scale()
- self.update_factors()
- self.update_center()
- self.update_scale()
- return True
-
- def release_point(self):
- for point in list(self.points.values()):
- point.clicked = False
- self.clicked_point = NO_POINT
-
- def _check_negative_scale(self):
- if self.right < self.left:
- if self.clicked_point in [RIGHT, BOTTOM_RIGHT, TOP_RIGHT]:
- self.right = self.left
- else:
- self.left = self.right
- if self.bottom < self.top:
- if self.clicked_point == [BOTTOM, BOTTOM_RIGHT, BOTTOM_LEFT]:
- self.bottom = self.top
- else:
- self.top = self.bottom
-
- def update_factors(self):
- self.bottom_factor = float(self.bottom) / float(self.area.height)
- self.top_factor = float(self.top) / float(self.area.height)
- self.left_factor = float(self.left) / float(self.area.width)
- self.right_factor = float(self.right) / float(self.area.width)
-
- def update_size(self, area):
- if area.width == 0 or area.height == 0:
- return
- self.area = area
- self.update_absolute()
-
- def init_size(self, area):
- self.area = area
- self.left = area.x
- self.right = area.x + area.width
- self.top = area.y
- self.bottom = area.y + area.height
- self.center = Point((self.left + self.right) / 2, (
- self.top + self.bottom) / 2, self.settings)
- self.init_points()
- self._update_measure()
-
- def update_absolute(self):
- self.top = self.top_factor * self.area.height
- self.left = self.left_factor * self.area.width
- self.bottom = self.bottom_factor * self.area.height
- self.right = self.right_factor * self.area.width
- self.update_center()
-
- def update_effect_properties(self):
- if self.transformation_properties:
- self.transformation_properties.disconnectSpinButtonsFromFlush()
- values = self.transformation_properties.spin_buttons
- values["tilt_x"].set_value(
- (self.center_factor.x - self.scale_x) / 2.0 + 0.5)
- values["tilt_y"].set_value(
- (self.center_factor.y - self.scale_y) / 2.0 + 0.5)
-
- values["scale_x"].set_value(self.scale_x)
- values["scale_y"].set_value(self.scale_y)
- self.transformation_properties.connectSpinButtonsToFlush()
-
-
class ViewerWidget(Gtk.AspectFrame, Loggable):
"""
@@ -845,159 +523,13 @@ class ViewerWidget(Gtk.AspectFrame, Loggable):
self._setting_ratio = True
self.set_property("ratio", float(ratio))
- def init_transformation_events(self):
- self.fixme("TransformationBox disabled")
- """
- self.set_events(Gdk.EventMask.BUTTON_PRESS_MASK
- | Gdk.EventMask.BUTTON_RELEASE_MASK
- | Gdk.EventMask.POINTER_MOTION_MASK
- | Gdk.EventMask.POINTER_MOTION_HINT_MASK)
- """
-
- def show_box(self):
- self.fixme("TransformationBox disabled")
- """
- if not self.box:
- self.box = TransformationBox(self.settings)
- self.box.init_size(self.area)
- self._update_gradient()
- self.connect("button-press-event", self.button_press_event)
- self.connect("button-release-event", self.button_release_event)
- self.connect("motion-notify-event", self.motion_notify_event)
- self.connect("size-allocate", self._sizeCb)
- self.box.set_transformation_properties(self.transformation_properties)
- self.renderbox()
- """
-
def _sizeCb(self, unused_widget, unused_area):
# The transformation box is cleared when using regular rendering
# so we need to flush the pipeline
self.seeker.flush()
- def hide_box(self):
- if self.box:
- self.box = None
- self.disconnect_by_func(self.button_press_event)
- self.disconnect_by_func(self.button_release_event)
- self.disconnect_by_func(self.motion_notify_event)
- self.seeker.flush()
- self.zoom = 1.0
- if self.sink:
- self.sink.set_render_rectangle(*self.area)
-
- def set_transformation_properties(self, transformation_properties):
- self.transformation_properties = transformation_properties
-
- def _store_pixbuf(self):
- """
- When not playing, store a pixbuf of the current viewer image.
- This will allow it to be restored for the transformation box.
- """
-
- if self.box and self.zoom != 1.0:
- # The transformation box is active and dezoomed
- # crop away 1 pixel border to avoid artefacts on the pixbuf
-
- self.pixbuf = Gdk.pixbuf_get_from_window(self.get_window(),
- self.box.area.x +
- 1, self.box.area.y + 1,
- self.box.area.width - 2, self.box.area.height - 2)
- else:
- self.pixbuf = Gdk.pixbuf_get_from_window(self.get_window(),
- 0, 0,
- self.get_window(
- ).get_width(),
- self.get_window().get_height())
-
- self.stored = True
-
- def button_release_event(self, unused_widget, event):
- if event.button == 1:
- self.box.update_effect_properties()
- self.box.release_point()
- self.seeker.flush()
- self.stored = False
- return True
-
- def button_press_event(self, unused_widget, event):
- if event.button == 1:
- self.box.select_point(event)
- return True
-
- def _currentStateCb(self, unused_pipeline, unused_state):
- self.fixme("TransformationBox disabled")
- """
- self.pipeline = pipeline
- if state == Gst.State.PAUSED:
- self._store_pixbuf()
- self.renderbox()
- """
-
- def motion_notify_event(self, unused_widget, event):
- if event.get_state() & Gdk.ModifierType.BUTTON1_MASK:
- if self.box.transform(event):
- if self.stored:
- self.renderbox()
- return True
-
- def do_expose_event(self, event):
- self.area = event.area
- if self.box:
- self._update_gradient()
- if self.zoom != 1.0:
- width = int(float(self.area.width) * self.zoom)
- height = int(float(self.area.height) * self.zoom)
- area = ((self.area.width - width) / 2,
- (self.area.height - height) / 2,
- width, height)
- self.sink.set_render_rectangle(*area)
- else:
- area = self.area
- self.box.update_size(area)
- self.renderbox()
-
- def _update_gradient(self):
- self.gradient_background = cairo.LinearGradient(
- 0, 0, 0, self.area.height)
- self.gradient_background.add_color_stop_rgb(0.00, .1, .1, .1)
- self.gradient_background.add_color_stop_rgb(0.50, .2, .2, .2)
- self.gradient_background.add_color_stop_rgb(1.00, .5, .5, .5)
-
- def renderbox(self):
- if self.box:
- cr = self.window.cairo_create()
- cr.push_group()
-
- if self.zoom != 1.0:
- # draw some nice background for zoom out
- cr.set_source(self.gradient_background)
- cr.rectangle(0, 0, self.area.width, self.area.height)
- cr.fill()
-
- # translate the drawing of the zoomed out box
- cr.translate(self.box.area.x, self.box.area.y)
-
- # clear the drawingarea with the last known clean video frame
- # translate when zoomed out
- if self.pixbuf:
- if self.box.area.width != self.pixbuf.get_width():
- scale = float(self.box.area.width) / float(
- self.pixbuf.get_width())
- cr.save()
- cr.scale(scale, scale)
- cr.set_source_pixbuf(self.pixbuf, 0, 0)
- cr.paint()
- if self.box.area.width != self.pixbuf.get_width():
- cr.restore()
-
- if self.pipeline and self.pipeline.getState() == Gst.State.PAUSED:
- self.box.draw(cr)
- cr.pop_group_to_source()
- cr.paint()
-
class PlayPauseButton(Gtk.Button, Loggable):
-
"""
Double state Gtk.Button which displays play/pause
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]