source: aedes_getcurrentmonitor.m

Last change on this file was 186, checked in by tjniskan, 6 years ago
  • Fixed (hopefully) some issues with multiple monitors. Aedes now tries to open on the monitor where the cursor is, if other Aedes windows are not open.
  • Fixed bugs with RGB overlays.

M aedes_createmosaic.m
M aedes.m
M aedes_export_gui.m
A aedes_getcurrentmonitor.m
M aedes_revision.m

File size: 2.7 KB
Line 
1function cMon=aedes_getcurrentmonitor(hFig)
2% AEDES_GETCURRENTMONITOR - Returns the monitor, where the pointer
3%                           currently resides
4%   
5%
6% Synopsis:
7%        CurrentMonitor=aedes_getcurrentmonitor(hFig);
8%
9% Description:
10%        If called without input arguments, returns the index for the
11%        monitor where the mouse pointer is currently located (1=primary,
12%        2=secondary). If a figure handle is given as an input argument the
13%        function returns the index of the monitor where the figure is
14%        current located.
15%
16% Examples:
17%       
18%        % Get the screen size of the monitor where the pointer is located
19%        scrsz = get(0,'MonitorPositions');
20%        sz = scrsz(aedes_getcurrentmonitor,:)
21%
22% See also:
23%        AEDES
24
25% This function is a part of Aedes - A graphical tool for analyzing
26% medical images
27%
28% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uef.fi>
29%
30% Department of Applied Physics, Department of Neurobiology
31% University of Eastern Finland, FINLAND
32%
33% This program may be used under the terms of the GNU General Public
34% License version 2.0 as published by the Free Software Foundation
35% and appearing in the file LICENSE.TXT included in the packaging of
36% this program.
37%
38% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
39% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
40
41% Default monitor
42cMon = 1;
43
44try
45        mon_pos = get(0,'MonitorPositions');
46catch
47        % If the above code fails, Matlab version is probably old and we cannot
48        % detect monitor positions at all...
49        return
50end
51
52% If only one monitor is attached
53nMonitors = size(mon_pos,1);
54if nMonitors==1
55        return
56end
57
58switch nargin
59        case 0
60               
61                % Get current pointer location
62                pl = get(0,'PointerLocation');
63               
64                ind = find(pl(1)>=mon_pos(:,1));
65                tmp_pos = mon_pos(ind,1);
66                [mn,ind2]=min(abs(tmp_pos-pl(1)));
67               
68                cMon = find(mon_pos(:,1)==tmp_pos(ind2));
69               
70                if isempty(cMon)
71                        cMon = 1;
72                end
73               
74        case 1
75               
76                % Check if the input argument is a figure handle
77                if ~ishandle(hFig) || ~strcmpi(get(hFig,'type'),'figure')
78                        error('Input argument has to be a valid figure handle.')
79                end
80               
81                % Get figure position
82                fig_pos = get(hFig,'position');
83               
84                % Calculate center of the figure in pixels
85                fig_c = fig_pos(1)+fig_pos(3)/2;
86                if fig_c < 1
87                        fig_c=1;
88                end
89               
90                ind = find(fig_c>=mon_pos(:,1));
91                tmp_pos = mon_pos(ind,1);
92                [mn,ind2]=min(abs(tmp_pos-fig_c));
93               
94                cMon = find(mon_pos(:,1)==tmp_pos(ind2));
95               
96                if isempty(cMon)
97                        cMon = 1;
98                end
99               
100                %cMon = min(max(1,length(find(~[mon_pos(:,1)<=fig_c],1))+1),nMonitors);
101               
102        otherwise
103                error('Too many input arguments.')
104end
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008