Esempio n. 1
0
        /// <summary>
        /// Set the text labels for the mil air zones, in a text block.
        /// </summary>
        /// <param name="mg">
        /// The MilGraphic associated with the labels.
        /// </param>
        /// <param name="labels">
        /// The label strings.
        /// </param>
        /// <returns>
        /// A TextBlock containing the label strings.
        /// </returns>
        private static TextBlock GenerateLabels(MilGraphic mg, string[] labels)
        {
            var tb = new TextBlock
            {
                Style      = SymbolData.GetStyle("BT20"),
                Foreground = mg.ContentControl.Brush,
            };

            tb.SetBinding(UIElement.VisibilityProperty,
                          new Binding {
                Source = mg.TextVisibility, Mode = BindingMode.OneWay
            });

            var count = labels.Length;

            for (int i = 0; i < count; i++)
            {
                tb.Inlines.Add(new Run {
                    Text = labels[i]
                });
                if (i < count - 1)
                {
                    tb.Inlines.Add(new LineBreak());
                }
            }

            tb.FindTextExtent();
            tb.SetValue(Canvas.TopProperty, mg.LabelOffset.Y * HalfSize);
            tb.SetValue(Canvas.LeftProperty, (mg.LabelOffset.X * HalfSize) - (tb.Width / 2.0));

            return(tb);
        }
Esempio n. 2
0
        /// <summary>
        /// Set the text labels for the mil lines, in a text block
        /// </summary>
        /// <param name="mg">
        /// The MilGraphic associated with the labels.
        /// </param>
        /// <param name="labels">
        /// The label strings.
        /// </param>
        /// <param name="pointStart">
        /// The starting point of the line to label.
        /// </param>
        /// <param name="pointEnd">
        /// The ending point of the line to label.
        /// </param>
        /// <param name="origin">
        /// The origin coordinate for the object as a whole.
        /// </param>
        /// <param name="offset">
        /// The multiplicative offset for the object as a whole.
        /// </param>
        /// <returns>
        /// The TextBlock representing the labels.
        /// </returns>
        public static TextBlock GenerateLabels(
            MilGraphic mg, string[] labels, Point pointStart, Point pointEnd, Point origin, Point offset)
        {
            bool            leftSide;
            MatrixTransform mt = GenerateLabelTransform(pointStart, pointEnd, origin, out leftSide);
            var             tb = new TextBlock
            {
                Style           = SymbolData.GetStyle("BT20"),
                RenderTransform = mt,
                Foreground      = mg.ContentControl.Brush,
                Name            = "Skip" + counter++
            };

            tb.SetBinding(UIElement.VisibilityProperty,
                          new Binding {
                Source = mg.TextVisibility, Mode = BindingMode.OneWay
            });

            var count = labels.Length;

            for (int i = 0; i < count; i++)
            {
                tb.Inlines.Add(new Run {
                    Text = labels[i]
                });
                if (i < count - 1)
                {
                    tb.Inlines.Add(new LineBreak());
                }
            }

            tb.FindTextExtent();
            double left;

            // if (offset.Y == 0.5)
            if (Math.Abs(offset.Y - 0.5) <= double.Epsilon)
            {
                left = leftSide ? tb.Width : 0.0;
            }
            else
            {
                left = leftSide ? 0.0 : tb.Width;
            }

            //// if (left != 0)
            ////if (Math.Abs(left) > double.Epsilon)
            ////{
            ////    tb.TextAlignment = TextAlignment.Right;
            ////}

            ////Point p = mt.Matrix.Rotate(new Point(tb.Height / 2.0, left));
            Point p = mt.Matrix.Rotate(new Point(offset.Y * tb.Height, offset.X * left));

            tb.SetValue(Canvas.TopProperty, pointStart.Y - p.X);
            tb.SetValue(Canvas.LeftProperty, pointStart.X - p.Y);
            return(tb);
        }
Esempio n. 3
0
        /// <summary>
        /// Generate the text block representing the possible echelon value
        /// </summary>
        /// <param name="ms">the symbol to which the generated rendering is attached.</param>
        /// <param name="symbolCode">the symbol code so we know which echelon to use</param>
        /// <returns>the height of the echelon text string above the symbol</returns>
        internal static double Generate(MilSymbol ms, string symbolCode)
        {
            // This is the maximum height generated by this combination of pieces
            Rect r = ms.BaseRect;

            if (r.IsEmpty)
            {
                return(0);
            }

            double top = r.Top;

            // Echelon ignored if modifier index represents Installation or Mobility
            char mi = ModifierCode.GetCode(symbolCode);

            if (mi == ModifierCode.Installation || mi == ModifierCode.Mobility || mi == ModifierCode.Towed)
            {
                return(top);
            }

            char echelon = GetCode(symbolCode);

            if (!Echelons.ContainsKey(echelon))
            {
                return(top);
            }

            var tb = new TextBlock {
                Style = SymbolData.GetStyle("EchelonLabels")
            };

            var height = (double)tb.GetValue(TextBlock.FontSizeProperty);

            tb.Text = Echelons[echelon];
            if (string.IsNullOrEmpty(tb.Text))
            {
                return(top);
            }

            // Make the text a little closer (0.90) to the symbol than it would otherwise be.
            top -= 0.90 * height;

            tb.FindTextExtent();
            tb.SetValue(Canvas.TopProperty, top); // this positions the top line just above the symbol, I think
            tb.SetValue(Canvas.LeftProperty, -tb.Width / 2);

            // Add the echelon to the symbol
            ms.AddChild("Echelon", tb);

            return(top); // return the new height so that other decorations can be properly placed
        }
        /// <summary>
        /// Generate a full or partial "X" shape to represent damaged or destroyed entities
        /// </summary>
        /// <param name="symbolCode">symbol code for the entity</param>
        /// <returns>shape representing the damage</returns>
        internal static Shape Generate(string symbolCode)
        {
            if (!SymbolData.Check(ref symbolCode))
            {
                return(null);
            }

            if (GetCode(symbolCode) == PresentDamaged)
            {
                return(new Path
                {
                    Style = SymbolData.GetStyle("TS50"),
                    Data = new PathGeometry
                    {
                        Figures = new PathFigureCollection
                        {
                            Segment(-120, 174, 120, -174)
                        }
                    }
                });
            }

            if (GetCode(symbolCode) == PresentDestroyed)
            {
                return(new Path
                {
                    Style = SymbolData.GetStyle("TS50"),
                    Data = new PathGeometry
                    {
                        Figures = new PathFigureCollection
                        {
                            Segment(-120, 174, 120, -174),
                            Segment(-120, -174, 120, 174)
                        }
                    }
                });
            }

            return(null);
        }