-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboardControlFig.m
63 lines (54 loc) · 1.88 KB
/
keyboardControlFig.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function keyboardControlFig(figH, zoomFactor)
%% keyboardControlFig
% Purpose: control figure scrolling and zooming with arrow keys and =/- keys
zoomFactor = setDefault('zoomFactor', 2);
% figH.UserData.zoomFactor = zoomFactor;
set(figH,'KeyPressFcn', @key_pressed_fcn);
function key_pressed_fcn(obj, evnt)
% get gca limits
xLims = xlim;
yLims = ylim;
% get current mouse position
mousePoint = get(gca,'CurrentPoint');
mousePoint = mousePoint(1,1:2);
% check if mouse in axis
inAxes = ...
xLims(1)<=mousePoint(1) && mousePoint(1)<=xLims(2) && ...
yLims(1)<=mousePoint(2) && mousePoint(2)<=yLims(2);
% if strcmpi(evnt.Key, 'rightarrow')
% if inAxes
% Xlimit = xLims - [mousePoint(1)-xLims(1) (mousePoint(1)-xLims(2))] /5;
% else
% Xlimit = (xLims - [diff(xLims) -diff(xLims)] /5);
% end
% xlim(Xlimit);
% elseif strcmpi(evnt.Key, 'leftarrow')
% if inAxes
% Xlimit = xLims + [mousePoint(1)-xLims(1) (mousePoint(1)-xLims(2))] /5;
% else
% Xlimit = (xLims + [diff(xLims) -diff(xLims)] /5);
% end
% xlim(Xlimit);
% elseif strcmpi(evnt.Key, 'uparrow')
% if inAxes
% Ylimit = yLims + [mousePoint(2)-yLims(1) (mousePoint(2)-yLims(2))] /5;
% else
% Ylimit = (yLims + [diff(yLims) -diff(yLims)] /5);
% end
% ylim(Ylimit);
% elseif strcmpi(evnt.Key, 'downarrow')
% if inAxes
% Ylimit = yLims - [mousePoint(2)-yLims(1) (mousePoint(2)-yLims(2))] /5;
% else
% Ylimit = (yLims - [diff(yLims) -diff(yLims)] /5);
% end
% ylim(Ylimit);
% elseif strcmpi(evnt.Key, 'add') || strcmpi(evnt.Key, 'equal')
% zoom(zoomFactor);
% elseif strcmpi(evnt.Key, 'subtract') || strcmpi(evnt.Key, 'hyphen')
% zoom(1/zoomFactor);
% % else
% % keyboard
% end
end
end