function varargout = test_motion(varargin)
% TEST_MOTION MATLAB code for test_motion.fig
%      TEST_MOTION, by itself, creates a new TEST_MOTION or raises the existing
%      singleton*.
%
%      H = TEST_MOTION returns the handle to a new TEST_MOTION or the handle to
%      the existing singleton*.
%
%      TEST_MOTION('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TEST_MOTION.M with the given input arguments.
%
%      TEST_MOTION('Property','Value',...) creates a new TEST_MOTION or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before test_motion_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to test_motion_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help test_motion

% Last Modified by GUIDE v2.5 11-Dec-2013 09:16:19

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @test_motion_OpeningFcn, ...
                   'gui_OutputFcn',  @test_motion_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before test_motion is made visible.
function test_motion_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

% Update handles structure
guidata(hObject, handles);


% --- Outputs from this function are returned to the command line.
function varargout = test_motion_OutputFcn(hObject, eventdata, handles) 

varargout{1} = handles.output;


function axes1_CreateFcn(hObject, eventdata, handles)
imshow('fragezeichen.jpg')


function axes2_CreateFcn(hObject, eventdata, handles)
imshow('fragezeichen.jpg')


function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
pos = get(handles.figure1,'Currentpoint');
x1 = pos(1);
y1 = pos(2);

% set(handles.axes3,'Units','normalized');
pos_axes3 = get(handles.axes3,'position');

if (x1>pos_axes3(1) && x1<(pos_axes3(1)+pos_axes3(3))) && (y1>pos_axes3(2) && y1<(pos_axes3(2)+pos_axes3(4)))
    axes(handles.axes3)
    if ~isfield(handles,'help3')
       handles.help3 = text(0.5*pos_axes3(3),0.5*pos_axes3(4),'help3'); 
    end
else
    if isfield(handles,'help3')
        delete(handles.help3)
        handles = rmfield(handles,'help3');
    end
end

% disp('x=%d, y=%d',x1,y1)
% disp(sprintf('X=%.3f Y=%.3f',x1,y1));

pos_panel = get(handles.uipanel1,'position');

% pos_axes1 = getpixelposition(handles.axes1,true);
pos_axes1 = get(handles.axes1,'position');
% Position auf figure1 beziehen
pos_axes1(1) = pos_axes1(1) + pos_panel(1);
pos_axes1(2) = pos_axes1(2) + pos_panel(2);

pos_axes2 = get(handles.axes2,'position');
% Position auf figure1 beziehen
pos_axes2(1) = pos_axes2(1) + pos_panel(1);
pos_axes2(2) = pos_axes2(2) + pos_panel(2);

if (x1>pos_axes1(1) && x1<(pos_axes1(1)+pos_axes1(3))) && (y1>pos_axes1(2) && y1<(pos_axes1(2)+pos_axes1(4)))
    axes(handles.axes1)
    if ~isfield(handles,'help1')
%         handles.help = text(x1,y1,'text1');
        handles.help1 = text((0.5*pos_axes1(3)),(0.5*pos_axes1(4)),...
            'text1','BackgroundColor',[.7 .9 .7],'EdgeColor','red','FontUnits','pixels'); % ,'Parent',handles.uipanel1
    end
    
else
    if isfield(handles,'help1')
        delete(handles.help1)
        handles = rmfield(handles,'help1');
    end
end

if (x1>pos_axes2(1) && x1<(pos_axes2(1)+pos_axes2(3))) && (y1>pos_axes2(2) && y1<(pos_axes2(2)+pos_axes2(4)))
    axes(handles.axes2)
    if ~isfield(handles,'help2')
        handles.help2 = text(0.5*pos_axes2(3),0.5*pos_axes2(4),...
            'text2','BackgroundColor',[.7 .9 .7],'EdgeColor','red','FontUnits','pixels');
    end
    
else
    if isfield(handles,'help2')
        delete(handles.help2)
        handles = rmfield(handles,'help2');
    end
end
    
guidata(hObject,handles)
    


% --- Executes during object creation, after setting all properties.
function axes3_CreateFcn(hObject, eventdata, handles)
imshow('fragezeichen.jpg','InitialMagnification','fit')
