Clear Filters
Clear Filters

Drawing with mouse while recording the movement

2 views (last 30 days)
Hello everyone.
I'm trying to make a signature recording program. It should be able to draw lines with mouse/pen tablet while also recording the movement (mouse position in axes) in real time.
I have modified mouseinput_timeout file to be able to record multiple lines.
%to call: out = mouseinput_timeout(timeoutval)
function selectedPts = mouseinput_timeout(timeoutval, axesHandle)
startTime = tic; %time start
a = 0;
if ~exist('axesHandle', 'var')
axesHandle = gca;
end
if ~exist('timeoutval', 'var')
timeoutval = inf;
end
if ~(ishandle(axesHandle) && strcmp(get(axesHandle,'type'),'axes'))
error('Axis handle is not valid');
end
if ~(isscalar(timeoutval) && (timeoutval > 0))
error('Timeout should be a positive scalar');
end
figHandle = get(axesHandle, 'parent');
selectedPts = [];
oldProperties = get(figHandle, ...
{'WindowButtonDownFcn','WindowButtonUpFcn',...
'WindowButtonMotionFcn', 'units','pointer'});
set(figHandle, ...
{'WindowButtonDownFcn','WindowButtonUpFcn',...
'WindowButtonMotionFcn','units','pointer'}, ...
{ @buttonDownCallback, @buttonUpCallback, ...
[], 'pixels', 'crosshair'});
figLocation = get(figHandle, 'Position');
if isinf(timeoutval)
uiwait(figHandle);
else
uiwait(figHandle, timeoutval);
end
set(figHandle, ...
{'WindowButtonDownFcn','WindowButtonUpFcn',...
'WindowButtonMotionFcn', 'units','pointer'}, ...
oldProperties);
function buttonMotionCallback(obj, eventdata) %#ok<INUSD>
pt = mapCurrentPosition();
selectedPts(end+1,:) = [pt(1,1:2) toc(startTime)];
end
function buttonStopCallback(obj, eventdata) %#ok<INUSD>
selectedPts(end+1,:) = [0 0 toc(startTime)];
end
function buttonDownCallback(obj, eventdata) %#ok<INUSD>
a = a+1;
if a == 1
selectedPts = [];
set(obj, 'WindowButtonMotionFcn', @buttonMotionCallback);
else
set(obj, 'WindowButtonMotionFcn', @buttonMotionCallback);
end
end
function buttonUpCallback(obj, eventdata) %#ok<INUSD>
set(obj, 'WindowButtonMotionFcn', @buttonStopCallback);
end
function pt = mapCurrentPosition()
scrn_pt = get(0, 'PointerLocation');
set(figHandle,'CurrentPoint',...
[scrn_pt(1) - figLocation(1) + 1, ...
scrn_pt(2) - figLocation(2) + 1]);
pt = get(axesHandle,'CurrentPoint');
end
end
However I'm still stuck with trying to make the program able to draw actual lines on the axes. Some of my attempt were combining it with mlPaint.m or this sketch function, but I haven't succeeded yet.
Thank you in advance.

Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!