From 824bf6c889645f2d5508fce0e4f858c829277d3b Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Tue, 17 Apr 2012 18:07:04 -0400 Subject: [PATCH] Get the board to print --- lib/goban.py | 22 ++++++++++++++++++++++ widgets/gogame.py | 30 ++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/lib/goban.py b/lib/goban.py index 2893c9a..18cef61 100644 --- a/lib/goban.py +++ b/lib/goban.py @@ -258,6 +258,28 @@ class Goban: return num_deleted + def draw_code(self, pos): + if not self._on_board(pos): + return None + + point = self.board[pos] + + if point == Goban.EMPTY: + code = self.def_draw_codes[pos] + elif point == Goban.BLACK: + code = 'b' + elif point == Goban.WHITE: + code = 'w' + + if pos == self.last_move: + code = code + 'T' + + if pos == self.ko: + code = code + 'C' + + return code + + # def draw_board(self, size, img_res): # ret = pygame.Surface((size,size)) diff --git a/widgets/gogame.py b/widgets/gogame.py index 0909885..fdac747 100644 --- a/widgets/gogame.py +++ b/widgets/gogame.py @@ -26,8 +26,6 @@ class GoGame(gtk.HBox): def init_widgets(self): - self.board_area = gtk.DrawingArea() - # All of this is to create the info box along the right side of the board info_box = gtk.VBox() info_rows = [] @@ -60,14 +58,34 @@ class GoGame(gtk.HBox): info_box.pack_start(self.pass_button, expand=False, padding=10) info_box.pack_start(self.resign_button, expand=False, padding=10) + self.board_area = gtk.DrawingArea() + self.board_area.set_size_request(800, 800) + self.board_area.connect('expose-event', self.draw_board) + self.pack_start(self.board_area) self.pack_end(info_box, expand=False) - def draw_board(self): - gc = self.board_area.get_style().fg_gc[gtk.STATE_NORMAL] - - # gtk.gdk.gdk_pixbuf_scale_simple(img, new_width, new_height, GDK_INTERP_BILINEAR) + # fixme: create a backbuffer pixmap and draw to *that* when we need to update + # the board, then just use *this* to print that to the DrawingArea... + def draw_board(self, widget, event): + gc = widget.get_style().fg_gc[gtk.STATE_NORMAL] + drawable = widget.window + # pixmap = gtk.gdk.Pixmap(window, width, height, depth=-1) + + width, height = widget.size_request() + size = min(width, height) + board_size = self.goban.board_size + inc = size / board_size + + for i in range(len(self.goban.board)): + # Get the right image and scale it + base_img = GoGame.img_res[self.goban.draw_code(i)] + img = base_img.scale_simple(inc, inc, gtk.gdk.INTERP_BILINEAR) + + row = i / board_size + col = i % board_size + drawable.draw_pixbuf(gc, img, 0, 0, inc * col, inc * row, inc, inc) def on_pass(self, widget):