/// <summary></summary>
		/// <param name="name"></param>
		/// <param name="width"></param>
		/// <param name="height"></param>
		/// <param name="samples"></param>
		/// <param name="fontHeight"></param>
		/// <param name="font"></param>
		/// <param name="minScale"></param>
		/// <param name="goodValue">The value that determines the transition from green to red on the graph</param>
		public Graph(string name, int width, int height, int samples, int fontHeight, float minScale, SpriteFont font, float goodValue)
			: base(new Vector2((float)width, (float)height), false)
		{
			if (width < fontHeight ||
				height < fontHeight)
				throw new ArgumentException("size is too small for font size");

			graph = new GraphDrawer(samples, Color.Red, new Vector2(), minScale, goodValue);
			float edge = 0.25f;

			graph.VerticalScaling = ElementScaling.FillToParentPlusSize;
			graph.HorizontalScaling = ElementScaling.FillToParentPlusSize;
			graph.Position = new Vector2((float)(fontHeight) *edge, (float)(fontHeight));
			graph.Size = -graph.Position;

			title = new TextElementRect(Vector2.Zero, name,font);
			title.VerticalAlignment = VerticalAlignment.Top;
			title.HorizontalAlignment = HorizontalAlignment.Left;
			title.HorizontalScaling = ElementScaling.FillToParentPlusSize;
			title.VerticalScaling = ElementScaling.FillToParentPlusSize;
			title.TextHorizontalAlignment = TextHorizontalAlignment.Centre;
			title.TextVerticalAlignment = VerticalAlignment.Top;
			title.Size = new Vector2(0, 0);

			value = new TextElementRect(Vector2.Zero, "0",font);
			value.VerticalAlignment = VerticalAlignment.Bottom;
			value.HorizontalAlignment = HorizontalAlignment.Left;
			value.HorizontalScaling = ElementScaling.FillToParentPlusSize;
			value.VerticalScaling = ElementScaling.FillToParentPlusSize;
			value.TextHorizontalAlignment = TextHorizontalAlignment.Right;
			value.TextVerticalAlignment = VerticalAlignment.Bottom;
			value.Size = new Vector2(0, 0);
			value.Position = new Vector2(-10, 0);

			this.Add(title);
			this.Add(value);
			this.Add(graph);

			float x = fontHeight / ((float)width);
			float y = fontHeight / ((float)height);

			this.AlphaBlendState = AlphaBlendState.Alpha;

			VertexPositionColor[] verts = new VertexPositionColor[]
			{
				new VertexPositionColor(new Vector3(x*edge,y,0),Color.White),
				new VertexPositionColor(new Vector3(1-x*edge,y,0),Color.White),
				new VertexPositionColor(new Vector3(x*edge,y,0),Color.White),
				new VertexPositionColor(new Vector3(x*edge,1-y,0),Color.White),
				
				new VertexPositionColor(new Vector3(edge*x,y + 0.25f * (1-y*2),0),new Color(255,255,255,16)),
				new VertexPositionColor(new Vector3(1-x*edge,y + 0.25f * (1-y*2),0),new Color(255,255,255,16)),
				
				new VertexPositionColor(new Vector3(edge*x,y + 0.5f * (1-y*2),0),new Color(255,255,255,16)),
				new VertexPositionColor(new Vector3(1-x*edge,y + 0.5f * (1-y*2),0),new Color(255,255,255,16)),
				
				new VertexPositionColor(new Vector3(edge*x,y + 0.75f * (1-y*2),0),new Color(255,255,255,16)),
				new VertexPositionColor(new Vector3(1-x*edge,y + 0.75f * (1-y*2),0),new Color(255,255,255,16)),
				
				new VertexPositionColor(new Vector3(edge*x,y,0),new Color(255,255,255,16)),
				new VertexPositionColor(new Vector3(1-x*edge,y,0),new Color(255,255,255,16)),
				
			};

			outline = new Vertices<VertexPositionColor>(verts);

			background = new Vertices<VertexPositionColor>(new VertexPositionColor[]
				{
					new VertexPositionColor(new Vector3(0,0,0),new Color(0,0,0,200)),
					new VertexPositionColor(new Vector3(0,1,0),new Color(0,0,0,200)),
					new VertexPositionColor(new Vector3(1,0,0),new Color(0,0,0,200)),
					new VertexPositionColor(new Vector3(1,1,0),new Color(0,0,0,200)),
				});
		}
