function tsWindowButtonMotionFcn(eventSrc, eventData, h)

%% Only take action if a time series has been selected and a starting point
%% recorded

if (strcmp(h.State,'TimeseriesScaling') || strcmp(h.State,'TimeseriesTranslating')) ...
        && ~h.SelectionStruct.Arrowpressed && ~isempty(h.SelectionStruct.StartPoint)               
    %% Get the current point
    pt = get(gca,'CurrentPoint');  
    point = pt(1,1:2);
    
    %% Move/scale the selected time series
    if strcmp(h.State,'TimeseriesTranslating')
        h.move(point,'motion')
    elseif strcmp(h.State,'TimeseriesScaling')
        h.scale(point,'motion')
    end
    %h.draw
elseif strcmp(h.State,'IntervalSelecting')
    %% Get the current point
    pt = get(gca,'CurrentPoint');  
    point = pt(1,1:2);
    
    %% For each selected wave update the last selection interval
    for k=1:length(h.Waves)
        if ~isempty(h.Waves(k).View.SelectedInterval)
            h.Waves(k).View.SelectedInterval(end,:) = [h.Waves(k).View.SelectedInterval(end,1), ...
                pt(1,1)];
        else
            thisview.SelectedInterval = [pt(1,1) pt(1,1)];
        end
    end  
    
    %% Refresh - call draw on each wave to avoid triggering a viewchnage
    for k=1:length(h.waves)
       %%% Disabled due to background rendering prob h.waves(k).RefreshMode = 'quick';
       h.waves(k).draw;
    end
    
    drawnow expose
    
elseif strcmp(h.State,'TimeSelecting')
    %% Get the current point
    pt = get(gca,'CurrentPoint');  
    point = pt(1,1:2);
    
    %% For each selected wave update the last selection interval
    for k=1:length(h.Waves)
        if ~isempty(h.Waves(k).View.SelectedTimes)
            h.Waves(k).View.SelectedTimes(end,:) = [h.Waves(k).View.SelectedTimes(end,1), ...
                pt(1,1)];
        else
            thisview.SelectedTimes = [pt(1,1) pt(1,1)];
        end
    end  
    
    %% Refresh - call draw on each wave to avoid triggering a viewchnage
    for k=1:length(h.waves)
       %%% Disabled due to background rendering prob h.waves(k).RefreshMode = 'quick';
       h.waves(k).draw;
    end
    
    drawnow expose
elseif strcmp(h.State,'None')
    hoverfig(eventSrc, eventData);
end