*/}}

la_animation.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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. laAction* laAnimiationNewAction(laActionHolder* ah, char* Name){
  65. laAction* aa=memAcquire(sizeof(laAction));
  66. if(!Name || !Name[0]){ Name="New Action"; }
  67. strSafeSet(&aa->Name,Name);
  68. aa->Length=2; aa->FrameCount=24; memAssignRef(aa,&aa->Holder,ah);
  69. memAssignRef(aa,&aa->HolderInstance,ah->Instance);
  70. memAssignRef(MAIN.Animation,&MAIN.Animation->CurrentAction,aa);
  71. void* lh=((uint8_t*)ah->Instance)+ah->ActionOffset;
  72. lstAppendItem(lh,aa);
  73. laNotifyInstanceUsers(ah->Instance);
  74. laNotifyUsers("la.animation.current_action");
  75. return aa;
  76. }
  77. laActionProp* laAnimationEnsureProp(laAction* aa, void* hyper1, laProp* p){
  78. int DataSize=la_GetKeyablePropertyStorageSize(p); if(!DataSize || !aa->HolderInstance || !aa->Holder) return 0;
  79. laListHandle *pl=((uint8_t*)aa->HolderInstance)+aa->Holder->PropOffset;
  80. for(laActionProp* ap=pl->pFirst;ap;ap=ap->Item.pNext){ if(ap->For==hyper1 && ap->Prop==p){ return ap; } }
  81. laActionProp* ap = memAcquire(sizeof(laActionProp)); lstAppendItem(pl,ap);
  82. memAssignRef(ap,&ap->For,hyper1); ap->Prop=p;
  83. ap->DataSize = DataSize;
  84. char _name[128]={0}, *name=_name; laTryGetInstanceIdentifier(hyper1, p->Container,_name,&name);
  85. strSafeSet(&ap->CachedName,name); strSafePrint(&ap->CachedName," ⯈ %s",p->Identifier);
  86. return ap;
  87. }
  88. laActionChannel* laAnimationEnsureChannel(laAction* aa, void* hyper1, laProp* p){
  89. laActionProp* ap=laAnimationEnsureProp(aa, hyper1,p); if(!ap) return 0; laActionChannel* ac;
  90. for(ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){ if(ac->AP==ap) return ac; }
  91. ac=memAcquire(sizeof(laActionChannel)); ac->AP=ap;
  92. lstAppendItem(&aa->Channels,ac); laNotifyUsers("la.animation.current_action.channels");
  93. return ac;
  94. }
  95. laActionChannel* laAnimationEnsureFrame(laActionChannel* ac, int frame){
  96. laActionKey* akf=0,*beforeakf=0;
  97. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  98. if(ak->At==frame){ akf=ak; break; } if(ak->At>frame){ beforeakf=ak; break; }
  99. }
  100. if(!akf){
  101. akf=memAcquireSimple(sizeof(laActionKey));
  102. akf->At=frame; akf->Data=memAcquireSimple(ac->AP->DataSize); akf->DataSize=ac->AP->DataSize;
  103. if(beforeakf){ lstInsertItemBefore(&ac->Keys, akf, beforeakf); }
  104. else{ lstAppendItem(&ac->Keys, akf); }
  105. }
  106. return akf;
  107. }
  108. void laAnimationStoreKeyValue(laActionChannel* ac, laActionKey* ak){
  109. laPropPack PP={0}; laPropStep PS={0}; laActionProp* ap=ac->AP; if(!ap) return;
  110. PS.p=ap->Prop; PS.Type='.'; PS.UseInstance=ap->For; PP.LastPs=&PS; PP.EndInstance=ap->For;
  111. switch(ap->Prop->PropertyType){
  112. case LA_PROP_INT: case LA_PROP_INT | LA_PROP_ARRAY: laGetIntArray(&PP,(int*)ak->Data); break;
  113. case LA_PROP_FLOAT: case LA_PROP_FLOAT | LA_PROP_ARRAY: laGetFloatArray(&PP,(real*)ak->Data); break;
  114. case LA_PROP_ENUM: case LA_PROP_ENUM | LA_PROP_ARRAY: laGetEnumArray(&PP,(laEnumItem**)ak->Data); break;
  115. case LA_PROP_SUB: case LA_PROP_OPERATOR: case LA_PROP_STRING: case LA_PROP_RAW: default: return;
  116. }
  117. }
  118. laActionKey* laAnimationInsertKeyFrame(laAction* aa, void* hyper1, laProp* p, int* error){
  119. if(error) *error=0; if(!aa) return 0;
  120. if(!aa->HolderInstance||!aa->Holder||!aa->Holder->Container){ if(error) *error=1; return 0; }
  121. if(aa->Holder->Container->ActionHolderVerify){
  122. if(!aa->Holder->Container->ActionHolderVerify(aa->HolderInstance,aa->Holder->Container,hyper1,p->Container)){
  123. if(error) *error=2; return 0;
  124. }
  125. }
  126. laActionChannel* ac=laAnimationEnsureChannel(aa,hyper1,p); if(!ac || !ac->AP || !ac->AP->For) return;
  127. int frame=LA_ACTION_FRAME(aa);
  128. laActionKey* ak=laAnimationEnsureFrame(ac,frame);
  129. laAnimationStoreKeyValue(ac,ak);
  130. laNotifyUsers("la.animation.current_action");
  131. return ak;
  132. }
  133. void laAnimationSetPlayStatus(int PlayStatus){
  134. if(PlayStatus>3||PlayStatus<0) PlayStatus=0; MAIN.Animation->PlayStatus=PlayStatus;
  135. if(PlayStatus) laRecordTime(&MAIN.Animation->TimeOrigin);
  136. laNotifyUsers("la.animation.play_status");
  137. }
  138. void laAnimationSetPlayHead(real time){
  139. MAIN.Animation->PlayHead=time;
  140. }
  141. STRUCTURE(laNewActionData){
  142. laActionHolder* SelectedHolder;
  143. };
  144. laActionHolder* laget_AnimationFirstActionHolder(void* unused1, void* unused2){
  145. return MAIN.Animation->ActionHolders.pFirst;
  146. }
  147. void laset_AnimationNewActionSetHolder(laNewActionData *np, laActionHolder *ah, int State){
  148. np->SelectedHolder = ah;
  149. }
  150. int OPINV_AnimationNewAction(laOperator *a, laEvent *e){
  151. laAnimationUpdateHolderList();
  152. laNewActionData* np= memAcquire(sizeof(laNewActionData));
  153. a->CustomData = np;
  154. laEnableOperatorPanel(a, 0, e->x-50,e->y-50,500,500,10000,0,0,0,0,0,0,0,e);
  155. return LA_RUNNING;
  156. }
  157. int OPMOD_AnimationNewAction(laOperator *a, laEvent *e){
  158. laNewActionData* np=a->CustomData;
  159. if(!a->ConfirmData) return LA_RUNNING;
  160. if(a->ConfirmData->Mode == LA_CONFIRM_CANCEL||a->ConfirmData->Mode == LA_CONFIRM_OK){ if(np) memFree(np); return LA_CANCELED; }
  161. if(a->ConfirmData->Mode == LA_CONFIRM_DATA){
  162. if (!np || !np->SelectedHolder){ if(np) memFree(np); return LA_CANCELED; }
  163. laAnimiationNewAction(np->SelectedHolder,0);
  164. laRecordInstanceDifferences(np->SelectedHolder->Instance,np->SelectedHolder->Container->Identifier);
  165. laRecordDifferences(0,"la.animation"); laPushDifferences("New action",0); memFree(np);
  166. return LA_FINISHED;
  167. }
  168. return LA_RUNNING;
  169. }
  170. void laui_AnimationNewAction(laUiList *uil, laPropPack *This, laPropPack *OperatorProps, laColumn *UNUSED, int context){
  171. laColumn *c = laFirstColumn(uil);
  172. laUiItem* ui=laShowItem(uil, c, OperatorProps, "holder");ui->SymbolID=3; ui->Flags|=LA_UI_FLAGS_NO_DECAL;
  173. }
  174. int OPINV_AnimationSelectAction(laOperator *a, laEvent *e){
  175. laEnableOperatorPanel(a, 0, e->x-50,e->y-50,500,500,10000,0,0,0,0,0,0,0,e);
  176. return LA_RUNNING;
  177. }
  178. void laui_AnimationSelectAction(laUiList *uil, laPropPack *This, laPropPack *OperatorProps, laColumn *UNUSED, int context){
  179. laColumn *c = laFirstColumn(uil);
  180. for(laActionHolderPath* ahp=MAIN.Animation->ActionHolderPaths.pFirst;ahp;ahp=ahp->Item.pNext){
  181. laShowLabel(uil,c,ahp->PP.LastPs->p->Name,0,0)->Flags|=LA_UI_FLAGS_DISABLED|LA_TEXT_MONO;
  182. 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;
  183. }
  184. }
  185. void laAnimationRemoveFrame(laActionChannel* ac, laActionKey* ak){
  186. ak->DataSize=0; memLeave(ak->Data); ak->Data=0;
  187. lstRemoveItem(&ac->Keys,ak); memLeave(ak);
  188. }
  189. void laAnimationRemoveChannel(laAction* aa, laActionChannel* ac){
  190. while(ac->Keys.pFirst){ laAnimationRemoveFrame(ac,ac->Keys.pFirst); }
  191. lstRemoveItem(&aa->Channels,ac); memLeave(ac);
  192. }
  193. void laAnimationRemoveAction(laAction* aa){
  194. while(aa->Channels.pFirst){ laAnimationRemoveChannel(aa,aa->Channels.pFirst); }
  195. strSafeDestroy(&aa->Name);
  196. if(aa=MAIN.Animation->CurrentAction){
  197. if(aa->Item.pNext){ memAssignRef(MAIN.Animation,&MAIN.Animation->CurrentAction,aa->Item.pNext); }
  198. else{ memAssignRef(MAIN.Animation,&MAIN.Animation->CurrentAction,aa->Item.pPrev); }
  199. }
  200. if(!aa->Holder || !aa->HolderInstance){ goto action_remove_clean; }
  201. laListHandle* al=((uint8_t*)aa->HolderInstance)+aa->Holder->ActionOffset;
  202. lstRemoveItem(al,aa);
  203. action_remove_clean:
  204. memLeave(aa);
  205. }
  206. int OPCHK_AnimationRemoveAction(laPropPack *This, laStringSplitor *Instructions){
  207. laPropContainer* pc; return LA_VERIFY_THIS_TYPE(This,pc,"la_animation_action");
  208. }
  209. int OPINV_AnimationRemoveAction(laOperator *a, laEvent *e){
  210. if(!a->This || !a->This->EndInstance){ return LA_CANCELED; }
  211. laAction* aa=a->This->EndInstance;
  212. char str[256]; sprintf(str,"Will remove action \"%s\".",SSTR(aa->Name));
  213. laEnableYesNoPanel(a,0,"Remove?",str,e->x,e->y,200,e);
  214. return LA_RUNNING;
  215. }
  216. int OPMOD_AnimationRemoveAction(laOperator *a, laEvent *e){
  217. if(!a->This || !a->This->EndInstance){ return LA_CANCELED; }
  218. laAction* aa=a->This->EndInstance;
  219. if(a->ConfirmData && a->ConfirmData->Mode==LA_CONFIRM_OK){
  220. laAnimationRemoveAction(aa); laNotifyUsers("la.animation");
  221. laRecordInstanceDifferences(aa->HolderInstance,aa->Holder->Container->Identifier);
  222. laRecordDifferences(0,"la.animation"); laPushDifferences("Remove action",0);
  223. }
  224. return LA_FINISHED;
  225. }
  226. int OPINV_AnimationPlayAction(laOperator *a, laEvent *e){
  227. char* str=strGetArgumentString(a->ExtraInstructionsP, "mode");
  228. int PlayStatus=LA_ANIMATION_STATUS_PAUSED;
  229. if(strSame(str,"forward")){ PlayStatus=LA_ANIMATION_STATUS_PLAY_FWD; }
  230. elif(strSame(str,"reverse")){ if(MAIN.Animation->PlayHead>0) PlayStatus=LA_ANIMATION_STATUS_PLAY_REV; }
  231. laAnimationSetPlayStatus(PlayStatus);
  232. return LA_FINISHED;
  233. }
  234. void la_AnimationActionSetOwnFrame(laAction* aa, int frame){
  235. if(!aa) return;
  236. aa->Offset+=(aa->PlayHead-(real)frame/aa->FrameCount)*aa->Length;
  237. la_AnimationEvaluateActions(0);
  238. laNotifyUsers("la.animation.current_action");
  239. }
  240. int OPINV_AnimationResetTime(laOperator *a, laEvent *e){
  241. char* arg=strGetArgumentString(a->ExtraInstructionsP,"current");
  242. if(strSame(arg,"true")){ la_AnimationActionSetOwnFrame(MAIN.Animation->CurrentAction,0); return LA_FINISHED; }
  243. laAnimationSetPlayHead(0); la_AnimationEvaluateActions(1);
  244. return LA_FINISHED;
  245. }
  246. laActionChannel* laAnimationGetFrame(laActionChannel* ac, int frame){
  247. if(ac->Keys.pFirst==ac->Keys.pLast){ return ac->Keys.pFirst; }
  248. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  249. if(ak->At<=frame && ((!ak->Item.pNext) ||ak->Item.pNext && ((laActionKey*)ak->Item.pNext)->At>frame)){ return ak; }
  250. }
  251. return ac->Keys.pFirst;
  252. }
  253. void la_AnimationMarkPropReset(){
  254. for(laActionHolder* ah=MAIN.Animation->ActionHolders.pFirst;ah;ah=ah->Item.pNext){
  255. if(!ah->Instance){ continue; } laListHandle* lp=((uint8_t*)ah->Instance)+ah->PropOffset;
  256. for(laActionProp* ap=lp->pFirst;ap;ap=ap->Item.pNext){ ap->Reset=1; }
  257. }
  258. }
  259. void la_AnimationInterpolateKeys(laActionChannel* ac, laActionKey* ak1, laActionKey* ak2, real PlayHead_mul_Length, void** data){
  260. int* id1,*id2,*iret=(*data); real* fd1,*fd2,*fret=(*data);
  261. if(!ak2){ *data=ak1->Data; return; } laActionProp* ap=ac->AP; if(!ap) return;
  262. int arrlen=ap->Prop->Len?ap->Prop->Len:1;
  263. real fac=tnsGetRatiod(ak1->At,ak2->At,PlayHead_mul_Length); TNS_CLAMP(fac,0,1);
  264. switch(ap->Prop->PropertyType){
  265. case LA_PROP_INT: case LA_PROP_INT|LA_PROP_ARRAY:
  266. id1=ak1->Data;id2=ak2->Data; for(int i=0;i<arrlen;i++){ iret[i]=tnsLinearItp(id1[i],id2[i],fac); } break;
  267. case LA_PROP_FLOAT: case LA_PROP_FLOAT|LA_PROP_ARRAY:
  268. fd1=ak1->Data;fd2=ak2->Data; for(int i=0;i<arrlen;i++){ fret[i]=tnsLinearItp(fd1[i],fd2[i],fac); } break;
  269. default:
  270. *data=ak1->Data; break;
  271. }
  272. }
  273. void la_AnimationSetPropValue(laActionProp* ap){
  274. void* data=ap->Data;
  275. laPropPack PP={0}; laPropStep PS={0}; if(!ap) return;
  276. PS.p=ap->Prop; PS.Type='.'; PS.UseInstance=ap->For; PP.LastPs=&PS; PP.EndInstance=ap->For;
  277. switch(ap->Prop->PropertyType){
  278. case LA_PROP_INT: laSetInt(&PP,*((int*)data)); break;
  279. case LA_PROP_INT|LA_PROP_ARRAY: laSetIntArrayAllArray(&PP,(int*)data); break;
  280. case LA_PROP_FLOAT: laSetFloat(&PP,*((real*)data)); break;
  281. case LA_PROP_FLOAT|LA_PROP_ARRAY: laSetFloatArrayAllArray(&PP,(real*)data); break;
  282. case LA_PROP_ENUM: laSetEnum(&PP,*((int*)data)); break;
  283. //case LA_PROP_ENUM|LA_PROP_ARRAY: laSetEnumArrayAllArray(&PP,(real*)data); break; //doesnt work
  284. default: break;
  285. }
  286. }
  287. void la_AnimationMixChannelValue(laActionChannel* ac, void* data, int MixMode, real Factor){
  288. laActionProp* ap=ac->AP; if(!ap) return; int* ip=ap->Data,*ipd=data; real* fp=ap->Data,*fpd=data;
  289. int arrlen=ap->Prop->Len?ap->Prop->Len:1;
  290. switch(ap->Prop->PropertyType){
  291. case LA_PROP_INT: case LA_PROP_INT|LA_PROP_ARRAY: for(int i=0;i<arrlen;i++){
  292. ip[i]=ap->Reset?ipd[i]:(MixMode==LA_ANIMATION_MIX_REPLACE?ipd[i]:(ipd[i]+ip[i]));
  293. } break;
  294. case LA_PROP_FLOAT: case LA_PROP_FLOAT|LA_PROP_ARRAY: for(int i=0;i<arrlen;i++){
  295. fp[i]=ap->Reset?fpd[i]:(MixMode==LA_ANIMATION_MIX_REPLACE?fpd[i]:(fpd[i]+fp[i]));
  296. } break;
  297. case LA_PROP_ENUM: ip[0]=ipd[0]; break;
  298. //case LA_PROP_ENUM|LA_PROP_ARRAY: laSetEnumArrayAllArray(&PP,(real*)data); break; //doesnt work
  299. default: break;
  300. }
  301. ap->Reset=0;
  302. }
  303. void la_AnimationEvaluateActionChannels(laAction* aa){
  304. int64_t _data[16]; void* data=_data;
  305. int frame=LA_ACTION_FRAME(aa); real totframe=aa->PlayHead*aa->FrameCount;
  306. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  307. data=_data;
  308. laActionKey* ak1=laAnimationGetFrame(ac,frame); if(!ak1) continue;
  309. laActionKey* ak2=ak1->Item.pNext;
  310. la_AnimationInterpolateKeys(ac,ak1,ak2,totframe,&data);
  311. la_AnimationMixChannelValue(ac, data, aa->MixMode, 0);
  312. }
  313. }
  314. void la_AnimationEvaluateActions(int ClampOffsets){
  315. int any=0;
  316. la_AnimationMarkPropReset();
  317. for(laActionHolder* ah=MAIN.Animation->ActionHolders.pFirst;ah;ah=ah->Item.pNext){
  318. if(!ah->Instance) continue;
  319. laListHandle* lh=((uint8_t*)ah->Instance)+ah->ActionOffset;
  320. for(laAction* aa=lh->pFirst;aa;aa=aa->Item.pNext){
  321. real preoffset=0,postoffset=aa->Offset/aa->Length;
  322. if(ClampOffsets || (MAIN.Animation->PlayStatus!=LA_ANIMATION_STATUS_PAUSED)){
  323. while(aa->Offset>aa->Length*2){ aa->Offset-=aa->Length*2; }
  324. while(aa->Offset<0){ aa->Offset+=aa->Length*2; }
  325. preoffset=aa->Offset; postoffset=0;
  326. }
  327. real UseTime=MAIN.Animation->PlayHead-preoffset;
  328. int repeats=(real)(UseTime/aa->Length);
  329. real remaining=UseTime-repeats*aa->Length;
  330. while(remaining<0){ remaining+=aa->Length; }
  331. if(aa->PlayMode==LA_ANIMATION_PLAY_MODE_REPEAT){ aa->PlayHead=remaining/aa->Length-postoffset; }
  332. elif(aa->PlayMode==LA_ANIMATION_PLAY_MODE_HOLD){ aa->PlayHead=((UseTime>aa->Length)?1.0:(UseTime<0?0:UseTime/aa->Length))-postoffset; }
  333. elif(aa->PlayMode==LA_ANIMATION_PLAY_MODE_BOUNCE){ real t=remaining/aa->Length; aa->PlayHead=((repeats%2)?(1-t):t)-postoffset; }
  334. any=1;
  335. la_AnimationEvaluateActionChannels(aa);
  336. }
  337. }
  338. for(laActionHolder* ah=MAIN.Animation->ActionHolders.pFirst;ah;ah=ah->Item.pNext){
  339. if(!ah->Instance){ continue; } laListHandle* lp=((uint8_t*)ah->Instance)+ah->PropOffset;
  340. for(laActionProp* ap=lp->pFirst;ap;ap=ap->Item.pNext){ if(ap->Reset){ continue; }
  341. la_AnimationSetPropValue(ap);
  342. }
  343. }
  344. if(any) laNotifyUsers("la.animation");
  345. }
  346. void la_AnimationPreFrame(){
  347. if(MAIN.Animation->PlayHead<0){
  348. MAIN.Animation->PlayHead=0; laAnimationSetPlayStatus(0);
  349. la_AnimationEvaluateActions(1);
  350. laNotifyUsers("la.animation.play_head");
  351. }
  352. if(MAIN.Animation->PlayStatus){
  353. la_AnimationEvaluateActions(0);
  354. }
  355. }
  356. void la_AnimationPostFrame(){
  357. laTimeRecorder cur={0};
  358. if(MAIN.Animation->PlayStatus){ laRecordTime(&cur);
  359. real td=laTimeElapsedSecondsf(&cur,&MAIN.Animation->TimeOrigin);
  360. laRecordTime(&MAIN.Animation->TimeOrigin);
  361. if(MAIN.Animation->PlayStatus==LA_ANIMATION_STATUS_PLAY_REV){ td*=-1; }
  362. MAIN.Animation->PlayHead+=td; laNotifyUsers("la.animation.play_head");
  363. }
  364. }
  365. void la_ActionDeselectFrames(laAction* aa){
  366. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  367. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  368. ak->Selected=0;
  369. }
  370. }
  371. }
  372. void la_ActionSelectFrame(laAction* aa, int Channel, real At, real zoomx){
  373. int tc=0;laActionChannel* ac;
  374. for(ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){ if(tc==Channel) break; tc++; }
  375. if(!ac) return;
  376. real ClosestDist=FLT_MAX; laActionKey* ClosestKey=0;
  377. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  378. real d=fabs(ak->At-At+0.5); if(d*zoomx<LA_RH*2 && d<ClosestDist){ ClosestDist=d; ClosestKey=ak; }
  379. }
  380. if(ClosestKey){ ClosestKey->Selected=1; }
  381. }
  382. int la_ActionSaveKeyOriginalAt(laAction* aa){
  383. int any=0;
  384. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  385. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){ if(!ak->Selected) continue; any=1; ak->OriginaAt=ak->At; }
  386. }
  387. return any;
  388. }
  389. void la_ActionEnsureFrameOrder(laAction* aa){
  390. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  391. laListHandle lst={0};
  392. laActionKey* ak; while(ak=lstPopItem(&ac->Keys)){ int done=0;
  393. if(!lst.pFirst){ lstAppendItem(&lst,ak); continue; }
  394. laActionKey* ak2=0;
  395. for(ak2=lst.pFirst;ak2;ak2=ak2->Item.pNext){
  396. if(ak2->At>=ak->At){ lstInsertItemBefore(&lst,ak,ak2); done=1; break; }
  397. }
  398. if(!done) lstAppendItem(&lst,ak);
  399. }
  400. lstCopyHandle(&ac->Keys,&lst);
  401. }
  402. }
  403. void la_ActionRestoreKeyOriginalAt(laAction* aa) {
  404. for (laActionChannel* ac = aa->Channels.pFirst; ac; ac = ac->Item.pNext) {
  405. for (laActionKey* ak = ac->Keys.pFirst; ak; ak = ak->Item.pNext) { if (!ak->Selected) continue; ak->At = ak->OriginaAt; }
  406. }
  407. la_ActionEnsureFrameOrder(aa);
  408. }
  409. void la_ActionRemoveDuplicatedFrames(laAction* aa){
  410. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  411. laActionKey* ak2; for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  412. while((ak2=ak->Item.pNext)&&ak->At==ak2->At){ lstRemoveItem(&ac->Keys,ak2); memLeave(ak2); }
  413. }
  414. }
  415. }
  416. void la_ActionMoveSelectedFrames(laAction* aa, int Delta){
  417. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  418. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){ if(!ak->Selected) continue;
  419. ak->At=ak->OriginaAt+Delta;
  420. }
  421. }
  422. la_ActionEnsureFrameOrder(aa);
  423. }
  424. int la_ActionDeleteSelectedFrames(laAction* aa){
  425. int any=0;
  426. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  427. laActionKey* NextAk; for(laActionKey* ak=ac->Keys.pFirst;ak;ak=NextAk){ NextAk=ak->Item.pNext;if(!ak->Selected) continue;
  428. lstRemoveItem(&ac->Keys, ak); memLeave(ak); any=1;
  429. }
  430. }
  431. return any;
  432. }
  433. int LAMOD_AnimationActionsCanvas(laOperator *a, laEvent *e){
  434. laUiItem *ui = a->Instance; laBoxedTheme *bt = (*ui->Type->Theme);
  435. laCanvasExtra *ex = a->CustomData; laAction* aa=ui->PP.EndInstance;
  436. if(!aa) LA_RUNNING_PASS;
  437. int W, H; W = ui->R - ui->L; H = ui->B - ui->U;
  438. int ShowSide=(ex->ShowLegend&&ex->LW<W-2*LA_RH);
  439. int ll=ui->L, lr=ll+(ShowSide?ex->LW:0), tl=lr, tr=ui->R;
  440. int FW=LA_RH/2;
  441. int Channels=aa?lstCountElements(&aa->Channels):0;
  442. int Modal=0; int mid=((W-lr)/2);
  443. if(e->Type==LA_M_MOUSE_DOWN){
  444. ex->UiMode=1; ex->ClickedX=e->x; ex->ClickedY=e->y; Modal=1; ex->Dragging=10;
  445. }elif(e->Type==LA_M_MOUSE_UP || e->Type==LA_L_MOUSE_UP){
  446. ex->UiMode=0; Modal=1; ex->Dragging=0; ex->TargetIndexVali=0;
  447. }
  448. if(ex->UiMode==1){
  449. if(e->Type&LA_MOUSE_EVENT){
  450. ex->PanY-=e->y-ex->ClickedY; ex->PanX-=e->x-ex->ClickedX;
  451. ex->ClickedX=e->x; ex->ClickedY=e->y; Modal=1;
  452. }
  453. }elif(ex->UiMode==2){ Modal=1;
  454. if(e->Type&LA_MOUSE_EVENT){
  455. ex->LW=e->x-ui->L+LA_SEAM_W; ex->ClickedX=e->x; ex->ClickedY=e->y;
  456. if(ex->LW<LA_RH*3 && ex->LW>=LA_RH/2){ ex->LW=LA_RH*3; }
  457. if(ex->LW<LA_RH/2 && ex->Dragging!=12){ ex->ShowLegend=0; ex->LW=0; }
  458. if(ex->LW<LA_RH*3){ ex->LW=LA_RH*3;}
  459. }
  460. }elif(ex->UiMode==3){ Modal=1;
  461. if(e->Type&LA_MOUSE_EVENT){ ex->ClickedX=e->x; ex->ClickedY=e->y;
  462. int SetFrame=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW;
  463. la_AnimationActionSetOwnFrame(aa,SetFrame);
  464. }
  465. }elif(ex->UiMode==4){ Modal=1;
  466. if(e->Type==LA_R_MOUSE_DOWN || (e->Type==LA_ESCAPE_DOWN)){ ex->UiMode=0; ex->Dragging=0;
  467. la_ActionRestoreKeyOriginalAt(aa); laNotifyUsers("la.animation.current_action");
  468. }elif(e->Type==LA_L_MOUSE_DOWN){ la_ActionRemoveDuplicatedFrames(aa);
  469. laNotifyUsers("la.animation.current_action"); ex->UiMode=0; ex->Dragging=0;
  470. }elif(e->Type&LA_MOUSE_EVENT){ Modal=1;
  471. int ToFrame=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW,FromFrame=(real)(ex->ClickedX-tl+ex->PanX)/ex->ZoomX/FW;
  472. la_ActionMoveSelectedFrames(aa,ToFrame-FromFrame); laNotifyUsers("la.animation.current_action");
  473. }
  474. }
  475. int MaxDN=LA_RH*(Channels+1)-H+bt->TP+bt->BP; if(MaxDN<0) MaxDN=0;
  476. if(!Modal){
  477. if(e->x<=lr){
  478. if(e->Type==LA_MOUSE_WHEEL_DOWN){ ex->PanY+=LA_RH*MAIN.ScrollingSpeed; Modal=1; }
  479. if(e->Type==LA_MOUSE_WHEEL_UP){ ex->PanY-=LA_RH*MAIN.ScrollingSpeed; Modal=1; }
  480. if(e->x>=lr-LA_SEAM_W*2){ if(!ex->TargetIndexVali){ ex->TargetIndexVali=1; Modal=1; }
  481. if(e->Type==LA_L_MOUSE_DOWN){
  482. ex->UiMode=2; ex->ClickedX=e->x; ex->ClickedY=e->y; Modal=1; ex->Dragging=10; Modal=1;
  483. }
  484. }else{ if(ex->TargetIndexVali){ ex->TargetIndexVali=0; Modal=1; } }
  485. }elif(aa){
  486. if((!ex->ShowLegend)&&e->x<=ll+LA_SEAM_W*2){
  487. if(!ex->TargetIndexVali){ ex->TargetIndexVali=1; Modal=1; }
  488. 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; }
  489. }else{ if(ex->TargetIndexVali){ ex->TargetIndexVali=0; Modal=1; } }
  490. if(e->Type==LA_MOUSE_WHEEL_DOWN){ ex->ZoomX*=0.9; ex->PanX+=mid; ex->PanX*=0.9; ex->PanX-=mid; Modal=1; }
  491. elif(e->Type==LA_MOUSE_WHEEL_UP){ ex->ZoomX*=1.1; ex->PanX+=mid; ex->PanX*=1.1; ex->PanX-=mid; Modal=1; }
  492. elif(e->Type==LA_L_MOUSE_DOWN){
  493. ex->UiMode=3; int SetFrame=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW;
  494. la_AnimationActionSetOwnFrame(aa,SetFrame); Modal=1;
  495. }elif(e->Type==LA_R_MOUSE_DOWN){
  496. int row=(e->y-ui->U-bt->BM-LA_RH)/LA_RH; real at=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW;
  497. if(!(e->SpecialKeyBit&LA_KEY_SHIFT)){ la_ActionDeselectFrames(aa); }
  498. la_ActionSelectFrame(aa,row,at,ex->ZoomX);
  499. laNotifyUsers("la.animation.current_action");
  500. }elif(e->Type==LA_KEY_DOWN&&e->key=='g'){
  501. int any=la_ActionSaveKeyOriginalAt(aa);
  502. if(any){ ex->ClickedX=e->x; ex->ClickedY=e->y; ex->UiMode=4; Modal=1; ex->Dragging=13;
  503. laNotifyUsers("la.animation.current_action");
  504. }
  505. }elif(e->Type==LA_KEY_DOWN&&e->key=='x'){
  506. int any=la_ActionDeleteSelectedFrames(aa);
  507. if(any){
  508. laNotifyUsers("la.animation.current_action");
  509. }
  510. }
  511. }
  512. }
  513. if(ex->PanY>MaxDN){ ex->PanY=MaxDN; } if(ex->PanY<0){ ex->PanY=0; }
  514. //if(ex->PanX<0){ ex->PanX=0; }
  515. if(ex->TargetIndexVali){ laSetWindowCursor(LA_LEFT_AND_RIGHT); }else{ laSetWindowCursor(LA_ARROW); }
  516. if(Modal){ laRedrawCurrentPanel(); return LA_RUNNING; }
  517. return LA_RUNNING_PASS;
  518. }
  519. void la_AnimationActionCanvasInit(laUiItem *ui){
  520. la_CanvasInit(ui);
  521. laCanvasExtra* ex=ui->Extra; ex->LW=LA_RH*7; ex->ShowLegend=1;
  522. }
  523. void la_AnimationActionDrawCanvas(laBoxedTheme *bt, laAction *aa, laUiItem* ui){
  524. laCanvasExtra* ex=ui->Extra; //laAction* aa=ui->PP.EndInstance;
  525. int W, H; W = ui->R - ui->L; H = ui->B - ui->U; if (W<=0 || H<=0) return;
  526. int ShowSide=(ex->ShowLegend&&ex->LW<W-2*LA_RH);
  527. int ll=ui->L, lr=ll+(ShowSide?ex->LW-1:0), tl=lr, tr=ui->R;
  528. int FW=LA_RH/2;
  529. //if (!e->OffScr || e->OffScr->pColor[0]->Height != ui->B - ui->U || e->Be.OffScr->pColor[0]->Width != ui->R - ui->L){
  530. // if (e->OffScr) tnsDelete2DOffscreen(e->OffScr);
  531. // e->OffScr = tnsCreate2DOffscreen(GL_RGBA, W, H, MAIN.PanelMultisample, 1, 0);
  532. //}
  533. real *bkg=laThemeColor(bt,LA_BT_NORMAL);
  534. real *txt=laThemeColor(bt,LA_BT_TEXT);
  535. real *act=laThemeColor(bt,LA_BT_ACTIVE);
  536. tnsUseNoTexture();
  537. tnsColor4d(LA_COLOR3(bkg),bkg[3]*0.3);
  538. tnsVertex2d(tl, ui->U); tnsVertex2d(tr, ui->U);
  539. tnsVertex2d(tr, ui->B); tnsVertex2d(tl, ui->B);
  540. tnsPackAs(GL_TRIANGLE_FAN);
  541. int row=1,curframe,cx; real fl,fr;
  542. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  543. tnsVertex2d(ui->L, ui->U+bt->TP+LA_RH); tnsVertex2d(ui->R, ui->U+bt->TP+LA_RH);
  544. tnsVertex2d(ui->R, ui->U); tnsVertex2d(ui->L, ui->U);
  545. tnsPackAs(GL_TRIANGLE_FAN);
  546. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));
  547. tnsVertex2d(tl, LA_RH+ui->U); tnsVertex2d(tr, LA_RH+ui->U);
  548. tnsPackAs(GL_LINES);
  549. tnsFlush();
  550. int sx,sy,sw,sh,vl,vr,vu,vb;
  551. la_DoUiScissor(ui,&sx,&sy,&sw,&sh,&vl,&vr,&vu,&vb);
  552. if(aa){
  553. curframe=LA_ACTION_FRAME(aa); fl=tl+curframe*FW*ex->ZoomX-ex->PanX, fr=tl+(curframe+1)*FW*ex->ZoomX-ex->PanX;
  554. tnsUseNoTexture();
  555. tnsColor4dv(laAccentColor(LA_BT_NORMAL));
  556. tnsVertex2d(fl, ui->U); tnsVertex2d(fr, ui->U);
  557. tnsVertex2d(fr, ui->B); tnsVertex2d(fl, ui->B);
  558. tnsPackAs(GL_TRIANGLE_FAN);
  559. tnsFlush(); glLineWidth(2);
  560. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
  561. real ku=ui->U+bt->TP+row*LA_RH-ex->PanY,kb=ku+LA_RH;
  562. for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
  563. real kl=tl+ak->At*FW*ex->ZoomX-ex->PanX, kr=tl+(ak->At+1)*FW*ex->ZoomX-ex->PanX;
  564. if(ak->Selected) tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE));
  565. elif(curframe==ak->At) tnsColor4d(LA_COLOR3(txt),txt[3]*0.6);
  566. else tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));
  567. tnsVertex2d(kl, ku); tnsVertex2d(kr, ku);
  568. tnsVertex2d(kr, kb); tnsVertex2d(kl, kb);
  569. tnsPackAs(GL_TRIANGLE_FAN);
  570. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT_ACTIVE));
  571. tnsVertex2d(kl, ku); tnsVertex2d(kr, ku);
  572. tnsVertex2d(kr, kb); tnsVertex2d(kl, kb);
  573. tnsPackAs(GL_LINE_LOOP);
  574. }
  575. row++;
  576. }
  577. tnsFlush(); glLineWidth(1);
  578. real end=tl+aa->FrameCount*FW*ex->ZoomX-ex->PanX;
  579. tnsColor4d(0,0,0,0.3);
  580. tnsVertex2d(end, ui->U+LA_RH); tnsVertex2d(end+1e6, ui->U+LA_RH);
  581. tnsVertex2d(end+1e6, ui->B); tnsVertex2d(end, ui->B);
  582. tnsPackAs(GL_TRIANGLE_FAN);
  583. tnsVertex2d(tl-ex->PanX, ui->U+LA_RH); tnsVertex2d(tl-ex->PanX-1e6, ui->U+LA_RH);
  584. tnsVertex2d(tl-ex->PanX-1e6, ui->B); tnsVertex2d(tl-ex->PanX, ui->B);
  585. tnsPackAs(GL_TRIANGLE_FAN);
  586. tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE));
  587. int FrameFix=aa->PlayHead<0?1:0;
  588. cx=tl+(aa->PlayHead*aa->FrameCount+FrameFix)*FW*ex->ZoomX-ex->PanX; tnsVertex2d(cx, ui->U); tnsVertex2d(cx, ui->B);
  589. tnsPackAs(GL_LINES); glLineWidth(3); tnsFlush(); glLineWidth(1);
  590. char buf[32]; sprintf(buf,"%d",curframe); real tlen=tnsStringGetDimension(buf,0,0,0,0,0)+bt->LP+bt->RP;
  591. tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE));
  592. tnsVertex2d(cx, ui->U+LA_RH); tnsVertex2d(cx+tlen, ui->U+LA_RH);
  593. tnsVertex2d(cx+tlen, ui->U); tnsVertex2d(cx, ui->U);
  594. tnsPackAs(GL_TRIANGLE_FAN);
  595. tnsDrawStringAuto(buf,laThemeColor(bt,LA_BT_TEXT_ACTIVE),cx+bt->LP,cx+LA_RH*2,ui->U+bt->TP,0);
  596. tnsPackAs(GL_TRIANGLE_FAN); tnsUseNoTexture();
  597. }
  598. if(ShowSide){
  599. tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));
  600. tnsVertex2d(ll, ui->U); tnsVertex2d(lr, ui->U);
  601. tnsVertex2d(lr, ui->B); tnsVertex2d(ll, ui->B);
  602. tnsPackAs(GL_TRIANGLE_FAN);
  603. if(!aa){
  604. tnsDrawStringAuto("No action selected",laThemeColor(bt,LA_BT_TEXT),ll+bt->LP,lr-bt->RP,ui->U+bt->BP,0);
  605. }else{ int row=1;
  606. tnsDrawStringAuto(SSTR(aa->Name),laThemeColor(bt,LA_BT_TEXT),ll+bt->LP,lr-bt->RP,ui->U+bt->BP,0);
  607. for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){ if(!ac->AP){ continue; }
  608. 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);
  609. row++;
  610. }
  611. }
  612. }
  613. if(ex->TargetIndexVali==1){
  614. int LR=TNS_MAX2(lr,ui->L+LA_SEAM_W*2);
  615. tnsColor4dv(act);tnsUseNoTexture();
  616. tnsVertex2d(LR, ui->B); tnsVertex2d(LR-LA_SEAM_W*2, ui->B);
  617. tnsVertex2d(LR-LA_SEAM_W*2, ui->U); tnsVertex2d(LR, ui->U);
  618. tnsPackAs(GL_TRIANGLE_FAN);
  619. }
  620. tnsFlush();
  621. tnsViewportWithScissor(sx,sy,sw,sh);
  622. tnsOrtho(vl,vr,vb,vu,-100,100);
  623. tnsUseNoTexture();
  624. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  625. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  626. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  627. tnsPackAs(GL_LINE_LOOP);
  628. }
  629. void la_AnimationActionDrawOverlay(laUiItem *ui, int h){
  630. laCanvasExtra *e = ui->Extra; laBoxedTheme *bt = (*ui->Type->Theme);
  631. tnsUseImmShader();
  632. if(MAIN.CurrentWindow->MaximizedUi!=ui){
  633. tnsUseNoTexture();
  634. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  635. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  636. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  637. tnsPackAs(GL_LINE_LOOP);
  638. }
  639. if (e->DrawCursor){
  640. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));
  641. int drawx=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_X);
  642. int drawy=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_Y);
  643. if(drawx) tnsVertex2d(e->OnX, ui->U); tnsVertex2d(e->OnX, ui->B);
  644. if(drawy) tnsVertex2d(ui->L, e->OnY); tnsVertex2d(ui->R, e->OnY);
  645. tnsPackAs(GL_LINES);
  646. tnsFlush();
  647. }
  648. return;
  649. }
  650. void laui_AnimationActionMenu(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
  651. }
  652. void la_RegisterAnimationResources(){
  653. laPropContainer *pc; laProp *p; laOperatorType *at; laEnumProp *ep;
  654. at=laCreateOperatorType("LA_animation_new_action", "New Action", "Add a new action",0,0,0,OPINV_AnimationNewAction,OPMOD_AnimationNewAction,U'🞦',0);
  655. pc = laDefineOperatorProps(at, 1);
  656. p = laAddSubGroup(pc, "holder", "Holder", "Action holder to add the new action into", "la_animation_action_holder",
  657. 0, 0, laui_IdentifierOnly, -1, laget_AnimationFirstActionHolder, 0, laget_ListNext, 0, 0, laset_AnimationNewActionSetHolder,0,0);
  658. laSubGroupExtraFunctions(p,0,0,0,0,laget_AnimationActionHolderCategory);
  659. at->UiDefine=laui_AnimationNewAction;
  660. at=laCreateOperatorType("LA_animation_remove_action", "Remove Action", "Remove this action",OPCHK_AnimationRemoveAction,0,0,OPINV_AnimationRemoveAction,OPMOD_AnimationRemoveAction,U'🞫',0);
  661. at=laCreateOperatorType("LA_animation_select_action", "Select Action", "Select an action",0,0,0,OPINV_AnimationSelectAction,OPMOD_FinishOnData,U'⯆',0);
  662. at->UiDefine=laui_AnimationSelectAction;
  663. laCreateOperatorType("LA_animation_set_play_status", "Set Play", "Set global animation player status",0,0,0,OPINV_AnimationPlayAction,0,0,0);
  664. laCreateOperatorType("LA_animation_reset_time", "Reset Time", "Reset Time",0,0,0,OPINV_AnimationResetTime,0,U'🡄',0);
  665. laCanvasTemplate* ct=laRegisterCanvasTemplate("la_AnimationActionDrawCanvas", "la_animation_action", LAMOD_AnimationActionsCanvas, la_AnimationActionDrawCanvas, la_AnimationActionDrawOverlay, la_AnimationActionCanvasInit, la_CanvasDestroy);
  666. 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);
  667. }