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
| figure ('windowbuttondownfcn', @wbdfcn, ...
'position', [ 100 100 500 500], ...
'tag', 'interfaceJeu');
uicontrol ( 'style', 'pushbutton', ...
'position', [ 20 20 120 30], ...
'string', 'Ouvrir', ...
'callback', @OuvrirFichier, ...
'tag', 'pb');
axes ( 'position', [ 0.2 0.2 0.5 0.5], ...
'tag', 'a');
data = guihandles (gcf);
data.vX = zeros(1,1);
data.vY = zeros(1,1);
data.nbPts = 0;
data.p = plot( data.vX, data.vY, 'ro');
xlim([0 1])
ylim([0 1])
guidata(gcf, data);
%%% callback %%%
function OuvrirFichier (obj, event)
data = guidata (gcbf);
I = imread ('0001.bmp');
image (I, 'parent', data.a);
guidata(gcbf, data);
function wbdfcn (obj, event)
data = guidata (gcbf);
cp = get(gca, 'currentpoint');
cp = cp(1,1:2);
data.nbPts = data.nbPts + 1;
data.vX(data.nbPts) = cp(1);
data.vY(data.nbPts) = cp(2);
set(data.p, 'xdata', data.vX, 'ydata', data.vY);
guidata (gcbf, data); |