Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

getscreen(figureHandle)
function screenNumber = getscreen(figureHandle)
% GETSCREEN says which screen a figure is on.

% UNFINISHED

% To do:
% 1. Expand to vector operation.
% 2. Expand to all gui elements - just find the parent of the GUI item and
% find it out from that.

% checks the inputs
error(nargchk(1, 1, nargin))

% currently only defined for one thing
if ~ishandle(figureHandle) || ~isscalar(figureHandle)
    % errors
    error('Must supply a valid scalar figure handle.')
end

% gets the current monitor sizes and positions
monitorPosition = get(0, 'MonitorPosition');

% gets the number of screens
numberOfScreens = size(monitorPosition, 1);

% shortcut for if there is only one monitor (or none?)
if numberOfScreens <= 1
    % return a 1
    screenNumber = 1;
    
else
    % gets the old figure units
    oldFigureUnits = get(figureHandle, 'Units');
    
    % temporarily turns them into pixels
    set(figureHandle, 'Units', 'pixels')
    
    % gets the current figure position
    figurePosition = get(figureHandle, 'Position');
    
    % sets the units back
    set(figureHandle, 'Units', oldFigureUnits)
    
    % defines the xy coordinates
    figureBottomLeft = figurePosition(1:2);
    figureTopRight = figureBottomLeft + figurePosition(3:4);
    figureTopLeft = [figureBottomLeft(1), figureTopRight(2)];
    figureBottomRight = [figureBottomLeft(2), figureTopRight(1)];
    
    % generates some x,y coordinates for the range of each screen - in rows
    % from the left, i.e. TL, TR, BL, BR
    
    % for each monitor
    for m = 1:numberOfScreens
        % defines two opposite points - can work the rest out from there
        bottomLeft(m, :) = monitorPosition(m, 1:2);
        topRight(m, :) = bottomLeft(m, :) + monitorPosition(m, 3:4);
        
        % and the opposites
        topLeft(m, :) = [bottomLeft(m, 1), topRight(m, 2)];
        bottomRight(m, :) = [bottomLeft(m, 2), topRight(m, 1)];
    end
end

Contact us