Code sample Home

Get polyline vertex by LC_EVENT_LBDOWN event

When user presses left mouse button on a polyline vertex, the vertex position will be changed.

...
lcEventSetProc( LC_EVENT_LBDOWN, EventProc, 0, 0 );
...
  
//-----------------------------------------------
void CALLBACK EventProc (HANDLE hEvent)
{
  int EventType;
  EventType = lcPropGetInt( hEvent, LC_PROP_EVENT_TYPE );
  switch( EventType ){
    ...
    case LC_EVENT_LBDOWN:  
      OnLBDown( hEvent );  
      break;
    ...
  }
}

//-----------------------------------------------
void OnLBDown (HANDLE hEvent)
{
  HANDLE hLcWnd, hEnt, hVer;
  double Delta, Angle, X, Y, X2, Y2;
  int    iVer, EntType;

  hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );
  // get entity by cursor position
  hEnt = lcWndGetEntByPoint( hLcWnd, -1, -1 );
  if (hEnt){
    // check if the entity is a polyline
    EntType = lcPropGetInt( hEnt, LC_PROP_ENT_TYPE );
    if (EntType == LC_ENT_POLYLINE){
      // cursor coordinates (drawing coordinate space)
      X = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT1 );
      Y = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT2 );
      // delta is the current size of cursor selecting square
      Delta = lcPropGetFloat( hLcWnd, LC_PROP_WND_PICKBOXSIZE );
      // get vertex of a polyline
      hVer = lcPlineGetVerPt( hEnt, X, Y, Delta );
      if (hVer){
        iVer = lcPropGetInt( hVer, LC_PROP_VER_INDEX );
        X2 = lcPropGetFloat( hVer, LC_PROP_VER_X );
        Y2 = lcPropGetFloat( hVer, LC_PROP_VER_Y );
        // move the vertex
        lcGetPolarPrm( X2, Y2, X, Y, &Angle, NULL );
        lcGetPolarPoint( X2, Y2, Angle, Delta*5.0, &X2, &Y2 );
        lcPropPutFloat( hVer, LC_PROP_VER_X, X2 );
        lcPropPutFloat( hVer, LC_PROP_VER_Y, Y2 );
        // undate view
        lcEntUpdate( hEnt );
        lcWndRedraw( hLcWnd );
        // disable default Litecad reaction on the event
        lcEventReturnCode( 1 );
      }
    }
  }
}

See Also:

Get one entity by "MouseLBDown" event
Get several entities by "MouseLBDown" event