function locklines(tagmoved,taglocked,delta,movecall,upcall) %LOCKLINES locks two movable straight lines created with TESTLINE % % Format: locklines(tagmoved,taglocked,delta,movecall,upcall) % -tagmoved = tag of line that is currently being moved % -taglocked = tag of line locked to moved line % -delta = x or y difference between lines to lock % delta='unlock' removes the movecall callback from both lines % delta='lock' sets the movecall callback for both lines % -movecall: % -if lines are locked, movecall is evaluated here % -if 'unlock' is given, userdata(4) of testlines are set to movecall % % Bill Miller % Updated April 10, 2001 if nargin<3,return,end if ~exist('movecall') movecall=''; end hm=findobj('tag',tagmoved); hl=findobj('tag',taglocked); if (isempty(hm) | isempty(hl)),return,end hax=get(hm,'parent'); pt=get(gca,'currentpoint'); pt=[pt(1,1) pt(1,2)]; ul=get(hl,'userdata'); um=get(hm,'userdata'); tp(1)=um{2}; tp(2)=ul{2}; if ~strcmp(tp(1),tp(2)),return,end xposm=get(hm,'xdata'); yposm=get(hm,'ydata'); xposl=get(hl,'xdata'); yposl=get(hl,'ydata'); xlim=get(hax,'xlim'); ylim=get(hax,'ylim'); if isstr(delta) switch delta case 'lock' switch tp(1) case 'h' delta=abs(yposm(1)-yposl(1)); case 'v' delta=abs(xposm(1)-xposl(1)); end sdelta=num2str(delta); ul{3}=['locklines(''' taglocked ''',''' tagmoved ''',' sdelta ');']; um{3}=['locklines(''' tagmoved ''',''' taglocked ''',' sdelta ');']; set(hl,'userdata',ul) set(hm,'userdata',um) case 'unlock' ul{3}=movecall; um{3}=movecall; set(hl,'userdata',ul) set(hm,'userdata',um) otherwise end return end %delta is a number switch tp(1) case 'h' postype='ydata'; if yposl(1)ylim(2) pos=yposl-delta; poshnd=hm; else pos=yposm+delta; poshnd=hl; end end case 'v' postype='xdata'; if xposl(1)xlim(2) pos=xposl-delta; poshnd=hm; else pos=xposm+delta; poshnd=hl; end end end wbmf=get(gcf,'WindowButtonMotionFcn'); set(gcf,'WindowButtonMotionFcn',''); drawnow set(poshnd,postype,pos) set(gcf,'WindowButtonMotionFcn',wbmf); drawnow %evaluate movecall eval(movecall)