Get the board to print

This commit is contained in:
2012-04-17 18:07:04 -04:00
parent f596e0f3ee
commit 824bf6c889
2 changed files with 46 additions and 6 deletions

View File

@ -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):