internal KeyTime (KeyTimeType type, double percent, TimeSpan time_span) { this.type = type; this.percent = percent; this.time_span = time_span; this.padding = 1; }
internal KeyTime(KeyTimeType type, double percent, TimeSpan time_span) { this.type = type; this.percent = percent; this.time_span = time_span; this.padding = 1; }
private void ResolveKeyTimes() { Debug.Assert(!_areKeyTimesValid, "KeyFrameColorAnimaton.ResolveKeyTimes() shouldn't be called if the key times are already valid."); int keyFrameCount = 0; if (_keyFrames != null) { keyFrameCount = _keyFrames.Count; } if (keyFrameCount == 0) { _sortedResolvedKeyFrames = null; _areKeyTimesValid = true; return; } _sortedResolvedKeyFrames = new ResolvedKeyFrameEntry[keyFrameCount]; int index = 0; // Initialize the _originalKeyFrameIndex. for ( ; index < keyFrameCount; index++) { _sortedResolvedKeyFrames[index]._originalKeyFrameIndex = index; } // calculationDuration represents the time span we will use to resolve // percent key times. This is defined as the value in the following // precedence order: // 1. The animation's duration, but only if it is a time span, not auto or forever. // 2. The largest time span specified key time of all the key frames. // 3. 1 second, to match the From/To/By animations. TimeSpan calculationDuration = TimeSpan.Zero; Duration duration = Duration; if (duration.HasTimeSpan) { calculationDuration = duration.TimeSpan; } else { calculationDuration = LargestTimeSpanKeyTime; } int maxKeyFrameIndex = keyFrameCount - 1; List <KeyTimeBlock> unspecifiedBlocks = new List <KeyTimeBlock>(); bool hasPacedKeyTimes = false; // // Pass 1: Resolve Percent and Time key times. // index = 0; while (index < keyFrameCount) { KeyTime keyTime = _keyFrames[index].KeyTime; switch (keyTime.Type) { case KeyTimeType.Percent: _sortedResolvedKeyFrames[index]._resolvedKeyTime = TimeSpan.FromMilliseconds( keyTime.Percent * calculationDuration.TotalMilliseconds); index++; break; case KeyTimeType.TimeSpan: _sortedResolvedKeyFrames[index]._resolvedKeyTime = keyTime.TimeSpan; index++; break; case KeyTimeType.Paced: case KeyTimeType.Uniform: if (index == maxKeyFrameIndex) { // If the last key frame doesn't have a specific time // associated with it its resolved key time will be // set to the calculationDuration, which is the // defined in the comments above where it is set. // Reason: We only want extra time at the end of the // key frames if the user specifically states that // the last key frame ends before the animation ends. _sortedResolvedKeyFrames[index]._resolvedKeyTime = calculationDuration; index++; } else if (index == 0 && keyTime.Type == KeyTimeType.Paced) { // Note: It's important that this block come after // the previous if block because of rule precendence. // If the first key frame in a multi-frame key frame // collection is paced, we set its resolved key time // to 0.0 for performance reasons. If we didn't, the // resolved key time list would be dependent on the // base value which can change every animation frame // in many cases. _sortedResolvedKeyFrames[index]._resolvedKeyTime = TimeSpan.Zero; index++; } else { if (keyTime.Type == KeyTimeType.Paced) { hasPacedKeyTimes = true; } KeyTimeBlock block = new KeyTimeBlock(); block.BeginIndex = index; // NOTE: We don't want to go all the way up to the // last frame because if it is Uniform or Paced its // resolved key time will be set to the calculation // duration using the logic above. // // This is why the logic is: // ((++index) < maxKeyFrameIndex) // instead of: // ((++index) < keyFrameCount) while ((++index) < maxKeyFrameIndex) { KeyTimeType type = _keyFrames[index].KeyTime.Type; if (type == KeyTimeType.Percent || type == KeyTimeType.TimeSpan) { break; } else if (type == KeyTimeType.Paced) { hasPacedKeyTimes = true; } } Debug.Assert(index < keyFrameCount, "The end index for a block of unspecified key frames is out of bounds."); block.EndIndex = index; unspecifiedBlocks.Add(block); } break; } } // // Pass 2: Resolve Uniform key times. // for (int j = 0; j < unspecifiedBlocks.Count; j++) { KeyTimeBlock block = unspecifiedBlocks[j]; TimeSpan blockBeginTime = TimeSpan.Zero; if (block.BeginIndex > 0) { blockBeginTime = _sortedResolvedKeyFrames[block.BeginIndex - 1]._resolvedKeyTime; } // The number of segments is equal to the number of key // frames we're working on plus 1. Think about the case // where we're working on a single key frame. There's a // segment before it and a segment after it. // // Time known Uniform Time known // ^ ^ ^ // | | | // | (segment 1) | (segment 2) | Int64 segmentCount = (block.EndIndex - block.BeginIndex) + 1; TimeSpan uniformTimeStep = TimeSpan.FromTicks((_sortedResolvedKeyFrames[block.EndIndex]._resolvedKeyTime - blockBeginTime).Ticks / segmentCount); index = block.BeginIndex; TimeSpan resolvedTime = blockBeginTime + uniformTimeStep; while (index < block.EndIndex) { _sortedResolvedKeyFrames[index]._resolvedKeyTime = resolvedTime; resolvedTime += uniformTimeStep; index++; } } // // Pass 3: Resolve Paced key times. // if (hasPacedKeyTimes) { ResolvePacedKeyTimes(); } // // Sort resolved key frame entries. // Array.Sort(_sortedResolvedKeyFrames); _areKeyTimesValid = true; return; }
private void ResolveKeyTimes() { int keyFramesCount = 0; if (_keyFrames != null) { keyFramesCount = _keyFrames.Count; } if (keyFramesCount == 0) { _sortedResolvedKeyFrames = null; _areKeyTimesValid = true; } else { _sortedResolvedKeyFrames = new ResolvedKeyFrameEntry[keyFramesCount]; int currentFrameIndex = 0; while (currentFrameIndex < keyFramesCount) { _sortedResolvedKeyFrames[currentFrameIndex].originalKeyFrameIndex = currentFrameIndex; currentFrameIndex++; } Duration duration = Duration; var time = duration.HasTimeSpan ? duration.TimeSpan : LargestTimeSpanKeyTime; int lastKeyFrameIndex = keyFramesCount - 1; List <KeyTimeBlock> blocks = new List <KeyTimeBlock>(); bool isPaced = false; currentFrameIndex = 0; while (currentFrameIndex < keyFramesCount) { // ReSharper disable once PossibleNullReferenceException KeyTime keyTime = _keyFrames[currentFrameIndex].KeyTime; switch (keyTime.Type) { case KeyTimeType.Uniform: case KeyTimeType.Paced: { if (currentFrameIndex != lastKeyFrameIndex) { break; } _sortedResolvedKeyFrames[currentFrameIndex].resolvedKeyTime = time; currentFrameIndex++; continue; } case KeyTimeType.Percent: { _sortedResolvedKeyFrames[currentFrameIndex].resolvedKeyTime = TimeSpan.FromMilliseconds(keyTime.Percent * time.TotalMilliseconds); currentFrameIndex++; continue; } case KeyTimeType.TimeSpan: { _sortedResolvedKeyFrames[currentFrameIndex].resolvedKeyTime = keyTime.TimeSpan; currentFrameIndex++; continue; } default: { continue; } } if ((currentFrameIndex == 0) && (keyTime.Type == KeyTimeType.Paced)) { _sortedResolvedKeyFrames[currentFrameIndex].resolvedKeyTime = TimeSpan.Zero; currentFrameIndex++; continue; } if (keyTime.Type == KeyTimeType.Paced) { isPaced = true; } KeyTimeBlock block = new KeyTimeBlock { BeginIndex = currentFrameIndex }; while (++currentFrameIndex < lastKeyFrameIndex) { KeyTimeType keyTimeType = _keyFrames[currentFrameIndex].KeyTime.Type; if (keyTimeType == KeyTimeType.Paced) { isPaced = true; } } block.EndIndex = currentFrameIndex; blocks.Add(block); } foreach (KeyTimeBlock block in blocks) { TimeSpan blockTime = TimeSpan.Zero; if (block.BeginIndex > 0) { blockTime = _sortedResolvedKeyFrames[block.BeginIndex - 1].resolvedKeyTime; } long blockIndices = (block.EndIndex - block.BeginIndex) + 1; TimeSpan blockTimeDiff = _sortedResolvedKeyFrames[block.EndIndex].resolvedKeyTime - blockTime; TimeSpan blockAvgTime = TimeSpan.FromTicks(blockTimeDiff.Ticks / blockIndices); currentFrameIndex = block.BeginIndex; TimeSpan currentBlockTime = blockTime + blockAvgTime; while (currentFrameIndex < block.EndIndex) { _sortedResolvedKeyFrames[currentFrameIndex].resolvedKeyTime = currentBlockTime; currentBlockTime += blockAvgTime; currentFrameIndex++; } } if (isPaced) { ResolvePacedKeyTimes(); } Array.Sort(_sortedResolvedKeyFrames); _areKeyTimesValid = true; } }
private KeyTime(KeyTimeType type, TimeSpan timeSpan, double percent) { this.Type = type; this.TimeSpan = timeSpan; this.Percent = percent; }
// Token: 0x06001775 RID: 6005 RVA: 0x00072B80 File Offset: 0x00070D80 private void ResolveKeyTimes() { int num = 0; if (this._keyFrames != null) { num = this._keyFrames.Count; } if (num == 0) { this._sortedResolvedKeyFrames = null; this._areKeyTimesValid = true; return; } this._sortedResolvedKeyFrames = new ResolvedKeyFrameEntry[num]; int i; for (i = 0; i < num; i++) { this._sortedResolvedKeyFrames[i]._originalKeyFrameIndex = i; } TimeSpan resolvedKeyTime = TimeSpan.Zero; Duration duration = base.Duration; if (duration.HasTimeSpan) { resolvedKeyTime = duration.TimeSpan; } else { resolvedKeyTime = this.LargestTimeSpanKeyTime; } int num2 = num - 1; ArrayList arrayList = new ArrayList(); bool flag = false; i = 0; while (i < num) { KeyTime keyTime = this._keyFrames[i].KeyTime; switch (keyTime.Type) { case KeyTimeType.Uniform: case KeyTimeType.Paced: if (i == num2) { this._sortedResolvedKeyFrames[i]._resolvedKeyTime = resolvedKeyTime; i++; } else if (i == 0 && keyTime.Type == KeyTimeType.Paced) { this._sortedResolvedKeyFrames[i]._resolvedKeyTime = TimeSpan.Zero; i++; } else { if (keyTime.Type == KeyTimeType.Paced) { flag = true; } ThicknessAnimationUsingKeyFrames.KeyTimeBlock keyTimeBlock = default(ThicknessAnimationUsingKeyFrames.KeyTimeBlock); keyTimeBlock.BeginIndex = i; while (++i < num2) { KeyTimeType type = this._keyFrames[i].KeyTime.Type; if (type == KeyTimeType.Percent || type == KeyTimeType.TimeSpan) { break; } if (type == KeyTimeType.Paced) { flag = true; } } keyTimeBlock.EndIndex = i; arrayList.Add(keyTimeBlock); } break; case KeyTimeType.Percent: this._sortedResolvedKeyFrames[i]._resolvedKeyTime = TimeSpan.FromMilliseconds(keyTime.Percent * resolvedKeyTime.TotalMilliseconds); i++; break; case KeyTimeType.TimeSpan: this._sortedResolvedKeyFrames[i]._resolvedKeyTime = keyTime.TimeSpan; i++; break; } } for (int j = 0; j < arrayList.Count; j++) { ThicknessAnimationUsingKeyFrames.KeyTimeBlock keyTimeBlock2 = (ThicknessAnimationUsingKeyFrames.KeyTimeBlock)arrayList[j]; TimeSpan timeSpan = TimeSpan.Zero; if (keyTimeBlock2.BeginIndex > 0) { timeSpan = this._sortedResolvedKeyFrames[keyTimeBlock2.BeginIndex - 1]._resolvedKeyTime; } long num3 = (long)(keyTimeBlock2.EndIndex - keyTimeBlock2.BeginIndex + 1); TimeSpan t = TimeSpan.FromTicks((this._sortedResolvedKeyFrames[keyTimeBlock2.EndIndex]._resolvedKeyTime - timeSpan).Ticks / num3); i = keyTimeBlock2.BeginIndex; TimeSpan timeSpan2 = timeSpan + t; while (i < keyTimeBlock2.EndIndex) { this._sortedResolvedKeyFrames[i]._resolvedKeyTime = timeSpan2; timeSpan2 += t; i++; } } if (flag) { this.ResolvePacedKeyTimes(); } Array.Sort <ResolvedKeyFrameEntry>(this._sortedResolvedKeyFrames); this._areKeyTimesValid = true; }