Example #2
0
        /// <summary></summary>
        /// <param name="name"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="samples"></param>
        /// <param name="fontHeight"></param>
        /// <param name="font"></param>
        /// <param name="minScale"></param>
        /// <param name="goodValue">The value that determines the transition from green to red on the graph</param>
        public Graph(string name, int width, int height, int samples, int fontHeight, float minScale, SpriteFont font, float goodValue)
            : base(new Vector2((float)width, (float)height), false)
        {
            if (width < fontHeight ||
                height < fontHeight)
            {
                throw new ArgumentException("size is too small for font size");
            }

            graph = new GraphDrawer(samples, Color.Red, new Vector2(), minScale, goodValue);
            float edge = 0.25f;

            graph.VerticalScaling   = ElementScaling.FillToParentPlusSize;
            graph.HorizontalScaling = ElementScaling.FillToParentPlusSize;
            graph.Position          = new Vector2((float)(fontHeight) * edge, (float)(fontHeight));
            graph.Size = -graph.Position;

            title = new TextElementRect(Vector2.Zero, name, font);
            title.VerticalAlignment       = VerticalAlignment.Top;
            title.HorizontalAlignment     = HorizontalAlignment.Left;
            title.HorizontalScaling       = ElementScaling.FillToParentPlusSize;
            title.VerticalScaling         = ElementScaling.FillToParentPlusSize;
            title.TextHorizontalAlignment = TextHorizontalAlignment.Centre;
            title.TextVerticalAlignment   = VerticalAlignment.Top;
            title.Size = new Vector2(0, 0);

            value = new TextElementRect(Vector2.Zero, "0", font);
            value.VerticalAlignment       = VerticalAlignment.Bottom;
            value.HorizontalAlignment     = HorizontalAlignment.Left;
            value.HorizontalScaling       = ElementScaling.FillToParentPlusSize;
            value.VerticalScaling         = ElementScaling.FillToParentPlusSize;
            value.TextHorizontalAlignment = TextHorizontalAlignment.Right;
            value.TextVerticalAlignment   = VerticalAlignment.Bottom;
            value.Size     = new Vector2(0, 0);
            value.Position = new Vector2(-10, 0);

            this.Add(title);
            this.Add(value);
            this.Add(graph);

            float x = fontHeight / ((float)width);
            float y = fontHeight / ((float)height);

            this.AlphaBlendState = AlphaBlendState.Alpha;

            VertexPositionColor[] verts = new VertexPositionColor[]
            {
                new VertexPositionColor(new Vector3(x * edge, y, 0), Color.White),
                new VertexPositionColor(new Vector3(1 - x * edge, y, 0), Color.White),
                new VertexPositionColor(new Vector3(x * edge, y, 0), Color.White),
                new VertexPositionColor(new Vector3(x * edge, 1 - y, 0), Color.White),

                new VertexPositionColor(new Vector3(edge * x, y + 0.25f * (1 - y * 2), 0), new Color(255, 255, 255, 16)),
                new VertexPositionColor(new Vector3(1 - x * edge, y + 0.25f * (1 - y * 2), 0), new Color(255, 255, 255, 16)),

                new VertexPositionColor(new Vector3(edge * x, y + 0.5f * (1 - y * 2), 0), new Color(255, 255, 255, 16)),
                new VertexPositionColor(new Vector3(1 - x * edge, y + 0.5f * (1 - y * 2), 0), new Color(255, 255, 255, 16)),

                new VertexPositionColor(new Vector3(edge * x, y + 0.75f * (1 - y * 2), 0), new Color(255, 255, 255, 16)),
                new VertexPositionColor(new Vector3(1 - x * edge, y + 0.75f * (1 - y * 2), 0), new Color(255, 255, 255, 16)),

                new VertexPositionColor(new Vector3(edge * x, y, 0), new Color(255, 255, 255, 16)),
                new VertexPositionColor(new Vector3(1 - x * edge, y, 0), new Color(255, 255, 255, 16)),
            };

            outline = new Vertices <VertexPositionColor>(verts);

            background = new Vertices <VertexPositionColor>(new VertexPositionColor[]
            {
                new VertexPositionColor(new Vector3(0, 0, 0), new Color(0, 0, 0, 200)),
                new VertexPositionColor(new Vector3(0, 1, 0), new Color(0, 0, 0, 200)),
                new VertexPositionColor(new Vector3(1, 0, 0), new Color(0, 0, 0, 200)),
                new VertexPositionColor(new Vector3(1, 1, 0), new Color(0, 0, 0, 200)),
            });
        }