summaryrefslogtreecommitdiff
path: root/ProjectedStripBoard/ProjectedStrip.cs
diff options
context:
space:
mode:
authorhurter2011-08-31 16:25:05 +0000
committerhurter2011-08-31 16:25:05 +0000
commit42dc1d36235292786322d28340a81c6cb3fd46c0 (patch)
tree6f4ef0d4ad672c54500d9457af90fc599ac9b299 /ProjectedStripBoard/ProjectedStrip.cs
parent5aa429a3e7e9f610f5b2dd8f8e2a865ecfd25ea3 (diff)
downloadamilis-42dc1d36235292786322d28340a81c6cb3fd46c0.zip
amilis-42dc1d36235292786322d28340a81c6cb3fd46c0.tar.gz
amilis-42dc1d36235292786322d28340a81c6cb3fd46c0.tar.bz2
amilis-42dc1d36235292786322d28340a81c6cb3fd46c0.tar.xz
Diffstat (limited to 'ProjectedStripBoard/ProjectedStrip.cs')
-rw-r--r--ProjectedStripBoard/ProjectedStrip.cs171
1 files changed, 171 insertions, 0 deletions
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);
+ }
+
+
+ /// <summary>
+ /// Return the requested strip with the marker index within the strip
+ /// </summary>
+ /// <param name="strips"></param>
+ /// <param name="markerId"></param>
+ /// <param name="idIndex"></param>
+ /// <returns></returns>
+ public static ProjectedStrip FindStrip(List<ProjectedStrip> 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);
+ }
+
+ /// <summary>
+ /// Update the strip position with the given tag index
+ /// </summary>
+ /// <param name="tagIndex"></param>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ 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; }
+ }
+}