123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- /*
- * LaGUI: A graphical application framework.
- * Copyright (C) 2022-2023 Wu Yiming
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "la_5.h"
- extern LA MAIN;
- int la_GetKeyablePropertyStorageSize(laProp* p);
- laAction* laAnimiationNewAction(char* Name){
- laAction* aa=memAcquire(sizeof(laAction));
- if(!Name || !Name[0]){ Name="New Action"; }
- strSafeSet(&aa->Name,Name);
- aa->Length=5; aa->FrameCount=120;
- lstAppendItem(&MAIN.Actions,aa);
- laNotifyUsers("la.actions");
- return aa;
- }
- laAnimationChannel* laAnimationEnsureChannel(laAction* aa, void* hyper1, laProp* p){
- laAnimationChannel* acf=0;
- int DataSize=la_GetKeyablePropertyStorageSize(p); if(!DataSize) return 0;
- for(laAnimationChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){
- if(ac->For==hyper1 && ac->Prop==p){ acf=ac; break; }
- }
- if(acf) return acf;
- acf=memAcquire(sizeof(laAnimationChannel));
- memAssignRef(acf,&acf->For,hyper1); acf->Prop=p;
- acf->DataSize = DataSize;
- lstAppendItem(&aa->Channels,acf);
- return acf;
- }
- laAnimationChannel* laAnimationEnsureFrame(laAnimationChannel* ac, int frame){
- laAnimationKey* akf=0,*beforeakf=0;
- for(laAnimationKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){
- if(ak->At==frame){ akf=ak; break; } if(ak->At>frame){ beforeakf=ak; break; }
- }
- if(!akf){
- akf=memAcquireSimple(sizeof(laAnimationKey)-sizeof(uint64_t)+ac->DataSize);
- akf->At=frame;
- if(beforeakf){ lstInsertItemBefore(&ac->Keys, akf, beforeakf); }
- lstAppendItem(&ac->Keys, akf);
- }
- return akf;
- }
- void laAnimationStoreKeyValue(laAnimationChannel* ac, laAnimationKey* ak){
- laPropPack PP={0}; laPropStep PS={0};
- PS.p=ac->Prop; PS.Type='.'; PS.UseInstance=ac->For; PP.LastPs=&PS; PP.EndInstance=ac->For;
- switch(ac->Prop->PropertyType){
- case LA_PROP_INT: case LA_PROP_INT | LA_PROP_ARRAY: laGetIntArray(&PP,(int*)&ak->Data);
- case LA_PROP_FLOAT: case LA_PROP_FLOAT | LA_PROP_ARRAY: laGetFloatArray(&PP,(real*)&ak->Data);
- case LA_PROP_ENUM: case LA_PROP_ENUM | LA_PROP_ARRAY: laGetEnumArray(&PP,(laEnumItem**)&ak->Data);
- case LA_PROP_SUB: case LA_PROP_OPERATOR: case LA_PROP_STRING: case LA_PROP_RAW: default: return;
- }
- }
- laAnimationKey* laAnimationInsertKeyFrame(laAction* aa, void* hyper1, laProp* p){
- laAnimationChannel* ac=laAnimationEnsureChannel(aa,hyper1,p); if(!ac || !ac->For) return;
- int frame=aa->PlayHead/aa->Length*aa->FrameCount;
- laAnimationKey* ak=laAnimationEnsureFrame(ac->DataSize,frame);
- laAnimationStoreKeyValue(ac,ak);
- }
- void laAnimationSetPlayStatus(int PlayStatus){
- if(PlayStatus>3||PlayStatus<0) PlayStatus=0; MAIN.AnimationPlayStatus=PlayStatus;
- if(PlayStatus) laRecordTime(&MAIN.AnimationTimeOrigin);
- laNotifyUsers("la.animation_play_status");
- }
- void laAnimationSetPlayHead(real time){
- MAIN.AnimationPlayHead=time;
- }
- int OPINV_AnimationNewAction(laOperator *a, laEvent *e){
- laAnimiationNewAction(0);
- return LA_FINISHED;
- }
- int OPINV_AnimationPlayAction(laOperator *a, laEvent *e){
- char* str=strGetArgumentString(a->ExtraInstructionsP, "mode");
- int PlayStatus=LA_ANIMATION_STATUS_PAUSED;
- if(strSame(str,"forward")){ PlayStatus=LA_ANIMATION_STATUS_PLAY_FWD; }
- elif(strSame(str,"reverse")){ if(MAIN.AnimationPlayHead>0) PlayStatus=LA_ANIMATION_STATUS_PLAY_REV; }
- laAnimationSetPlayStatus(PlayStatus);
- return LA_FINISHED;
- }
- int OPINV_AnimationResetTime(laOperator *a, laEvent *e){
- laAnimationSetPlayHead(0);
- return LA_FINISHED;
- }
- void la_AnimationEvaluateActions(){
- /* ehh well */
- }
- void la_AnimationPreFrame(){
- if(MAIN.AnimationPlayHead<0){
- MAIN.AnimationPlayHead=0; laAnimationSetPlayStatus(0);
- laNotifyUsers("la.animation_play_head");
- }
- if(MAIN.AnimationPlayStatus){
- la_AnimationEvaluateActions();
- }
- }
- void la_AnimationPostFrame(){
- laTimeRecorder cur={0};
- if(MAIN.AnimationPlayStatus){ laRecordTime(&cur);
- real td=laTimeElapsedSecondsf(&cur,&MAIN.AnimationTimeOrigin);
- laRecordTime(&MAIN.AnimationTimeOrigin);
- if(MAIN.AnimationPlayStatus==LA_ANIMATION_STATUS_PLAY_REV){ td*=-1; }
- MAIN.AnimationPlayHead+=td; laNotifyUsers("la.animation_play_head");
- }
- }
- void la_RegisterAnimationResources(){
- laPropContainer *pc; laProp *p; laOperatorType *at; laEnumProp *ep;
- laCreateOperatorType("LA_animation_new_action", "New Action", "Add a new action",0,0,0,OPINV_AnimationNewAction,0,0,0);
- laCreateOperatorType("LA_animation_set_play_status", "Set Play", "Set global animation player status",0,0,0,OPINV_AnimationPlayAction,0,0,0);
- laCreateOperatorType("LA_animation_reset_time", "Reset Time", "Reset Time",0,0,0,OPINV_AnimationResetTime,0,U'🡄',0);
- }
|