I'm trying to implement a line drawn in an axes, that when clicked on will follow the mouse so long as the button is down, and when the button is released the line will stop following. In short, reposition a line on a graph to a new position based on click and drag.
I've been able to get up the point of having the line follow the mouse pointer, the issue is getting the WindowButtonUpFcn to have the line stop following the mouse. I.e. How can I turn WindowButtonMotionFcn off?
Here is the code. It's rough because it's only a mini test program, so don't criticize too much.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x = 0:.1:10;
y = zeros(size(x))+.5;
line(x,y, 'Tag', 'newLine');
set(findobj('Tag', 'newLine'),'ButtonDownFcn',@button_down)
end
function button_down(src,evnt)
% src - the object that is the source of the event
% evnt - empty for this property
set(src,'Selected','on')
set(gcf, 'WindowButtonMotionFcn', @button_motion);
end
function button_motion(src, evnt)
h = findobj('Tag', 'axes1');
pos = get(h, 'CurrentPoint');
disp(pos);
hndl = findobj('Tag', 'newLine');
delete(hndl);
x = 0:.1:10;
y = zeros(size(x))+pos(3);
line(x,y, 'Tag', 'newLine');
set(gcf, 'WindowButtonUpFcn', @button_up);
end
function button_up(src, evnt)
%What to do here?
end