/*------------ Replace Visualization Boxes' Labels ------------*/
        public static void ReplaceVisualizationLabel(TextGroupVisual3D textGroup, int oldVisBoxIndex, int newBoxIndex, string content,
                                                     Point3D center, float[] dims, Color color)
        {
            TextVisual3D labelLeft  = new TextVisual3D();
            TextVisual3D labelRight = new TextVisual3D();

            labelLeft.Text  = content;
            labelRight.Text = content;

            labelLeft.Position  = new Point3D(center.X + (dims[0] / 2 + 0.01), center.Y, center.Z);
            labelRight.Position = new Point3D(center.X - (dims[0] / 2 + 0.01), center.Y, center.Z);

            labelLeft.Height  = Math.Min(dims[1], dims[2]);
            labelRight.Height = Math.Min(dims[1], dims[2]);

            labelLeft.UpDirection  = new Vector3D(0, 0, 1);
            labelRight.UpDirection = new Vector3D(0, 0, 1);

            labelLeft.TextDirection  = new Vector3D(0, 1, 0);
            labelRight.TextDirection = new Vector3D(0, 1, 0);

            labelLeft.Padding  = new Thickness(2);
            labelRight.Padding = new Thickness(2);

            labelLeft.Background  = Brushes.Transparent;
            labelRight.Background = Brushes.Transparent;

            int mid = (color.R + color.G + color.B) / 3;

            if (mid < 120)
            {
                labelLeft.Foreground  = Brushes.White;
                labelRight.Foreground = Brushes.White;
            }
            else
            {
                labelLeft.Foreground  = Brushes.Black;
                labelRight.Foreground = Brushes.Black;
            }

            textGroup.Children.RemoveAt((2 * oldVisBoxIndex) - 1);
            textGroup.Children.RemoveAt((2 * oldVisBoxIndex) - 2);

            textGroup.Children.Insert((2 * newBoxIndex) - 2, labelLeft);
            textGroup.Children.Insert((2 * newBoxIndex) - 1, labelRight);
        }
        /*------------ Change Foreground Color Of The Visualization Labels ------------*/
        public static void ChangeVisualizationLabelColor(TextGroupVisual3D textGroup,
                                                         int index, byte[] color)
        {
            TextVisual3D labelLeft  = textGroup.Children[(2 * index) - 2] as TextVisual3D;
            TextVisual3D labelRight = textGroup.Children[(2 * index) - 1] as TextVisual3D;


            int mid = (color[0] + color[1] + color[2]) / 3;

            if (mid < 120)
            {
                labelLeft.Foreground  = Brushes.White;
                labelRight.Foreground = Brushes.White;
            }
            else
            {
                labelLeft.Foreground  = Brushes.Black;
                labelRight.Foreground = Brushes.Black;
            }
        }
Пример #3
0
        public void CreateTextMaterial_Correct_ElementPositions()
        {
            List <TextItem> items = new List <TextItem> {
                new BillboardTextItem {
                    Text = "Test"
                }
            };
            Dictionary <string, FrameworkElement> elementMap;
            Dictionary <FrameworkElement, Rect>   elementPositions;

            var material = TextGroupVisual3D.CreateTextMaterial(
                items, CreateElement, Brushes.White, out elementMap, out elementPositions);

            Assert.NotNull(material);

            // The element positions are rounded and the values should be between 0 and 1 (inclusive)
            Assert.True(elementPositions.All(kv => kv.Value.Top >= 0 && kv.Value.Top <= 1));
            Assert.True(elementPositions.All(kv => kv.Value.Bottom >= 0 && kv.Value.Bottom <= 1));
            Assert.True(elementPositions.All(kv => kv.Value.Left >= 0 && kv.Value.Left <= 1));
            Assert.True(elementPositions.All(kv => kv.Value.Right >= 0 && kv.Value.Right <= 1));
        }