public ConfigToken ToToken(Dictionary <string, Type> effects, IServiceProvider services, Surface effectSourceSurface) { ConfigToken token = new ConfigToken(); for (int i = 0; i < Effects.Count; i++) { EffectConfigToken stepToken = null; Type type; if (effects.TryGetValue(Effects[i], out type)) { Effect effect = (Effect)(type.GetConstructor(Type.EmptyTypes).Invoke(new object[0])); effect.Services = services; effect.EnvironmentParameters = new EffectEnvironmentParameters(allcolors[i].First, allcolors[i].Second, 2, new PdnRegion(effectSourceSurface.Bounds), effectSourceSurface); if (effect.Options.Flags.HasFlag(EffectFlags.Configurable)) { try { EffectConfigDialog dialog = effect.CreateConfigDialog(); stepToken = dialog.EffectToken; if (effect is PropertyBasedEffect) { PropertyBasedEffectConfigToken pbect = stepToken as PropertyBasedEffectConfigToken; IEnumerator <Property> enumerator = pbect.Properties.Properties.GetEnumerator(); for (int ii = 0; ii < Properties[i].Length; ii++) { try { enumerator.MoveNext(); enumerator.Current.ReadOnly = false; if (enumerator.Current.Value is FontFamily) { enumerator.Current.Value = new FontFamily((string)Properties[i][ii]); } else { enumerator.Current.Value = Properties[i][ii]; } } catch (ReadOnlyException) { } } } else { Type t = stepToken.GetType(); SetObjectPropertiesAndFields(stepToken, Properties[i], Fields[i], effects, services, effectSourceSurface); } } catch (Exception) { } } token.effects.Add(new ScriptStep(effect.Name, effect.Image, type, stepToken, Colors[i].First, Colors[i].Second)); } else { token.effects.Add(new ScriptStep(Effects[i], null, null, null, Colors[i].First, Colors[i].Second)); } } return(token); }
protected override void InitDialogFromToken(EffectConfigToken effectToken) { ConfigToken token = (ConfigToken)effectToken; theEffectToken = token; lbScript.Items.Clear(); lbScript.Items.AddRange(token.effects.ConvertAll(step => step.Name).ToArray()); }
private void ChangeSelectedEffect() { if (lbScript.SelectedItem != null) { ConfigToken token = (ConfigToken)theEffectToken; int i = lbScript.SelectedIndex; ScriptStep step = token.effects[i]; Type type = step.EffectType; if (type != null) { Effect effect = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(new object[0]); effect.EnvironmentParameters = Effect.EnvironmentParameters; effect.Services = Services; if (effect.CheckForEffectFlags(EffectFlags.Configurable)) { try { EffectConfigDialog dialog = effect.CreateConfigDialog(); dialog.EffectSourceSurface = EffectSourceSurface; dialog.Selection = Selection; dialog.Effect = effect; dialog.EffectToken = (EffectConfigToken)step.Token.Clone(); if (effect.Image != null) { dialog.Icon = Icon.FromHandle(((Bitmap)effect.Image).GetHicon()); } if (dialog.ShowDialog(this) == DialogResult.OK) { step.Token = dialog.EffectToken; FinishTokenUpdate(); } } catch (Exception e) { MessageBox.Show(this, "Error occurred in configuration dialog for " + effect.Name + ":\n\n" + e.ToString(), effect.Name + " Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(this, step.Name + " is not installed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static ScriptLabScript FromToken(ConfigToken token) { ScriptLabScript sls = new ScriptLabScript(); foreach (ScriptStep step in token.effects) { if (step.EffectType == null) { sls.Add(step.Name, step.Name, new object[0], new object[0], Pair.Create(step.PrimaryColor, step.SecondaryColor)); } else if (step.Token == null) { sls.Add(step.EffectType.FullName + ":" + step.Name, step.Name, null, null, Pair.Create(step.PrimaryColor, step.SecondaryColor)); } else if (step.Token is PropertyBasedEffectConfigToken) { PropertyBasedEffectConfigToken pbect = step.Token as PropertyBasedEffectConfigToken; object[] properties = new object[pbect.Properties.Count]; IEnumerator <Property> enumerator = pbect.Properties.Properties.GetEnumerator(); for (int i = 0; i < pbect.Properties.Count; i++) { enumerator.MoveNext(); if (enumerator.Current.Value is FontFamily) { properties[i] = (enumerator.Current.Value as FontFamily).Name; } else if (enumerator.Current.Value.GetType().IsSerializable) { properties[i] = enumerator.Current.Value; } } sls.Add(step.EffectType.FullName + ":" + step.Name, step.Name, properties, null, Pair.Create(step.PrimaryColor, step.SecondaryColor)); } else { object[][] propertiesAndFields = MembersToObjectArray(step.Token); sls.Add(step.EffectType.FullName + ":" + step.Name, step.Name, propertiesAndFields[0], propertiesAndFields[1], Pair.Create(step.PrimaryColor, step.SecondaryColor)); } } return(sls); }
void AddSelectedEffect() { if (lbAvailable.SelectedItem != null) { ConfigToken token = (ConfigToken)theEffectToken; string effectidentifiername = SearchResultEffects[lbAvailable.SelectedIndex]; Type t = AvailableEffects[effectidentifiername]; Effect effect = (Effect)t.GetConstructor(Type.EmptyTypes).Invoke(new object[0]); effect.EnvironmentParameters = Effect.EnvironmentParameters; effect.Services = Services; if (effect.CheckForEffectFlags(EffectFlags.Configurable)) { try { EffectConfigDialog dialog = effect.CreateConfigDialog(); dialog.EffectSourceSurface = EffectSourceSurface; dialog.Selection = Selection; dialog.Effect = effect; if (effect.Image != null) { dialog.Icon = effect.Image.ToIcon(); } if (dialog.ShowDialog(this) == DialogResult.OK) { token.effects.Add(new ScriptStep(effect.Name, effect.Image, t, dialog.EffectToken, Effect.EnvironmentParameters.PrimaryColor, Effect.EnvironmentParameters.SecondaryColor)); lbScript.Items.Add(effect.Name); FinishTokenUpdate(); } } catch (Exception e) { MessageBox.Show(this, "Error occurred in configuration dialog for " + effect.Name + ":\n\n" + e.ToString(), effect.Name + " Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { token.effects.Add(new ScriptStep(effect.Name, effect.Image, t, null, Effect.EnvironmentParameters.PrimaryColor, Effect.EnvironmentParameters.SecondaryColor)); lbScript.Items.Add(effect.Name); FinishTokenUpdate(); } } }
private void EnableScriptControlButtons() { if (lbScript.SelectedIndices.Count == 0) { btnChange.Enabled = false; btnChangeColor.Enabled = false; btnMoveUp.Enabled = false; btnMoveDown.Enabled = false; btnDeleteEffect.Enabled = false; } else if (lbScript.SelectedIndices.Count == 1) { btnChange.Enabled = false; btnChangeColor.Enabled = true; btnMoveUp.Enabled = true; btnMoveDown.Enabled = true; btnDeleteEffect.Enabled = true; //check if the selected effect is configurable ConfigToken token = (ConfigToken)theEffectToken; int i = lbScript.SelectedIndex; ScriptStep step = token.effects[i]; Type type = step.EffectType; if (type != null) { Effect effect = (Effect)type.GetConstructor(Type.EmptyTypes).Invoke(new object[0]); if (effect.CheckForEffectFlags(EffectFlags.Configurable)) { btnChange.Enabled = true; } } } else { btnChange.Enabled = false; btnChangeColor.Enabled = true; btnMoveUp.Enabled = false; btnMoveDown.Enabled = false; btnDeleteEffect.Enabled = true; } }
private void btnMoveDown_Click(object sender, EventArgs e) { if (lbScript.SelectedItem != null && lbScript.SelectedIndex + 1 < lbScript.Items.Count) { ConfigToken token = (ConfigToken)theEffectToken; int i = lbScript.SelectedIndex; object temp; temp = lbScript.Items[i]; lbScript.Items[i] = lbScript.Items[i + 1]; lbScript.Items[i + 1] = temp; temp = token.effects[i]; token.effects[i] = token.effects[i + 1]; token.effects[i + 1] = (ScriptStep)temp; lbScript.SelectedIndices.Clear(); lbScript.SelectedIndices.Add(i + 1); FinishTokenUpdate(); } }
private bool LoadFile(string filename, out Exception exception) { exception = null; object o; if (FileMan.LoadFileBinary(filename, out o, true) || FileMan.LoadFileBinary(filename, out o, false)) { ScriptLabScript sls = o as ScriptLabScript; sls.ForceCompatibility(); ConfigToken token = sls.ToToken(AvailableEffects, Services, EffectSourceSurface); lbScript.Items.Clear(); ((ConfigToken)theEffectToken).effects.Clear(); ((ConfigToken)theEffectToken).effects.AddRange(token.effects); lbScript.Items.AddRange(token.effects.ConvertAll(step => step.Name).ToArray()); FinishTokenUpdate(); return(true); } else { exception = (Exception)o; return(false); } }
private void ChangeSelectedEffectColors() { if (lbScript.SelectedItem != null) { ConfigToken token = (ConfigToken)theEffectToken; int i = lbScript.SelectedIndex; ScriptStep step = token.effects[i]; using (TwoColorDialog cd = new TwoColorDialog()) { cd.SetColors(step.PrimaryColor, step.SecondaryColor); if (cd.ShowDialog(this) == DialogResult.OK) { foreach (int index in lbScript.SelectedIndices) { step = token.effects[index]; step.PrimaryColor = cd.Color1; step.SecondaryColor = cd.Color2; } lbScript.Invalidate(); FinishTokenUpdate(); } } } }
protected ConfigToken(ConfigToken copyMe) : base(copyMe) { effects = copyMe.effects; }
protected override void InitialInitToken() { theEffectToken = new ConfigToken(); }
public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { ConfigToken token = (ConfigToken)parameters; PdnRegion selection = EnvironmentParameters.GetSelection(srcArgs.Bounds); if (changed) { changed = false; if (dialog != null) { dialog.SetProgressBarMaximum(token.effects.Count, tilesPerCpu * renderingThreadCount); dialog.EnableOKButton(false); } using (Surface scratch = new Surface(srcArgs.Size)) { scratch.CopySurface(srcArgs.Surface); for (int i = 0; i < token.effects.Count; ++i) { ScriptStep step = token.effects[i]; Type type = step.EffectType; if (type == null) { if (dialog != null) { dialog.IncrementProgressBarValue(i, 1); } } else { Effect effect = (Effect)(type.GetConstructor(Type.EmptyTypes).Invoke(new object[0])); effect.Services = Services; effect.EnvironmentParameters = new EffectEnvironmentParameters( step.PrimaryColor, step.SecondaryColor, EnvironmentParameters.BrushWidth, selection, EnvironmentParameters.SourceSurface); BackgroundEffectRenderer ber = new BackgroundEffectRenderer(effect, step.Token, dstArgs, new RenderArgs(scratch), selection, null, tilesPerCpu * renderingThreadCount, renderingThreadCount); ber.RenderedTile += (sender, e) => RenderedTile((BackgroundEffectRenderer)sender, i, e.TileCount); ber.Start(); ber.Join(); scratch.CopySurface(dstArgs.Surface); } if (IsCancelRequested) { return; } } if (dialog != null) { dialog.ClearProgressBars(); dialog.EnableOKButton(true); } } } }