impoly 工具似乎修改了figure window 的WindowButtonDownFcn、WindowButtonMotionFcn、WindowButtonUpFcn、WindowKeyPressFcn 和WindowKeyReleaseFcn 回调。我原本以为你不能修改其中的任何一个,因为它们会被impoly 用于其功能的回调函数覆盖。但是,事实证明它们仍然可以正确调用。这为您提供了更多选择:
修改WindowButtonDownFcn:
要添加检测双击的功能,您必须使用WindowButtonDownFcn 回调。例如:
set(gcf, 'WindowButtonDownFcn', @double_click_fcn);
h = impoly();
% Define this function somewhere (nested, local, etc.):
function double_click_fcn(hSource, ~)
if strcmp(get(hSource, 'SelectionType'), 'open')
% Advance to next frame
end
end
修改WindowScrollWheelFcn:
每当我创建一个必须滚动浏览多个时间点/绘图/图像的 GUI 时,我喜欢使用 WindowScrollWheelFcn 回调来推进(向上滚动)或倒回(向下滚动)数据。您可以使用它从帧滚动到帧,显示已经绘制的任何多边形(如果有的话)或允许用户创建一个新多边形。例如:
set(gcf, 'WindowScrollWheelFcn', @scroll_fcn)
h = impoly();
% Define this function somewhere (nested, local, etc.):
function scroll_fcn(~, eventData)
if (eventData.VerticalScrollCount < 0)
% Mouse has been scrolled up; move to next frame
else
% Mouse has been scrolled down; move to previous frame
end
end
修改WindowKeyPressFcn
您还可以使用WindowKeyPressFcn 回调来允许您使用键盘按钮(例如左右箭头键)前进帧。例如:
set(gcf, 'WindowKeyPressFcn', @keypress_fcn)
h = impoly();
% Define this function somewhere (nested, local, etc.):
function keypress_fcn(~, eventData)
switch eventData.Key
case 'rightarrow'
% Right arrow pressed; move to next frame
case 'leftarrow'
% Left arrow pressed; move to previous frame
end
end
有关创建所有这些回调的更多信息,see here。