Code sample Home

Get polyline vertex by LC_EVENT_LBDOWN event

1) When user presses left mouse button on a polyline vertex, its Y coordinate will be increased by 30 pixels.

...
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, hBlock, hEnt, hVer;
  double X, Y, Delta;
  int    EntType;

  // handle of active block
  hBlock = lcPropGetHandle( hEvent, LC_PROP_EVENT_BLOCK );
  // handle of graphics window
  hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );
  // get entity under cursor
  hEnt = lcWndGetEntByPoint( hLcWnd, -1, -1 );
  if (hEnt){
    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 );
      // get size of pickbox square
      Delta = lcPropGetFloat( hLcWnd, LC_PROP_WND_PICKBOXSIZE );
      // get polyline vertex
      hVer = lcPlineGetVerPt( hEnt, X, Y, Delta );
      if (hVer){
        // move up the vertex
        Delta = lcPropGetFloat( hLcWnd, LC_PROP_WND_PIXELSIZE );
        Delta = Delta * 30;
        Y = lcPropGetFloat( hVer, LC_PROP_VER_Y );
        Y += Delta;
        lcPropPutFloat( hVer, LC_PROP_VER_Y, Y );
        lcBlockUpdate( hBlock, true, hEnt );
        lcWndRedraw( hLcWnd );
        // disable LiteCAD default actions on Mouse Down event
        lcEventReturnCode( 1 );
      }
    }
  }
}

2) When user presses left mouse button on a polyline segment, its vertices Y coordinates will be increased by 30 pixels.

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

  hLcWnd = lcPropGetHandle( hEvent, LC_PROP_EVENT_WND );
  // get entity under cursor position
  hEnt = lcWndGetEntByPoint( hLcWnd, -1, -1 );
  if (hEnt){
    EntType = lcPropGetInt( hEnt, LC_PROP_ENT_TYPE );
    if (EntType == LC_ENT_POLYLINE){
      X = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT1 );
      Y = lcPropGetFloat( hEvent, LC_PROP_EVENT_FLOAT2 );
      Delta = lcPropGetFloat( hLcWnd, LC_PROP_WND_PICKBOXSIZE );
      hVer = lcPlineGetSeg( hEnt, X, Y, Delta );
      if (hVer){
        Delta = lcPropGetFloat( hLcWnd, LC_PROP_WND_PIXELSIZE );
        Delta = Delta * 30;
        // move up the vertex
        Y = lcPropGetFloat( hVer, LC_PROP_VER_Y );
        Y += Delta;
        lcPropPutFloat( hVer, LC_PROP_VER_Y, Y );
        // move up the next vertex
        hVer = lcPlineGetNextVer( hEnt, hVer );
        Y = lcPropGetFloat( hVer, LC_PROP_VER_Y );
        Y += Delta;
        lcPropPutFloat( hVer, LC_PROP_VER_Y, Y );
        hBlock = lcPropGetHandle( hEvent, LC_PROP_EVENT_BLOCK );
        lcBlockUpdate( hBlock, true, hEnt );
        lcWndRedraw( hLcWnd );
        // disable LiteCAD default actions on Mouse Down event
        lcEventReturnCode( 1 );
      }
    }
  }
}
Used functions:

lcWndGetEntByPoint
lcPlineGetVerPt
lcPlineGetSeg
lcPlineGetNextVer
lcBlockUpdate
lcWndRedraw
lcEventReturnCode

lcPropGetFloat
lcPropGetHandle
lcPropGetInt
lcPropPutInt