pitivi r1221 - in branches/SOC_2008_BLEWIS: . pitivi/ui
- From: blewis svn gnome org
- To: svn-commits-list gnome org
- Subject: pitivi r1221 - in branches/SOC_2008_BLEWIS: . pitivi/ui
- Date: Fri, 25 Jul 2008 23:22:39 +0000 (UTC)
Author: blewis
Date: Fri Jul 25 23:22:38 2008
New Revision: 1221
URL: http://svn.gnome.org/viewvc/pitivi?rev=1221&view=rev
Log:
* pitivi/ui/ruler.py:
rewrote drawRuler() to be a bit more intelligent about how it
determines line spacing and where to place text. added
min_tick_spacing property to control when ticks should become visible.
Softened the appearence of the tick lines by setting their color to
dark gray value.
Modified:
branches/SOC_2008_BLEWIS/ChangeLog
branches/SOC_2008_BLEWIS/pitivi/ui/ruler.py
Modified: branches/SOC_2008_BLEWIS/pitivi/ui/ruler.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/ruler.py (original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/ruler.py Fri Jul 25 23:22:38 2008
@@ -28,6 +28,7 @@
import gst
import pitivi.instance as instance
from complexinterface import Zoomable
+from pitivi.utils import time_to_string
class ScaleRuler(gtk.Layout, Zoomable):
@@ -41,6 +42,7 @@
}
border = 0
+ min_tick_spacing = 3
def __init__(self, hadj):
gst.log("Creating new ScaleRule")
@@ -199,86 +201,66 @@
self.queue_resize()
def drawRuler(self, context, allocation):
- context.save()
-
- zoomRatio = self.getZoomRatio()
-
- paintpos = float(self.border) + 0.5
- seconds = 0
- secspertic = 1
-
- timeprint = 0
- ticspertime = 1
-
- # FIXME : this should be beautified (instead of all the if/elif/else)
- if zoomRatio < 0.05:
- #Smallest tic is 10 minutes
- secspertic = 600
- if zoomRatio < 0.006:
- ticspertime = 24
- elif zoomRatio < 0.0125:
- ticspertime = 12
- elif zoomRatio < 0.025:
- ticspertime = 6
- else:
- ticspertime = 3
- elif zoomRatio < 0.5:
- #Smallest tic is 1 minute
- secspertic = 60
- if zoomRatio < 0.25:
- ticspertime = 10
- else:
- ticspertime = 5
- elif zoomRatio < 3:
- #Smallest tic is 10 seconds
- secspertic = 10
- if zoomRatio < 1:
- ticspertime = 12
- else:
- ticspertime = 6
- else:
- #Smallest tic is 1 second
- if zoomRatio < 5:
- ticspertime = 20
- elif zoomRatio < 10:
- ticspertime = 10
- elif zoomRatio < 20:
- ticspertime = 5
- elif zoomRatio < 40:
- ticspertime = 2
-
- while paintpos < allocation.width:
+ # there are 4 lengths of tick mark:
+ # full height: largest increments, 1 minute
+ # 3/4 height: 10 seconds
+ # 1/2 height: 1 second
+ # 1/4 height: 1/10 second (might later be changed to 1 frame in
+ # project framerate)
+
+ # At the highest level of magnification, all ticmarks are visible. At
+ # the lowest, only the full height tic marks are visible. The
+ # appearance of text is dependent on the spacing between tics: text
+ # only appears when there is enough space between tics for it to be
+ # readable.
+
+ def textSize(text):
+ return context.text_extents(text)[2:4]
+
+ def drawTick(paintpos, height):
context.move_to(paintpos, 0)
+ context.line_to(paintpos, allocation.height * height)
- if seconds % 600 == 0:
- context.line_to(paintpos, allocation.height)
- elif seconds % 60 == 0:
- context.line_to(paintpos, allocation.height * 3 / 4)
- elif seconds % 10 == 0:
- context.line_to(paintpos, allocation.height / 2)
- else:
- context.line_to(paintpos, allocation.height / 4)
-
- if timeprint == 0:
- # draw the text position
- hours = int(seconds / 3600)
- mins = seconds % 3600 / 60
- secs = seconds % 60
- time = "%02d:%02d:%02d" % (hours, mins, secs)
- txtwidth, txtheight = context.text_extents(time)[2:4]
- context.move_to( paintpos - txtwidth / 2.0,
- allocation.height - 2 )
- context.show_text( time )
- timeprint = ticspertime
- timeprint -= 1
-
- paintpos += zoomRatio * secspertic
- seconds += secspertic
-
- #Since drawing is done in batch we can't use different styles
- context.set_line_width(1)
- context.set_source_rgb(0, 0, 0)
+ def drawText(paintpos, time, txtwidth, txtheight):
+ # draw the text position
+ time = time_to_string(time)
+ context.move_to( paintpos - txtwidth / 2.0,
+ allocation.height - 2 )
+ context.show_text( time )
+
+ def drawTicks(interval, height):
+ paintpos = float(self.border) + 0.5
+ spacing = zoomRatio * interval
+ if spacing >= self.min_tick_spacing:
+ while paintpos < allocation.width:
+ drawTick(paintpos, height)
+ paintpos += zoomRatio * interval
+
+ def drawTimes(interval):
+ # figure out what the optimal offset is
+ paintpos = float(self.border) + 0.5
+ seconds = 0
+ spacing = zoomRatio * interval
+ textwidth, textheight = textSize(time_to_string(0))
+ if spacing > textwidth:
+ while paintpos < allocation.width:
+ timevalue = long(seconds * gst.SECOND)
+ drawText(paintpos, timevalue, textwidth, textheight)
+ paintpos += spacing
+ seconds += interval
+ context.save()
+ zoomRatio = self.getZoomRatio()
+ # looks better largest tick doesn't run into the text label
+ interval_sizes = ((60, 0.80), (10, 0.75), (1, 0.5), (0.1, 0.25))
+ for interval, height in interval_sizes:
+ drawTicks(interval, height)
+ drawTimes(interval)
+
+ #set a slightly thicker line. This forces anti-aliasing, and gives the
+ #a softer appearance
+ context.set_line_width(1.1)
+ context.set_source_rgb(0.4, 0.4, 0.4)
context.stroke()
context.restore()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]