void DemoEntLBDown (HANDLE hEvent)
{
HANDLE hLcWnd, hDrw, hBlock, hCmd, hPtStyle, hEnt, hPnt;
double X, Y, X2, Y2, Dist, D2p;
BOOL bCtrl;
WCHAR* szName = L"MyPtStyle";
// get state of <Ctrl> key
bCtrl = lcPropGetInt( hEvent, LC_PROP_EVENT_INT4 );
if (bCtrl == false){
return;
}
//------- This part is used to set style for new points
// get drawing handle
hDrw = lcPropGetHandle( hEvent, LC_PROP_EVENT_DRW );
// set active point style
hPtStyle = lcDrwGetObjectByName( hDrw, LC_OBJ_PNTSTYLE, szName );
if (hPtStyle == 0){
// the point style don't exist, create it
hPtStyle = lcDrwAddPntStyle( hDrw, szName, 0, 1.0, 0, 1.0, 1.0 );
lcPropPutInt( hPtStyle, LC_PROP_PSTYLE_PTMODE, LC_POINT_PLUS|LC_POINT_CIRCLE );
lcPropPutFloat( hPtStyle, LC_PROP_PSTYLE_PTSIZE, -1.0 );
}
// set active point style
lcPropPutHandle( hDrw, LC_PROP_DRW_PNTSTYLE, hPtStyle );
//-------------------------
// get window handle
hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );
// get active command
hCmd = lcPropGetHandle( hLcWnd, LC_PROP_WND_COMMAND );
if (hCmd != 0){
return;
}
// get block handle
hBlock = lcPropGetHandle( hEvent, LC_PROP_EVENT_BLOCK );
// get entity by cursor position
hEnt = lcWndGetEntByPoint( hLcWnd, -1, -1 );
if (hEnt != 0){
// get cursor coordinates
X = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT1 );
Y = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT2 );
// by the click point, get position on entity outline
D2p = lcEntGetDist( hEnt, X, Y, &X2, &Y2, &Dist );
if (D2p >= 0.0){
// at found position, add point entity
hPnt = lcBlockAddPoint( hBlock, X2, Y2 );
lcPropPutInt( hPnt, LC_PROP_ENT_COLOR, RGB(255,100,0) );
lcBlockUpdate( hBlock, false, hPnt );
lcWndRedraw( hLcWnd );
// disable default Litecad reaction on the event
lcEventReturnCode( 1 );
}
}
}