[pitivi] ruler.py: draw times using gtk.Ruler method of determining scale/interval
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pitivi] ruler.py: draw times using gtk.Ruler method of determining scale/interval
- Date: Thu, 10 Sep 2009 12:07:12 +0000 (UTC)
commit 4ab34db138d77182f31812e2c0b236af00ff200e
Author: Brandon Lewis <brandon_lewis berkeley edu>
Date: Tue Sep 8 12:40:17 2009 -0700
ruler.py: draw times using gtk.Ruler method of determining scale/interval
pitivi/ui/ruler.py | 45 +++++++++++++++++++++++++++------------------
1 files changed, 27 insertions(+), 18 deletions(-)
---
diff --git a/pitivi/ui/ruler.py b/pitivi/ui/ruler.py
index 073bf94..69ea7c0 100644
--- a/pitivi/ui/ruler.py
+++ b/pitivi/ui/ruler.py
@@ -47,6 +47,7 @@ class ScaleRuler(gtk.Layout, Zoomable, Loggable):
border = 0
min_tick_spacing = 3
+ scale = [0.1, 0.25, 0.5, 1, 2, 5, 10, 60, 300, 600, 3600]
def __init__(self, hadj):
gtk.Layout.__init__(self)
@@ -305,31 +306,39 @@ class ScaleRuler(gtk.Layout, Zoomable, Loggable):
drawTick(paintpos, height)
paintpos += zoomRatio * interval
- def drawTimes(interval):
+ def drawTimes():
# figure out what the optimal offset is
- spacing = zoomRatio * interval
+
+ layout = self.create_pango_layout(time_to_string(0))
+ textwidth, textheight = layout.get_pixel_size()
+
+ for s in self.scale:
+ spacing = Zoomable.zoomratio * s
+ if spacing > 2 * textwidth:
+ break
+
+ interval = long(gst.SECOND * s)
+
offset = self.pixmap_offset % spacing
seconds = self.pixelToNs(self.pixmap_offset)
paintpos = float(self.border) + 2
if offset > 0:
seconds += self.pixelToNs(spacing - offset)
paintpos += spacing - offset
- layout = self.create_pango_layout(time_to_string(0))
- textwidth, textheight = layout.get_pixel_size()
shaded = self.getShadedDurationWidth()
- if spacing > textwidth:
- while paintpos < allocation.width:
- timevalue = time_to_string(long(seconds))
- layout.set_text(timevalue)
- if paintpos < shaded:
- state = gtk.STATE_ACTIVE
- else:
- state = gtk.STATE_NORMAL
- self.pixmap.draw_layout(
- self.style.fg_gc[state],
- int(paintpos), 0, layout)
- paintpos += spacing
- seconds += long(interval * gst.SECOND)
+
+ while paintpos < allocation.width:
+ timevalue = time_to_string(long(seconds))
+ layout.set_text(timevalue)
+ if paintpos < shaded:
+ state = gtk.STATE_ACTIVE
+ else:
+ state = gtk.STATE_NORMAL
+ self.pixmap.draw_layout(
+ self.style.fg_gc[state],
+ int(paintpos), 0, layout)
+ paintpos += spacing
+ seconds += interval
def drawFrameBoundaries():
ns_per_frame = float(1 / self.frame_rate) * gst.SECOND
@@ -354,9 +363,9 @@ class ScaleRuler(gtk.Layout, Zoomable, Loggable):
zoomRatio = self.zoomratio
interval_sizes = ((60, 0.70), (10, 0.5), (1, 0.25), (0.1, 0.15))
drawFrameBoundaries()
+ drawTimes()
for interval, height in interval_sizes:
drawTicks(interval, height)
- drawTimes(interval)
def drawPosition(self, context, allocation):
if self.getShadedDuration() <= 0:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]