MDL Draw closed shape

Within a MDL application, the user is asked to enter a closed shape.

In order to do so, we have an array of points that is initialized within a function that also calls "mdlState_startPrimitive()" passing it a callback function for each pint entered.

This latter function calls "mdlState_setFunction()" passing it "STATE_DATAPOINT" and a second callback.

This callback checks whether the last point entered is 'near' the origin and closes the shape if so.

In order to help the user, we would like to add the "anchor" (yellow cross) that appears when drawing a shape manually.

I'm a beginner with MDL drawing and I really have no iudea where to start.

The code so far is.

Initial function:

static void laFence()
{
  /* Se esiste una fence, la tiro via */
  if ( tcb->fence )
    togliFence ();

  tcb->fbfdcn.overlap = 0;

  mdlState_startPrimitive (laFence_p1, laFence, 0, 0);
  mdlOutput_printf (MSG_PROMPT, TXT_PuntiSpezzata);
  nPunti = 0;
}

Second function:

static void laFence_p1 (Dpoint3d *pt)
{
  /* Salvo primo punto */
  iPnt[nPunti++] = *pt;

  /* Set datapoint state function per gli altri punti */
  mdlState_setFunction (STATE_DATAPOINT, laFence_p2);

  /* Dynamic update */
  mdlState_dynamicUpdate (generateLineString, FALSE);
}

Final function:

static void laFence_p2 (Dpoint3d *pt)
{
  double laDist;
  if ( mdlVec_pointEqual (pt, &(iPnt[nPunti-1])) )
    return;
  iPnt[nPunti++] = *pt;
  laDist = mdlVec_distance(&(iPnt[nPunti-1]), &(iPnt[0]));
  if ( laDist < DELTA_PICCOLO_PER_FENCE && nPunti > 3 )
    laFence_done();
}

Does anybody have an idea how to solve this?