draggableRectangle

버전 1.0.4 (3.95 KB) 작성자: Hyeokjin Jho
Draws rectangle which can be dragged or resized by mouse pointer
다운로드 수: 43
업데이트 날짜: 2020/12/16

라이선스 보기

Draws rectangle which can be dragged or resized by mouse pointer

D = draggableRectangle (parent_axes,xrange,yrange,...);
input
parent_axes : axes object : axes for drawing rectangle
xrange : 1 x 2 numeric : [xmin xmax]
yrange : 1 x 2 numeric : [ymin ymax]

name-value pairs
xdirlock : logical scalar : lock x direction drag
ydirlock : logical scalar : lock y direction drag
buttonDownFcn : function handle : callback executed upon mouse click
buttonDragFcn : function handle : callback executed upon mouse drag movement
buttonUpFcn : function handle : callback executed upon mouse release

additional name-value pair argument for 'patch' can be followed after these arguments (see:https://www.mathworks.com/help/matlab/ref/matlab.graphics.primitive.patch-properties.html)

properties
xrange : 1 x 2 numeric : current x range of rectangle
yrange : 1 x 2 numeric : current y range of rectangle
xdirlock : logical scalar : if true, locks x dir dragging
ydirlock : logical scalar : if true, locks y dir dragging
bezel : numeric positive scalar : determines width of edge dragging region
isdragging : logical scalar (read only) : true if object under dragging
buttonDownFcn(hObject,eventdata) : function handle : function executed when mouse is clicked on this object
buttonDragFcn(hObject,eventdata) : function handle : function executed when mouse is moved during drag
buttonUpFcn(hObject,eventdata) : function handle : function executed when drag is finished

Additional properties for 'patch' are available.
Standard get & set functions are available.

methods
D.drag_start([movingx,movingy]);

example
% draw axis
axis([0 40 0 60]);
% draw rectangle
D = draggableRectangle([10 30],[20 40],'facecolor','r');
% force start dragging
D.drag_start([-1,0]) % move left edge

% wait until dragging is done
while D.isdragging
pause(0.05)
end

% Here, we change rectangle's properties (same properties as 'patch')
D.FaceColor = 'y';
set(D,'EdgeColor','none');

% force start dragging
D.drag_start([1,1]) % move top right vertex

% wait until dragging is done
while D.isdragging
pause(0.05)
end

% Here, we define user callback
% force start dragging
D.drag_start([0,0]) % move position
% set mouse release callback
D.buttonUpFcn = @(h,~) fprintf('moved position : [%.2f %.2f %.2f %.2f]\n',h.xrange,h.yrange);

인용 양식

Hyeokjin Jho (2024). draggableRectangle (https://www.mathworks.com/matlabcentral/fileexchange/84370-draggablerectangle), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2020b
R2019b 이상 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.4

Added properties to control patch appearance

1.0.3

changed wrong description

1.0.2

bugfix : suppress error on edge clicking

1.0.1

Changed patch to one piece
set some methods to private

1.0.0