ptrend under photon builder

Hello,
I need some help about the widget ptrend, I just want to make some curve but I don’t understand how the widget work, specificaly the Pt_ARG_TREND_DATA property. I can draw something, but it’s with random values.So can someone help me please???

This code will do a pretty basic series of points if you make into a call back for a PtTrend widget created in PhAb.

int draw( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
short data[10];

data[0] = 2;
data[1] = 12;
data[2] = 32;
data[3] = 72;
data[4] = 12;	
data[5] = 2;
data[6] = 12;
data[7] = 32;
data[8] = 72;
data[9] = 12;	
/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

printf("Running...\n");

PtSetResource(widget,Pt_ARG_TREND_MIN,0,0);
PtSetResource(widget,Pt_ARG_TREND_MAX,100,0);
PtSetResource(widget,Pt_ARG_TREND_INC,10,0);
PtTrendChangeData(widget,(short const *) &data,0,10);

return( Pt_CONTINUE );

}

I think if you want bezier curves or something, you need to work it out yourself, might be better off looking at PtBezier.

Cheers

Garry

Thank you, i test this immediatly.

:smiley:

thank you !!!

I’m no expert on multithreading C, but maybe something like this is what you want…

void * drawing_thread (void * widget)
{
short data[10];
data[0] = 2;
data[1] = 12;
data[2] = 32;
data[3] = 72;
data[4] = 12;
data[5] = 2;
data[6] = 12;
data[7] = 32;
data[8] = 72;
data[9] = 12;

printf("Running in thread...\n");

PtSetResource((PtWidget_t *) widget,Pt_ARG_TREND_MIN,0,0);
PtSetResource((PtWidget_t *) widget,Pt_ARG_TREND_MAX,100,0);
PtSetResource((PtWidget_t *) widget,Pt_ARG_TREND_INC,10,0);
PtTrendChangeData((PtWidget_t *) widget,(short const *) &data,0,10);

return (PtWidget_t *) widget;

}

int draw( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t cbinfo )
{
/
eliminate ‘unreferenced’ warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

printf("Running...\n");
pthread_create(NULL,NULL,&drawing_thread,widget);
return( Pt_CONTINUE );

}

However, I’m not sure how thread-safe all the Photon widgets are, particularly reading and writing resources at the same time from different threads.

HTH

Garry

Photon library is NOT thread safe, check PtEnter and PtLeave to protect Photon calls.

Thank you !!