public static ShapeDescription ComputeData(BaseControl ctl) { ShapeDescription shape = default(ShapeDescription); switch (ctl.Description.Shape) { case Shape.None: case Shape.Sprite: break; case Shape.Custom: break; case Shape.Triangle: break; case Shape.Circle: break; case Shape.LeftTrapezoidUpside: break; case Shape.LeftTrapezoidDownside: break; case Shape.RightTrapezoidUpside: break; case Shape.RightTrapezoidDownside: break; case Shape.Rectangle: case Shape.RectangleMesh: shape = DrawRectangle(ctl); break; default: throw Error.WrongCase("shape", "ComputeData", shape); } shape.Tag = ctl.Id; shape.Depth = ctl.Depth; return shape; }
public UpdateElement(BaseControl control, UpdateAction action) : this() { Control = control; Action = action; if (Action == UpdateAction.None) Console.WriteLine("!Terribile"); }
protected XmlBaseControl(BaseControl control) { if (control == null) throw Error.InCreatingFromObject("control", GetType(), typeof (BaseControl)); Id = control.Id; Position = control.Position; Size = control.Size; PositionString = (control.Position != Vector2.Zero) ? XmlCommon.EncodeVector2(control.Position) : string.Empty; SizeString = (control.Size != Size.Empty) ? XmlCommon.EncodeSize(control.Size) : string.Empty; IsEnabled = control.IsEnabled; IsVisible = control.IsVisible; TextStyleClass = control.TextDescriptionClass; ControlDescriptionClass = control.ControlDescriptionClass; }
/// <summary> /// Computes the eight points bounding this control. /// <remarks>Index 0 is northwest corner.<br>Index 7 is west point.</br></remarks> /// </summary> /// <param name="control">The control whose bounds to compute.</param> /// <returns>The array of points, stored in clockwise order.</returns> public static Vector2[] ComputeBounds(BaseControl control) { Vector2 cornerNE = control.AbsolutePosition; int width = control.Size.Width; int height = control.Size.Height; return new[]{ cornerNE, new Vector2(cornerNE.X + width/2f, cornerNE.Y), new Vector2(cornerNE.X + width, cornerNE.Y), new Vector2(cornerNE.X + width, cornerNE.Y + height/2f), new Vector2(cornerNE.X + width, cornerNE.Y + height), new Vector2(cornerNE.X + width/2f, cornerNE.Y + height), new Vector2(cornerNE.X, cornerNE.Y + height), new Vector2(cornerNE.X, cornerNE.Y + height/2f) }; }
public XmlPanel(BaseControl control) : base(control) { }
public override void Init() { Hud.BeginDesign(); Button button = new Button { Size = new Size(128, 64) }; button.BringToFront(); button.Position = Layout.CenterControl(button, Hud); Hud.Controls.Add(button); Hud.EndDesign(); Scene.BuildRenderScene(); Hud.AddToScene(this,Scene); DeviceContext.Immediate.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; //Camera.Update(); Scene.Update(); control = button; }
internal static Vector2 ComputeTextPosition(BaseControl hostControl, TextLiteral textControl) { float x; float y; Thickness padding = hostControl.Description.Padding; Thickness borderSize = hostControl.Description.BorderSize; switch (textControl.TextDescription.HorizontalAlignment) { case HorizontalAlignment.NotSet: case HorizontalAlignment.Left: x = borderSize.Left + padding.Left; break; case HorizontalAlignment.Center: x = padding.Left + borderSize.Left + (hostControl.ContentAreaSize.Width/2 - textControl.Size.Width/2); break; case HorizontalAlignment.Right: x = (hostControl.ContentAreaSize.Width - textControl.Size.Width) - borderSize.Right - padding.Right; break; default: throw Error.WrongCase("HorizontalAlignment", "ComputeTextPosition", textControl.TextDescription.HorizontalAlignment); } switch (textControl.TextDescription.VerticalAlignment) { case VerticalAlignment.NotSet: case VerticalAlignment.Top: y = borderSize.Top + padding.Top; break; case VerticalAlignment.Center: y = borderSize.Top + padding.Top + (hostControl.ContentAreaSize.Height/2 - textControl.Size.Height/2); break; case VerticalAlignment.Bottom: y = (hostControl.ContentAreaSize.Height - textControl.Size.Height) -borderSize.Bottom - padding.Bottom; break; default: throw Error.WrongCase("VerticalAlignment", "ComputeTextPosition", textControl.TextDescription.VerticalAlignment); } return new Vector2(x, y); }
public void Remove(BaseControl control) { PrivateControlCollection.Remove(control); }
public void Insert(int index, BaseControl control) { PublicControlCollection.Insert(index, control); }
/// <summary> /// Determines whether the <b>ContainerControl</b> contains the specified keys. /// </summary> /// <param name="control">The control to locate in the control collection.</param> /// <returns><b>True</b> if it the collection contains that element ,<b>false</b> otherwise. </returns> /// <remarks>The control passed as parameter does not have to be a top level child, /// but this method will also return true if the specified <see cref="BaseControl"/> belongs to the tree formed /// by the ContainerControl's children.</remarks> public bool ContainsControl(BaseControl control) { if (control == null) throw Error.ArgumentNull("control", GetType(), "ContainsControl"); return PublicControlCollection.Contains(control); }
static ShapeDescription DrawRectangle(BaseControl control) { ControlDescription desc = control.Description; Designer d = control.GetDesigner(); d.Position = control.AbsoluteOrthoPosition; foreach (BorderShader borderShader in desc.BorderShaders) { d.BorderSize = borderShader.Borders != Borders.All ? MaskBorderSize(borderShader.Borders, desc.BorderSize) : desc.BorderSize; d.Shader = borderShader; d.DrawRectangle(); } d.Position = new Vector3 (d.Position.X + desc.BorderSize.Left, d.Position.Y - desc.BorderSize.Top, d.Position.Z); d.Width = control.ClientSize.Width; d.Height = control.ClientSize.Height; foreach (IGradientShader colorShader in desc.Enabled) { switch (colorShader.GradientType) { default: d.Shader = colorShader; d.FillRectangle(); break; case GradientType.Radial: RadialShader rs = (RadialShader)colorShader; //// First draw background color from the radial shader's outermost color //d.Shader = LinearShader.CreateUniform(rs.Gradient[rs.Gradient.Length - 1].Color); //d.FillRectangle(); d.Shader = rs; OrthoRectangle rectangle = new OrthoRectangle(d.Position.X, d.Position.Y, d.Width, d.Height); bool test = Intersection.EllipseRectangleTest(rs.CreateEllipse(rectangle), rectangle); if (!test) d.DrawEllipse(); else d.DrawClippedEllipse(); break; } } //d.Vertices = new Vector4[] { d.Position.ToVector4(), d.Position.ToVector4() + new Vector4(50, -50f, 0, 1.0f), // d.Position.ToVector4() + new Vector4(75, 200, 0, 1.0f) }; return d.Output; }
public static float CenterControlVertical(BaseControl control, BaseControl container) { return (container.ClientSize.Height - control.Size.Height)/2f; }
public static Vector2 CenterControl(BaseControl control, BaseControl container) { return new Vector2(CenterControlHorizontal(control,container), CenterControlVertical(control,container)); }
private void UpdateShapes(BaseControl control) { LogEvent.Engine.Write("Updating Hud shapes"); control.UpdateShape(); foreach (ShapeDescription sDesc in control.Shapes) { if (!sDesc.IsDirty) continue; Array.Copy(sDesc.Vertices, 0, hudInterface.Vertices, sDesc.ArrayOffset, sDesc.Vertices.Length); sDesc.IsDirty = false; } }
private void RemoveControl(BaseControl control) { foreach (ShapeDescription sDesc in control.Shapes) hudShapes.Remove(sDesc); ISpriteObject sCtl = control as ISpriteObject; if (sCtl != null) spriteControls.Remove(sCtl); IContainer containerControl = control as IContainer; if (containerControl != null) foreach (BaseControl childControl in TreeTraversal.PreOrderControlVisit(containerControl)) RemoveControl(childControl); }
private void AddControl(BaseControl control) { if (control.Description.HasShape) hudShapes.AddRange(control.Shapes.Array); ISpriteObject sObj = control as ISpriteObject; if (sObj != null) spriteControls.Add(sObj); IContainer containerControl = control as IContainer; if (containerControl != null) ComputeShapes(containerControl); if (!HudDescription.Multithreaded) UpdateSprites(); else if (!uiUCommand.ContainsTask(UpdateSprites)) { if (sObj != null || (containerControl != null && containerControl.ContainsSprites)) { uiUCommand.EnqueueTask(UpdateSprites); uiUCommand.EnqueueTask(uiRCommand.UpdateItems); } } }
/// <summary> /// Enqueues a control for update. /// </summary> /// <remarks>Multiple events in rapid succession may cause a control to update its appearance. /// This makes sure that a control is not added multiple times to the queue if it has not yet /// been updated. /// <para>When a control is updated, the entire vertex buffer is discared and rewritten, for /// performance purposes.</para></remarks> /// <param name="control">The control to update.</param> public void EnqueueForUpdate(BaseControl control, UpdateAction updateAction) { if (control.IsBeingUpdated) return; ///TODO //Console.WriteLine(string.Format("Enqueing {0} for {1}",control.Id, updateAction)); UpdateElement updateElement = new UpdateElement(control, updateAction); updateQueue.Enqueue(updateElement); control.IsBeingUpdated = true; uiUCommand.Resume(); }
protected override void OnInit(object sender, EventArgs e) { Hud.BeginDesign(); Button button = new Button { Size = new Size(128, 64) }; button.BringToFront(); button.Position = Layout.CenterControl(button, Hud); Hud.Controls.Add(button); Hud.EndDesign(); //Camera.Update(); Scene.Update(); control = button; ActiveShader = control.Description.Enabled[0]; }
public static float CenterControlHorizontal(BaseControl control, BaseControl container) { return (container.ClientSize.Width - control.Size.Width)/2f; }
protected XmlContainerControl(BaseControl control) : base(control) { xmlControlList = new List<XmlBaseControl>(); }
public void Add(BaseControl control) { PublicControlCollection.Add(control); }
public HitManager(BaseControl ownerControl, Size sensibleArea) { this.ownerControl = ownerControl; SensibleArea = sensibleArea; }