OnAnnMouseDown example for Delphi
// This example is also for:
// AnnAddUndoNode method, AnnCreate method, AnnDefine method,
// AnnSetAutoDefaults method
// AnnSetSelected method
// SetMousePos method
// OnAnnMouseMove event
// OnAnnMouseUp event
var
x0, y0 : integer;
hRectObject, hEllipseObject : L_HANDLE;
.
.
.
procedure TForm1.LEADAnn1AnnMouseDown (Button, Shift, x, y: Integer);
begin
x0 := x;
y0:= y;
Case LEADAnn1.AnnTool of
ANNTOOL_USER_FIRST:
begin
//create the objects
LEADAnn1.AnnSetSelected (LEADAnn1.AnnContainer, False, True);
LEADAnn1.AnnAddUndoNode ();
hRectObject:= LEADAnn1.AnnCreate (ANNOBJECT_RECT, True, True);
hEllipseObject:= LEADAnn1.AnnCreate (ANNOBJECT_ELLIPSE, True, True);
// set the automation defaults to the objects newly created
LEADAnn1.AnnSetAutoDefaults (hRectObject, 0);
LEADAnn1.AnnSetAutoDefaults (hEllipseObject, 0);
//start defining them from the x, y coordinate
LEADAnn1.AnnDefine (hRectObject, x, y, ANNDEFINE_BEGINSET);
LEADAnn1.AnnDefine (hEllipseObject, x, y, ANNDEFINE_BEGINSET);
end;
end;
end;
procedure TForm1.LEADAnn1AnnMouseMove (Button, Shift, x, y: Integer);
begin
if ( Button = 1 ) then
begin
Case LEADAnn1.AnnTool of
ANNTOOL_USER_FIRST:
begin
//update the objects from the x, y coordinate
LEADAnn1.AnnDefine (hRectObject, x, y, ANNDEFINE_UPDATE);
LEADAnn1.AnnDefine (hEllipseObject, x, y, ANNDEFINE_UPDATE);
end;
ANNTOOL_RECT:
begin
AdjustMousePos (Shift, x, y);
end;
ANNTOOL_ELLIPSE:
begin
AdjustMousePos (Shift, x, y);
end;
end;
end;
end;
procedure TForm1.LEADAnn1AnnMouseUp (Button, Shift, x, y: Integer);
begin
case (LEADAnn1.AnnTool)of ANNTOOL_USER_FIRST:
begin
LEADAnn1.AnnDefine (hRectObject, x, y, ANNDEFINE_END); LEADAnn1.AnnDefine (hEllipseObject, x, y, ANNDEFINE_END);
LEADAnn1.AnnSetSelected (hRectObject, True, False);
LEADAnn1.AnnSetSelected (hEllipseObject, True, False);
LEADAnn1.AnnGroup (LEADAnn1.AnnContainer, ANNFLAG_RECURSE + ANNFLAG_SELECTED, Nil);
hEllipseObject:= 0;
hRectObject:= 0;
end;
ANNTOOL_RECT:
begin
AdjustMousePos (Shift, x, y);
end;
ANNTOOL_ELLIPSE:
begin
AdjustMousePos (Shift, x, y);
end;
end;
end;
procedure TForm1.AdjustMousePos(Shift: Integer; x: Longint; y: longint);
var
dx, dy: longint;
begin
//if shift key is down, draw rectangles or circles
if ( Shift = 1 ) then
begin
//if shift key is down, force the creation of squares
dx:= Abs(x - x0);
dy:= Abs(y - y0);
if (dx > dy) then
begin
// Adjust y to be as far from y0 as x is from x0
if ( y > y0) then
y := y0 + dx
else
y := y0 – dx
end
else
begin
//adjust x to be as far from x0 as y is from y0
if ( x > x0 ) then
x := x0 + dy
else x := x0 - dy;
end;
// set the mouse cursor and update its position
LEADAnn1.SetMousePos ( x, y, False );
end;
end;