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 64 65 66 67 68 69 70 71 72 73 74 75
| function TestPointeur
%------------- BEGIN CODE --------------
clear all
close all
clc
pointeur=1; % pointeur=1=hand // % pointeur=0=fullcross
scnSize = get(0,'ScreenSize');
posMainFig = [scnSize(1) scnSize(2) scnSize(3) scnSize(4)];
hMainFig = figure('Name','Probleme Pointeur',...
'NumberTitle','off',...
'OuterPosition',posMainFig,'Units','normalized',...
'Toolbar','none','Menubar','none',...
'windowButtonMotionFcn',@PointerInGraph);
hAxes1 = axes('Units','normalized','Position',[0.25 0.1 0.66 0.39],'Color','black');
hAxes2 = axes('Units','normalized','Position',[0.25 0.51 0.66 0.19],'Color','black');
hAxes3 = axes('Units','normalized','Position',[0.25 0.71 0.66 0.19],'Color','black');
hModifPointeur = uicontrol('Style','toggleButton','Units','normalized','Position',[0.05 0.9 0.15 0.09],'String','Change pour fullcross','Callback',@ModifPointeur);
plot(hAxes1,rand(1,1000));
plot(hAxes2,rand(1,1000));
plot(hAxes3,rand(1,1000));
function ModifPointeur(~,~)
if get(hModifPointeur,'Value')
set(hModifPointeur,'String','Change pour Hand')
pointeur=0;
else
set(hModifPointeur,'String','Change pour fullcross')
pointeur=1;
end
end
function PointerInGraph(~,~)
posi=get(hMainFig,'CurrentPoint');
ed=posi(2);
axall = localHittest(hMainFig,ed,'axes');
if ~isempty(axall)
try
if (axall==hAxes1) || (axall==hAxes2) || (axall==hAxes3)
if pointeur
set(hMainFig,'pointer','hand'); % pointeur = 1
else
set(hMainFig,'pointer','fullcross'); % pointeur = 0
end
else
setptr(hMainFig,'arrow');
end
catch
setptr(hMainFig,'arrow');
end
else
setptr(hMainFig,'arrow');
end
function obj = localHittest(hFig,evd,varargin)
if ~graphicsversion(hFig,'handlegraphics')
obj = plotedit([{'hittestHGUsingMATLABClasses',hFig,evd},varargin(:)]);
else
obj = double(hittest(hFig,varargin{:}));
% Ignore objects whose 'hittest' property is 'off'
obj = obj(arrayfun(@(x)(strcmpi(get(x,'HitTest'),'on')),obj));
end
end
end
end
%------------- END OF CODE -------------- |
Partager