Get the board to print
This commit is contained in:
parent
f596e0f3ee
commit
824bf6c889
22
lib/goban.py
22
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))
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user