OnAnnMouseDown example for C++ Builder
// This example is also for:
// AnnAddUndoNode method, AnnCreate method, AnnDefine method,
// AnnSetAutoDefaults method
// AnnSetSelected method
// SetMousePos method
// OnAnnMouseMove event
// OnAnnMouseUp event
long x0, y0;
L_HANDLE hRectObject, hEllipseObject;
.
.
.
void __fastcall TForm1::LEADAnn1AnnMouseDown (int Button, int Shift, int x,
int y)
{
x0= x;
y0= y;
switch (LEADAnn1->AnnTool)
{
case ANNTOOL_USER_FIRST:
{
//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);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LEADAnn1AnnMouseMove (int Button, int Shift,
int x, int y)
{
if ( Button == 1 )
{
switch ( LEADAnn1->AnnTool )
{
case ANNTOOL_USER_FIRST:
{
//update the objects from the x, y coordinate
LEADAnn1->AnnDefine (hRectObject, x, y, ANNDEFINE_UPDATE);
LEADAnn1->AnnDefine (hEllipseObject, x, y, ANNDEFINE_UPDATE);
}
break;
case ANNTOOL_RECT:
{
AdjustMousePos (Shift, x, y);
}
break;
case ANNTOOL_ELLIPSE:
{
AdjustMousePos (Shift, x, y);
}
break;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LEADAnn1AnnMouseUp (int Button, int Shift,
int x, int y)
{
switch (LEADAnn1->AnnTool)
{
case ANNTOOL_USER_FIRST:
{
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, NULL);
hEllipseObject= 0;
hRectObject= 0;
}
break;
case ANNTOOL_RECT:
{
AdjustMousePos (Shift, x, y);
}
break;
case ANNTOOL_ELLIPSE:
{
AdjustMousePos (Shift, x, y);
}
break;
}
}
//---------------------------------------------------------------------------
void TForm1::AdjustMousePos(int Shift, long x, long y)
{
long dx, dy;
//if shift key is down, draw rectangles or circles
if ( Shift == 1 )
{
//if shift key is down, force the creation of squares
dx= abs(x - x0);
dy= abs(y - y0);
if (dx > dy)
{
// adjust y to be as far from y0 as x is from x0
if ( y > y0)
y = y0 + dx;
else
y = y0 - dx;
}
else
{
//adjust x to be as far from x0 as y is from y0
if ( x > x0 )
x= x0 + dy;
else
x= x0 - dy;
}
// set the mouse cursor and update its position
LEADAnn1->SetMousePos (x, y, False);
}
}