forked from sakoay/MovieSlider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makePositionedFigure.m
41 lines (32 loc) · 1.3 KB
/
makePositionedFigure.m
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
function [figHandle, position] = makePositionedFigure(position, monitor, positionMode, varargin)
% Default arguments
if nargin < 2
monitor = 1;
end
if nargin < 3 || isempty(positionMode)
positionMode = 'OuterPosition';
end
% Get the screen coordinates to reference the figure position against
screenSize = get(0, 'MonitorPosition');
if monitor < 0
monitor = size(screenSize, 1) + monitor+1;
end
screenSize = screenSize(min(monitor,end), :);
% Convert position to relative coordinate if necessary
position(1:2) = standardCoordinate(position(1:2), screenSize(3:4)) + screenSize(1:2);
position(3:4) = standardCoordinate(position(3:4), screenSize(3:4));
% Create and return the figure
figHandle = figure( varargin{:} ...
, positionMode, position ...
);
end
function coordinate = standardCoordinate(coordinate, range)
for iCoord = 1:numel(coordinate)
if coordinate(iCoord) < 0
coordinate(iCoord) = range(iCoord) + coordinate(iCoord)+1;
elseif abs(coordinate(iCoord)) <= 1
coordinate(iCoord) = range(iCoord) * coordinate(iCoord);
end
end
coordinate(isnan(coordinate)) = min(coordinate, [], 'omitnan');
end