Started implementing hover and did some additional implementation with the draw code
This commit is contained in:
parent
824bf6c889
commit
8976349450
|
@ -180,23 +180,6 @@ class GUI:
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
def do_hover(self, event):
|
|
||||||
x, y = event.pos
|
|
||||||
row = y / self.board_inc
|
|
||||||
col = x / self.board_inc
|
|
||||||
|
|
||||||
if _magnitude(event.rel) < 3:
|
|
||||||
if x < self.board_size and y < self.board_size:
|
|
||||||
self.goban.set_hover((row,col))
|
|
||||||
else:
|
|
||||||
self.goban.clear_hover()
|
|
||||||
|
|
||||||
elif self.goban.hover != self.goban._real_pos((row,col)):
|
|
||||||
self.goban.clear_hover()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _magnitude(vector):
|
def _magnitude(vector):
|
||||||
x,y = vector
|
x,y = vector
|
||||||
return math.sqrt(x*x + y*y)
|
return math.sqrt(x*x + y*y)
|
||||||
|
|
BIN
ui/res/transparent.png
Normal file
BIN
ui/res/transparent.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 178 B |
|
@ -60,12 +60,41 @@ class GoGame(gtk.HBox):
|
||||||
|
|
||||||
self.board_area = gtk.DrawingArea()
|
self.board_area = gtk.DrawingArea()
|
||||||
self.board_area.set_size_request(800, 800)
|
self.board_area.set_size_request(800, 800)
|
||||||
|
self.board_area.set_events(gtk.gdk.POINTER_MOTION_MASK |
|
||||||
|
gtk.gdk.POINTER_MOTION_HINT_MASK |
|
||||||
|
gtk.gdk.BUTTON_PRESS_MASK |
|
||||||
|
gtk.gdk.BUTTON_RELEASE_MASK)
|
||||||
|
|
||||||
self.board_area.connect('expose-event', self.draw_board)
|
self.board_area.connect('expose-event', self.draw_board)
|
||||||
|
self.board_area.connect('motion-notify-event', self.do_hover)
|
||||||
|
self.board_area.connect('button-press-event', self.do_play)
|
||||||
|
|
||||||
self.pack_start(self.board_area)
|
self.pack_start(self.board_area)
|
||||||
self.pack_end(info_box, expand=False)
|
self.pack_end(info_box, expand=False)
|
||||||
|
|
||||||
|
|
||||||
|
def do_hover(self, widget, event):
|
||||||
|
x = event.x
|
||||||
|
y = event.y
|
||||||
|
width, height = widget.size_request()
|
||||||
|
size = min(width, height)
|
||||||
|
board_size = self.goban.board_size
|
||||||
|
inc = size / board_size
|
||||||
|
|
||||||
|
row = int(y / inc)
|
||||||
|
col = int(x / inc)
|
||||||
|
|
||||||
|
if max(row,col) < board_size:
|
||||||
|
if self.goban._real_pos((row,col)) != self.goban.hover:
|
||||||
|
self.goban.set_hover((row,col))
|
||||||
|
else:
|
||||||
|
self.goban.clear_hover()
|
||||||
|
|
||||||
|
|
||||||
|
def do_play(self, widget, event):
|
||||||
|
print 'GoGame:do_play(): stub'
|
||||||
|
|
||||||
|
|
||||||
# fixme: create a backbuffer pixmap and draw to *that* when we need to update
|
# 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...
|
# the board, then just use *this* to print that to the DrawingArea...
|
||||||
def draw_board(self, widget, event):
|
def draw_board(self, widget, event):
|
||||||
|
@ -111,23 +140,31 @@ def _build_img_res():
|
||||||
ret = {}
|
ret = {}
|
||||||
|
|
||||||
triangle = _load_png('go_t.png')
|
triangle = _load_png('go_t.png')
|
||||||
|
circle = _load_png('go_c.png')
|
||||||
|
|
||||||
ret['w'] = _load_png('go_w.png')
|
ret['w'] = _load_png('go_w.png')
|
||||||
ret['wT'] = _load_png('go_w.png')
|
ret['wT'] = _load_png('go_w.png')
|
||||||
# ret['wT'].blit(triangle, (0,0))
|
|
||||||
ret['wH'] = _load_png('go_w.png', 128)
|
ret['wH'] = _load_png('go_w.png', 128)
|
||||||
|
|
||||||
|
width = ret['wT'].get_width()
|
||||||
|
height = ret['wT'].get_height()
|
||||||
|
triangle.composite(ret['wT'], 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, 255)
|
||||||
|
|
||||||
ret['b'] = _load_png('go_b.png')
|
ret['b'] = _load_png('go_b.png')
|
||||||
ret['bT'] = _load_png('go_b.png')
|
ret['bT'] = _load_png('go_b.png')
|
||||||
# ret['bT'].blit(triangle, (0,0))
|
|
||||||
ret['bH'] = _load_png('go_b.png', 128)
|
ret['bH'] = _load_png('go_b.png', 128)
|
||||||
|
|
||||||
circle = _load_png('go_c.png')
|
width = ret['bT'].get_width()
|
||||||
|
height = ret['bT'].get_height()
|
||||||
|
triangle.composite(ret['bT'], 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, 255)
|
||||||
|
|
||||||
for d in ('u', 'd', 'l', 'r', 'm', 'dl', 'dr', 'ul', 'ur', 'h'):
|
for d in ('u', 'd', 'l', 'r', 'm', 'dl', 'dr', 'ul', 'ur', 'h'):
|
||||||
ret[d] = _load_png('go_' + d + '.png')
|
ret[d] = _load_png('go_' + d + '.png')
|
||||||
ret[d + 'C'] = _load_png('go_' + d + '.png')
|
ret[d + 'C'] = _load_png('go_' + d + '.png')
|
||||||
# ret[d + 'C'].blit(circle, (0,0))
|
|
||||||
|
width = ret[d + 'C'].get_width()
|
||||||
|
height = ret[d + 'C'].get_height()
|
||||||
|
circle.composite(ret[d + 'C'], 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, 255)
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -137,7 +174,31 @@ def _load_png(name, alpha=None):
|
||||||
fullname = os.path.join('ui/res/', name)
|
fullname = os.path.join('ui/res/', name)
|
||||||
image = gtk.gdk.pixbuf_new_from_file(fullname)
|
image = gtk.gdk.pixbuf_new_from_file(fullname)
|
||||||
|
|
||||||
# if alpha is not None:
|
if alpha is not None:
|
||||||
# image.set_alpha(alpha)
|
image = _set_alpha(image, alpha)
|
||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_trans_png = None
|
||||||
|
|
||||||
|
def _set_alpha(image, alpha):
|
||||||
|
"""
|
||||||
|
change_opacity - changes the opacity of pixbuf by combining
|
||||||
|
the pixbuf with a pixbuf derived from a transparent .png
|
||||||
|
|
||||||
|
arguments:
|
||||||
|
alpha -
|
||||||
|
returns: a pixbuf with the transperancy
|
||||||
|
"""
|
||||||
|
|
||||||
|
global _trans_png
|
||||||
|
|
||||||
|
if _trans_png is None:
|
||||||
|
_trans_png = _load_png('transparent.png')
|
||||||
|
|
||||||
|
width = image.get_width()
|
||||||
|
height = image.get_height()
|
||||||
|
_trans_png = _trans_png.scale_simple(width,height,gtk.gdk.INTERP_NEAREST)
|
||||||
|
image.composite(_trans_png, 0, 0, width, height, 0, 0, 1, 1, gtk.gdk.INTERP_NEAREST, alpha)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user