NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/basics/stretchbox.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function stretchbox(action)
2 % STRETCHBOX creates a box and stretches it following the mouse
3 %
4 % TO USE: set(gcf,'WindowButtonDownFcn','stretchbox')
5 %
6 % Written by: Brian Blanton (Dec 98)
7
8 if nargin==0  % Button pushed, initialize
9
10   % Get the current WindowButton*Fcn's, and store globally
11   % for return
12   global WindowButtonDownFcn WindowButtonMotionFcn WindowButtonUpFcn
13   WindowButtonDownFcn = get(gcf,'WindowButtonDownFcn');
14   WindowButtonMotionFcn = get(gcf,'WindowButtonMotionFcn');
15   WindowButtonUpFcn = get(gcf,'WindowButtonUpFcn');
16
17 % Delete any previous text and lines from stretchbox
18   delete(findobj(gca,'Tag','Box Lines For stretchbox'))
19   delete(findobj(gca,'Tag','Text1 For stretchbox'))
20   delete(findobj(gca,'Tag','Text2 For stretchbox'))
21
22   % Determine the location of the mouse and create the XData,
23   % YData, and ZData for the box lines.
24   currrentpoint = get(gca,'CurrentPoint');
25   xpos = [currrentpoint(1) currrentpoint(1) currrentpoint(1) ...
26           currrentpoint(1) currrentpoint(1)];
27   ypos = [currrentpoint(3) currrentpoint(3) currrentpoint(3) ...
28           currrentpoint(3) currrentpoint(3)];
29   zpos = [0 0 0 0 0];
30  
31   % Add some text that displays the current point
32   tp1 = text(currrentpoint(1),currrentpoint(3),...
33         sprintf('(%8.3f,%8.3f)',currrentpoint(1),currrentpoint(3)), ...
34        'Tag','Text1 For stretchbox','HorizontalAlignment','center',...
35        'FontWeight','bold');
36        
37   % Create the initial box
38   hs = line('XData',xpos,'YData',ypos,'ZData',zpos, ...
39        'Color','r','EraseMode','xor', ...
40        'LineStyle','--','Tag','Box Lines For stretchbox','LineWidth',2);
41
42   % Add some text that displays the current point
43   tp2 = text(currrentpoint(1),currrentpoint(3),...
44         sprintf('(%8.3,%8.3f)',currrentpoint(1),currrentpoint(3)), ...
45        'EraseMode','xor','Tag','Text2 For stretchbox','HorizontalAlignment','center',...
46        'FontWeight','bold');
47
48   % Set the WindowButtonMotionFcn WindowButtonUpFcn
49   set(gcf,'WindowButtonMotionFcn','stretchbox move', ...
50           'WindowButtonDownFcn','stretchbox up')
51
52 elseif strcmp(action,'move');  % Mouse moved
53
54   % Get the location of the mouse
55   currrentpoint = get(gca,'CurrentPoint');
56  
57   % Find the handle to the surface plot and text object
58   hs = findobj(gca,'Type','line','Tag','Box Lines For stretchbox');
59   tp2 = findobj(gca,'Type','text','Tag','Text2 For stretchbox');
60
61   % Update the locations of the line plot and text object #2
62   xpos = get(hs,'XData');
63   ypos = get(hs,'YData');
64   xpos(3:4) = [currrentpoint(1) currrentpoint(1)];
65   ypos(2:3) = [currrentpoint(3) currrentpoint(3)];
66   set(hs,'XData',xpos,'YData',ypos)
67   set(tp2,'Position',[currrentpoint(1) currrentpoint(3) 0],...
68           'String',sprintf('(%8.3f,%8.3f)',currrentpoint(1),currrentpoint(3)));
69
70 elseif strcmp(action,'up')   
71 %%%%
72 %%%% Mouse button released
73 %%%
74    % Set the WindowButtonDownFcn WindowButtonMotionFcn, and
75    % WindowButtonUpFcn to original values.
76    global WindowButtonDownFcn WindowButtonMotionFcn WindowButtonUpFcn
77    set(gcf,'WindowButtonDownFcn',WindowButtonDownFcn, ...
78            'WindowButtonMotionFcn',WindowButtonMotionFcn, ...
79            'WindowButtonUpFcn',WindowButtonUpFcn)
80    clear global WindowButtonDownFcn WindowButtonMotionFcn WindowButtonUpFcn
81   hs = findobj(gca,'Type','line','Tag','Box Lines For stretchbox');
82   set(hs,'LineWidth',.25)
83
84 end 
85
86 %set(gcf,'WindowButtonDownFcn','', ...
87 %          'WindowButtonMotionFcn','', ...
88 %          'WindowButtonUpFcn','')
Note: See TracBrowser for help on using the browser.