Commit 3c5859f0 authored by Alexandru Băluț's avatar Alexandru Băluț Committed by Thibault Saunier

ruler: Nicer playhead handle

Reviewed-by: Thibault Saunier's avatarThibault Saunier <tsaunier@gnome.org>
Differential Revision: https://phabricator.freedesktop.org/D562
parent c5e5d11a
...@@ -8,6 +8,7 @@ pixmap_DATA = \ ...@@ -8,6 +8,7 @@ pixmap_DATA = \
pitivi-group-24.svg \ pitivi-group-24.svg \
pitivi-keyframe-24.svg \ pitivi-keyframe-24.svg \
pitivi-keyframe.svg \ pitivi-keyframe.svg \
pitivi-playhead.svg \
pitivi-relink-24.svg \ pitivi-relink-24.svg \
pitivi-relink.svg \ pitivi-relink.svg \
pitivi-render-16.png \ pitivi-render-16.png \
......
This diff is collapsed.
...@@ -22,21 +22,22 @@ ...@@ -22,21 +22,22 @@
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
import cairo import cairo
import os
from gi.repository import Gtk
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import GdkPixbuf
from gi.repository import Gst from gi.repository import Gst
from gi.repository import Gtk
from gettext import gettext as _ from gettext import gettext as _
from pitivi import configure
from pitivi.utils.loggable import Loggable
from pitivi.utils.pipeline import Seeker from pitivi.utils.pipeline import Seeker
from pitivi.utils.timeline import Zoomable from pitivi.utils.timeline import Zoomable
from pitivi.utils.loggable import Loggable
from pitivi.utils.ui import NORMAL_FONT, PLAYHEAD_WIDTH, set_cairo_color, time_to_string, beautify_length from pitivi.utils.ui import NORMAL_FONT, PLAYHEAD_WIDTH, set_cairo_color, time_to_string, beautify_length
HEIGHT = 25
# Tuples of: # Tuples of:
# - an interval lengths in seconds for which a timestamp will be displayed # - an interval lengths in seconds for which a timestamp will be displayed
# - how the ticks should be displayed for this interval: # - how the ticks should be displayed for this interval:
...@@ -116,10 +117,9 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable): ...@@ -116,10 +117,9 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
self.position = 0 # In nanoseconds self.position = 0 # In nanoseconds
self.frame_rate = Gst.Fraction(1 / 1) self.frame_rate = Gst.Fraction(1 / 1)
self.ns_per_frame = float(1 / self.frame_rate) * Gst.SECOND self.ns_per_frame = float(1 / self.frame_rate) * Gst.SECOND
self.connect('draw', self.drawCb)
self.connect('configure-event', self.configureEventCb) self.playhead_pixbuf = GdkPixbuf.Pixbuf.new_from_file(
self.callback_id = None os.path.join(configure.get_pixmap_dir(), "pitivi-playhead.svg"))
self.set_size_request(0, HEIGHT)
self.scales = SCALES self.scales = SCALES
...@@ -142,9 +142,10 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable): ...@@ -142,9 +142,10 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
self.queue_draw() self.queue_draw()
# Gtk.Widget overrides # Gtk.Widget overrides
def configureEventCb(self, widget, unused_event, unused_data=None):
width = widget.get_allocated_width() def do_configure_event(self, unused_event):
height = widget.get_allocated_height() width = self.get_allocated_width()
height = self.get_allocated_height()
self.debug("Configuring, height %d, width %d", width, height) self.debug("Configuring, height %d, width %d", width, height)
# Destroy previous buffer # Destroy previous buffer
...@@ -167,7 +168,7 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable): ...@@ -167,7 +168,7 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
return False return False
def drawCb(self, unused_widget, context): def do_draw(self, context):
if self.pixbuf is None: if self.pixbuf is None:
self.info('No buffer to paint') self.info('No buffer to paint')
return False return False
...@@ -377,11 +378,20 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable): ...@@ -377,11 +378,20 @@ class ScaleRuler(Gtk.DrawingArea, Zoomable, Loggable):
frame_num += 1 frame_num += 1
def drawPosition(self, context): def drawPosition(self, context):
height = self.pixbuf.get_height()
# Add 0.5 so that the line center is at the middle of the pixel, # Add 0.5 so that the line center is at the middle of the pixel,
# without this the line appears blurry. # without this the line appears blurry.
xpos = self.nsToPixel(self.position) - self.pixbuf_offset + 0.5 xpos = self.nsToPixel(self.position) - self.pixbuf_offset + 0.5
context.set_line_width(PLAYHEAD_WIDTH + 2) context.set_line_width(PLAYHEAD_WIDTH)
set_cairo_color(context, (255, 0, 0)) set_cairo_color(context, (255, 0, 0))
context.move_to(xpos, 0) context.move_to(xpos, height / 2)
context.line_to(xpos, context.get_target().get_height()) context.line_to(xpos, height)
context.stroke() context.stroke()
playhead_width = self.playhead_pixbuf.props.width
playhead_height = self.playhead_pixbuf.props.height
xpos -= playhead_width / 2
ypos = (height - playhead_height) / 2
Gdk.cairo_set_source_pixbuf(context, self.playhead_pixbuf, xpos, ypos)
context.rectangle(xpos, ypos, playhead_width, playhead_height)
context.fill()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment