function swooshprop(varargin)
% SWOOSHPROP(OBJ, PROP, VALUE, ...)
%
% Make the setting of the object OBJ property PROP be lazy, or
% slow. The VALUE is the destination value.
%
% This works with a timer, so that users can continue interacting
% with a plot, and possibly redirect an in progress animation.
if mod(nargin,3) ~= 0
error('Wrong number of arguments for swooshprop.'); %#ok
end
idx = 1;
for i=1:3:length(varargin)
opv(idx).obj = varargin{i}; %#ok
if ~ishandle(opv(idx).obj)
error('Argument %d must be an HG handle.', i); %#ok
end
opv(idx).prop = varargin{i+1}; %#ok
if ~ischar(opv(idx).prop)
error('Argument %d must be a string/Property name for %s',...
i+1, get(opv(idx).obj,'type')); %#ok
end
opv(idx).val = varargin{i+2}; %#ok
if ~isnumeric(opv(idx).val)
error('Argument %d must be numeric',...
i+2); %#ok
end
opv(idx).steps = 10; %#ok
idx = idx+1;
end
origopv = getappdata(0,'SwooshPropVector');
newopv = struct('obj',[],'prop',[],'val',[],'steps',[]);
idx = 1;
for i=1:length(origopv)
if origopv.steps > 0
newopv(idx) = origopv(i);
idx = idx+1;
end
end
for i=1:length(opv)
matchingobj = find([newopv.obj] == opv(i).obj);
matchingprop = find(strcmp({newopv(matchingobj).prop}, opv(i).prop));
if ~isempty(matchingprop)
newopv(matchingprop) = opv(i);
else
newopv(idx) = opv(i);
idx = idx+1;
end
end
setappdata(0,'SwooshPropVector', newopv);
llt = getappdata(0,'SwooshPropTimer');
if isempty(llt)
llt = timer('Period',.1,...
'StopFcn',@stopfcn,...
'TimerFcn',@timeoutfcn,...
'ErrorFcn',@errfcn,...
'BusyMode','Queue',...
'ExecutionMode','fixedDelay');
setappdata(0,'SwooshPropTimer', llt);
end
% llt
set(llt,'TasksToExecute',max([newopv.steps]));
if strcmp(get(llt,'Running'),'off')
start(llt);
end
function errfcn(obj, event) %#ok
disp('An error occured in the timeout fcn.');
function timeoutfcn(obj, event)
obj; %#ok
event; %#ok
opv = getappdata(0,'SwooshPropVector');
for i=1:length(opv)
try
%opv(i)
nextvalue(opv(i));
opv(i).steps = opv(i).steps - 1;
catch
opv(i).step = 0;
end
end
setappdata(0,'SwooshPropVector',opv);
drawnow;
function stopfcn(obj, event)
obj; %#ok
event; %#ok
opv = getappdata(0,'SwooshPropVector');
for i=1:length(opv)
try %#ok
nextvalue(opv(i), opv(i).val);
end
opv(i).steps = 0;
end
rmappdata(0,'SwooshPropVector');
drawnow;
function value = nextvalue(opv, value)
prop = opv.prop;
startval = get(opv.obj,prop);
if nargin == 1
dest = opv.val;
value = (dest - startval) / 2 + startval;
end
set(opv.obj,prop,value);