Drehen animiert (sogar während die Karte noch umgedreht wird. Auch mehrfachklicken...
authorJoachim Breitner <mail@joachim-breitner.de>
Thu, 10 May 2007 22:03:39 +0000 (22:03 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Thu, 10 May 2007 22:03:39 +0000 (22:03 +0000)
cairoboard.py
engine.py

index 08f6078..3ddbbe2 100644 (file)
@@ -251,6 +251,7 @@ class CairoPile:
     def __init__(self, fabric, slot):
         self.pile = self.slot
         self.flip_d = None # How far the card has been flipped
+        self.last_rot = 0
 
     def card_flipped(self):
         def update():
@@ -261,6 +262,22 @@ class CairoPile:
             return self.flip_d < 1
 
         self.flip_d = 0
+        self.last_rot = 0
+        gobject.timeout_add(40, update)
+
+    def start_rotation(self, dir):
+        def update():
+            if dir != self.rot_dir:
+                return False
+            self.last_rot -= dir*5
+            if dir*self.last_rot < 0:
+                self.last_rot = 0
+            self.fabric.redraw()
+            return self.last_rot
+
+        self.last_rot += dir * 100
+        self.rot_dir = dir
+
         gobject.timeout_add(40, update)
 
     def translate(self, cr):
@@ -315,22 +332,27 @@ class CairoPile:
         cr.move_to(-w/2, h/2)
         cr.show_text(str(len(self.pile.cards)))
         cr.fill()
+        cr.set_matrix(matrix)
 
-        if self.flip_d == 1:
+        if self.flip_d == 1 and self.last_rot == 0:
             self.super.draw(self, window)
         elif self.slot.card:
             cr = window.cairo_create()
             cr.translate( PILE_X, PILE_Y )
             cr.scale(SCALE, SCALE)
+
             if self.flip_d != 0.5: # Da gibts nichts zu malen
                 cr.translate(0, (1-self.flip_d) * (-3))
                 cr.scale(1, (2 * self.flip_d - 1) )
 
-                self.fabric.setup(self.slot.card)
-                if self.flip_d < 0.5: # back side
-                    self.slot.card.guiinfo.draw_back(cr)
-                else:
-                    self.slot.card.guiinfo.draw(cr)
+            if self.last_rot:
+                cr.rotate(self.last_rot/100.0 * math.pi/2)
+
+            self.fabric.setup(self.slot.card)
+            if self.flip_d < 0.5: # back side
+                self.slot.card.guiinfo.draw_back(cr)
+            else:
+                self.slot.card.guiinfo.draw(cr)
              
 class CairoCard:
     def __init__(self, fabric, card):
index 7e62080..1022718 100644 (file)
--- a/engine.py
+++ b/engine.py
@@ -271,10 +271,14 @@ class Pile(Slot):
 
     def rotate_right(self):
         if self.card:
+            if self.guiinfo:
+                self.guiinfo.start_rotation(-1)
             self.card.rotate_right()
 
     def rotate_left(self):
         if self.card:
+            if self.guiinfo:
+                self.guiinfo.start_rotation(1)
             self.card.rotate_left()
         
 class HandSlot(Slot):