CompositionEffectBrush GetCompositionEffectBrush(CompositionEffectBrush obj) { if (GetExisting(obj, out CompositionEffectBrush result)) { return(result); } var effectBase = obj.GetEffect(); switch (effectBase.Type) { case GraphicsEffectType.CompositeEffect: var compositeEffect = (CompositeEffect)effectBase; var newCompositeEffect = new CompositeEffect { Mode = compositeEffect.Mode, }; var effectFactory = _c.CreateEffectFactory(newCompositeEffect); var compositeEffectBrush = effectFactory.CreateBrush(); result = CacheAndInitializeCompositionObject(obj, compositeEffectBrush); foreach (var source in compositeEffect.Sources) { newCompositeEffect.Sources.Add(new CompositionEffectSourceParameter(source.Name)); result.SetSourceParameter(source.Name, GetCompositionBrush(obj.GetSourceParameter(source.Name))); } break; default: throw new InvalidOperationException(); } StartAnimationsAndFreeze(obj, result); return(result); }
private void ThumbnailList_SizeChanged(object sender, SizeChangedEventArgs e) { if (_destinationSprite != null) { _destinationSprite.Size = e.NewSize.ToVector2(); ComboBoxItem item = EffectSelection.SelectedValue as ComboBoxItem; switch ((EffectTypes)item.Tag) { case EffectTypes.Mask: { CompositionEffectBrush brush = (CompositionEffectBrush)_destinationSprite.Brush; CompositionSurfaceBrush surfaceBrush = (CompositionSurfaceBrush)brush.GetSourceParameter("SecondSource"); surfaceBrush.CenterPoint = e.NewSize.ToVector2() * .5f; break; } default: break; } } }
private void EffectToString(StringBuilder sb, int indent, IGraphicsEffect effect, CompositionEffectBrush brush) { const int indentIncrement = 4; Type type = effect.GetType(); sb.AppendFormat("{0}{1}\r\n{0}{{\r\n", Indent(indent), type.Name); Dictionary <string, object> expandedProperties = new Dictionary <string, object>(); indent += indentIncrement; foreach (PropertyInfo info in effect.GetType().GetProperties()) { string propertyName = info.Name.ToLower(); if (propertyName == "cacheoutput" || propertyName == "bufferprecision" || propertyName == "colorhdr" || propertyName == "issupported" || propertyName == "clampoutput" || propertyName == "name" || propertyName == "alphamode") { continue; } object obj = info.GetValue(effect); if (obj != null) { if (obj is IGraphicsEffect || obj is IList <IGraphicsEffectSource> ) { expandedProperties.Add(info.Name, obj); } else { if (obj is CompositionEffectSourceParameter) { CompositionEffectSourceParameter param = (CompositionEffectSourceParameter)obj; CompositionBrush sourceBrush = brush.GetSourceParameter(param.Name); string s = String.Format("{0}{1} :\r\n{0}{{\r\n", Indent(indent), info.Name); sb.Append(s); BrushToString(sb, indent + indentIncrement, sourceBrush); sb.AppendFormat("{0}}}\r\n", Indent(indent)); } else { sb.AppendFormat("{0}{1} : {2}\r\n", Indent(indent), info.Name, Helpers.ToString(obj)); } } } } // Moved all of the nested source properties to the end of the list foreach (KeyValuePair <string, object> entry in expandedProperties) { string name = entry.Key; object obj = entry.Value; if (obj is IGraphicsEffect) { string s = String.Format("{0}{1} :\r\n{0}{{\r\n", Indent(indent), name); sb.Append(s); EffectToString(sb, indent + indentIncrement, (IGraphicsEffect)obj, brush); sb.AppendFormat("{0}}}\r\n", Indent(indent)); } else if (obj is IList <IGraphicsEffectSource> ) { IList <IGraphicsEffectSource> list = (IList <IGraphicsEffectSource>)obj; sb.AppendFormat("{0}{1} :\r\n{0}[\r\n", Indent(indent), name); foreach (IGraphicsEffectSource source in list) { EffectToString(sb, indent + indentIncrement, (IGraphicsEffect)source, brush); } sb.AppendFormat("{0}]\r\n", Indent(indent)); } } indent -= indentIncrement; sb.AppendFormat("{0}}}\r\n", Indent(indent)); }