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)