| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559 | /** 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);void la_AnimationEvaluateActions(int ClampOffsets);laAction* laAnimiationNewAction(char* Name){    laAction* aa=memAcquire(sizeof(laAction));    if(!Name || !Name[0]){ Name="New Action"; }    strSafeSet(&aa->Name,Name);    aa->Length=2; aa->FrameCount=24;    memAssignRef(MAIN.Animation,&MAIN.Animation->CurrentAction,aa);    lstAppendItem(&MAIN.Animation->Actions,aa); laNotifyUsers("la.animation.actions");    return aa;}laActionProp* laAnimationEnsureProp(void* hyper1, laProp* p){    int DataSize=la_GetKeyablePropertyStorageSize(p); if(!DataSize) return 0;    for(laActionProp* ap=MAIN.Animation->Props.pFirst;ap;ap=ap->Item.pNext){        if(ap->For==hyper1 && ap->Prop==p){ return ap; }    }    laActionProp* ap = memAcquire(sizeof(laActionProp)); lstAppendItem(&MAIN.Animation->Props,ap);    memAssignRef(ap,&ap->For,hyper1); ap->Prop=p;    ap->DataSize = DataSize;    char _name[128]={0}, *name=_name; laTryGetInstanceIdentifier(hyper1, p->Container,_name,&name);    strSafeSet(&ap->CachedName,name); strSafePrint(&ap->CachedName," ⯈ %s",p->Identifier);    return ap;}laActionChannel* laAnimationEnsureChannel(laAction* aa, void* hyper1, laProp* p){    laActionProp* ap=laAnimationEnsureProp(hyper1,p); if(!ap) return 0; laActionChannel* ac;    for(ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){        if(ac->AP==ap) return ac;    }    ac=memAcquire(sizeof(laActionChannel)); ac->AP=ap;    lstAppendItem(&aa->Channels,ac); laNotifyUsers("la.animation.current_action.channels");    return ac;}laActionChannel* laAnimationEnsureFrame(laActionChannel* ac, int frame){    laActionKey* akf=0,*beforeakf=0;    for(laActionKey* 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(laActionKey)-sizeof(uint64_t)+ac->AP->DataSize);        akf->At=frame;        if(beforeakf){ lstInsertItemBefore(&ac->Keys, akf, beforeakf); }        else{ lstAppendItem(&ac->Keys, akf); }    }    return akf;}void laAnimationStoreKeyValue(laActionChannel* ac, laActionKey* ak){    laPropPack PP={0}; laPropStep PS={0}; laActionProp* ap=ac->AP; if(!ap) return;    PS.p=ap->Prop; PS.Type='.'; PS.UseInstance=ap->For; PP.LastPs=&PS; PP.EndInstance=ap->For;    switch(ap->Prop->PropertyType){    case LA_PROP_INT: case LA_PROP_INT | LA_PROP_ARRAY:     laGetIntArray(&PP,(int*)&ak->Data); break;    case LA_PROP_FLOAT: case LA_PROP_FLOAT | LA_PROP_ARRAY: laGetFloatArray(&PP,(real*)&ak->Data); break;    case LA_PROP_ENUM: case LA_PROP_ENUM | LA_PROP_ARRAY:   laGetEnumArray(&PP,(laEnumItem**)&ak->Data); break;    case LA_PROP_SUB: case LA_PROP_OPERATOR: case LA_PROP_STRING: case LA_PROP_RAW: default: return;    }}laActionKey* laAnimationInsertKeyFrame(laAction* aa, void* hyper1, laProp* p){    if(!aa) return 0;    laActionChannel* ac=laAnimationEnsureChannel(aa,hyper1,p); if(!ac || !ac->AP || !ac->AP->For) return;    int frame=LA_ACTION_FRAME(aa);    laActionKey* ak=laAnimationEnsureFrame(ac,frame);    laAnimationStoreKeyValue(ac,ak);    laNotifyUsers("la.animation.current_action");    return ak;}void laAnimationSetPlayStatus(int PlayStatus){    if(PlayStatus>3||PlayStatus<0) PlayStatus=0; MAIN.Animation->PlayStatus=PlayStatus;    if(PlayStatus) laRecordTime(&MAIN.Animation->TimeOrigin);    laNotifyUsers("la.animation.play_status");}void laAnimationSetPlayHead(real time){    MAIN.Animation->PlayHead=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.Animation->PlayHead>0) PlayStatus=LA_ANIMATION_STATUS_PLAY_REV; }    laAnimationSetPlayStatus(PlayStatus);    return LA_FINISHED;}void la_AnimationActionSetOwnFrame(laAction* aa, int frame){    if(!aa) return;    aa->Offset+=(aa->PlayHead-(real)frame/aa->FrameCount)*aa->Length-1e-4;    la_AnimationEvaluateActions(0);    laNotifyUsers("la.animation.current_action");}int OPINV_AnimationResetTime(laOperator *a, laEvent *e){    char* arg=strGetArgumentString(a->ExtraInstructionsP,"current");    if(strSame(arg,"true")){ la_AnimationActionSetOwnFrame(MAIN.Animation->CurrentAction,0); return LA_FINISHED; }    laAnimationSetPlayHead(0); la_AnimationEvaluateActions(1);    return LA_FINISHED;}laActionChannel* laAnimationGetFrame(laActionChannel* ac, int frame){    if(ac->Keys.pFirst==ac->Keys.pLast){ return ac->Keys.pFirst; }    for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){        if(ak->At<=frame && ((!ak->Item.pNext) ||ak->Item.pNext && ((laActionKey*)ak->Item.pNext)->At>frame)){ return ak; }    }    return ac->Keys.pFirst;}void la_AnimationMarkPropReset(){    for(laActionProp* ap=MAIN.Animation->Props.pFirst;ap;ap=ap->Item.pNext){ ap->Reset=1; }}void la_AnimationInterpolateKeys(laActionChannel* ac, laActionKey* ak1, laActionKey* ak2, real PlayHead_mul_Length, void** data){    int* id1,*id2,*iret=(*data); real* fd1,*fd2,*fret=(*data);    if(!ak2){ *data=&ak1->Data; return; } laActionProp* ap=ac->AP; if(!ap) return;    int arrlen=ap->Prop->Len?ap->Prop->Len:1;    real fac=tnsGetRatiod(ak1->At,ak2->At,PlayHead_mul_Length); TNS_CLAMP(fac,0,1);    switch(ap->Prop->PropertyType){    case LA_PROP_INT: case LA_PROP_INT|LA_PROP_ARRAY:        id1=&ak1->Data;id2=&ak2->Data; for(int i=0;i<arrlen;i++){ iret[i]=tnsLinearItp(id1[i],id2[i],fac); } break;    case LA_PROP_FLOAT: case LA_PROP_FLOAT|LA_PROP_ARRAY:        fd1=&ak1->Data;fd2=&ak2->Data; for(int i=0;i<arrlen;i++){ fret[i]=tnsLinearItp(fd1[i],fd2[i],fac); } break;    default:        *data=ak1->Data; break;    }}void la_AnimationSetPropValue(laActionProp* ap){    void* data=ap->Data;    laPropPack PP={0}; laPropStep PS={0}; if(!ap) return;    PS.p=ap->Prop; PS.Type='.'; PS.UseInstance=ap->For; PP.LastPs=&PS; PP.EndInstance=ap->For;    switch(ap->Prop->PropertyType){    case LA_PROP_INT: laSetInt(&PP,*((int*)data)); break;    case LA_PROP_INT|LA_PROP_ARRAY: laSetIntArrayAllArray(&PP,(int*)data); break;    case LA_PROP_FLOAT: laSetFloat(&PP,*((real*)data)); break;    case LA_PROP_FLOAT|LA_PROP_ARRAY: laSetFloatArrayAllArray(&PP,(real*)data); break;    case LA_PROP_ENUM: laSetEnum(&PP,*((int*)data)); break;    //case LA_PROP_ENUM|LA_PROP_ARRAY: laSetEnumArrayAllArray(&PP,(real*)data); break; //doesnt work    default: break;    }}void la_AnimationMixChannelValue(laActionChannel* ac, void* data, int MixMode, real Factor){    laActionProp* ap=ac->AP; if(!ap) return;  int* ip=&ap->Data,*ipd=data; real* fp=&ap->Data,*fpd=data;    int arrlen=ap->Prop->Len?ap->Prop->Len:1;    switch(ap->Prop->PropertyType){    case LA_PROP_INT:  case LA_PROP_INT|LA_PROP_ARRAY: for(int i=0;i<arrlen;i++){             ip[i]=ap->Reset?ipd[i]:(MixMode==LA_ANIMATION_MIX_REPLACE?ipd[i]:(ipd[i]+ip[i]));        } break;    case LA_PROP_FLOAT: case LA_PROP_FLOAT|LA_PROP_ARRAY: for(int i=0;i<arrlen;i++){             fp[i]=ap->Reset?fpd[i]:(MixMode==LA_ANIMATION_MIX_REPLACE?fpd[i]:(fpd[i]+fp[i]));        } break;    case LA_PROP_ENUM: ip[0]=ipd[0]; break;    //case LA_PROP_ENUM|LA_PROP_ARRAY: laSetEnumArrayAllArray(&PP,(real*)data); break; //doesnt work    default: break;    }    ap->Reset=0;}void la_AnimationEvaluateActionChannels(laAction* aa){    int64_t _data[16]; void* data=_data;    int frame=LA_ACTION_FRAME(aa); real totframe=aa->PlayHead*aa->FrameCount;    for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){        laActionKey* ak1=laAnimationGetFrame(ac,frame); if(!ak1) continue;        laActionKey* ak2=ak1->Item.pNext;        la_AnimationInterpolateKeys(ac,ak1,ak2,totframe,&data);        la_AnimationMixChannelValue(ac, data, aa->MixMode, 0);    }}void la_AnimationEvaluateActions(int ClampOffsets){    int any=0;    la_AnimationMarkPropReset();    for(laAction* aa=MAIN.Animation->Actions.pFirst;aa;aa=aa->Item.pNext){        real preoffset=0,postoffset=aa->Offset/aa->Length;        if(ClampOffsets || (MAIN.Animation->PlayStatus!=LA_ANIMATION_STATUS_PAUSED)){            while(aa->Offset>aa->Length){ aa->Offset-=aa->Length; }            while(aa->Offset<-1e-6){ aa->Offset+=aa->Length; }            preoffset=aa->Offset; postoffset=0;        }        real UseTime=MAIN.Animation->PlayHead-preoffset;        int repeats=UseTime/aa->Length;        real remaining=UseTime-repeats*aa->Length;        while(remaining<0){ remaining+=aa->Length; }        if(aa->PlayMode==LA_ANIMATION_PLAY_MODE_REPEAT){ aa->PlayHead=remaining/aa->Length-postoffset; }        elif(aa->PlayMode==LA_ANIMATION_PLAY_MODE_HOLD){ aa->PlayHead=((UseTime>aa->Length)?1.0:(UseTime<0?0:UseTime/aa->Length))-postoffset; }        elif(aa->PlayMode==LA_ANIMATION_PLAY_MODE_BOUNCE){ real t=remaining/aa->Length; aa->PlayHead=((repeats%2)?(1-t):t)-postoffset; }        any=1;        la_AnimationEvaluateActionChannels(aa);    }    for(laActionProp* ap=MAIN.Animation->Props.pFirst;ap;ap=ap->Item.pNext){ if(ap->Reset){ continue; }        la_AnimationSetPropValue(ap);    }    if(any) laNotifyUsers("la.animation");}void la_AnimationPreFrame(){    if(MAIN.Animation->PlayHead<0){        MAIN.Animation->PlayHead=0; laAnimationSetPlayStatus(0);        la_AnimationEvaluateActions(1);        laNotifyUsers("la.animation.play_head");    }    if(MAIN.Animation->PlayStatus){        la_AnimationEvaluateActions(0);    }}void la_AnimationPostFrame(){    laTimeRecorder cur={0};    if(MAIN.Animation->PlayStatus){ laRecordTime(&cur);        real td=laTimeElapsedSecondsf(&cur,&MAIN.Animation->TimeOrigin);        laRecordTime(&MAIN.Animation->TimeOrigin);        if(MAIN.Animation->PlayStatus==LA_ANIMATION_STATUS_PLAY_REV){ td*=-1; }        MAIN.Animation->PlayHead+=td; laNotifyUsers("la.animation.play_head");    }}void la_ActionDeselectFrames(laAction* aa){    for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){        for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){            ak->Selected=0;        }    }}void la_ActionSelectFrame(laAction* aa, int Channel, real At, real zoomx){    int tc=0;laActionChannel* ac;    for(ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){ if(tc==Channel) break; tc++; }    if(!ac) return;    real ClosestDist=FLT_MAX; laActionKey* ClosestKey=0;    for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){        real d=fabs(ak->At-At+0.5); if(d*zoomx<LA_RH*2 && d<ClosestDist){ ClosestDist=d; ClosestKey=ak; }    }    if(ClosestKey){ ClosestKey->Selected=1; }}int la_ActionSaveKeyOriginalAt(laAction* aa){    int any=0;    for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){        for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){ if(!ak->Selected) continue; any=1; ak->OriginaAt=ak->At; }    }    return any;}void la_ActionRestoreKeyOriginalAt(laAction* aa){    for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){        for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){ if(!ak->Selected) continue; ak->At=ak->OriginaAt; }    }    la_ActionEnsureFrameOrder(aa);}void la_ActionEnsureFrameOrder(laAction* aa){    for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){        laListHandle lst={0};        laActionKey* ak; while(ak=lstPopItem(&ac->Keys)){ int done=0;            if(!lst.pFirst){ lstAppendItem(&lst,ak); continue; }            laActionKey* ak2=0;            for(ak2=lst.pFirst;ak2;ak2=ak2->Item.pNext){                if(ak2->At>=ak->At){ lstInsertItemBefore(&lst,ak,ak2); done=1; break; }            }            if(!done) lstAppendItem(&lst,ak);        }        lstCopyHandle(&ac->Keys,&lst);    }}void la_ActionRemoveDuplicatedFrames(laAction* aa){    for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){        laActionKey* ak2; for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){            while((ak2=ak->Item.pNext)&&ak->At==ak2->At){ lstRemoveItem(&ac->Keys,ak2); memLeave(ak2); }        }    }}void la_ActionMoveSelectedFrames(laAction* aa, int Delta){    for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){        for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){ if(!ak->Selected) continue;            ak->At=ak->OriginaAt+Delta;        }    }    la_ActionEnsureFrameOrder(aa);}int la_ActionDeleteSelectedFrames(laAction* aa){    int any=0;    for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){        laActionKey* NextAk; for(laActionKey* ak=ac->Keys.pFirst;ak;ak=NextAk){ NextAk=ak->Item.pNext;if(!ak->Selected) continue;            lstRemoveItem(&ac->Keys, ak); memLeave(ak); any=1;        }    }    return any;}int LAMOD_AnimationActionsCanvas(laOperator *a, laEvent *e){    laUiItem *ui = a->Instance; laBoxedTheme *bt = (*ui->Type->Theme);    laCanvasExtra *ex = a->CustomData; laAction* aa=ui->PP.EndInstance;    if(!aa) LA_RUNNING_PASS;    int W, H; W = ui->R - ui->L; H = ui->B - ui->U;    int ShowSide=(ex->ShowLegend&&ex->LW<W-2*LA_RH);    int ll=ui->L, lr=ll+(ShowSide?ex->LW:0), tl=lr, tr=ui->R;    int FW=LA_RH/2;    int Channels=aa?lstCountElements(&aa->Channels):0;    int Modal=0; int mid=((W-lr)/2);        if(e->Type==LA_M_MOUSE_DOWN){        ex->UiMode=1; ex->ClickedX=e->x; ex->ClickedY=e->y; Modal=1; ex->Dragging=10;    }elif(e->Type==LA_M_MOUSE_UP || e->Type==LA_L_MOUSE_UP){        ex->UiMode=0; Modal=1; ex->Dragging=0; ex->TargetIndexVali=0;    }    if(ex->UiMode==1){        if(e->Type&LA_MOUSE_EVENT){            ex->PanY-=e->y-ex->ClickedY; ex->PanX-=e->x-ex->ClickedX;            ex->ClickedX=e->x; ex->ClickedY=e->y; Modal=1;        }    }elif(ex->UiMode==2){ Modal=1;        if(e->Type&LA_MOUSE_EVENT){            ex->LW=e->x-ui->L+LA_SEAM_W; ex->ClickedX=e->x; ex->ClickedY=e->y;            if(ex->LW<LA_RH*3 && ex->LW>=LA_RH/2){ ex->LW=LA_RH*3; }            if(ex->LW<LA_RH/2 && ex->Dragging!=12){ ex->ShowLegend=0; ex->LW=0; }            if(ex->LW<LA_RH*3){ ex->LW=LA_RH*3;}        }    }elif(ex->UiMode==3){ Modal=1;        if(e->Type&LA_MOUSE_EVENT){ ex->ClickedX=e->x; ex->ClickedY=e->y;            int SetFrame=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW;            la_AnimationActionSetOwnFrame(aa,SetFrame);        }    }elif(ex->UiMode==4){ Modal=1;        if(e->Type==LA_R_MOUSE_DOWN || (e->Type==LA_ESCAPE_DOWN)){ ex->UiMode=0; ex->Dragging=0;            la_ActionRestoreKeyOriginalAt(aa); laNotifyUsers("la.animation.current_action");        }elif(e->Type==LA_L_MOUSE_DOWN){ la_ActionRemoveDuplicatedFrames(aa);            laNotifyUsers("la.animation.current_action"); ex->UiMode=0; ex->Dragging=0;        }elif(e->Type&LA_MOUSE_EVENT){ Modal=1;            int ToFrame=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW,FromFrame=(real)(ex->ClickedX-tl+ex->PanX)/ex->ZoomX/FW;            la_ActionMoveSelectedFrames(aa,ToFrame-FromFrame); laNotifyUsers("la.animation.current_action");        }    }    int MaxDN=LA_RH*(Channels+1)-H+bt->TP+bt->BP; if(MaxDN<0) MaxDN=0;    if(!Modal){        if(e->x<=lr){            if(e->Type==LA_MOUSE_WHEEL_DOWN){ ex->PanY+=LA_RH*MAIN.ScrollingSpeed; Modal=1; }            if(e->Type==LA_MOUSE_WHEEL_UP){ ex->PanY-=LA_RH*MAIN.ScrollingSpeed; Modal=1; }            if(e->x>=lr-LA_SEAM_W*2){ if(!ex->TargetIndexVali){ ex->TargetIndexVali=1; Modal=1; }                if(e->Type==LA_L_MOUSE_DOWN){                    ex->UiMode=2; ex->ClickedX=e->x; ex->ClickedY=e->y; Modal=1; ex->Dragging=10; Modal=1;                }            }else{ if(ex->TargetIndexVali){ ex->TargetIndexVali=0; Modal=1; } }        }elif(aa){            if((!ex->ShowLegend)&&e->x<=ll+LA_SEAM_W*2){                if(!ex->TargetIndexVali){ ex->TargetIndexVali=1; Modal=1; }                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; }            }else{ if(ex->TargetIndexVali){ ex->TargetIndexVali=0; Modal=1; } }            if(e->Type==LA_MOUSE_WHEEL_DOWN){ ex->ZoomX*=0.9; ex->PanX+=mid; ex->PanX*=0.9; ex->PanX-=mid; Modal=1; }            elif(e->Type==LA_MOUSE_WHEEL_UP){ ex->ZoomX*=1.1; ex->PanX+=mid; ex->PanX*=1.1; ex->PanX-=mid; Modal=1; }            elif(e->Type==LA_L_MOUSE_DOWN){                ex->UiMode=3; int SetFrame=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW;                la_AnimationActionSetOwnFrame(aa,SetFrame); Modal=1;            }elif(e->Type==LA_R_MOUSE_DOWN){                int row=(e->y-ui->U-bt->BM-LA_RH)/LA_RH; real at=(real)(e->x-tl+ex->PanX)/ex->ZoomX/FW;                if(!(e->SpecialKeyBit&LA_KEY_SHIFT)){ la_ActionDeselectFrames(aa); }                la_ActionSelectFrame(aa,row,at,ex->ZoomX);                laNotifyUsers("la.animation.current_action");            }elif(e->Type==LA_KEY_DOWN&&e->key=='g'){                int any=la_ActionSaveKeyOriginalAt(aa);                if(any){ ex->ClickedX=e->x; ex->ClickedY=e->y; ex->UiMode=4; Modal=1; ex->Dragging=13;                    laNotifyUsers("la.animation.current_action");                }            }elif(e->Type==LA_KEY_DOWN&&e->key=='x'){                int any=la_ActionDeleteSelectedFrames(aa);                if(any){                    laNotifyUsers("la.animation.current_action");                }            }        }    }    if(ex->PanY>MaxDN){ ex->PanY=MaxDN; } if(ex->PanY<0){ ex->PanY=0; }    //if(ex->PanX<0){ ex->PanX=0; }    if(ex->TargetIndexVali){ laSetWindowCursor(LA_LEFT_AND_RIGHT); }else{ laSetWindowCursor(LA_ARROW); }    if(Modal){ laRedrawCurrentPanel(); return LA_RUNNING; }    return LA_RUNNING_PASS;}void la_AnimationActionCanvasInit(laUiItem *ui){    la_CanvasInit(ui);    laCanvasExtra* ex=ui->Extra; ex->LW=LA_RH*7; ex->ShowLegend=1;}void la_AnimationActionDrawCanvas(laBoxedTheme *bt, laAction *aa, laUiItem* ui){    laCanvasExtra* ex=ui->Extra; //laAction* aa=ui->PP.EndInstance;    int W, H; W = ui->R - ui->L; H = ui->B - ui->U; if (W<=0 || H<=0) return;    int ShowSide=(ex->ShowLegend&&ex->LW<W-2*LA_RH);    int ll=ui->L, lr=ll+(ShowSide?ex->LW-1:0), tl=lr, tr=ui->R;    int FW=LA_RH/2;    //if (!e->OffScr || e->OffScr->pColor[0]->Height != ui->B - ui->U || e->Be.OffScr->pColor[0]->Width != ui->R - ui->L){    //    if (e->OffScr) tnsDelete2DOffscreen(e->OffScr);    //    e->OffScr = tnsCreate2DOffscreen(GL_RGBA, W, H, MAIN.PanelMultisample, 1, 0);    //}    real *bkg=laThemeColor(bt,LA_BT_NORMAL);    real *txt=laThemeColor(bt,LA_BT_TEXT);    real *act=laThemeColor(bt,LA_BT_ACTIVE);    tnsUseNoTexture();    tnsColor4d(LA_COLOR3(bkg),bkg[3]*0.3);    tnsVertex2d(tl, ui->U); tnsVertex2d(tr, ui->U);    tnsVertex2d(tr, ui->B); tnsVertex2d(tl, ui->B);    tnsPackAs(GL_TRIANGLE_FAN);    int row=1,curframe,cx; real fl,fr;    tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));    tnsVertex2d(ui->L, ui->U+bt->TP+LA_RH); tnsVertex2d(ui->R, ui->U+bt->TP+LA_RH);    tnsVertex2d(ui->R, ui->U); tnsVertex2d(ui->L, ui->U);    tnsPackAs(GL_TRIANGLE_FAN);    tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));    tnsVertex2d(tl, LA_RH+ui->U); tnsVertex2d(tr, LA_RH+ui->U);    tnsPackAs(GL_LINES);    tnsFlush();    int sx,sy,sw,sh,vl,vr,vu,vb;    la_DoUiScissor(ui,&sx,&sy,&sw,&sh,&vl,&vr,&vu,&vb);    if(aa){        curframe=LA_ACTION_FRAME(aa); fl=tl+curframe*FW*ex->ZoomX-ex->PanX, fr=tl+(curframe+1)*FW*ex->ZoomX-ex->PanX;        tnsUseNoTexture();        tnsColor4dv(laAccentColor(LA_BT_NORMAL));        tnsVertex2d(fl, ui->U); tnsVertex2d(fr, ui->U);        tnsVertex2d(fr, ui->B); tnsVertex2d(fl, ui->B);        tnsPackAs(GL_TRIANGLE_FAN);        tnsFlush(); glLineWidth(2);        for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){            real ku=ui->U+bt->TP+row*LA_RH-ex->PanY,kb=ku+LA_RH;            for(laActionKey* ak=ac->Keys.pFirst;ak;ak=ak->Item.pNext){                real kl=tl+ak->At*FW*ex->ZoomX-ex->PanX, kr=tl+(ak->At+1)*FW*ex->ZoomX-ex->PanX;                if(ak->Selected) tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE));                elif(curframe==ak->At) tnsColor4d(LA_COLOR3(txt),txt[3]*0.6);                else tnsColor4dv(laThemeColor(bt,LA_BT_ACTIVE));                tnsVertex2d(kl, ku); tnsVertex2d(kr, ku);                tnsVertex2d(kr, kb); tnsVertex2d(kl, kb);                tnsPackAs(GL_TRIANGLE_FAN);                tnsColor4dv(laThemeColor(bt,LA_BT_TEXT_ACTIVE));                tnsVertex2d(kl, ku); tnsVertex2d(kr, ku);                tnsVertex2d(kr, kb); tnsVertex2d(kl, kb);                tnsPackAs(GL_LINE_LOOP);            }            row++;        }        tnsFlush(); glLineWidth(1);        real end=tl+aa->FrameCount*FW*ex->ZoomX-ex->PanX;        tnsColor4d(0,0,0,0.3);        tnsVertex2d(end, ui->U+LA_RH); tnsVertex2d(end+1e6, ui->U+LA_RH);        tnsVertex2d(end+1e6, ui->B); tnsVertex2d(end, ui->B);        tnsPackAs(GL_TRIANGLE_FAN);         tnsVertex2d(tl-ex->PanX, ui->U+LA_RH); tnsVertex2d(tl-ex->PanX-1e6, ui->U+LA_RH);        tnsVertex2d(tl-ex->PanX-1e6, ui->B); tnsVertex2d(tl-ex->PanX, ui->B);        tnsPackAs(GL_TRIANGLE_FAN);         tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE));        int FrameFix=aa->PlayHead<0?1:0;        cx=tl+(aa->PlayHead*aa->FrameCount+FrameFix)*FW*ex->ZoomX-ex->PanX; tnsVertex2d(cx, ui->U); tnsVertex2d(cx, ui->B);        tnsPackAs(GL_LINES); glLineWidth(3); tnsFlush(); glLineWidth(1);        char buf[32]; sprintf(buf,"%d",curframe); real tlen=tnsStringGetDimension(buf,0,0,0,0,0)+bt->LP+bt->RP;        tnsColor4dv(laAccentColor(LA_BT_TEXT_ACTIVE));        tnsVertex2d(cx, ui->U+LA_RH); tnsVertex2d(cx+tlen, ui->U+LA_RH);        tnsVertex2d(cx+tlen, ui->U); tnsVertex2d(cx, ui->U);        tnsPackAs(GL_TRIANGLE_FAN);        tnsDrawStringAuto(buf,laThemeColor(bt,LA_BT_TEXT_ACTIVE),cx+bt->LP,cx+LA_RH*2,ui->U+bt->TP,0);        tnsPackAs(GL_TRIANGLE_FAN); tnsUseNoTexture();    }    if(ShowSide){        tnsColor4dv(laThemeColor(bt,LA_BT_NORMAL));        tnsVertex2d(ll, ui->U); tnsVertex2d(lr, ui->U);        tnsVertex2d(lr, ui->B); tnsVertex2d(ll, ui->B);        tnsPackAs(GL_TRIANGLE_FAN);        if(!aa){            tnsDrawStringAuto("No action selected",laThemeColor(bt,LA_BT_TEXT),ll+bt->LP,lr-bt->RP,ui->U+bt->BP,0);        }else{ int row=1;            tnsDrawStringAuto(aa->Name->Ptr,laThemeColor(bt,LA_BT_TEXT),ll+bt->LP,lr-bt->RP,ui->U+bt->BP,0);            for(laActionChannel* ac=aa->Channels.pFirst;ac;ac=ac->Item.pNext){                tnsDrawStringAuto(ac->AP->CachedName->Ptr,laThemeColor(bt,LA_BT_TEXT),ll+bt->LP,lr-bt->RP,ui->U+bt->TP+row*LA_RH-ex->PanY,0);                row++;            }        }    }    if(ex->TargetIndexVali==1){        int LR=TNS_MAX2(lr,ui->L+LA_SEAM_W*2);        tnsColor4dv(act);tnsUseNoTexture();        tnsVertex2d(LR, ui->B); tnsVertex2d(LR-LA_SEAM_W*2, ui->B);        tnsVertex2d(LR-LA_SEAM_W*2, ui->U); tnsVertex2d(LR, ui->U);        tnsPackAs(GL_TRIANGLE_FAN);    }    tnsFlush();    tnsViewportWithScissor(sx,sy,sw,sh);    tnsOrtho(vl,vr,vb,vu,-100,100);    tnsUseNoTexture();    tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));    tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);    tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);    tnsPackAs(GL_LINE_LOOP);}void la_AnimationActionDrawOverlay(laUiItem *ui, int h){    laCanvasExtra *e = ui->Extra; laBoxedTheme *bt = (*ui->Type->Theme);    tnsUseImmShader();    if(MAIN.CurrentWindow->MaximizedUi!=ui){        tnsUseNoTexture();        tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));        tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);        tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);        tnsPackAs(GL_LINE_LOOP);    }    if (e->DrawCursor){        tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));        int drawx=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_X);        int drawy=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_Y);        if(drawx) tnsVertex2d(e->OnX, ui->U); tnsVertex2d(e->OnX, ui->B);        if(drawy) tnsVertex2d(ui->L, e->OnY); tnsVertex2d(ui->R, e->OnY);        tnsPackAs(GL_LINES);        tnsFlush();    }    return;}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,U'🞦',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);    laCanvasTemplate* ct=laRegisterCanvasTemplate("la_AnimationActionDrawCanvas", "la_animation_action", LAMOD_AnimationActionsCanvas, la_AnimationActionDrawCanvas, la_AnimationActionDrawOverlay, la_AnimationActionCanvasInit, la_CanvasDestroy);    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);    }
 |