www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgsurfview/@movieplot/movieplot.m
function obj = movieplot(varargin) %MOVIEPLOT Constructor for movie plot component % % obj = cgsurfview.movieplot(varargin) % % Parameters are name-value pairs. Required values are % Parent: figure handle % hColorMap: a colour map matrix % % Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin && isa(varargin{1}, 'cgsurfview.movieplot') obj = varargin{1}; varargin(1) = []; else obj = cgsurfview.movieplot; end % Call parent class constructor obj.abstractplot(varargin{:}); w = mbcgui.widget.AxesContainer(... 'Parent',obj.Parent,... 'Visible', obj.Visible,... 'PositionSetting','outer'); obj.hAxes = w.AxesHandle; set(obj.hAxes,... 'Box','on',... 'Visible',obj.Visible); view(obj.hAxes,3); mv_rotate3d(obj.hAxes, 'ON'); obj.hSlider = xregGui.axisslider('parent',obj.Parent,... 'visible',obj.Visible,'Orientation','horizontal',... 'MarkerSize',8,... 'DragMode','on',... 'DragStopCallback',{@i_Slider,obj},... 'ClickCallback',{@i_Slider,obj}); leftbtn = xregGui.iconuicontrol('parent',obj.Parent,... 'ImageFile',fullfile(cgrespath,'leftarrow.bmp'),... 'TransparentColor',[0 255 0],... 'Callback',{@i_Step,obj,-1}); rightbtn = xregGui.iconuicontrol('parent',obj.Parent,... 'ImageFile',fullfile(cgrespath,'rightarrow.bmp'),... 'TransparentColor',[0 255 0],... 'Callback',{@i_Step,obj,1}); obj.hPlay = uicontrol('Parent',obj.Parent,... 'String','Play','Callback',{@i_Play,obj}); obj.Display = xreggridbaglayout(obj.Parent,... 'elements',{... w, [], [], [], [], []; ... obj.hPlay, [], leftbtn, obj.hSlider, rightbtn, [];... [], [], [], [], [], []},... 'dimension',[3 6],... 'mergeblock',{[1 1],[1 6]},... % axes 'mergeblock',{[2 3],[4 4]},... % slider 'mergeblock',{[2 3],[1 1]},... % play 'rowsizes',[-1 15 15],... 'colsizes',[60 5 15 -1 15 15],... 'border',[10 10 10 10],... 'correctalg','on',... 'gapx',5,... 'visible',obj.Visible); obj.hColorMap = parula(64); obj.plot([]); if isempty(obj.PlotOptions) error(message('mbc:cgsurfview:movieplot:InvalidState')); end i_AddLinkedAxes(obj.PlotOptions,obj.hAxes); %--------------------------- function i_AddLinkedAxes(opts,ax) opts.linkedAxes = [opts.linkedAxes ax]; opts.listeners = mbcgui.hgclassesutil.proplistener(opts.linkedAxes, 'View', 'PostSet', ... mbcutils.callback(@i_AxesRotated,opts)); %--------------------------- function i_AxesRotated(src,evt,opts) if opts.linkRotation % vectorised vw = get(evt.AffectedObject, 'View'); set(opts.linkedAxes,'View',vw); end %--------------------------- function i_Slider(unused1,unused2,obj) obj.pPlotNext; %--------------------------- function i_Step(unused1,unused2,obj,increment) t = getVariableValues(obj.PlotData,3); slider_val = obj.hSlider.Value; [ignore,index] = min(abs(t-slider_val)); index = index + increment; if index>numel(t) || index<1 return; end set(obj.hSlider,'Value',t(index)); obj.pPlotNext; %-------------------------- function i_Play(unused1,unused2,obj) set(obj.hPlay,'String','Stop','UserData',0,... 'Callback',{@i_Stop,obj},'Interruptible','on'); t = getVariableValues(obj.PlotData,3); try for i=1:numel(t) set(obj.hSlider,'Value',t(i)); obj.pPlotNext; drawnow; if get(obj.hPlay,'UserData')==1 break; end end catch ME % It's important that we complete this function, so that % we reset the "Play" button disp(sprintf('Error during "movie" playing: %s',ME.message)); end set(obj.hPlay,'String','Play','UserData',0,'Callback',{@i_Play,obj}); %--------------------------- function i_Stop(unused1,unused2,obj) set(obj.hPlay,'UserData',1);