void KCMarkPanel::draw(QPainter *painter, QTextBlock *block, int x, int y, int w, int h, bool isCurrentLine) { Q_UNUSED(isCurrentLine); int blockNum=block->blockNumber(); if(blockNum>=vecMark.size()) { vecMark.resize(blockNum+1); } QPoint _global(x,y); vecMark[blockNum].rect.setTopLeft(mapToGlobal(_global)); vecMark[blockNum].rect.setWidth(w); vecMark[blockNum].rect.setHeight(h); if(vecMark[blockNum].marked) { painter->drawPixmap(x, y - 3, markPix.width(), markPix.height(), markPix); } }
void callInternalFunction(dplVal *returnValue, dplVal *name, dplVal *args) { dplVal *function; if(dplHashFind(&_global(fst), STR_VALUE(name), STR_LEN(name) + 1, (void **) &function) == FAILURE) { dplError(DPL_WARNINGL, "call to undefined function: %s", STR_VALUE(name)); } else { function->value.function(returnValue, args); } }
SectionAnimation_Handler( long version, GlobalFunc *_global, LWItemMotionHandler *local, void *serverData) { if ( version != LWITEMMOTION_VERSION ) return AFUNC_BADVERSION; _iti = (LWItemInfo *)_global(LWITEMINFO_GLOBAL, GFUSE_TRANSIENT); if (_iti==NULL) { return AFUNC_BADGLOBAL; } local->inst->create = Create; local->inst->destroy = (void (*)(void *))Destroy; local->inst->load = (const char *(__cdecl *)(void *,const struct st_LWLoadState *))Load; local->inst->save = (const char *(__cdecl *)(void *,const struct st_LWSaveState *))Save; local->inst->copy = (const char *(__cdecl *)(void *,void *))Copy; local->inst->descln = (const char *(__cdecl *)(void *))Describe; local->evaluate = (void (__cdecl *)(void *,const struct st_LWItemMotionAccess *))Evaluate; local->flags = (unsigned int (__cdecl *)(void *))Flags; return AFUNC_OK; }
int registerFunctions(functionEntry *functions) { functionEntry *ptr = functions; dplVal function; while(ptr->functionName) { function.type = IS_INTERNAL_FUNCTION; function.value.function = ptr->function; if(!function.value.function) { return FAILURE; } if(dplHashAddElement(&_global(fst), ptr->functionName, strlen(ptr->functionName) + 1, &function, sizeof(dplVal)) == FAILURE) { return FAILURE; } ptr++; } return SUCCESS; }
int ExportSecAnim(LWXPanelID pan) { LWItemID idMasterObjID; char strMessage[256]; Matrix12 bi_mRot; _iFrame = 0; _ctFrames = 0; _ctBones = 0; ctBoneEnvelopes = 0; ctMorphEnvelopes = 0; if(!_evaluate) { // lightwave error _msg->error("Lightwave process error !\nClose plugins window and try again.\n", NULL); return AFUNC_BADAPP; } // !!!! make it work with a selected object, not the first one in scene ReloadGlobalObjects(); bool bExportOnlySelected = false; int ctSkeletonBones=0; // find selected object - to be replaced with the master bone int ctSelected = 0; int ctMeshes=0; _objid = _iti->first(LWI_OBJECT,0); idMasterObjID = LWITEM_NULL; while(_objid != LWITEM_NULL) { if(_iti->type(_objid) == LWI_OBJECT) { if(_ifi->itemFlags(_objid) & LWITEMF_SELECTED) { ctSelected++; idMasterObjID = _objid; } ctMeshes++; } _objid = _iti->next(_objid); } if (idMasterObjID == LWITEM_NULL) { // lightwave error _msg->error("ERROR: Object for top level bone not selected.\n", NULL); return AFUNC_BADAPP; } if (ctSelected > 1) { // lightwave error _msg->error("ERROR: More than one object selected.\n", NULL); return AFUNC_BADAPP; } // get scene name _strFileName = strdup(_sci->filename); // open the file to print into char fnmOut[256]; strcpy(fnmOut, _strFileName); char *pchDot = strrchr(fnmOut, '.'); if (pchDot!=NULL) { strcpy(pchDot, ".aa"); } _ctNumBones = 0; AddBoneToCount(idMasterObjID); if ((_f = fopen(fnmOut,"w")) == NULL) { _msg->error("ERROR: File open.\n", NULL); return AFUNC_BADAPP; } // calculate number of frames to export _ctFrames = ((_ifi->previewEnd-_ifi->previewStart)/_ifi->previewStep)+1; if (_ctFrames<=0) { _ctFrames = 1; } // find all morph channels for the current mesh _pmiFirst = NULL; FindMorphChannels(NULL); AddMotionHandler(idMasterObjID); sprintf(strMessage,"ctBoneEnvelopes: %d",_ctBones); _msg->error(strMessage,fnmOut); bRecordDefaultFrame = true; if (!ExecCmd("GoToFrame 0")) { // goto end; } bRecordDefaultFrame = false; int bExportAnimBackward = *(int*)_xpanf->formGet( pan, ID_ANIM_ORDER); float fTime; // export normal order if(!bExportAnimBackward) { // for each frame in current preview selection for (int iFrame=_ifi->previewStart; iFrame<=_ifi->previewEnd; iFrame+=_ifi->previewStep) { // go to that frame if (!ExecCmd("GoToFrame %d", iFrame)) { // goto end; } assert(_iFrame>=0 && _iFrame<_ctFrames); // NOTE: walking all frames implicitly lets the internal itemmotion handler record all bone positions // we walk the morph maps manually _iFrame++; } // get time fTime = (float) GetCurrentTime(); // export backward } else { // remember time in last frame if (!ExecCmd("GoToFrame %d", _ifi->previewEnd)) { //goto end; return AFUNC_BADGLOBAL; } // get time fTime = (float) GetCurrentTime(); // for each frame in current preview selection going from last to first for (int iFrame=_ifi->previewEnd; iFrame>=_ifi->previewStart; iFrame-=_ifi->previewStep) { // go to that frame if (!ExecCmd("GoToFrame %d", iFrame)) { //goto end; return AFUNC_BADGLOBAL; } assert(_iFrame>=0 && _iFrame<_ctFrames); LWTimeInfo *_tmi = (LWTimeInfo *)_global( LWTIMEINFO_GLOBAL, GFUSE_TRANSIENT ); // NOTE: walking all frames implicitly lets the internal itemmotion handler record all bone positions // we walk the morph maps manually _iFrame++; } } // find the number of morph envelopes for(MorphInfo *ptmpmi=_pmiFirst;ptmpmi!=NULL; ptmpmi = ptmpmi->mi_pmiNext) ctMorphEnvelopes++; fTime = (float) GetCurrentTime(); char strAnimID[256]; strcpy(strAnimID,_strFileName); GetAnimID(strAnimID); fprintf(_f, "SE_ANIM %s;\n\n",SE_ANIM_VER); fprintf(_f, "SEC_PER_FRAME %g;\n",fTime / _ifi->previewEnd * _ifi->previewStep); fprintf(_f, "FRAMES %d;\n", _ctFrames); fprintf(_f, "ANIM_ID \"%s\";\n\n", strAnimID); fprintf(_f, "BONEENVELOPES %d\n{\n", _ctNumBones); BoneInfo *pbiLast = NULL; for (BoneInfo *pbi=_pbiFirst; pbi!=NULL; pbi = pbi->bi_pbiNext) { bool bRootBone = false; // write its info fprintf(_f, " NAME \"%s\"\n", pbi->bi_strName); // write first frame - default pose fprintf(_f, " DEFAULT_POSE {"); BoneFrame &bfDef = pbi->bi_abfFrames[0]; MakeRotationAndPosMatrix(bi_mRot,bfDef.fi_vPos,bfDef.fi_vRot); PrintMatrix(_f,bi_mRot,0); fprintf(_f, "}\n"); fprintf(_f, " {\n"); LWItemType itLast; if(!pbiLast) itLast = LWI_OBJECT; else itLast = pbiLast->bi_lwItemType; // write anim // for each frame for (int iFrame=0; iFrame<_ctFrames; iFrame++) { // Fill 3x4 matrix and store rotation and position in it BoneFrame &bf = pbi->bi_abfFrames[iFrame]; MakeRotationAndPosMatrix(bi_mRot,bf.fi_vPos,bf.fi_vRot); // write matrix to file PrintMatrix(_f,bi_mRot,4); fprintf(_f,"\n"); } pbiLast = pbi; fprintf(_f," }\n\n"); } fprintf(_f,"}\n"); fprintf(_f, "\nMORPHENVELOPES %d\n{\n", ctMorphEnvelopes); // for each morph in list {for (MorphInfo *pmi=_pmiFirst; pmi!=NULL; pmi = pmi->mi_pmiNext) { // write its info fprintf(_f, " NAME \"%s\"\n", pmi->mi_strName); fprintf(_f, " {\n"); for (int iFrame=0; iFrame<_ctFrames; iFrame++) { fprintf(_f, " %g;\n", pmi->mi_afFrames[iFrame]); } fprintf(_f," }\n\n"); } } fprintf(_f,"}\n"); // free all morph infos { MorphInfo *pmi=_pmiFirst; MorphInfo *pmiNext=NULL; for(;;) { if(pmi==NULL) { break; } pmiNext = pmi->mi_pmiNext; free(pmi->mi_strName); free(pmi->mi_afFrames); free(pmi); pmi = pmiNext; }} fprintf(_f, "SE_ANIM_END;\n"); fclose(_f); RemoveMotionHandler(idMasterObjID); _pbiFirst = NULL; return AFUNC_OK; };
void arrayAssign(dplVal *name, dplVal *element, dplVal *value) { #ifdef DEBUG printf("assigning array (name = %s,element = %d)\n", name->value.str.val, element->value.ival); #endif dplVal array; /* fetch the array */ if(variableFetch(&array, name) == FAILURE) { dplError(DPL_WARNINGL, "array was not initialized."); return; } #ifdef DEBUG printf("array check (init = %d, ce = %d)\n", array.value.array.elements->isInit, array.value.array.currentElement); #endif /* check if element exists */ if(arrayElementExists(&array, element) == TRUE) { #ifdef DEBUG printf("element %d in array %s exists...updating\n", element->value.ival, name->value.str.val); #endif /* perform a hash update */ if(dplHashUpdateIndexElement(array.value.array.elements, element->value.ival, value, sizeof(dplVal)) == FAILURE) { dplError(DPL_CORE, "failed updating index %d in %s", element->value.ival, name->value.str.val); return; } else { #ifdef DEBUG printf("updated array element %d successfully\n", element->value.ival); #endif } } else { #ifdef DEBUG printf("element %d in array %s does not exist...adding\n", element->value.ival, name->value.str.val); #endif /* perform a hash add */ if(dplHashAddIndexElement(array.value.array.elements, element->value.ival, value, sizeof(dplVal)) == FAILURE) { dplError(DPL_CORE,"failed adding index %d in %s", element->value.ival, name->value.str.val); return; } else { #ifdef DEBUG printf("added array element %d successfully\n",element->value.ival); #endif } /* commit the changes of the array back */ if(dplHashUpdateElement(&_global(vst), name->value.str.val, name->value.str.len + 1, &array, sizeof(dplVal)) == FAILURE) { dplError(DPL_CORE, "failed udpating the array %s", name->value.str.val); } else { #ifdef DEBUG printf("commited the array back successfully\n"); #endif } } }