How to draw rectangle on a figure, based on mouse location?
Show older comments
Hello, I'd like to "live-draw" a rectangle on my figure, based on mouse location.
I'm using the following:
set (gcf, 'WindowButtonMotionFcn', @mg_BPP_mouseMove);
function mg_BPP_mouseMove(object,eventdata)
windowSize = 64;
C = get (gca, 'CurrentPoint');
topLeftCornerX = round(C(1,1)) - windowSize/2;
topLeftCornerY = round(C(1,2)) - windowSize/2;
width = windowSize;
height = windowSize;
imrect(gca, [topLeftCornerX, topLeftCornerY, width, height]);
end
Two questions:
1. How can I make the windowSize be an input variable of mg_BPP_mouseMove? I don't want explicitly define it within the function itself.
2. At the moment it draws lots of rectangles (like a "snake") as my mouse moves across the figure. I'd like to display only the last one. I mean, I would like to have one rectangle that "flows" with my mouse cursor.
Accepted Answer
More Answers (1)
Walter Roberson
on 19 Jul 2016
0 votes
1 Comment
Mark Golberg
on 19 Jul 2016
Edited: Mark Golberg
on 19 Jul 2016
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!