public RenderArgs(FlatPrototype prot, DeviceContext context, RectangleF bounds, Size2 screen) { Prototype = prot; Context = context; Bounds = bounds; Screen = screen; }
RectangleF GetBounds(FlatPrototype prot, RectangleF parent, Size2 screen) { var x = prot.Parameter.ContainsKey("X") ? Transform((ScreenPos)prot.Parameter["X"].Value, parent.Size, screen, false) : 0; var y = prot.Parameter.ContainsKey("Y") ? Transform((ScreenPos)prot.Parameter["Y"].Value, parent.Size, screen, true) : 0; x += parent.X; y += parent.Y; var w = prot.Parameter.ContainsKey("Width") ? Transform((ScreenPos)prot.Parameter["Width"].Value, parent.Size, screen, false) : parent.Right - x; var h = prot.Parameter.ContainsKey("Height") ? Transform((ScreenPos)prot.Parameter["Height"].Value, parent.Size, screen, true) : parent.Bottom - y; return(new RectangleF(x, y, w, h)); }
/// <summary> /// Flatten this whole inheritance tree to a single prototype. After this all changes to /// the inheritance tree are ignored to the previous flatten result. /// All the current informations are stored in the helper. /// </summary> /// <param name="helper"> /// in this helper the information about this objectare stored /// </param> /// <returns>The flattened result</returns> public FlatPrototype Flatten(PrototypeFlattenerHelper helper) { var flat = new FlatPrototype(); Flatten(flat, helper); //flat.Container.AddRange(Container.ConvertAll((pb) => pb.Flatten())); if (flat.RenderName == null) { flat.RenderName = typeof(PrototypeBase).FullName; } flat.Name = Name; return(flat); }
/// <summary> /// Move all reference targets of the flatten result to its variables /// </summary> /// <param name="helper">helper informations</param> /// <param name="prot">flattened result</param> void MoveTargets(PrototypeFlattenerHelper helper, FlatPrototype prot) { foreach (var a in prot.Animations) { a.MoveTargets(helper); } foreach (var c in prot.Container) { MoveTargets(helper, c); } foreach (var p in prot.Parameter) { p.Value.MoveTargets(helper); } }
/// <summary> /// flatten this prototype /// </summary> /// <param name="flat">target of informations</param> /// <param name="helper">information that helps this flattening</param> private void Flatten(FlatPrototype flat, PrototypeFlattenerHelper helper) { if (BasePrototype != null) { BasePrototype.Flatten(flat, helper); } flat.Container.AddRange(Container.ConvertAll((p) => { var h = new PrototypeFlattenerHelper(); var f = p.Flatten(h); helper.Import(h); return(f); })); foreach (var p in flat.Parameter.ToArray()) { if (Parameter.ContainsKey(p.Key)) { var par = p.Value; var current = Parameter[p.Key]; var newPar = current.Clone(); helper.Conversion[par] = newPar; helper.Conversion[current] = newPar; flat.Parameter[p.Key] = newPar; } } foreach (var p in Parameter) { if (!flat.Parameter.ContainsKey(p.Key)) { var par = p.Value.Clone(); helper.Conversion[p.Value] = par; flat.Parameter[p.Key] = par; } } foreach (var a in Animations) { var anim = a.Clone(); helper.Animations[a] = anim; flat.Animations.Add(anim); } MoveTargets(helper, flat); if (RenderName != null) { flat.RenderName = RenderName; } }
void RenderObject(Renderer source, FlatPrototype prot, RectangleF parent, Size2 screen) { var bounds = GetBounds(prot, parent, screen); if (prot.Parameter.ContainsKey("Visible") && !(bool)prot.Parameter["Visible"].Value) { return; } foreach (var sub in prot.Container) { RenderObject(source, sub, bounds, screen); } if (Renderer.ContainsKey(prot.RenderName)) { Renderer[prot.RenderName].Render(new RenderArgs(prot, source.SharpRender.d2dContext, bounds, screen)); } }
bool ClickObject(Renderer source, Vector2 point, FlatPrototype prot, RectangleF parent, Size2 screen, Physic.ClickButton button) { var bounds = GetBounds(prot, parent, screen); var contains = bounds.Contains(point); var found = false; var force = prot.Parameter.ContainsKey("MouseSolid") && (bool)prot.Parameter["MouseSolid"].Value; if (!force || contains) { foreach (var sub in prot.Container) { if (ClickObject(source, point, sub, bounds, screen, button)) { return(true); } } } if (contains) { foreach (var anim in prot.Animations) { foreach (var act in anim.Activations) { if ((act is Physic.ClickAnimation) && act.Enabled) { var click = (Physic.ClickAnimation)act; if (click.Button.Exists && click.Button.Value != button) { continue; } source.Animation.ExecuteAnimation(anim); found = true; break; } } } } return(force && found); }