예제 #1
0
        public void Render(Canvas funky, Canvas parent, Canvas window, CompositeTransform textRotation, Action<Action> dispatcher, RoomInfo location)
        {
            dispatcher(() =>
            {
                CompositeTransform c = (CompositeTransform)funky.RenderTransform;
                c.CenterX = buildingBounds.CenterX;
                c.CenterY = buildingBounds.CenterY;
                funky.Width = buildingBounds.Width;
                funky.Height = buildingBounds.Height;
                c.TranslateX = -buildingBounds.CenterX + window.ActualWidth / 2;
                c.TranslateY = -buildingBounds.CenterY + window.ActualHeight / 2;
            });

            foreach (var description in elements.Where(p => p.Parent == ParentType.Labels || p.Parent == ParentType.Rooms))
            {
                this.checkRunActions(50, () => RenderElement(parent, textRotation, description), dispatcher);
            }

            // Highlight the correct room
            this.checkRunActions(1, () =>
            {
                var roomElement = parent.Children.OfType<Path>().FirstOrDefault(p => ToInt(p.Tag as string) == location.Room);
                if (roomElement != null)
                {
                    roomElement.Fill = new SolidColorBrush(Colors.Magenta);
                }
            }, dispatcher);

            foreach (var description in elements.Where(p => p.Parent == ParentType.Background))
            {
                // Fewer because these paths are more complex
                this.checkRunActions(5, () => RenderElement(parent, textRotation, description), dispatcher);
            }

            this.checkRunActions(0, () => { }, dispatcher);
        }
예제 #2
0
 private static void RenderElement(Canvas parent, CompositeTransform textRotation, ElementDescription element)
 {
     switch (element.Type)
     {
         case ElementType.Circle:
             Ellipse e = new Ellipse()
             {
                 Width = element.Width,
                 Height = element.Height,
                 Fill = BrushForColor(element.Fill),
                 Stroke = BrushForColor(element.Stroke),
             };
             parent.Children.Add(e);
             Canvas.SetLeft(e, element.CenterX);
             Canvas.SetTop(e, element.CenterY);
             break;
         case ElementType.Path:
             Path path = new Path()
             {
                 Data = ProcessPathData(element.Path),
                 Tag = element.Text,
                 Fill = BrushForColor(element.Fill),
                 Stroke = BrushForColor(element.Stroke),
             };
             parent.Children.Add(path);
             break;
         case ElementType.Text:
             Grid g = new Grid() { Width = 200, Height = 200 };
             parent.Children.Add(g);
             Canvas.SetLeft(g, element.CenterX - g.Width / 2);
             Canvas.SetTop(g, element.CenterY - g.Height / 2);
             TextBlock tb = new TextBlock()
             {
                 HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                 VerticalAlignment = System.Windows.VerticalAlignment.Center,
                 RenderTransform = textRotation,
                 Foreground = BrushForColor(element.Stroke),
                 FontSize = element.FontSize,
                 Text = element.Text,
             };
             g.Children.Add(tb);
             break;
         default:
             throw new InvalidOperationException("Unexpected node: " + element.Type);
     }
 }