def paint(self, desktop, cr): # check for special "transform" cards that have two sides if self.faceup: cardid = self.cardid else: if not cards.is_token(self.cardid) and self.cardid[-1] == "a": cardid = self.cardid[:-1] + "b" else: cardid = "deckmaster" width = int(math.ceil((self.h if self.tapped else self.w) * desktop.zoom)) surface = desktop.picfactory.get(cardid, width) assert(isinstance(surface, cairo.Surface)) # rotate image phi = math.pi / 2 if self.tapped else 0 phi += math.pi if self.flipped else 0 if self.tapped: cr.translate(surface.get_height() / 2, surface.get_width() / 2) else: cr.translate(surface.get_width() / 2, surface.get_height() / 2) cr.rotate(phi) cr.translate(-surface.get_width() / 2, -surface.get_height() / 2) cr.set_source_surface(surface) cr.paint()
def mouse_motion(self, widget, event): hand = self.get_hand() if self._dragndrop is not None: # Dragging something item = self._dragndrop.item item.repaint() # Update movement coordinates i = self._dragndrop.hand_index self._dragndrop.update_pos(event.x, event.y) if isinstance(item, CardItem): # Card items can be moved to the hand item.visible = (not self.is_over_hand(event.x, event.y) or item.istoken) if not item.istoken and i is not self._dragndrop.hand_index: self.repaint_hand() item.clamp_coords() item.repaint() # Update drag status self._dragndrop.last_x = event.x self._dragndrop.last_y = event.y else: # Not dragging item = self.get_item_at(event.x, event.y) handcard = self.get_hand_card(event.x, event.y) if handcard is not None: self.show_enlarged_card(handcard.id) if self.hover_callback is not None: self.hover_callback(handcard) elif (item is not None and item.visible and isinstance(item, CardItem)): if item.faceup: self.show_enlarged_card(item.cardid, item.flipped) # check for special "transform" cards that have two sides elif (not cards.is_token(item.cardid) and item.cardid[-1] == "a"): self.show_enlarged_card(item.cardid[:-1] + "b", item.flipped) elif item.mine: self.show_enlarged_card(item.cardid, item.flipped) else: self.show_enlarged_card(None) else: self.show_enlarged_card(None) if item is not None and self.hover_callback is not None: self.hover_callback(item)