📄 bvqxfigure.m
字号:
'UserData', iStr.UserData, ...
'Visible', iVis);
% what type
switch iCTyp
% axes
case {'xaxes'}
% axes options are in caption
if ischar(iCap) && ...
~isempty(iCap)
[myaxopts, myonum] = splittocell(iCap, ',');
% remove last if impair number
if rem(myonum, 2)
myaxopts(end) = [];
myonum = myonum - 1;
end
% basic test on options
for myon = 1:2:myonum
% option name in hyphens
if ~isempty(myaxopts{myon}) && ...
myaxopts{myon}(1) == '''' && ...
myaxopts{myon}(end) == ''''
myaxopts{myon} = myaxopts{myon}(2:end-1);
end
% option setting with value evaluation
try
oStr.(myaxopts{myon}) = eval(myaxopts{myon + 1});
catch
break;
end
end
end
% create axes object
hOut = axes(oStr);
% images
case {'ximage'}
% no useful argument
if isempty(iCap)
error( ...
'BVQXfigure:BadImageContent', ...
'Images either need a filename or a binary content.' ...
);
end
% filename
if ischar(iCap)
% try to read image
try
imgpdata = imread(iCap(:)');
if isempty(imgpdata)
error('INVALID_IMAGE');
end
catch
error( ...
'BVQXfigure:BadImageFile', ...
'The file (%s) is not readable or corrupt.', ...
iCap(:)' ...
);
end
% binary image data
elseif isnumeric(iCap)
imgpdata = iCap;
iStr.Caption = '';
% only 2-D -> grayscale
if ndims(imgpdata) < 3
imgpdata(:, :, 2:3) = imgpdata(:, :, [1, 1]);
end
% invalid content
else
error( ...
'BVQXfigure:BadImageContent', ...
'Images either need a filename or a binary content.' ...
);
end
% apply shading if requested (watermarks, etc.)
if hasBGColor && ...
hasFGColor
imgpdata(:, :, 1) = ...
uint8(floor(double(imgpdata(:, :, 1)) * iCFG(1) + ...
255 * iCBG(1) * (1 - iCFG(1))));
imgpdata(:, :, 2) = ...
uint8(floor(double(imgpdata(:, :, 2)) * iCFG(2) + ...
255 * iCBG(2) * (1 - iCFG(2))));
imgpdata(:, :, 3) = ...
uint8(floor(double(imgpdata(:, :, 3)) * iCFG(3) + ...
255 * iCBG(3) * (1 - iCFG(3))));
end
% create axes object and image
hOut = axes(oStr);
xchildren = image(imgpdata, 'Parent', hOut);
% MATLAB BUG !!! image() resets the axes' DeleteFcn !!!
set(hOut, 'DeleteFcn', oStr.DeleteFcn);
% reset axes visibility to off
set(hOut, 'Visible', 'off');
set(xchildren, 'Visible', iVis, 'UserData', uuid);
% extended labels (with tex func :)
case {'xlabel', 'xlink'}
% replace empty labels with 'tex:' label
if isempty(iCap)
iCap = 'tex:';
end
% create axes object and text child
hOut = axes(oStr);
myct = struct('Parent', hOut);
myct.Units = 'normalized';
myct.Position = [0.0 0.0];
myct.HorizontalAlign = iStr.HAlign;
myct.VerticalAlign = iStr.VAlign;
myct.FontAngle = iStr.FontItalic;
myct.FontName = iStr.FontName;
myct.FontSize = iStr.FontSize;
myct.FontWeight = iStr.FontWeight;
myct.FontUnits = 'points';
if ~isempty(iStr.Rotation)
myct.Rotation = iStr.Rotation(1);
end
myct.UserData = uuid;
% interpreter
if numel(iCap) > 3 && ...
strcmpi(iCap(1:4), 'tex:')
myct.Interpreter = 'tex';
iCap(1:4) = [];
else
myct.Interpreter = 'none';
end
% y - wise rotation
if numel(iCap) > 1 && ...
strcmpi(iCap(1:2), 'y:')
myct.Rotation = 90;
iCap(1:2) = [];
end
% special "align" treatment
switch lower(iStr.HAlign)
case {'center'}
myct.Position(1) = 0.5;
case {'right'}
myct.Position(1) = 1.0;
end
switch lower(iStr.VAlign)
case {'middle'}
myct.Position(2) = 0.5;
case {'top'}
myct.Position(2) = 1.0;
end
% do we deal with a link ?
LinkTarget = [];
if strcmp(iCTyp, 'xlink')
CapParts = splittocell(iCap, '|', 1);
iCap = CapParts{1};
if numel(CapParts) > 1
LinkTarget = CapParts{2};
end
end
% finally, set Position
xchildren = text(myct.Position(1), myct.Position(2), iCap, myct);
set(hOut, 'Visible', 'off');
set(xchildren, 'Visible', iVis);
iStr.Caption = iCap;
oStr.Label = myct;
% set link handler
if ~isempty(LinkTarget) && ...
~isempty(bvqxfigure_factory.linkhandler)
set(xchildren, 'ButtonDownFcn', ...
['!' bvqxfigure_factory.linkhandler{1} ...
deblank(LinkTarget) ...
bvqxfigure_factory.linkhandler{2}]);
try
set(xchildren, 'Color', 'red');
catch
% do nothing
end
end
% keep note of children and color
oStr.xcolor = get(xchildren, 'Color');
% progress bars
case {'xprogress'}
% set correct empty caption
if isempty (iCap)
iCap = 'x: ';
end
% set progress bar range
if numel(iStr.MinMaxTop) > 2 && ...
~any(isnan(iStr.MinMaxTop) || ...
isinf(iStr.MinMaxTop))
iStr.MinMaxTop = iStr.MinMaxTop(1:3);
else
iStr.MinMaxTop = [0, 1, 0];
end
% create axes object
hOut = axes(oStr);
set(hOut, 'Units', 'normalized');
% the problem with images is that they do not have a position
% property for the parent axes object, so we need TWO axes objects
% so as to make this work "properly"...
% with no sliderstep value make "flat" bar with rectangle
if isempty(iStr.SliderStep) || ...
iStr.SliderStep(1) ~= 1
iStr.ProgType = 'flat';
% make bar from filling rectangle and surrounding line
xchildren = rectangle( ...
'Position', [0, 0, eps, eps], ...
'FaceColor', iCFG, ...
'EdgeColor', iCFG, ...
'EraseMode', 'background', ...
'UserData', uuid, ...
'Visible', iVis);
% make "round" progress bars with graded colour image
else
iStr.ProgType = 'round';
try
iStr.Value(end + 1) = 0;
catch
% do nothing
end
% how many colors
numlines = max(bvqxfigure_factory.progbarface, iStr.SliderStep(2));
numcols = fix((numlines + 1) / 2);
% put together bar image
imgpdata(1, numlines, 3) = uint8(0);
for colc = 1:numcols
colb = (numcols - colc) / numcols;
colf = colc / numcols;
ridx = [colc (1 + numlines - colc)];
imgpdata(1, ridx, 1) = ...
uint8(fix(255 * (colb * iCBG(1) + colf * iCFG(1)) + 0.5));
imgpdata(1, ridx, 2) = ...
uint8(fix(255 * (colb * iCBG(2) + colf * iCFG(2)) + 0.5));
imgpdata(1, ridx, 3) = ...
uint8(fix(255 * (colb * iCBG(3) + colf * iCFG(3)) + 0.5));
end
% if direction is Y-axes, reshape image to Yx1
if numel(iCap) < 1 || lower(iCap(1)) ~= 'y'
imgpdata = reshape(imgpdata, [numlines, 1, 3]);
end
% add image to "first" axes
xchildren = image(imgpdata, 'Parent', hOut);
set(xchildren, 'Visible', iVis, 'UserData', uuid);
set(hOut, 'UserData', uuid, 'Visible', 'off');
% create "second" axes object for outline and caption
hOut = axes(oStr);
set(hOut, 'Units', 'normalized');
end
xchildren = [xchildren, line( ...
[0, 1, 1, 0, 0], [0, 0, 1, 1, 0], ...
'Parent', hOut, ...
'EraseMode', 'none', ...
'Color', iCBG * 0.75, ...
'UserData', uuid, ...
'Visible', iVis)];
% prepare Caption
if numel(iCap) > 1 && ...
iCap(2) == ':'
ixCap = {iCap(1), iCap(3:end)};
else
ixCap = {'x', iCap};
end
myct = struct('Parent', hOut);
myct.Units = 'normalized';
myct.Position = [0.5 0.5];
myct.HorizontalAlign = 'center';
myct.VerticalAlign = 'middle';
myct.FontAngle = iStr.FontItalic;
myct.FontName = iStr.FontName;
myct.FontSize = iStr.FontSize;
myct.FontUnits = 'points';
myct.FontWeight = iStr.FontWeight;
myct.UserData = uuid;
myct.Visible = iVis;
if prod(iCFG) < 0.125 && ...
all(iCFG < 0.25)
itColor = [0.9325 0.9325 0.9325];
else
itColor = iCBG * 0.125;
end
myct.Color = itColor;
% if tex interpreter is requested (prefix: "tex:") use it!
if numel(ixCap{2}) > 3 && ...
strcmpi(ixCap{2}(1:4), 'tex:')
myct.Interpreter = 'tex';
ixCap{2} = ixCap{2}(5:end);
else
myct.Interpreter = 'none';
end
% generate text object
hTxt = text(myct.Position(1), myct.Position(2), ixCap{2}, myct);
if ~isempty(ixCap{1}) && ...
lower(ixCap{1}) =='y'
set(hTxt, 'Rotation', 90);
iStr.ProgDir = 'y';
else
iStr.ProgDir = 'x';
end
iStr.Caption = ixCap{2};
% get size, set Units back to original units and init progress
set(hOut, 'Units', iStr.Units, 'Visible', 'off');
try
oStr.progress = iStr.Value(end);
catch
oStr.progress = 0;
end
xchildren(end + 1) = hTxt;
end
% keep a note on what type was used
iStr.xtype = iCTyp;
% "only" a MATLAB uicontrol type
else
% deal with radiobutton / radiogroup click events
iStr.Callbacks{1} = iStr.Callback;
if strcmp(iRTyp, 'radiobutton') && ...
~isempty(iStr.RGroup)
iStr.Callback = 'BVQXfigure(gcbo,''rgroupclick'');';
% otherwise standard behaviour
else
iStr.Callbacks = {iStr.Callback, '', iStr.CallbackDblClick};
iStr.Callback = 'BVQXfigure(gcbo,''doubleclick'');';
end
% check MinMaxTop according to edit/multiedit type
if strcmp(iCTyp, 'edit')
iStr.MinMaxTop = [0 0 0];
elseif strcmp(iCTyp, 'multiedit')
iStr.MinMaxTop = [0 2 0];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -