*/}}

la_animation.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "la_5.h"
  19. extern LA MAIN;
  20. extern tnsMain* T;
  21. void la_AnimationEvaluateActions(int ClampOffsets);
  22. void laget_AnimationActionHolderCategory(void* a_unused, laActionHolder* ah, char* copy, char** ptr);
  23. void laui_AnimationActionHolder(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *ExtraColumns, int context);
  24. int laAnimationRegisterHolderPath(const char* Path){
  25. laPropPack PP={0}; if(!la_GetPropFromPath(&PP,0,Path,0)){ la_FreePropStepCache(PP.Go); return 0; }
  26. la_EnsureSubTarget(PP.LastPs->p,0);
  27. if((!PP.LastPs->p->SubProp) || (!la_PropLookup(&PP.LastPs->p->SubProp->Props,"__actions__"))){
  28. la_FreePropStepCache(PP.Go); return 0;
  29. }
  30. laActionHolderPath* ahp=memAcquire(sizeof(laActionHolderPath));
  31. ahp->OriginalPath=Path;
  32. la_CopyPropPack(&PP,&ahp->PP); lstAppendItem(&MAIN.Animation->ActionHolderPaths,ahp);
  33. la_FreePropStepCache(PP.Go);
  34. return 1;
  35. }
  36. void laAnimationUpdateHolderList(){
  37. laActionHolder* ah;
  38. while(ah=lstPopItem(&MAIN.Animation->ActionHolders)){
  39. strSafeDestroy(&ah->Name); strSafeDestroy(&ah->CategoryTitle); memFree(ah);
  40. }
  41. for(laActionHolderPath* ahp=MAIN.Animation->ActionHolderPaths.pFirst;ahp;ahp=ahp->Item.pNext){
  42. la_StepPropPack(&ahp->PP); laSubProp* pa=ahp->PP.LastPs->p; la_EnsureSubTarget(pa,0); laPropIterator pi={0};
  43. int ListOffset=0,PropOffset=0;
  44. laSubProp* paa=la_PropLookup(&pa->Base.SubProp->Props,"__actions__");
  45. laSubProp* paap=la_PropLookup(&pa->Base.SubProp->Props,"__action_props__");
  46. if((!paa) || (!paap) || (!paa->ListHandleOffset) || (!paap->ListHandleOffset)){ continue; }
  47. ListOffset=paa->ListHandleOffset; PropOffset=paap->ListHandleOffset;
  48. void* inst=laGetInstance(ahp->PP.LastPs->p,ahp->PP.LastPs->UseInstance,&pi); int FirstIn=1;
  49. while(inst){
  50. ah=memAcquire(sizeof(laActionHolder));
  51. memAssignRef(ah,&ah->Instance,inst);
  52. ah->ActionOffset=ListOffset; ah->PropOffset=PropOffset;
  53. ah->Container=ahp->PP.LastPs->p->SubProp;
  54. char _id[64]="unamed", *id=_id;
  55. laTryGetInstanceIdentifier(inst,pa->Base.SubProp,_id,&id);
  56. strSafeSet(&ah->Name,id);
  57. if(FirstIn){ strSafeSet(&ah->CategoryTitle,pa->Base.SubProp->Name); FirstIn=0; }
  58. lstAppendItem(&MAIN.Animation->ActionHolders,ah);
  59. inst=laGetNextInstance(ahp->PP.LastPs->p, inst, &pi);
  60. }
  61. }
  62. laNotifyUsers("la.animation.action_holders");
  63. }
  64. laActionHolder* laFindAnimationHolder(void* inst,char* container){
  65. for(laActionHolder*ah=MAIN.Animation->ActionHolders.pFirst;ah;ah=ah->Item.pNext){
  66. if(ah->Instance==inst){ if(ah->Container&&strSame(ah->Container->Identifier,container)) return ah; }
  67. }
  68. return 0;
  69. }
  70. laAction* laAnimiationNewAction(laActionHolder* ah, char* Name){
  71. laAction* aa=memAcquire(sizeof(laAction));
  72. if(!Name || !Name[0]){ Name="New Action"; }
  73. strSafeSet(&aa->Name,Name);
  74. aa->Length=2; aa->FrameCount=24; aa->HolderContainer=ah->Container;
  75. memAssignRef(aa,&aa->HolderInstance,ah->Instance);
  76. memAssignRef(MAIN.Animation,&MAIN.Animation->CurrentAction,aa);
  77. void* lh=((uint8_t*)ah->Instance)+ah->ActionOffset;
  78. lstAppendItem(lh,aa);
  79. laNotifyInstanceUsers(ah->Instance);
  80. laNotifyUsers("la.animation.current_action");
  81. return aa;
  82. }
  83. laActionProp* laAnimationEnsureProp(laAction* aa, void* hyper1, laProp* p){
  84. int DataSize=la_GetKeyablePropertyStorageSize(p); if(!DataSize || !aa->HolderInstance || !aa->HolderContainer) return 0;
  85. laSubProp* paap=la_PropLookup(&aa->HolderContainer->Props,"__action_props__"); if(!paap){ return 0; }
  86. laListHandle *pl=((uint8_t*)aa->HolderInstance)+paap->ListHandleOffset;
  87. for(laActionProp* ap=pl->pFirst;ap;ap=ap->Item.pNext){ if(ap->For==hyper1 && ap->Prop==p){ return ap; } }
  88. laActionProp* ap = memAcquire(sizeof(laActionProp)); lstAppendItem(pl,ap);
  89. memAssignRef(ap,&ap->For,hyper1); ap->Prop=p;
  90. ap->DataSize = DataSize;
  91. char _name[128]={0}, *name=_name; laTryGetInstanceIdentifier(hyper1, p->Container,_name,&name);
  92. strSafeSet(&ap->CachedName,name); strSafePrint(&ap->CachedName," ⯈ %s",p->Identifier);
  93. return ap;
  94. }
  95. laActionChannel* laAnimationEnsureChannel(laAction* aa, void* hyper1, laProp* p){
  96. laActionProp* ap=laAnimationEnsureProp(aa, hyper1,p); if(!ap) return 0; laActionChannel* ac;
  97. for(ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){ if(ac->AP==ap) return ac; }
  98. ac=memAcquire(sizeof(laActionChannel)); ac->AP=ap;
  99. lstAppendItem(&aa->Channels,ac); laNotifyUsers("la.animation.current_action.channels");
  100. return ac;
  101. }
  102. laActionChannel* laAnimationEnsureFrame(laActionChannel* ac, int frame){
  103. laActionKey* akf=0,*beforeakf=0;
  104. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  105. if(ak->At==frame){ akf=ak; break; } if(ak->At>frame){ beforeakf=ak; break; }
  106. }
  107. if(!akf){
  108. akf=memAcquireSimple(sizeof(laActionKey));
  109. akf->At=frame; akf->Data=memAcquireSimple(ac->AP->DataSize); akf->DataSize=ac->AP->DataSize;
  110. if(beforeakf){ lstInsertItemBefore(&ac->Keys, akf, beforeakf); }
  111. else{ lstAppendItem(&ac->Keys, akf); }
  112. }
  113. return akf;
  114. }
  115. void laAnimationStoreKeyValue(laActionChannel* ac, laActionKey* ak){
  116. laPropPack PP={0}; laPropStep PS={0}; laActionProp* ap=ac->AP; if(!ap) return;
  117. PS.p=ap->Prop; PS.Type='.'; PS.UseInstance=ap->For; PP.LastPs=&PS; PP.EndInstance=ap->For;
  118. switch(ap->Prop->PropertyType){
  119. case LA_PROP_INT: case LA_PROP_INT | LA_PROP_ARRAY: laGetIntArray(&PP,(int*)ak->Data); break;
  120. case LA_PROP_FLOAT: case LA_PROP_FLOAT | LA_PROP_ARRAY: laGetFloatArray(&PP,(real*)ak->Data); break;
  121. case LA_PROP_ENUM: case LA_PROP_ENUM | LA_PROP_ARRAY: laGetEnumArray(&PP,(laEnumItem**)ak->Data); break;
  122. case LA_PROP_SUB: case LA_PROP_OPERATOR: case LA_PROP_STRING: case LA_PROP_RAW: default: return;
  123. }
  124. }
  125. laActionKey* laAnimationInsertKeyFrame(laAction* aa, void* hyper1, laProp* p, int* error){
  126. if(error) *error=0; if(!aa) return 0;
  127. if(!aa->HolderInstance||!aa->HolderContainer){ if(error) *error=1; return 0; }
  128. if(aa->HolderContainer->ActionHolderVerify){
  129. if(!aa->HolderContainer->ActionHolderVerify(aa->HolderInstance,aa->HolderContainer,hyper1,p->Container)){
  130. if(error) *error=2; return 0;
  131. }
  132. }
  133. laActionChannel* ac=laAnimationEnsureChannel(aa,hyper1,p); if(!ac || !ac->AP || !ac->AP->For) return 0;
  134. int frame=LA_ACTION_FRAME(aa,-1);
  135. laActionKey* ak=laAnimationEnsureFrame(ac,frame);
  136. laAnimationStoreKeyValue(ac,ak);
  137. laNotifyUsers("la.animation.current_action");
  138. return ak;
  139. }
  140. void laAnimationSetPlayStatus(int PlayStatus){
  141. if(PlayStatus>3||PlayStatus<0) PlayStatus=0; MAIN.Animation->PlayStatus=PlayStatus;
  142. if(PlayStatus) laRecordTime(&MAIN.Animation->TimeOrigin);
  143. laNotifyUsers("la.animation.play_status");
  144. }
  145. void laAnimationSetPlayHead(real time){
  146. MAIN.Animation->PlayHead=time;
  147. }
  148. STRUCTURE(laNewActionData){
  149. laActionHolder* SelectedHolder;
  150. };
  151. laActionHolder* laget_AnimationFirstActionHolder(void* unused1, void* unused2){
  152. return MAIN.Animation->ActionHolders.pFirst;
  153. }
  154. void laset_AnimationNewActionSetHolder(laNewActionData *np, laActionHolder *ah, int State){
  155. np->SelectedHolder = ah;
  156. }
  157. int OPINV_AnimationNewAction(laOperator *a, laEvent *e){
  158. laAnimationUpdateHolderList();
  159. laNewActionData* np= memAcquire(sizeof(laNewActionData));
  160. a->CustomData = np;
  161. laEnableOperatorPanel(a, 0, e->x-50,e->y-50,500,500,10000,0,0,0,0,0,0,0,e);
  162. return LA_RUNNING;
  163. }
  164. int OPMOD_AnimationNewAction(laOperator *a, laEvent *e){
  165. laNewActionData* np=a->CustomData;
  166. if(!a->ConfirmData) return LA_RUNNING;
  167. if(a->ConfirmData->Mode == LA_CONFIRM_CANCEL||a->ConfirmData->Mode == LA_CONFIRM_OK){ if(np) memFree(np); return LA_CANCELED; }
  168. if(a->ConfirmData->Mode == LA_CONFIRM_DATA){
  169. if (!np || !np->SelectedHolder){ if(np) memFree(np); return LA_CANCELED; }
  170. laAnimiationNewAction(np->SelectedHolder,0);
  171. laRecordInstanceDifferences(np->SelectedHolder->Instance,np->SelectedHolder->Container->Identifier);
  172. laRecordDifferences(0,"la.animation"); laPushDifferences("New action",0); memFree(np);
  173. return LA_FINISHED;
  174. }
  175. return LA_RUNNING;
  176. }
  177. void laui_AnimationNewAction(laUiList *uil, laPropPack *This, laPropPack *OperatorProps, laColumn *UNUSED, int context){
  178. laColumn *c = laFirstColumn(uil);
  179. laUiItem* ui=laShowItem(uil, c, OperatorProps, "holder");ui->SymbolID=3; ui->Flags|=LA_UI_FLAGS_NO_DECAL;
  180. }
  181. int OPINV_AnimationSelectAction(laOperator *a, laEvent *e){
  182. laEnableOperatorPanel(a, 0, e->x-50,e->y-50,500,500,10000,0,0,0,0,0,0,0,e);
  183. return LA_RUNNING;
  184. }
  185. void laui_AnimationSelectAction(laUiList *uil, laPropPack *This, laPropPack *OperatorProps, laColumn *UNUSED, int context){
  186. laColumn *c = laFirstColumn(uil);
  187. for(laActionHolderPath* ahp=MAIN.Animation->ActionHolderPaths.pFirst;ahp;ahp=ahp->Item.pNext){
  188. laShowLabel(uil,c,ahp->PP.LastPs->p->Name,0,0)->Flags|=LA_UI_FLAGS_DISABLED|LA_TEXT_MONO;
  189. laShowItemFull(uil,c,0,ahp->OriginalPath,LA_WIDGET_COLLECTION,"feedback=NONE",laui_AnimationActionHolder,0)->Flags|=LA_UI_FLAGS_NO_DECAL|LA_UI_FLAGS_NO_GAP;
  190. }
  191. }
  192. void laAnimationRemoveFrame(laActionChannel* ac, laActionKey* ak){
  193. ak->DataSize=0; memLeave(ak->Data); ak->Data=0;
  194. lstRemoveItem(&ac->Keys,ak); memLeave(ak);
  195. }
  196. void laAnimationRemoveChannel(laAction* aa, laActionChannel* ac){
  197. while(ac->Keys.pFirst){ laAnimationRemoveFrame(ac,ac->Keys.pFirst); }
  198. lstRemoveItem(&aa->Channels,ac); memLeave(ac);
  199. }
  200. void laAnimationRemoveAction(laAction* aa){
  201. while(aa->Channels.pFirst){ laAnimationRemoveChannel(aa,aa->Channels.pFirst); }
  202. if(!aa->HolderContainer || !aa->HolderInstance){ return; }
  203. strSafeDestroy(&aa->Name);
  204. if(aa==MAIN.Animation->CurrentAction){
  205. if(aa->Item.pNext){ memAssignRef(MAIN.Animation,&MAIN.Animation->CurrentAction,aa->Item.pNext); }
  206. else{ memAssignRef(MAIN.Animation,&MAIN.Animation->CurrentAction,aa->Item.pPrev); }
  207. }
  208. laSubProp* paa=la_PropLookup(&aa->HolderContainer->Props,"__actions__"); if(!paa){ goto action_remove_clean; }
  209. laListHandle* al=((uint8_t*)aa->HolderInstance)+paa->ListHandleOffset;
  210. lstRemoveItem(al,aa);
  211. action_remove_clean:
  212. memLeave(aa);
  213. }
  214. void* laAnimationGetRetargetedPropInstance(laProp* p, void* Instance){
  215. laPropContainer* pc=p->Container;
  216. laProp* rp = la_PropLookup(&pc->Props,"__action_retarget__");
  217. if(rp->PropertyType!=LA_PROP_SUB) return Instance;
  218. laPropIterator pi={0};
  219. void* retargeted = laGetInstance(rp,Instance,&pi);
  220. return retargeted;
  221. }
  222. void laAnimationEnsureRetarget(void* HolderInstance, laListHandle* action_list, laActionRetarget** retarget){
  223. if((*retarget) || (!HolderInstance) || (!action_list)){ return; }
  224. int count = lstCountElements(action_list); if(!count){ return; }
  225. laActionRetarget* ar=memAcquire(sizeof(laActionRetarget));
  226. ar->ActionCount = count; ar->Actions = action_list; ar->HolderInstance = HolderInstance;
  227. ar->Retargeted = memAcquireSimple(sizeof(laRetargetedAction)*count);
  228. int i=0;
  229. for(laAction* aa=action_list->pFirst;aa;aa=aa->Item.pNext){
  230. int channels = lstCountElements(&aa->Channels);
  231. ar->Retargeted[i].Instances = memAcquireSimple(sizeof(void*)*channels);
  232. ar->Retargeted[i].PlayStatus = aa->PlayByDefault?LA_ANIMATION_STATUS_PLAY_FWD:0;
  233. int j=0;
  234. for(laActionChannel* ac = aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  235. ar->Retargeted[i].Instances[j] = laAnimationGetRetargetedPropInstance(ac->AP->Prop,ac->AP->For); j++;
  236. }
  237. i++;
  238. }
  239. *retarget = ar;
  240. }
  241. laActionRetarget* laAnimationCopyRetargetFrom(laActionRetarget* from_ar){
  242. if(!from_ar) return 0;
  243. laActionRetarget* ar=0;
  244. laAnimationEnsureRetarget(from_ar->HolderInstance, from_ar->Actions, &ar);
  245. return ar;
  246. }
  247. void laAnimationClearRetarget(laActionRetarget **ar_ptr){
  248. if(!ar_ptr) return;
  249. laActionRetarget *ar = *ar_ptr;
  250. if(!ar || !ar->ActionCount) return;
  251. for(int i=0;i<ar->ActionCount;i++){ memFree(ar->Retargeted[i].Instances); }
  252. memFree(ar->Retargeted); memFree(ar); *ar_ptr=0;
  253. }
  254. void laSetRunPlayHead(real RunPlayHead){
  255. MAIN.Animation->RunPlayHead = RunPlayHead;
  256. }
  257. int OPCHK_AnimationRemoveAction(laPropPack *This, laStringSplitor *Instructions){
  258. laPropContainer* pc; return LA_VERIFY_THIS_TYPE(This,pc,"la_animation_action");
  259. }
  260. int OPINV_AnimationRemoveAction(laOperator *a, laEvent *e){
  261. if(!a->This || !a->This->EndInstance){ return LA_CANCELED; }
  262. laAction* aa=a->This->EndInstance;
  263. char str[256]; sprintf(str,"Will remove action \"%s\".",SSTR(aa->Name));
  264. laEnableYesNoPanel(a,0,"Remove?",str,e->x,e->y,200,e);
  265. return LA_RUNNING;
  266. }
  267. int OPMOD_AnimationRemoveAction(laOperator *a, laEvent *e){
  268. if(!a->This || !a->This->EndInstance){ return LA_CANCELED; }
  269. laAction* aa=a->This->EndInstance;
  270. if(a->ConfirmData && a->ConfirmData->Mode==LA_CONFIRM_OK){
  271. laAnimationRemoveAction(aa); laNotifyUsers("la.animation");
  272. laRecordInstanceDifferences(aa->HolderInstance,aa->HolderContainer->Identifier);
  273. laRecordDifferences(0,"la.animation"); laPushDifferences("Remove action",0);
  274. }
  275. return LA_FINISHED;
  276. }
  277. int OPINV_AnimationPlayAction(laOperator *a, laEvent *e){
  278. char* str=strGetArgumentString(a->ExtraInstructionsP, "mode");
  279. int PlayStatus=LA_ANIMATION_STATUS_PAUSED;
  280. if(strSame(str,"forward")){ PlayStatus=LA_ANIMATION_STATUS_PLAY_FWD; }
  281. elif(strSame(str,"reverse")){ if(MAIN.Animation->PlayHead>0) PlayStatus=LA_ANIMATION_STATUS_PLAY_REV; }
  282. laAnimationSetPlayStatus(PlayStatus);
  283. return LA_FINISHED;
  284. }
  285. void la_AnimationActionSetOwnFrame(laAction* aa, int frame, int clamp){
  286. if(!aa) return;
  287. aa->Offset+=(aa->PlayHead-(real)frame/aa->FrameCount)*aa->Length;
  288. la_AnimationEvaluateActions(clamp);
  289. laNotifyUsers("la.animation.current_action");
  290. }
  291. int OPINV_AnimationResetTime(laOperator *a, laEvent *e){
  292. char* arg=strGetArgumentString(a->ExtraInstructionsP,"current");
  293. if(strSame(arg,"true")){ la_AnimationActionSetOwnFrame(MAIN.Animation->CurrentAction,0,1); return LA_FINISHED; }
  294. laAnimationSetPlayHead(0); la_AnimationEvaluateActions(1);
  295. return LA_FINISHED;
  296. }
  297. laActionChannel* laAnimationGetFrame(laActionChannel* ac, int frame){
  298. if(ac->Keys.pFirst==ac->Keys.pLast){ return ac->Keys.pFirst; }
  299. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  300. if(ak->At<=frame && ((!ak->Item.pNext) ||ak->Item.pNext && ((laActionKey*)ak->Item.pNext)->At>frame)){ return ak; }
  301. }
  302. return ac->Keys.pFirst;
  303. }
  304. void la_AnimationMarkPropReset(){
  305. for(laActionHolder* ah=MAIN.Animation->ActionHolders.pFirst;ah;ah=ah->Item.pNext){
  306. if(!ah->Instance){ continue; } laListHandle* lp=((uint8_t*)ah->Instance)+ah->PropOffset;
  307. for(laActionProp* ap=lp->pFirst;ap;ap=ap->Item.pNext){ ap->Reset=1; }
  308. }
  309. }
  310. void la_AnimationInterpolateKeys(laActionChannel* ac, laActionKey* ak1, laActionKey* ak2, real PlayHead_mul_Length, void** data){
  311. int* id1,*id2,*iret=(*data); real* fd1,*fd2,*fret=(*data);
  312. if(!ak2){ *data=ak1->Data; return; } laActionProp* ap=ac->AP; if(!ap) return;
  313. int arrlen=ap->Prop->Len?ap->Prop->Len:1;
  314. real fac=tnsGetRatiod(ak1->At,ak2->At,PlayHead_mul_Length); TNS_CLAMP(fac,0,1);
  315. switch(ap->Prop->PropertyType){
  316. case LA_PROP_INT: case LA_PROP_INT|LA_PROP_ARRAY:
  317. id1=ak1->Data;id2=ak2->Data; for(int i=0;i<arrlen;i++){ iret[i]=tnsLinearItp(id1[i],id2[i],fac); } break;
  318. case LA_PROP_FLOAT: case LA_PROP_FLOAT|LA_PROP_ARRAY:
  319. fd1=ak1->Data;fd2=ak2->Data; for(int i=0;i<arrlen;i++){ fret[i]=tnsLinearItp(fd1[i],fd2[i],fac); } break;
  320. default:
  321. *data=ak1->Data; break;
  322. }
  323. }
  324. void la_AnimationSetPropValue(laActionProp* ap, void* OverrideInstance){
  325. void* data=ap->Data;
  326. laPropPack PP={0}; laPropStep PS={0}; if(!ap) return;
  327. PS.p=ap->Prop; PS.Type='.'; PS.UseInstance=OverrideInstance?OverrideInstance:ap->For; PP.LastPs=&PS; PP.EndInstance=OverrideInstance?OverrideInstance:ap->For;
  328. switch(ap->Prop->PropertyType){
  329. case LA_PROP_INT: laSetInt(&PP,*((int*)data)); break;
  330. case LA_PROP_INT|LA_PROP_ARRAY: laSetIntArrayAllArray(&PP,(int*)data); break;
  331. case LA_PROP_FLOAT: laSetFloat(&PP,*((real*)data)); break;
  332. case LA_PROP_FLOAT|LA_PROP_ARRAY: laSetFloatArrayAllArray(&PP,(real*)data); break;
  333. case LA_PROP_ENUM: laSetEnum(&PP,*((int*)data)); break;
  334. //case LA_PROP_ENUM|LA_PROP_ARRAY: laSetEnumArrayAllArray(&PP,(real*)data); break; //doesnt work
  335. default: break;
  336. }
  337. }
  338. void la_AnimationMixChannelValue(laActionChannel* ac, void* data, int MixMode, real Factor){
  339. laActionProp* ap=ac->AP; if(!ap) return; int* ip=ap->Data,*ipd=data; real* fp=ap->Data,*fpd=data;
  340. int arrlen=ap->Prop->Len?ap->Prop->Len:1;
  341. switch(ap->Prop->PropertyType){
  342. case LA_PROP_INT: case LA_PROP_INT|LA_PROP_ARRAY: for(int i=0;i<arrlen;i++){
  343. ip[i]=ap->Reset?ipd[i]:(MixMode==LA_ANIMATION_MIX_REPLACE?ipd[i]:(ipd[i]+ip[i]));
  344. } break;
  345. case LA_PROP_FLOAT: case LA_PROP_FLOAT|LA_PROP_ARRAY: for(int i=0;i<arrlen;i++){
  346. fp[i]=ap->Reset?fpd[i]:(MixMode==LA_ANIMATION_MIX_REPLACE?fpd[i]:(fpd[i]+fp[i]));
  347. } break;
  348. case LA_PROP_ENUM: ip[0]=ipd[0]; break;
  349. //case LA_PROP_ENUM|LA_PROP_ARRAY: laSetEnumArrayAllArray(&PP,(real*)data); break; //doesnt work
  350. default: break;
  351. }
  352. ap->Reset=0;
  353. }
  354. void la_AnimationEvaluateActionChannels(laAction* aa, real OverridePlayHead){
  355. int64_t _data[16]; void* data=_data;
  356. int frame=LA_ACTION_FRAME(aa,OverridePlayHead); real totframe=((OverridePlayHead>=0)?OverridePlayHead:aa->PlayHead)*aa->FrameCount;
  357. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  358. data=_data;
  359. laActionKey* ak1=laAnimationGetFrame(ac,frame); if(!ak1) continue;
  360. laActionKey* ak2=ak1->Item.pNext;
  361. la_AnimationInterpolateKeys(ac,ak1,ak2,totframe,&data);
  362. la_AnimationMixChannelValue(ac, data, aa->MixMode, 0);
  363. }
  364. }
  365. void la_AnimationEvaluateActions(int ClampOffsets){
  366. int any=0;
  367. la_AnimationMarkPropReset();
  368. for(laActionHolder* ah=MAIN.Animation->ActionHolders.pFirst;ah;ah=ah->Item.pNext){
  369. if(!ah->Instance) continue;
  370. laListHandle* lh=((uint8_t*)ah->Instance)+ah->ActionOffset;
  371. for(laAction* aa=lh->pFirst;aa;aa=aa->Item.pNext){
  372. real preoffset=0,postoffset=aa->Offset/aa->Length;
  373. if(ClampOffsets || (MAIN.Animation->PlayStatus!=LA_ANIMATION_STATUS_PAUSED)){
  374. while(aa->Offset>aa->Length*2){ aa->Offset-=aa->Length*2; }
  375. while(aa->Offset<0){ aa->Offset+=aa->Length*2; }
  376. preoffset=aa->Offset; postoffset=0;
  377. }
  378. real UseTime=MAIN.Animation->PlayHead-preoffset+aa->Length*2;
  379. int repeats=(real)(UseTime/aa->Length);
  380. real remaining=UseTime-repeats*aa->Length;
  381. while(remaining<0){ remaining+=aa->Length; }
  382. if(aa->PlayMode==LA_ANIMATION_PLAY_MODE_REPEAT){ aa->PlayHead=remaining/aa->Length-postoffset; }
  383. elif(aa->PlayMode==LA_ANIMATION_PLAY_MODE_HOLD){ aa->PlayHead=((UseTime>aa->Length)?1.0:(UseTime<0?0:UseTime/aa->Length))-postoffset; }
  384. elif(aa->PlayMode==LA_ANIMATION_PLAY_MODE_BOUNCE){ real t=remaining/aa->Length; aa->PlayHead=((repeats%2)?(1-t):t)-postoffset; }
  385. any=1;
  386. la_AnimationEvaluateActionChannels(aa,-1);
  387. }
  388. }
  389. for(laActionHolder* ah=MAIN.Animation->ActionHolders.pFirst;ah;ah=ah->Item.pNext){
  390. if(!ah->Instance){ continue; } laListHandle* lp=((uint8_t*)ah->Instance)+ah->PropOffset;
  391. for(laActionProp* ap=lp->pFirst;ap;ap=ap->Item.pNext){ if(ap->Reset){ continue; }
  392. la_AnimationSetPropValue(ap,0);
  393. }
  394. }
  395. if(any) laNotifyUsers("la.animation");
  396. }
  397. void la_AnimationMarkRetargetedReset(laActionRetarget* ar){
  398. for(laAction* aa=ar->Actions->pFirst;aa;aa=aa->Item.pNext){
  399. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  400. if(ac->AP) ac->AP->Reset = 1;
  401. }
  402. }
  403. }
  404. laRetargetedAction* la_AnimationGetRetargetedAction(laActionRetarget* ar, laAction* aa){
  405. int i=0; for(laAction* a=ar->Actions->pFirst;a&&i<ar->ActionCount;a=a->Item.pNext){ if(a==aa) return &ar->Retargeted[i]; i++; }
  406. }
  407. int laAnimationSyncRetarget(laActionRetarget* ar, real PlayHead){
  408. int need_sync = (ar->PlaySync != PlayHead);
  409. real delta = PlayHead-ar->PlaySync; ar->PlaySync = PlayHead; int i=0;
  410. for(laAction* aa=ar->Actions->pFirst;aa;aa=aa->Item.pNext){
  411. if(ar->Retargeted[i].PlayStatus && need_sync){
  412. int fac_direction = ((ar->Retargeted[i].Direction<0)?-1:1);
  413. ar->Retargeted[i].PlayHead += delta / aa->Length * fac_direction;
  414. }
  415. if(aa->PlayMode==LA_ANIMATION_PLAY_MODE_REPEAT){ ar->Retargeted[i].Direction = 1;ar->Retargeted[i].PlayHead=fmod(ar->Retargeted[i].PlayHead,1.0f); }
  416. elif(aa->PlayMode==LA_ANIMATION_PLAY_MODE_HOLD){ ar->Retargeted[i].Direction = 1; TNS_CLAMP(ar->Retargeted[i].PlayHead,0.0f,1.0f); }
  417. elif(aa->PlayMode==LA_ANIMATION_PLAY_MODE_BOUNCE){
  418. if(ar->Retargeted[i].PlayHead<0){ ar->Retargeted[i].PlayHead=-ar->Retargeted[i].PlayHead; ar->Retargeted[i].Direction = 1; }
  419. elif(ar->Retargeted[i].PlayHead>1.0f){ ar->Retargeted[i].PlayHead=1.0f-(ar->Retargeted[i].PlayHead-1.0f); ar->Retargeted[i].Direction = -1; }
  420. }
  421. i++;
  422. }
  423. return 1;
  424. }
  425. int laAnimationEvaluateRetargetedActions(laActionRetarget* ar){
  426. int any=0; if(!ar || !ar->Retargeted){ return 0; }
  427. la_AnimationMarkRetargetedReset(ar); int i=0;
  428. for(laAction* aa=ar->Actions->pFirst;aa;aa=aa->Item.pNext){
  429. la_AnimationEvaluateActionChannels(aa,ar->Retargeted[i].PlayHead);
  430. i++;
  431. }
  432. i=0;
  433. for(laAction* aa=ar->Actions->pFirst;aa;aa=aa->Item.pNext){
  434. int j=0;
  435. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  436. if(ac->AP->Reset){ j++; continue; }
  437. la_AnimationSetPropValue(ac->AP,ar->Retargeted[i].Instances[j]);
  438. j++; any=1;
  439. }
  440. i++;
  441. }
  442. return any;
  443. }
  444. void la_AnimationPreFrame(){
  445. if(MAIN.Animation->PlayHead<0){
  446. MAIN.Animation->PlayHead=0; laAnimationSetPlayStatus(0);
  447. la_AnimationEvaluateActions(1);
  448. laNotifyUsers("la.animation.play_head");
  449. }
  450. if(MAIN.Animation->PlayStatus){
  451. la_AnimationEvaluateActions(0);
  452. }
  453. }
  454. void la_AnimationPostFrame(){
  455. laTimeRecorder cur={0};
  456. if(MAIN.Animation->PlayStatus){ laRecordTime(&cur);
  457. real td=laTimeElapsedSecondsf(&cur,&MAIN.Animation->TimeOrigin);
  458. laRecordTime(&MAIN.Animation->TimeOrigin);
  459. if(MAIN.Animation->PlayStatus==LA_ANIMATION_STATUS_PLAY_REV){ td*=-1; }
  460. MAIN.Animation->PlayHead+=td; laNotifyUsers("la.animation.play_head");
  461. }
  462. }
  463. void la_ActionDeselectFrames(laAction* aa){
  464. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  465. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  466. ak->Selected=0;
  467. }
  468. }
  469. }
  470. void la_ActionSelectFrame(laAction* aa, int Channel, real At, real zoomx){
  471. int tc=0;laActionChannel* ac;
  472. for(ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){ if(tc==Channel) break; tc++; }
  473. if(!ac) return;
  474. real ClosestDist=FLT_MAX; laActionKey* ClosestKey=0;
  475. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  476. real d=fabs(ak->At-At+0.5); if(d*zoomx<LA_RH*2 && d<ClosestDist){ ClosestDist=d; ClosestKey=ak; }
  477. }
  478. if(ClosestKey){ ClosestKey->Selected=1; }
  479. }
  480. int la_ActionSaveKeyOriginalAt(laAction* aa){
  481. int any=0;
  482. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  483. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){ if(!ak->Selected) continue; any=1; ak->OriginaAt=ak->At; }
  484. }
  485. return any;
  486. }
  487. void la_ActionEnsureFrameOrder(laAction* aa){
  488. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  489. laListHandle lst={0};
  490. laActionKey* ak; while(ak=lstPopItem(&ac->Keys)){ int done=0;
  491. if(!lst.pFirst){ lstAppendItem(&lst,ak); continue; }
  492. laActionKey* ak2=0;
  493. for(ak2=lst.pFirst;ak2;ak2=ak2->Item.pNext){
  494. if(ak2->At>=ak->At){ lstInsertItemBefore(&lst,ak,ak2); done=1; break; }
  495. }
  496. if(!done) lstAppendItem(&lst,ak);
  497. }
  498. lstCopyHandle(&ac->Keys,&lst);
  499. }
  500. }
  501. void la_ActionRestoreKeyOriginalAt(laAction* aa) {
  502. for (laActionChannel* ac = aa->Channels.pFirst; ac; ac = ac->Item.pNext) {
  503. for (laActionKey* ak = ac->Keys.pFirst; ak; ak = ak->Item.pNext) { if (!ak->Selected) continue; ak->At = ak->OriginaAt; }
  504. }
  505. la_ActionEnsureFrameOrder(aa);
  506. }
  507. void la_ActionRemoveDuplicatedFrames(laAction* aa){
  508. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  509. laActionKey* ak2; for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  510. while((ak2=ak->Item.pNext)&&ak->At==ak2->At){ lstRemoveItem(&ac->Keys,ak2); memLeave(ak2); }
  511. }
  512. }
  513. }
  514. void la_ActionMoveSelectedFrames(laAction* aa, int Delta){
  515. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  516. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){ if(!ak->Selected) continue;
  517. ak->At=ak->OriginaAt+Delta;
  518. }
  519. }
  520. la_ActionEnsureFrameOrder(aa);
  521. }
  522. int la_ActionDeleteSelectedFrames(laAction* aa){
  523. int any=0; laActionChannel* NextAc;
  524. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=NextAc){ NextAc=ac->Item.pNext;
  525. laActionKey* NextAk; for(laActionKey* ak=ac->Keys.pFirst;ak;ak=NextAk){ NextAk=ak->Item.pNext;if(!ak->Selected) continue;
  526. laAnimationRemoveFrame(ac,ak); any=1;
  527. }
  528. if(!ac->Keys.pFirst){ laAnimationRemoveChannel(aa,ac); any=1; }
  529. }
  530. return any;
  531. }
  532. int LAMOD_AnimationActionsCanvas(laOperator *a, laEvent *e){
  533. laUiItem *ui = a->Instance; laBoxedTheme *bt = (*ui->Type->Theme);
  534. laCanvasExtra *ex = a->CustomData; laAction* aa=ui->PP.EndInstance;
  535. if(!aa) LA_RUNNING_PASS;
  536. int W, H; W = ui->R - ui->L; H = ui->B - ui->U;
  537. int ShowSide=(ex->ShowLegend&&ex->LW<W-2*LA_RH);
  538. int ll=ui->L, lr=ll+(ShowSide?ex->LW:0), tl=lr, tr=ui->R;
  539. int FW=LA_RH/2;
  540. int Channels=aa?lstCountElements(&aa->Channels):0;
  541. int Modal=0; int mid=((W-lr)/2);
  542. if(e->type==LA_M_MOUSE_DOWN){
  543. ex->UiMode=1; ex->ClickedX=e->x; ex->ClickedY=e->y; Modal=1; ex->Dragging=10;
  544. }elif(e->type==LA_M_MOUSE_UP || e->type==LA_L_MOUSE_UP){
  545. ex->UiMode=0; Modal=1; ex->Dragging=0; ex->TargetIndexVali=0;
  546. }
  547. if(ex->UiMode==1){
  548. if(e->type&LA_MOUSE_EVENT){
  549. ex->PanY-=e->y-ex->ClickedY; ex->PanX-=e->x-ex->ClickedX;
  550. ex->ClickedX=e->x; ex->ClickedY=e->y; Modal=1;
  551. }
  552. }elif(ex->UiMode==2){ Modal=1;
  553. if(e->type&LA_MOUSE_EVENT){
  554. ex->LW=e->x-ui->L+LA_SEAM_W; ex->ClickedX=e->x; ex->ClickedY=e->y;
  555. if(ex->LW<LA_RH*3 && ex->LW>=LA_RH/2){ ex->LW=LA_RH*3; }
  556. if(ex->LW<LA_RH/2 && ex->Dragging!=12){ ex->ShowLegend=0; ex->LW=0; }
  557. if(ex->LW<LA_RH*3){ ex->LW=LA_RH*3;}
  558. }
  559. }elif(ex->UiMode==3){ Modal=1;
  560. if(e->type&LA_MOUSE_EVENT){ ex->ClickedX=e->x; ex->ClickedY=e->y;
  561. int SetFrame=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW;
  562. la_AnimationActionSetOwnFrame(aa,SetFrame,0);
  563. }
  564. }elif(ex->UiMode==4){ Modal=1;
  565. if(e->type==LA_R_MOUSE_DOWN || (e->type==LA_ESCAPE_DOWN)){ ex->UiMode=0; ex->Dragging=0;
  566. la_ActionRestoreKeyOriginalAt(aa); laNotifyUsers("la.animation.current_action");
  567. }elif(e->type==LA_L_MOUSE_DOWN){ la_ActionRemoveDuplicatedFrames(aa);
  568. laNotifyUsers("la.animation.current_action"); ex->UiMode=0; ex->Dragging=0;
  569. }elif(e->type&LA_MOUSE_EVENT){ Modal=1;
  570. int ToFrame=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW,FromFrame=(real)(ex->ClickedX-tl+ex->PanX)/ex->ZoomX/FW;
  571. la_ActionMoveSelectedFrames(aa,ToFrame-FromFrame); laNotifyUsers("la.animation.current_action");
  572. }
  573. }
  574. int MaxDN=LA_RH*(Channels+1)-H+bt->TP+bt->BP; if(MaxDN<0) MaxDN=0;
  575. if(!Modal){
  576. if(e->x<=lr){
  577. if(e->type==LA_MOUSE_WHEEL_DOWN){ ex->PanY+=LA_RH*MAIN.ScrollingSpeed; Modal=1; }
  578. if(e->type==LA_MOUSE_WHEEL_UP){ ex->PanY-=LA_RH*MAIN.ScrollingSpeed; Modal=1; }
  579. if(e->x>=lr-LA_SEAM_W*2){ if(!ex->TargetIndexVali){ ex->TargetIndexVali=1; Modal=1; }
  580. if(e->type==LA_L_MOUSE_DOWN){
  581. ex->UiMode=2; ex->ClickedX=e->x; ex->ClickedY=e->y; Modal=1; ex->Dragging=10; Modal=1;
  582. }
  583. }else{ if(ex->TargetIndexVali){ ex->TargetIndexVali=0; Modal=1; } }
  584. }elif(aa){
  585. if((!ex->ShowLegend)&&e->x<=ll+LA_SEAM_W*2){
  586. if(!ex->TargetIndexVali){ ex->TargetIndexVali=1; Modal=1; }
  587. if(e->type==LA_L_MOUSE_DOWN){ ex->LW=LA_RH*4; ex->Dragging=12; ex->ShowLegend=1; Modal=1; ex->UiMode=2; ex->TargetIndexVali=1; }
  588. }else{ if(ex->TargetIndexVali){ ex->TargetIndexVali=0; Modal=1; } }
  589. if(e->type==LA_MOUSE_WHEEL_DOWN){ ex->ZoomX*=0.9; ex->PanX+=mid; ex->PanX*=0.9; ex->PanX-=mid; Modal=1; }
  590. elif(e->type==LA_MOUSE_WHEEL_UP){ ex->ZoomX*=1.1; ex->PanX+=mid; ex->PanX*=1.1; ex->PanX-=mid; Modal=1; }
  591. elif(e->type==LA_L_MOUSE_DOWN){
  592. ex->UiMode=3; int SetFrame=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW;
  593. la_AnimationActionSetOwnFrame(aa,SetFrame,0); Modal=1;
  594. }elif(e->type==LA_R_MOUSE_DOWN){
  595. int row=(e->y-ui->U-bt->BM-LA_RH)/LA_RH; real at=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW;
  596. if(!(e->SpecialKeyBit&LA_KEY_SHIFT)){ la_ActionDeselectFrames(aa); }
  597. la_ActionSelectFrame(aa,row,at,ex->ZoomX);
  598. laNotifyUsers("la.animation.current_action");
  599. }elif(e->type==LA_KEY_DOWN&&e->key=='g'){
  600. int any=la_ActionSaveKeyOriginalAt(aa);
  601. if(any){ ex->ClickedX=e->x; ex->ClickedY=e->y; ex->UiMode=4; Modal=1; ex->Dragging=13;
  602. laNotifyUsers("la.animation.current_action");
  603. }
  604. }elif(e->type==LA_KEY_DOWN&&e->key=='x'){
  605. int any=la_ActionDeleteSelectedFrames(aa);
  606. if(any){
  607. laNotifyUsers("la.animation.current_action");
  608. }
  609. }
  610. }
  611. }
  612. if(ex->PanY>MaxDN){ ex->PanY=MaxDN; } if(ex->PanY<0){ ex->PanY=0; }
  613. //if(ex->PanX<0){ ex->PanX=0; }
  614. if(ex->TargetIndexVali){ laSetWindowCursor(LA_LEFT_AND_RIGHT); }else{ laSetWindowCursor(LA_ARROW); }
  615. if(Modal){ laRedrawCurrentPanel(); return LA_RUNNING; }
  616. return LA_RUNNING_PASS;
  617. }
  618. void la_AnimationActionCanvasInit(laUiItem *ui){
  619. la_CanvasInit(ui);
  620. laCanvasExtra* ex=ui->Extra; ex->LW=LA_RH*7; ex->ShowLegend=1;
  621. }
  622. void la_AnimationActionDrawCanvas(laBoxedTheme *bt, laAction *aa, laUiItem* ui){
  623. laCanvasExtra* ex=ui->Extra; //laAction* aa=ui->PP.EndInstance;
  624. int W, H; W = ui->R - ui->L; H = ui->B - ui->U; if (W<=0 || H<=0) return;
  625. int ShowSide=(ex->ShowLegend&&ex->LW<W-2*LA_RH);
  626. int ll=ui->L, lr=ll+(ShowSide?ex->LW-1:0), tl=lr, tr=ui->R;
  627. int FW=LA_RH/2;
  628. //if (!e->OffScr || e->OffScr->pColor[0]->Height != ui->B - ui->U || e->Be.OffScr->pColor[0]->Width != ui->R - ui->L){
  629. // if (e->OffScr) tnsDelete2DOffscreen(e->OffScr);
  630. // e->OffScr = tnsCreate2DOffscreen(GL_RGBA, W, H, MAIN.PanelMultisample, 1, 0);
  631. //}
  632. real *bkg=laThemeColor(bt,LA_BT_NORMAL);
  633. real *txt=laThemeColor(bt,LA_BT_TEXT);
  634. real *act=laThemeColor(bt,LA_BT_ACTIVE);
  635. tnsUseNoTexture();
  636. tnsColor4d(LA_COLOR3(bkg),bkg[3]*0.3);
  637. tnsVertex2d(tl, ui->U); tnsVertex2d(tr, ui->U);
  638. tnsVertex2d(tr, ui->B); tnsVertex2d(tl, ui->B);
  639. tnsPackAs(GL_TRIANGLE_FAN);
  640. int row=1,curframe,cx; real fl,fr;
  641. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  642. tnsVertex2d(ui->L, ui->U+bt->TP+LA_RH); tnsVertex2d(ui->R, ui->U+bt->TP+LA_RH);
  643. tnsVertex2d(ui->R, ui->U); tnsVertex2d(ui->L, ui->U);
  644. tnsPackAs(GL_TRIANGLE_FAN);
  645. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));
  646. tnsVertex2d(tl, LA_RH+ui->U); tnsVertex2d(tr, LA_RH+ui->U);
  647. tnsPackAs(GL_LINES);
  648. tnsFlush();
  649. int sx,sy,sw,sh,vl,vr,vu,vb;
  650. la_DoUiScissor(ui,&sx,&sy,&sw,&sh,&vl,&vr,&vu,&vb);
  651. if(aa){
  652. curframe=LA_ACTION_FRAME(aa,-1); fl=tl+curframe*FW*ex->ZoomX-ex->PanX, fr=tl+(curframe+1)*FW*ex->ZoomX-ex->PanX;
  653. tnsUseNoTexture();
  654. tnsColor4dv(laAccentColor(LA_BT_NORMAL));
  655. tnsVertex2d(fl, ui->U); tnsVertex2d(fr, ui->U);
  656. tnsVertex2d(fr, ui->B); tnsVertex2d(fl, ui->B);
  657. tnsPackAs(GL_TRIANGLE_FAN);
  658. tnsFlush(); glLineWidth(2);
  659. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  660. real ku=ui->U+bt->TP+row*LA_RH-ex->PanY,kb=ku+LA_RH;
  661. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  662. real kl=tl+ak->At*FW*ex->ZoomX-ex->PanX, kr=tl+(ak->At+1)*FW*ex->ZoomX-ex->PanX;
  663. if(ak->Selected) tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE));
  664. elif(curframe==ak->At) tnsColor4d(LA_COLOR3(txt),txt[3]*0.6);
  665. else tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  666. tnsVertex2d(kl, ku); tnsVertex2d(kr, ku);
  667. tnsVertex2d(kr, kb); tnsVertex2d(kl, kb);
  668. tnsPackAs(GL_TRIANGLE_FAN);
  669. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT_ACTIVE));
  670. tnsVertex2d(kl, ku); tnsVertex2d(kr, ku);
  671. tnsVertex2d(kr, kb); tnsVertex2d(kl, kb);
  672. tnsPackAs(GL_LINE_LOOP);
  673. }
  674. row++;
  675. }
  676. tnsFlush(); glLineWidth(1);
  677. real end=tl+aa->FrameCount*FW*ex->ZoomX-ex->PanX;
  678. tnsColor4d(0,0,0,0.3);
  679. tnsVertex2d(end, ui->U+LA_RH); tnsVertex2d(end+1e6, ui->U+LA_RH);
  680. tnsVertex2d(end+1e6, ui->B); tnsVertex2d(end, ui->B);
  681. tnsPackAs(GL_TRIANGLE_FAN);
  682. tnsVertex2d(tl-ex->PanX, ui->U+LA_RH); tnsVertex2d(tl-ex->PanX-1e6, ui->U+LA_RH);
  683. tnsVertex2d(tl-ex->PanX-1e6, ui->B); tnsVertex2d(tl-ex->PanX, ui->B);
  684. tnsPackAs(GL_TRIANGLE_FAN);
  685. tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE));
  686. int FrameFix=aa->PlayHead<0?1:0;
  687. cx=tl+(aa->PlayHead*aa->FrameCount+FrameFix)*FW*ex->ZoomX-ex->PanX; tnsVertex2d(cx, ui->U); tnsVertex2d(cx, ui->B);
  688. tnsPackAs(GL_LINES); glLineWidth(3); tnsFlush(); glLineWidth(1);
  689. char buf[32]; sprintf(buf,"%d",curframe); real tlen=tnsStringGetDimension(buf,0,0,0,0,0)+bt->LP+bt->RP;
  690. tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE));
  691. tnsVertex2d(cx, ui->U+LA_RH); tnsVertex2d(cx+tlen, ui->U+LA_RH);
  692. tnsVertex2d(cx+tlen, ui->U); tnsVertex2d(cx, ui->U);
  693. tnsPackAs(GL_TRIANGLE_FAN);
  694. tnsDrawStringAuto(buf,laThemeColor(bt,LA_BT_TEXT_ACTIVE),cx+bt->LP,cx+LA_RH*2,ui->U+bt->TP,0);
  695. tnsPackAs(GL_TRIANGLE_FAN); tnsUseNoTexture();
  696. }
  697. if(ShowSide){
  698. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  699. tnsVertex2d(ll, ui->U); tnsVertex2d(lr, ui->U);
  700. tnsVertex2d(lr, ui->B); tnsVertex2d(ll, ui->B);
  701. tnsPackAs(GL_TRIANGLE_FAN);
  702. if(!aa){
  703. tnsDrawStringAuto("No action selected",laThemeColor(bt,LA_BT_TEXT),ll+bt->LP,lr-bt->RP,ui->U+bt->BP,0);
  704. }else{ int row=1;
  705. tnsDrawStringAuto(SSTR(aa->Name),laThemeColor(bt,LA_BT_TEXT),ll+bt->LP,lr-bt->RP,ui->U+bt->BP,0);
  706. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){ if(!ac->AP){ continue; }
  707. tnsDrawStringAuto(SSTR(ac->AP->CachedName),laThemeColor(bt,LA_BT_TEXT),ll+bt->LP,lr-bt->RP,ui->U+bt->TP+row*LA_RH-ex->PanY,0);
  708. row++;
  709. }
  710. }
  711. }
  712. if(ex->TargetIndexVali==1){
  713. int LR=TNS_MAX2(lr,ui->L+LA_SEAM_W*2);
  714. tnsColor4dv(act);tnsUseNoTexture();
  715. tnsVertex2d(LR, ui->B); tnsVertex2d(LR-LA_SEAM_W*2, ui->B);
  716. tnsVertex2d(LR-LA_SEAM_W*2, ui->U); tnsVertex2d(LR, ui->U);
  717. tnsPackAs(GL_TRIANGLE_FAN);
  718. }
  719. tnsFlush();
  720. tnsViewportWithScissor(sx,sy,sw,sh);
  721. tnsOrtho(vl,vr,vb,vu,-100,100);
  722. tnsUseNoTexture();
  723. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  724. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  725. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  726. tnsPackAs(GL_LINE_LOOP);
  727. }
  728. void la_AnimationActionDrawOverlay(laUiItem *ui, int h){
  729. laCanvasExtra *e = ui->Extra; laBoxedTheme *bt = (*ui->Type->Theme);
  730. tnsUseImmShader();
  731. if(MAIN.CurrentWindow->MaximizedUi!=ui){
  732. tnsUseNoTexture();
  733. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  734. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  735. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  736. tnsPackAs(GL_LINE_LOOP);
  737. }
  738. if (e->DrawCursor){
  739. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));
  740. int drawx=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_X);
  741. int drawy=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_Y);
  742. if(drawx) tnsVertex2d(e->OnX, ui->U); tnsVertex2d(e->OnX, ui->B);
  743. if(drawy) tnsVertex2d(ui->L, e->OnY); tnsVertex2d(ui->R, e->OnY);
  744. tnsPackAs(GL_LINES);
  745. tnsFlush();
  746. }
  747. return;
  748. }
  749. void laui_AnimationActionMenu(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  750. }
  751. void la_RegisterAnimationResources(){
  752. laPropContainer *pc; laProp *p; laOperatorType *at; laEnumProp *ep;
  753. at=laCreateOperatorType("LA_animation_new_action", "New Action", "Add a new action",0,0,0,OPINV_AnimationNewAction,OPMOD_AnimationNewAction,U'🞦',0);
  754. pc = laDefineOperatorProps(at, 1);
  755. p = laAddSubGroup(pc, "holder", "Holder", "Action holder to add the new action into", "la_animation_action_holder",
  756. 0, 0, laui_IdentifierOnly, -1, laget_AnimationFirstActionHolder, 0, laget_ListNext, 0, 0, laset_AnimationNewActionSetHolder,0,0);
  757. laSubGroupExtraFunctions(p,0,0,0,0,laget_AnimationActionHolderCategory);
  758. at->UiDefine=laui_AnimationNewAction;
  759. at=laCreateOperatorType("LA_animation_remove_action", "Remove Action", "Remove this action",OPCHK_AnimationRemoveAction,0,0,OPINV_AnimationRemoveAction,OPMOD_AnimationRemoveAction,U'🞫',0);
  760. at=laCreateOperatorType("LA_animation_select_action", "Select Action", "Select an action",0,0,0,OPINV_AnimationSelectAction,OPMOD_FinishOnData,U'⯆',0);
  761. at->UiDefine=laui_AnimationSelectAction;
  762. laCreateOperatorType("LA_animation_set_play_status", "Set Play", "Set global animation player status",0,0,0,OPINV_AnimationPlayAction,0,0,0);
  763. laCreateOperatorType("LA_animation_reset_time", "Reset Time", "Reset Time",0,0,0,OPINV_AnimationResetTime,0,U'🡄',0);
  764. laCanvasTemplate* ct=laRegisterCanvasTemplate("la_AnimationActionDrawCanvas", "la_animation_action", LAMOD_AnimationActionsCanvas, la_AnimationActionDrawCanvas, la_AnimationActionDrawOverlay, la_AnimationActionCanvasInit, la_CanvasDestroy);
  765. pc = laCanvasHasExtraProps(ct,sizeof(laCanvasExtra),2); laAddIntProperty(pc, "height_coeff", "Ui Height", "Ui Height Coefficiency Entry", 0, 0, "Rows", 100, -100, 1, 0, 0, offsetof(laCanvasExtra, HeightCoeff), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  766. }