def drag_begin(self, widget, drag_context, data):
self.dnd_data_received = False
# get x,y co-ords of source square
x, y = data
if gv.verbose:
print("in drag begin")
print("data=", data)
print("widget_name=", widget.get_name())
print("source sq=", x, y)
stm = gv.jcchess.get_side_to_move()
# convert the x, y co-ords into the shogi representation
# (e.g. 8, 6 is 1g)
sq = gv.board.get_square_posn(x, y)
self.src = sq
if gv.verbose:
print("source square: (x, y) = (", x, ",", y, ") ", sq)
self.src_x = x
self.src_y = y
# set the icon for the drag and drop to the piece that is being
# dragged
self.piece = gv.board.get_piece(x, y)
# get width/height of board square
a = gv.gui.get_event_box(x, y).get_allocation()
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, a.width, a.height)
svghandle = gv.board.get_piece_handle(x, y)
dim = svghandle.get_dimensions()
cr = cairo.Context(surface)
sfw = (a.width * 1.0 / dim.width) * SCALE
sfh = (a.height * 1.0 / dim.height) * SCALE
cr.scale(sfw, sfh)
svghandle.render_cairo(cr)
# set mouse pointer to be in middle of drag icon
surface.set_device_offset(-a.width/2, -a.height/2)
Gtk.drag_set_icon_surface(drag_context, surface)
# clear the square where the piece is being moved from
gv.board.set_square_as_unoccupied(x, y)
评论列表
文章目录