self.clickcount=0
+ self.angle=0
+
def timePressed(self):
""" return how much time a button is pressed """
dt=time.time() - self.lastpress
def getSize(self):
return(self.config.iconsize+self.config.iconspace)
- def draw(self, cr, x, y, mode):
+ def setAngle(self, angle):
+ if self.angle==angle:
+ print "Same angle"
+ return
+
+ self.angle=angle
+
+ # The caller should be responsible for redrawing.
+ # If we call invalidate() here there is the risk of having
+ # icons rotate individually using different angles
+# self.invalidate()
+
+ def draw(self, cr, x, y):
+ self.draw_queued=False
self.x=x
self.y=y
return
cr.save()
+
cr.set_source_rgba(0.1, 0.1, 0.1, 1)
cr.set_line_width(5)
icon=self.icon
- if mode=='l':
- icon2=icon
- else:
- icon2=icon.rotate_simple(gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE)
+ icon2=icon
+
+# Old method. Faster rotation but without support for rotation
+# animation
+
+# if mode=='l':
+# icon2=icon
+# else:
+# icon2=icon.rotate_simple(gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE)
+
+# cr.save()
+# x3=x + (self.config.iconspace/2)
+# y3=y + (self.config.iconspace/2)
+# cr.set_source_pixbuf(icon2, x3, y3)
+#
+# cr.paint()
+# cr.restore()
+
+ # Width is the iconsize plus the empty border around the icon
+ w=self.config.iconsize + self.config.iconspace
+
+ # This is used to locate the center of the surface
+ dx=int(w/2)
+
+ # This is the delta from the center where icons are drawn
+ dx2=int(self.config.iconsize/2)
+
+ # A surface to draw on
+ t_s=cairo.ImageSurface(cairo.FORMAT_ARGB32, w, w)
+
+ # And a context to draw
+ t_cr0=cairo.Context(t_s)
+ t_cr=gtk.gdk.CairoContext(t_cr0)
+
+ # A transformation matrix with dx/dy set to point to the center
+ m=cairo.Matrix(1, 0, 0, 1, dx, dx)
+ t_cr.set_matrix(m)
+ # Transform degrees to rads
+ rot=-1 * pi * 2 * self.angle / 360
+ t_cr.rotate(rot)
+ # Draw the icon
+ t_cr.set_source_pixbuf(icon2, -dx2, -dx2)
+ t_cr.paint()
+
+ # Draw the rotated icon on the main cairo context
cr.save()
- x3=x + (self.config.iconspace/2)
- y3=y + (self.config.iconspace/2)
- cr.set_source_pixbuf(icon2, x3, y3)
+ cr.set_source_surface(t_s, x, y)
cr.paint()
cr.restore()
def doCancel(self):
self.ispressed=False
+ def setWindow(self, window):
+ self.window=window
+
def invalidate(self, window=None):
if window==None:
window=self.window
if window==None:
return
+ if self.draw_queued:
+ print "queued"
+ return
+ self.draw_queued=True
w=self.config.iconsize + self.config.iconspace
rect=gdk.Rectangle(self.x, self.y, w, w)
gdk.Window.invalidate_rect(window, rect, True)
def __init__(self, isconfig=False):
# self.__gobject_init__()
+ self.init_done=False
+
self.size=(0,0)
self.isconfig=isconfig
self.draw_pending=False
+ self.mode=None
+
def do_realize(self, config):
self.config=config
return(ret)
def setMode(self, mode):
+ if self.mode==mode:
+ print "same mode"
+ return
+
self.mode=mode
if not isinstance(self, gtk.Widget):
return
+ do_draw=False
+
try:
v=self.get_property('is-on-current-desktop')
if v:
- self.queue_draw()
+ do_draw=True
else:
self.draw_pending=True
except TypeError:
- self.queue_draw()
+ do_draw=True
+
+ if do_draw:
+ #self.queue_draw()
+ self.angle_timer_start=time.time()
+ gobject.timeout_add(20, self.timerAngle)
+
+ def timerAngle(self):
+ self.queue_draw()
+
+ if self.angle_timer_start==0:
+ self.angle_timer_start=time.time()
+
+ dt=time.time()-self.angle_timer_start
+
+ da=90.0*dt/0.5
+
+ if self.mode=='l':
+ angle=90-da
+ else:
+ angle=da
+
+ if angle>=90:
+ angle=90
+ ret=False
+ elif angle<0:
+ angle=0
+ ret=False
+ else:
+ ret=True
+
+ self.setAngle(angle)
+
+ if ret==False:
+ self.angle_timer_start=0
+
+ return(ret)
def iconAt(self, x, y):
""" Get icon at coordinates x,y. X and Y are in pixels """
continue
ico=self.icons.get(x,y)
- ico.draw(cr, x2, y2, self.mode)
+ ico.draw(cr, x2, y2)
+
+ def setAngle(self, angle):
+ for x,y in self.icons:
+ ic=self.icons.get(x,y)
+ ic.setAngle(angle)
def do_expose_event(self, event):
cr=self.window.cairo_create()
cr.clip()
+ if not self.init_done:
+ self.icons.setWindow(self.window)
+ self.init_done=True
+
self._draw(cr, event)
def setLastIcon(self, icon):