def mouse_callback(event, x, y, flags, param):
global refPt, image, tiles, wall, selected_tile, l_mouse_button_down, mouse_over_tile,\
clone, offsets
if event == cv2.EVENT_LBUTTONDOWN:
l_mouse_button_down = True
refPt = [(x, y)]
if not draw_tile:
if find_hovered_tile(x,y):
mouse_over_tile = True
offsets = (x - selected_tile.wx - selected_tile.l, y-selected_tile.wy - selected_tile.t)
else:
mouse_over_tile = False
elif event == cv2.EVENT_LBUTTONUP:
l_mouse_button_down = False
if draw_tile:
#Restrict to create tiles that are at least 100 sqpixel big
if (abs(refPt[0][0] - x) * abs(refPt[0][1] - y) >= 100):
newTile = Tile(abs(refPt[0][0] - x), abs(refPt[0][1] - y))
wall.add_tile(newTile, min(refPt[0][0], x), min(refPt[0][1], y))
wall.draw(image)
tiles.append(newTile)
else:
print("dragging the tile")
elif event == cv2.EVENT_RBUTTONUP:
if find_hovered_tile(x,y):
tile_popup()
elif event == cv2.EVENT_MOUSEMOVE:
# TODO: Implement the t r b resize too
if l_mouse_button_down and mouse_over_tile and x >= selected_tile.wx and x <= selected_tile.wx + 5:
new_w = selected_tile.w + selected_tile.wx + selected_tile.l - x
# TODO: Fix when the bezel is resized to the left
print(
"selected_tile.w = {} selected_tile.wx = {} x = {} new_w = {}".format(selected_tile.w, selected_tile.wx, x,
new_w))
if new_w >= MINIMUM_RESIZE_WIDTH:
selected_tile.w = new_w
selected_tile.wx = x - selected_tile.l
image = clone.copy()
wall.draw(image)
print("RESIZING")
elif l_mouse_button_down and mouse_over_tile and not draw_tile:
selected_tile.wx = x - offsets[0]
selected_tile.wy = y - offsets[1]
image = clone.copy()
wall.draw(image)
#TODO: Implement an else that will start drawing the tile while in the draw mode
评论列表
文章目录