From: <umg...@us...> - 2006-09-20 15:59:46
|
Revision: 345 http://svn.sourceforge.net/pybridge/?rev=345&view=rev Author: umgangee Date: 2006-09-20 08:59:34 -0700 (Wed, 20 Sep 2006) Log Message: ----------- Added turn indicator to CardArea. Fixed a couple of bugs. Modified Paths: -------------- trunk/pybridge/pybridge/ui/canvas.py trunk/pybridge/pybridge/ui/cardarea.py trunk/pybridge/pybridge/ui/window_bridgetable.py Modified: trunk/pybridge/pybridge/ui/canvas.py =================================================================== --- trunk/pybridge/pybridge/ui/canvas.py 2006-09-20 11:00:26 UTC (rev 344) +++ trunk/pybridge/pybridge/ui/canvas.py 2006-09-20 15:59:34 UTC (rev 345) @@ -79,7 +79,7 @@ """ if self.items.get(id): area = self.items[id]['area'] - del self.item[id] + del self.items[id] self.redraw(*area) @@ -123,7 +123,7 @@ # TODO: Find sources which intersect with area. area = gtk.gdk.Rectangle(x, y, width, height) items = self.items.values() - items.sort(lambda i, j : cmp(i['z-index'], j['z-index']), reverse=True) + items.sort(lambda i, j : cmp(i['z-index'], j['z-index'])) for item in items: pos_x, pos_y = item['area'][0:2] Modified: trunk/pybridge/pybridge/ui/cardarea.py =================================================================== --- trunk/pybridge/pybridge/ui/cardarea.py 2006-09-20 11:00:26 UTC (rev 344) +++ trunk/pybridge/pybridge/ui/cardarea.py 2006-09-20 15:59:34 UTC (rev 345) @@ -208,8 +208,14 @@ """Sets the current trick. Draws representation of current trick to context. - @param trick: a (leader, cards_played) pair. + @param trick: a (leader, cards_played) pair, or None. """ + id = 'trick' + self.trick = trick + if trick is None: + self.remove_item(id) + return + width, height = 200, 200 # (x, y) positions to fit within (width, height) bound box. pos = {Seat.North : ((width - self.card_width)/2, 0 ), @@ -235,7 +241,6 @@ pos_x, pos_y = pos[seat] self.draw_card(context, pos_x, pos_y, card) - id = 'trick' if id in self.items: self.update_item(id, source=surface) else: @@ -244,21 +249,36 @@ - def set_turn(self, seat): + def set_turn(self, turn): + """Sets the turn indicator. + + The turn indicator is displayed as a rounded rectangle around + the hand matching the specified seat. + + @param turn: a member of Seat, or None. """ + id = 'turn' + if turn is None: + self.remove_item(id) + return - @param seat: a member of Seat. - """ -# hand_surface = self.hands[seat]['surface'] -# x = self.hands[seat]['xy'] - 10 -# y = self.hands[seat]['xy'] - 10 -# width = surface.get_width() + 20 -# height = surface.get_height() + 20 -# args = ('turn', surface, pos_x, pos_y, -1) -# if self.items.get('turn'): -# self.update_item(*args) -# else: -# self.add_item(*args) + def xy(w, h): + x, y = self.items['hand-%s' % turn]['xy'](w, h) + return x-10, y-10 + + # TODO: select colours that don't clash with the background. + # TODO: one colour if user can click card, another if not. + width = self.hands[turn]['surface'].get_width() + 20 + height = self.hands[turn]['surface'].get_height() + 20 + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) + context = cairo.Context(surface) + context.set_source_rgb(0.3, 0.6, 0) # Green. + context.paint_with_alpha(0.5) + + if id in self.items: + self.update_item(id, source=surface, xy=xy) + else: + self.add_item(id, surface, xy, -1) def button_release(self, widget, event): Modified: trunk/pybridge/pybridge/ui/window_bridgetable.py =================================================================== --- trunk/pybridge/pybridge/ui/window_bridgetable.py 2006-09-20 11:00:26 UTC (rev 344) +++ trunk/pybridge/pybridge/ui/window_bridgetable.py 2006-09-20 15:59:34 UTC (rev 345) @@ -283,9 +283,12 @@ def setTurnIndicator(self): """Sets the statusbar text to indicate which player is on turn.""" - turn = self.table.game and not self.table.game.isComplete() \ - and self.table.game.whoseTurn() + turn = None + if self.table.game and not self.table.game.isComplete(): + turn = self.table.game.whoseTurn() + self.cardarea.set_turn(turn) + context = self.statusbar.get_context_id('turn') self.statusbar.pop(context) if turn: @@ -385,7 +388,7 @@ self.setDealer(table.dealer) self.setVuln(table.game.vulnNS, table.game.vulnEW) - self.redrawTrick() + self.redrawTrick() # Clear trick. for position in table.game.deal: self.redrawHand(position) if table.seated: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |