def find_cut_and_handles_closest_to_mouse(mouse_x, mouse_y):
"""
takes the mouse's coordinates in the sequencer area and returns the two strips
who share the cut closest to the mouse, or the strip with the closest handle.
Use it to find the handle(s) to select with the grab on the fly operator
"""
view2d = bpy.context.region.view2d
closest_cut = (None, None)
distance_to_closest_cut = 1000000.0
for s in bpy.context.sequences:
channel_offset = s.channel + 0.5
start_x, start_y = view2d.view_to_region(s.frame_final_start, channel_offset)
end_x, end_y = view2d.view_to_region(s.frame_final_start, channel_offset)
distance_to_start = calculate_distance(start_x, start_y, mouse_x, mouse_y)
distance_to_end = calculate_distance(end_x, end_y, mouse_x, mouse_y)
if distance_to_start < distance_to_closest_cut:
closest_cut = (start_x, start_y)
distance_to_closest_cut = distance_to_start
if distance_to_end < distance_to_closest_cut:
closest_cut = (end_x, end_y)
distance_to_closest_cut = distance_to_end
closest_cut_local_coords = view2d.region_to_view(closest_cut[0], closest_cut[1])
frame, channel = round(closest_cut_local_coords[0]), floor(closest_cut_local_coords[1])
return frame, channel
video_editing_mouse.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录