From 42dc1d36235292786322d28340a81c6cb3fd46c0 Mon Sep 17 00:00:00 2001 From: hurter Date: Wed, 31 Aug 2011 16:25:05 +0000 Subject: --- ProjectedStripBoard/ProjectedStrip.cs | 171 ++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 ProjectedStripBoard/ProjectedStrip.cs (limited to 'ProjectedStripBoard/ProjectedStrip.cs') diff --git a/ProjectedStripBoard/ProjectedStrip.cs b/ProjectedStripBoard/ProjectedStrip.cs new file mode 100644 index 0000000..b6032e6 --- /dev/null +++ b/ProjectedStripBoard/ProjectedStrip.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenTK; +using OpenTK.Graphics.OpenGL; +using System.Drawing; +using AnotoData; + +namespace ProjectedStripBoard +{ + public class ProjectedStrip + { + public enum DrawingMod { Normal, Markers }; + + #region Static members + + static public float DX = 0.050f; + static public float DY = 0.03f; + static public float MarkerWidth = 0.062f; + static public float MarkerHeight = 0.075f; + + static public Vector2 TopLeft = new Vector2(0.08f, 0.13f); + static public Vector2 BottomRight = new Vector2(0.93f, 0.89f); + + static public Font TheFont = new Font("Arial", 20.0f, FontStyle.Bold); + + static public Color DefaultColor = Color.FromArgb(100,100,100,100); + static public Brush DefaultTextColor = Brushes.Black; + static public Brush SelectedStripBrushColor = new SolidBrush(Color.FromArgb(150,0,50,100)); + + #endregion + + public Color StripColor = ProjectedStrip.DefaultColor; + public Brush TextColor = ProjectedStrip.DefaultTextColor; + + public Vector2 Postition; + public string Name; + public Color Color = Color.Blue; + + public AnotoStrip TheAnotoStrip; + public bool[] VisibleTags; + + public ProjectedStrip(AnotoStrip item) + { + TheAnotoStrip = item; + VisibleTags = new bool[TheAnotoStrip.TagIds.Length]; + } + + public void ClearVisibleTags() + { + VisibleTags = new bool[TheAnotoStrip.TagIds.Length]; + } + + static public Vector2 GetCorrectedPostion(Vector2 pos) + { + float corretedX = GenericScaleF(pos.X, 0, TopLeft.X, 1, BottomRight.X); + float corretedY = GenericScaleF(pos.Y, 0, TopLeft.Y, 1, BottomRight.Y); + + return new Vector2(corretedX, corretedY); + } + + public void Draw(DrawingMod drawingMod, Color BackColor, Graphics g, float screenWidth, float screenHeight, Font font) + { + //First, we need to scale the view + Vector2 correctedPos = GetCorrectedPostion(Postition); + + + RectangleF OuterBound = new RectangleF((correctedPos.X - DX) * screenWidth, (correctedPos.Y - DY) * screenHeight, (MarkerWidth*5) * screenWidth, (MarkerHeight) * screenHeight); + + string text = TheAnotoStrip.CallSign; + SizeF size = g.MeasureString(text, TheFont); + + if (drawingMod == DrawingMod.Markers) + { + for (int i = 0; i < VisibleTags.Length; i++) + { + if (VisibleTags[i]) + { + OuterBound = new RectangleF((correctedPos.X + i * MarkerWidth - DX) * screenWidth, (correctedPos.Y - DY) * screenHeight, (MarkerWidth) * screenWidth, (MarkerHeight) * screenHeight); + + g.DrawRectangle(new Pen(Color, 1.0f), OuterBound.X, OuterBound.Y, OuterBound.Width, OuterBound.Height); + // g.DrawString(Name, font, Brushes.Black, Postition.X * screenWidth, Postition.Y * screenHeight); + g.DrawString(TheAnotoStrip.TagIds[i].ToString(), TheFont, TextColor, new PointF(OuterBound.X, OuterBound.Y + TheFont.Height)); + } + } + } + + if (drawingMod == DrawingMod.Normal) + { + //Draw only if one tag is visible + if (VisibleTags.Contains(true)) + { + if ( IsSelected) + g.FillRectangle(Brushes.DarkBlue, OuterBound); + else + g.FillRectangle(new SolidBrush(StripColor), OuterBound); + // g.DrawString(Name, font, Brushes.Black, Postition.X * screenWidth, Postition.Y * screenHeight); + // g.DrawString(text, TheFont, TextColor, new PointF(OuterBound.X + (OuterBound.Width - size.Width) / 2, OuterBound.Y + (OuterBound.Height - size.Height) / 2)); + g.DrawString(text, TheFont, TextColor, new PointF(OuterBound.X + 10, OuterBound.Y + 10)); + } + + if ( !(VisibleTags.Contains(true)) && IsSelected ) + { + //This is strip that is not in the strip board, then display it as a virtual one + this.Postition = new Vector2(0.3f,1.05f); + g.FillRectangle(SelectedStripBrushColor, OuterBound); + g.DrawString(text, TheFont, TextColor, new PointF(OuterBound.X + (OuterBound.Width - size.Width) / 2, OuterBound.Y + (OuterBound.Height - size.Height) / 2)); + + } + } + } + + static public float GenericScaleF(float input, float i1, float o1, float i2, float o2) + { + if (i2 == i1) return ((o2 + o1) / 2.0f); + float a = (o2 - o1) / (i2 - i1); + float b = o1 - a * i1; + return (a * input + b); + } + + + /// + /// Return the requested strip with the marker index within the strip + /// + /// + /// + /// + /// + public static ProjectedStrip FindStrip(List strips, int markerId, out int idIndex) + { + idIndex = -1; + foreach (var strip in strips) + { + if (strip.HasThisMarker(markerId)) + { + idIndex = Array.IndexOf(strip.TheAnotoStrip.TagIds, markerId); + return strip; + } + } + return null; + + } + + private bool HasThisMarker(int markerId) + { + return TheAnotoStrip.TagIds.Contains(markerId); + } + + /// + /// Update the strip position with the given tag index + /// + /// + /// + /// + internal void UpdatePosition(int tagIndex, float x, float y) + { + //if (tagIndex == 0) + //{ + this.Postition.X = x - tagIndex * MarkerWidth; + this.Postition.Y = y; + VisibleTags[tagIndex] = true; + //} + //else + // VisibleTags[tagIndex] = false; + + } + + public bool IsSelected { get; set; } + } +} -- cgit v1.1