cmDspBuiltIn.c, cmDspValue.h/c : text in 'label' object can now be updated with any variable type.
This commit is contained in:
parent
220ca1577c
commit
90bfc6c05b
@ -1702,7 +1702,8 @@ cmDspClass_t* cmMeterClassCons( cmDspCtx_t* ctx )
|
||||
enum
|
||||
{
|
||||
kInLbId,
|
||||
kAlignLbId
|
||||
kAlignLbId,
|
||||
kTextLbId
|
||||
};
|
||||
|
||||
cmDspClass_t _cmLabelDC;
|
||||
@ -1710,27 +1711,68 @@ cmDspClass_t _cmLabelDC;
|
||||
typedef struct
|
||||
{
|
||||
cmDspInst_t inst;
|
||||
cmChar_t* label;
|
||||
} cmDspLabel_t;
|
||||
|
||||
cmDspInst_t* _cmDspLabelAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
|
||||
{
|
||||
cmDspVarArg_t args[] =
|
||||
const unsigned argCnt = 3;
|
||||
cmDspVarArg_t args[argCnt+1];
|
||||
cmChar_t* label = NULL;
|
||||
unsigned align = kLeftAlignDuiId;
|
||||
va_list vl1;
|
||||
|
||||
va_copy(vl1,vl);
|
||||
|
||||
if( va_cnt < 1 )
|
||||
{
|
||||
{ "in", kInLbId, 0, 0, kInDsvFl | kStrzDsvFl | kReqArgDsvFl, "LabelText" },
|
||||
{ "align",kAlignLbId, 0, 0, kInDsvFl | kUIntDsvFl | kOptArgDsvFl, "Alignment 0=right 1=left 2=center" },
|
||||
{ NULL, 0, 0, 0, 0 }
|
||||
};
|
||||
va_end(vl1);
|
||||
cmDspClassErr(ctx,classPtr,kVarArgParseFailDspRC,"The 'label' constructor argument list must contain at least one argument.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cmDspLabel_t* p = cmDspInstAlloc(cmDspLabel_t,ctx,classPtr,args,instSymId,id,storeSymId,va_cnt,vl);
|
||||
// get the default label
|
||||
const char* clabel = va_arg(vl,const char*);
|
||||
if( clabel != NULL && strlen(clabel) > 0 )
|
||||
{
|
||||
label = cmLhAllocStr(ctx->lhH,clabel);
|
||||
printf("%s\n",label);
|
||||
}
|
||||
|
||||
cmDspSetDefaultDouble(ctx, &p->inst, kAlignLbId, 0.0, kLeftAlignDuiId);
|
||||
// if an alignment id was provided
|
||||
if( va_cnt > 1 )
|
||||
align = va_arg(vl,double);
|
||||
|
||||
// setup the arg. config. array.
|
||||
cmDspArgSetup(ctx,args+0,"in", cmInvalidId, kInLbId, 0,0, kInDsvFl | kTypeDsvMask, "Input to set label" );
|
||||
cmDspArgSetup(ctx,args+1,"align",cmInvalidId, kAlignLbId, 0,0, kInDsvFl | kUIntDsvFl, "Justification: 0=right 1=center 2=left" );
|
||||
cmDspArgSetup(ctx,args+2,"text", cmInvalidId, kTextLbId, 0,0, kInDsvFl | kStrzDsvFl, "Label text");
|
||||
cmDspArgSetupNull(args + argCnt);
|
||||
|
||||
// create the instance
|
||||
cmDspLabel_t* p = cmDspInstAlloc(cmDspLabel_t,ctx,classPtr,args,instSymId,id,storeSymId,0,vl1);
|
||||
|
||||
p->label = label;
|
||||
|
||||
// set the default variable values
|
||||
cmDspSetDefaultDouble(ctx, &p->inst, kAlignLbId, 0.0, align);
|
||||
cmDspSetDefaultStrcz( ctx, &p->inst, kTextLbId, NULL, label==NULL ? "" : label );
|
||||
|
||||
// create the UI control
|
||||
cmDspUiLabelCreate(ctx,&p->inst,kInLbId,kAlignLbId);
|
||||
cmDspUiLabelCreate(ctx,&p->inst,kTextLbId,kAlignLbId);
|
||||
|
||||
va_end(vl1);
|
||||
|
||||
return &p->inst;
|
||||
}
|
||||
|
||||
cmDspRC_t _cmDspLabelFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
||||
{
|
||||
cmDspLabel_t* p = (cmDspLabel_t*)inst;
|
||||
cmLhFree(ctx->lhH,p->label);
|
||||
return kOkDspRC;
|
||||
}
|
||||
|
||||
cmDspRC_t _cmDspLabelReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
||||
{
|
||||
cmDspApplyAllDefaults(ctx,inst);
|
||||
@ -1739,6 +1781,21 @@ cmDspRC_t _cmDspLabelReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
|
||||
|
||||
cmDspRC_t _cmDspLabelRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
|
||||
{
|
||||
const unsigned bN = 128;
|
||||
cmChar_t b[ bN+1 ];
|
||||
|
||||
// if this event is arriving on the 'in' port ...
|
||||
if( evt->dstVarId == kInLbId )
|
||||
{
|
||||
cmDspLabel_t* p = (cmDspLabel_t*)inst;
|
||||
// ... then convert it to a string
|
||||
cmDsvToString( evt->valuePtr, p->label, b, bN );
|
||||
|
||||
// and set the 'label' variable
|
||||
return cmDspSetStrcz(ctx, inst, kTextLbId, b );
|
||||
}
|
||||
|
||||
|
||||
return cmDspSetEvent(ctx,inst,evt);
|
||||
}
|
||||
|
||||
@ -1747,7 +1804,7 @@ cmDspClass_t* cmLabelClassCons( cmDspCtx_t* ctx )
|
||||
cmDspClassSetup(&_cmLabelDC,ctx,"Label",
|
||||
NULL,
|
||||
_cmDspLabelAlloc,
|
||||
NULL,
|
||||
_cmDspLabelFree,
|
||||
_cmDspLabelReset,
|
||||
NULL,
|
||||
_cmDspLabelRecv,
|
||||
|
@ -1527,3 +1527,76 @@ void cmDsvPrint( const cmDspValue_t* vp, const cmChar_t* label, cmRpt_t* rpt )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmDsvToString( const cmDspValue_t* vp, const cmChar_t* label, cmChar_t* s, unsigned sN )
|
||||
{
|
||||
vp = _vcptr(vp);
|
||||
|
||||
const char* noLbl="";
|
||||
const char* lbl = label==NULL? noLbl : label;
|
||||
|
||||
if( cmDsvIsMtx(vp) )
|
||||
{
|
||||
unsigned i,j;
|
||||
unsigned rn = cmDsvCols(vp);
|
||||
unsigned cn = cmDsvRows(vp);
|
||||
for(i=0; i<rn; ++i)
|
||||
{
|
||||
for(j=0; j<cn && sN>2; ++j)
|
||||
{
|
||||
switch( cmDsvBasicType(vp) )
|
||||
{
|
||||
case kCharDsvFl: snprintf(s,sN,"%s%c ",lbl,vp->u.m.u.cp[ (j*rn) + i ]); break;
|
||||
case kUCharDsvFl: snprintf(s,sN,"%s%c ",lbl,vp->u.m.u.ucp[ (j*rn) + i ]); break;
|
||||
case kShortDsvFl: snprintf(s,sN,"%s%i ",lbl,vp->u.m.u.sp[ (j*rn) + i ]); break;
|
||||
case kUShortDsvFl: snprintf(s,sN,"%s%i ",lbl,vp->u.m.u.usp[ (j*rn) + i ]); break;
|
||||
case kLongDsvFl: snprintf(s,sN,"%s%li ",lbl,vp->u.m.u.lp[ (j*rn) + i ]); break;
|
||||
case kULongDsvFl: snprintf(s,sN,"%s%li ",lbl,vp->u.m.u.ulp[ (j*rn) + i ]); break;
|
||||
case kIntDsvFl: snprintf(s,sN,"%s%i ",lbl,vp->u.m.u.ip[ (j*rn) + i ]); break;
|
||||
case kUIntDsvFl: snprintf(s,sN,"%s%i ",lbl,vp->u.m.u.up[ (j*rn) + i ]); break;
|
||||
case kFloatDsvFl: snprintf(s,sN,"%s%f ",lbl,vp->u.m.u.fp[ (j*rn) + i ]); break;
|
||||
case kDoubleDsvFl: snprintf(s,sN,"%s%f ",lbl,vp->u.m.u.dp[ (j*rn) + i ]); break;
|
||||
case kSampleDsvFl: snprintf(s,sN,"%s%f ",lbl,vp->u.m.u.ap[ (j*rn) + i ]); break;
|
||||
case kRealDsvFl: snprintf(s,sN,"%s%f ",lbl,vp->u.m.u.rp[ (j*rn) + i ]); break;
|
||||
case kStrzDsvFl: snprintf(s,sN,"%s%s ",lbl,vp->u.m.u.zp[ (j*rn) + i ]); break;
|
||||
case kJsonDsvFl: cmJsonLeafToString(vp->u.m.u.jp[ (j*rn) + i ],s,sN); break;
|
||||
default:
|
||||
{ assert(0); }
|
||||
}
|
||||
|
||||
unsigned n = strlen(s);
|
||||
sN -= n;
|
||||
s += n;
|
||||
|
||||
|
||||
}
|
||||
if( sN > 2 )
|
||||
snprintf(s,sN,"\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch( cmDsvBasicType(vp) )
|
||||
{
|
||||
case kBoolDsvFl: snprintf(s,sN,"%s%s ",lbl,vp->u.b ? "true" : "false"); break;
|
||||
case kCharDsvFl: snprintf(s,sN,"%s%c ",lbl,vp->u.c); break;
|
||||
case kUCharDsvFl: snprintf(s,sN,"%s%c ",lbl,vp->u.uc); break;
|
||||
case kShortDsvFl: snprintf(s,sN,"%s%i ",lbl,vp->u.s); break;
|
||||
case kUShortDsvFl: snprintf(s,sN,"%s%i ",lbl,vp->u.us); break;
|
||||
case kLongDsvFl: snprintf(s,sN,"%s%li ",lbl,vp->u.l); break;
|
||||
case kULongDsvFl: snprintf(s,sN,"%s%li ",lbl,vp->u.ul); break;
|
||||
case kIntDsvFl: snprintf(s,sN,"%s%i ",lbl,vp->u.i); break;
|
||||
case kUIntDsvFl: snprintf(s,sN,"%s%i ",lbl,vp->u.u); break;
|
||||
case kFloatDsvFl: snprintf(s,sN,"%s%f ",lbl,vp->u.f); break;
|
||||
case kDoubleDsvFl: snprintf(s,sN,"%s%f ",lbl,vp->u.d); break;
|
||||
case kSampleDsvFl: snprintf(s,sN,"%s%f ",lbl,vp->u.a); break;
|
||||
case kRealDsvFl: snprintf(s,sN,"%s%f ",lbl,vp->u.r); break;
|
||||
case kPtrDsvFl: snprintf(s,sN,"%s%p ",lbl,vp->u.vp); break;
|
||||
case kStrzDsvFl: snprintf(s,sN,"%s%s ",lbl,vp->u.z); break;
|
||||
case kSymDsvFl: snprintf(s,sN,"%s%i ",lbl,vp->u.u); break;
|
||||
case kJsonDsvFl: cmJsonLeafToString(vp->u.j,s,sN); break;
|
||||
default:
|
||||
{ assert(0); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -331,6 +331,7 @@ extern "C" {
|
||||
cmDsvRC_t cmDsvDeserializeJson( cmDspValue_t* vp, cmJsonH_t jsH );
|
||||
|
||||
void cmDsvPrint( const cmDspValue_t* vp, const cmChar_t* label, cmRpt_t* rpt );
|
||||
void cmDsvToString( const cmDspValue_t* vp, const cmChar_t* label, cmChar_t* s, unsigned sN );
|
||||
|
||||
//)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user