1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| function obj = ProgressBarCircular2(varargin)
% Input arguments number check
if ~nargin || mod(nargin,2)
error('Incorrect number of input arguments');
end
% Initialize parameters
action = '';
value = -1;
obj = -1;
tag = '';
color=[50/255 155/255 255/255 ];
% Input arguments assign
for k=1:2:nargin
prop = varargin{k};
data = varargin{k+1};
if strcmpi(prop,'action')
action = data;
elseif strcmpi(prop,'value')
value = data;
elseif strcmpi(prop,'handle')
obj = data;
elseif strcmpi(prop,'color')
color =data;
end
end
% Process data
if strcmpi(action,'new')
% Create a new loader and return handle
initLoader(obj);
elseif strcmpi(action,'update')
% Check if a valid value has been specified
if ~isnumeric(value) || value < 0 || value > 100
error('Value property value must be a number between 0 and 100')
end
% Update desired loader
updateLoader(obj,value,color)
elseif strcmpi(action,'finish')
if ~isnumeric(value) || value ~= 100
error('Value property value must be a number between 0 and 100')
end
finishLoader(obj,value,color)
else
error('Action property value must evaluate to ''new'',''update'' or ''finish''')
end
end
%%
% Create a new loader
function initLoader(obj)
% Create axes and progress text
hdl.hAxes = axes(...
'Parent',obj,...
'Units','pixels',...
'Position',[390 158 40 40 ],...
'Xtick',[],...
'Ytick',[],...
'xlim',[-1 1],...
'ylim',[-1 1],...
'color',[1 1 1],...
'XLimMode','manual',...
'tag','handler_Axe',...
'YLimMode','manual');
hdl.progressText = uicontrol(...
'style','text',...
'Units','pixels',...
'Position',[420 150 150 40],...
'string','Progress : 0%',...
'BackgroundColor',[1 1 1],...
'HorizontalAlignment','left',...
'tag','handler_Circulaire',...
'ForegroundColor','r');
set(hdl.hAxes,...
'Units', 'normalized');
set(hdl.progressText ,...
'Units', 'normalized');
% Axes settings
axis equal
axis off
% Update gui data
guidata(obj,hdl);
end
%%
% Update the desired loader
function updateLoader(obj,value,color)
% Get gui data
hdl = guidata(obj);
% Clear axes
cla(hdl.hAxes)
% draw preloader
sectors = 360;
angles = 0:2*pi/sectors : 2*pi*value/100;
xs = .6*[sin(angles),.5*sin(flipdim(angles,2))];
ys = .6*[cos(angles),.5*cos(flipdim(angles,2))];
hdl.pre = fill(xs,ys,color,'Parent',hdl.hAxes);
% Axes settings
axis(hdl.hAxes,'equal')
axis(hdl.hAxes,'off')
hold(hdl.hAxes,'off')
set(hdl.hAxes,...
'Xtick',[],...
'Ytick',[],...
'xlim',[-1.5 1.5],...
'ylim',[-1.5 1.5],...
'XLimMode','manual',...
'YLimMode','manual');
% Update progress text
set(hdl.progressText,'string',sprintf('Effacement en cours : \n %d %%',value))
% Update gui data
guidata(obj,hdl);
end
function finishLoader(obj,value,color)
% Delete figure if progress has reached 100%
if value == 100
% Get gui data
hdl = guidata(obj);
% Clear axes
cla(hdl.hAxes)
tic;%depart du chronometre
for i=1:10000000
t=toc;
if t<2
set(hdl.progressText,'string',sprintf('Effacement en cours : \n %d %%',value))
elseif t>2 && t<7
set(hdl.progressText,'string',sprintf(' RAZ Données : \n Terminée'))
pause(0.01)
elseif t>7
delete(hdl.progressText)
delete(hdl.hAxes)
break;
end
end
end
end |
Partager