function varargout = draggable_GUI(varargin)
% DRAGGABLE_GUI MATLAB code for draggable_GUI.fig
%      DRAGGABLE_GUI, by itself, creates a new DRAGGABLE_GUI or raises the existing
%      singleton*.
%
%      H = DRAGGABLE_GUI returns the handle to a new DRAGGABLE_GUI or the handle to
%      the existing singleton*.
%
%      DRAGGABLE_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DRAGGABLE_GUI.M with the given input arguments.
%
%      DRAGGABLE_GUI('Property','Value',...) creates a new DRAGGABLE_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before draggable_GUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to draggable_GUI_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 draggable_GUI

% Last Modified by GUIDE v2.5 08-Mar-2018 14:46:35

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @draggable_GUI_OpeningFcn, ...
                   'gui_OutputFcn',  @draggable_GUI_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 draggable_GUI is made visible.
function draggable_GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to draggable_GUI (see VARARGIN)

% Choose default command line output for draggable_GUI
handles.output = hObject;

%% Clear CW
clc

%% Data
handles.P1 = [1.7 10.0]; 
handles.P2 = [3.0  2.0]; 
handles.P3 = [6.0  0.0]; 
handles.P4 = [7.5  3.5];
handles.P5 = [8.7  8.0];

handles.Points = [handles.P1; handles.P2; handles.P3; handles.P4; handles.P5]; 

%% Plotting
%  All 5 points
hold on
for i = 1:5
    
    handles.hP(i) = plot(handles.Points(i,1), handles.Points(i,2),'-yo','LineWidth',2,'MarkerEdgeColor',[0.0 0.0 0.0],'MarkerFaceColor',[0.8 0.2 0.6],'MarkerSize',10);                                                                                               

end

%  Change color of 4th point to red -> thi sPoint should be draggable.
set(handles.hP(4),'MarkerFaceColor',[1 0 0])

%  Make 4th Point dragable
draggable(handles.hP(4), @movefcn)

handles

%  Update handles structure
guidata(hObject, handles);

% UIWAIT makes draggable_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);



function movefcn(obj)
clc
xPos = get(obj,'XData')
yPos = get(obj,'YData')
handles



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

