ENGINE_NAMESPACE_BEGIN_MOVIESYSTEM //------------------------------------------------------------------------------------------------- void sdAnimUIntTrack::GetValue(float fTime, uint& uiValue) { if (GetNumKeys() == 0) { uiValue = (uint)-1; return; } else if (GetNumKeys() == 1) { uiValue = GetKeyTime(0) <= fTime ? m_kTracks[0].m_uiValue : (uint)-1; return; } else { for (int i = 1; i < GetNumKeys(); ++i) { if (fTime >= GetKeyTime(i-1) && fTime < GetKeyTime(i)) { uiValue = m_kTracks[i-1].m_uiValue; return; } } uiValue = m_kTracks[GetNumKeys() - 1].m_uiValue; } }
void LinkTimeControl::MapKeys(TimeMap *map,DWORD flags) { int n = NumKeys(); BOOL changed = FALSE; if (n) { fOwner->ActivateSort(false); if (flags&TRACK_DOALL) { for (int i = 0; i < n; i++) { ChangeKeyTime( i, map->map( GetKeyTime(i) ) ); changed = TRUE; } } else if (flags&TRACK_DOSEL) { BOOL slide = flags&TRACK_SLIDEUNSEL; TimeValue delta = 0, prev; int start, end, inc; if (flags&TRACK_RIGHTTOLEFT) { start = n-1; end = -1; inc = -1; } else { start = 0; end = n; inc = 1; } for (int i = start; i != end; i += inc) { if ( IsKeySelected(i) ) { prev = GetKeyTime(i); ChangeKeyTime( i, map->map( GetKeyTime(i) ) ); delta = GetKeyTime(i) - prev; changed = TRUE; static int a=2; if (i!=a) { int b =0; b++; } } else if (slide) { ChangeKeyTime( i, GetKeyTime(i) + delta ); changed = TRUE; } } } fOwner->ActivateSort(true); if (changed) { fOwner->LinkTimeChanged(); NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); } } StdControl::MapKeys(map,flags); }
int LinkTimeControl::HitTestFCurves( ParamDimensionBase *dim, TrackHitTab& hits, Rect& rcHit, Rect& rcGraph, float tzoom, int tscroll, float vzoom, int vscroll, DWORD flags ) { int h = rcGraph.h()-1; bool hit = false; const int n = NumKeys(); for ( int i=0; i<n; ++i ) { BOOL sel = IsKeySelected( i ); if ( ( flags & HITTRACK_SELONLY ) && !sel ) continue; if ( ( flags & HITTRACK_UNSELONLY ) && sel ) continue; TimeValue t = GetKeyTime( i ); int x = TimeToScreen( t, tzoom, tscroll ); float val; Interval valid; GetValue( t, &val, valid ); int y = ValueToScreen( dim->Convert(val), h, vzoom, vscroll ); if ( rcHit.Contains( IPoint2( x, y ) ) ) { hit = true; TrackHitRecord rec( i, 0 ); hits.Append( 1, &rec ); if ( flags & HITTRACK_ABORTONHIT ) break; } } return hit ? HITCURVE_KEY : HITCURVE_NONE; }
void FMoveKeys::GetKeySnapTimes(TArray<float>& OutSnapTimes, TSharedPtr<FTrackNode> SequencerNode) { // snap to non-selected keys TArray< TSharedRef<FSectionKeyAreaNode> > KeyAreaNodes; SequencerNode->GetChildKeyAreaNodesRecursively(KeyAreaNodes); for (int32 NodeIndex = 0; NodeIndex < KeyAreaNodes.Num(); ++NodeIndex) { TArray< TSharedRef<IKeyArea> > KeyAreas = KeyAreaNodes[NodeIndex]->GetAllKeyAreas(); for (int32 KeyAreaIndex = 0; KeyAreaIndex < KeyAreas.Num(); ++KeyAreaIndex) { auto KeyArea = KeyAreas[KeyAreaIndex]; TArray<FKeyHandle> KeyHandles = KeyArea->GetUnsortedKeyHandles(); for( int32 KeyIndex = 0; KeyIndex < KeyHandles.Num(); ++KeyIndex ) { FKeyHandle KeyHandle = KeyHandles[KeyIndex]; bool bKeyIsSnappable = true; for ( FSelectedKey SelectedKey : SelectedKeys ) { if (SelectedKey.KeyArea == KeyArea && SelectedKey.KeyHandle.GetValue() == KeyHandle) { bKeyIsSnappable = false; break; } } if (bKeyIsSnappable) { OutSnapTimes.Add(KeyArea->GetKeyTime(KeyHandle)); } } } } }
TOptional<FKeyHandle> FNameCurveKeyArea::DuplicateKey(FKeyHandle KeyToDuplicate) { if (!Curve.IsKeyHandleValid(KeyToDuplicate)) { return TOptional<FKeyHandle>(); } return Curve.AddKey(GetKeyTime(KeyToDuplicate), Curve.GetKey(KeyToDuplicate).Value); }
void FRichCurve::ScaleCurve(float ScaleOrigin, float ScaleFactor, TSet<FKeyHandle>& KeyHandles) { for (auto It = KeyHandlesToIndices.CreateIterator(); It; ++It) { const FKeyHandle& KeyHandle = It.Key(); if (KeyHandles.Num() != 0 && KeyHandles.Contains(KeyHandle)) { SetKeyTime(KeyHandle, (GetKeyTime(KeyHandle) - ScaleOrigin) * ScaleFactor + ScaleOrigin); } } }
void FRichCurve::ShiftCurve(float DeltaTime, TSet<FKeyHandle>& KeyHandles) { for (auto It = KeyHandlesToIndices.CreateIterator(); It; ++It) { const FKeyHandle& KeyHandle = It.Key(); if (KeyHandles.Num() != 0 && KeyHandles.Contains(KeyHandle)) { SetKeyTime(KeyHandle, GetKeyTime(KeyHandle)+DeltaTime); } } }
int LinkTimeControl::PaintFCurves( ParamDimensionBase *dim, HDC hdc, Rect& rcGraph, Rect& rcPaint, float tzoom, int tscroll, float vzoom, int vscroll, DWORD flags ) { const int n = NumKeys(); if ( n == 0 ) return 0; Interval valid; int h = rcGraph.h()-1; HPEN dpen,spen; BOOL init=FALSE; Interval range = GetTimeRange(TIMERANGE_ALL); SetBkMode(hdc,TRANSPARENT); dpen = CreatePen(PS_DOT,0,GetColorManager()->GetColor(kFunctionCurveFloat)); spen = CreatePen(PS_SOLID,0,GetColorManager()->GetColor(kFunctionCurveFloat)); SIZE size; GetTextExtentPoint( hdc, _T("0"), 1, &size ); float val; TimeValue leftTime = ScreenToTime(rcPaint.left,tzoom,tscroll); TimeValue rightTime = ScreenToTime(rcPaint.right,tzoom,tscroll); int x, y; // dotted line to left of keys if ( leftTime < range.Start() ) { SelectObject(hdc,dpen); GetValue(range.Start(),&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); MoveToEx(hdc,rcPaint.left,y,NULL); LineTo(hdc,TimeToScreen(range.Start(),tzoom,tscroll),y); } SelectObject(hdc,spen); // first node text { TimeValue t = GetKeyTime( 0 ); if ( t >= leftTime && t <= rightTime ) { GetValue(t,&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); x = TimeToScreen(t,tzoom,tscroll); INode* node = fOwner->GetNode( 0 ); DLTextOut( hdc, x, y-1-size.cy, node ? node->GetName() : _T("World") ); } } // solid line between keys for ( int i=1; i<n; ++i ) { TimeValue t0 = GetKeyTime( i-1 ); TimeValue t1 = GetKeyTime( i ); if ( t1 < leftTime || t0 > rightTime ) continue; GetValue(t0,&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); MoveToEx(hdc,TimeToScreen(t0,tzoom,tscroll),y,NULL); x = TimeToScreen(t1,tzoom,tscroll); LineTo(hdc,x,y); GetValue(t1,&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); LineTo(hdc,x,y); INode* node = fOwner->GetNode( i ); DLTextOut( hdc, x, y-1-size.cy, node ? node->GetName() : _T("World") ); } // dotted line to right of keys if ( rightTime > range.End() ) { SelectObject(hdc,dpen); GetValue(range.End(),&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); MoveToEx(hdc,TimeToScreen(range.End(),tzoom,tscroll),y,NULL); LineTo(hdc,rcPaint.right,y); } SelectObject( hdc, spen ); HBRUSH hUnselBrush = CreateSolidBrush(GetColorManager()->GetColor(kTrackbarKeys)); HBRUSH hSelBrush = CreateSolidBrush(GetColorManager()->GetColor(kTrackbarSelKeys)); // render keys themselves for ( int i=0; i<n; ++i ) { TimeValue t = GetKeyTime( i ); if ( t < leftTime || t > rightTime ) continue; GetValue(t,&val,valid); y = ValueToScreen(dim->Convert(val),h,vzoom,vscroll); x = TimeToScreen(t,tzoom,tscroll); SelectObject( hdc, IsKeySelected( i ) ? hSelBrush : hUnselBrush ); Rectangle(hdc,x-3,y-3,x+3,y+3); } SetBkMode(hdc,OPAQUE); SelectObject(hdc,GetStockObject(BLACK_PEN)); DeleteObject(spen); DeleteObject(dpen); DeleteObject(hUnselBrush); DeleteObject(hSelBrush); return 0; }
STARTDECL(gl_lasttime) (Value &name, Value &on) { auto t = GetKeyTime(name.sval->str(), on.ival); name.DEC(); return Value(t); }