Exemplo n.º 1
0
        private void PaintMap(List <PaintObject> PaintObjectList)
        {
            pnlMap.Width  = scena.map.GetMap().GetLength(0) * Zoom;
            pnlMap.Height = scena.map.GetMap().GetLength(1) * Zoom;
            pnlMap.Children.Clear();

            pnlMap.Background = Brushes.Transparent;
            for (int n = 0; n < PaintObjectList.Count; n++)
            {
                PaintObject obj = PaintObjectList[n];
                if (obj.GetName() == "path")
                {
                    string         data  = obj.GetAttributeValue("data");
                    SVSObjectStyle style = obj.GetStyle();

                    Path path = new Path();
                    path.Data            = Geometry.Parse(data);
                    path.Fill            = new System.Windows.Media.SolidColorBrush(Color.FromArgb(style.FillColor.A, style.FillColor.R, style.FillColor.G, style.FillColor.B));
                    path.Stroke          = new System.Windows.Media.SolidColorBrush(Color.FromArgb(style.BorderColor.A, style.BorderColor.R, style.BorderColor.G, style.BorderColor.B));
                    path.StrokeThickness = (double)style.BorderSize;
                    System.Drawing.Drawing2D.Matrix m = obj.GetTransformMatrix();
                    Matrix matrix = new Matrix((double)m.Elements[0], (double)m.Elements[1], (double)m.Elements[2], (double)m.Elements[3], (double)m.OffsetX, (double)m.OffsetY);
                    matrix.Scale(Zoom, Zoom);
                    path.RenderTransform = new MatrixTransform(matrix);
                    pnlMap.Children.Add(path);
                }
                if (obj.GetName() == "rect")
                {
                    double         x     = PaintObject.StringToDoubleConvertor(obj.GetAttributeValue("x"));
                    double         y     = PaintObject.StringToDoubleConvertor(obj.GetAttributeValue("y"));
                    double         w     = PaintObject.StringToDoubleConvertor(obj.GetAttributeValue("width"));
                    double         h     = PaintObject.StringToDoubleConvertor(obj.GetAttributeValue("height"));
                    SVSObjectStyle style = obj.GetStyle();

                    Rectangle rect = new Rectangle();
                    rect.SetValue(Canvas.LeftProperty, x * Zoom);
                    rect.SetValue(Canvas.TopProperty, y * Zoom);
                    rect.Width           = w;
                    rect.Height          = h;
                    rect.Fill            = new System.Windows.Media.SolidColorBrush(Color.FromArgb(style.FillColor.A, style.FillColor.R, style.FillColor.G, style.FillColor.B));
                    rect.Stroke          = new System.Windows.Media.SolidColorBrush(Color.FromArgb(style.BorderColor.A, style.BorderColor.R, style.BorderColor.G, style.BorderColor.B));
                    rect.StrokeThickness = (double)style.BorderSize;
                    System.Drawing.Drawing2D.Matrix m = obj.GetTransformMatrix();
                    Matrix matrix = new Matrix((double)m.Elements[0], (double)m.Elements[1], (double)m.Elements[2], (double)m.Elements[3], (double)m.OffsetX, (double)m.OffsetY);
                    matrix.Scale(Zoom, Zoom);
                    rect.RenderTransform = new MatrixTransform(matrix);
                    pnlMap.Children.Add(rect);
                }
            }
        }
Exemplo n.º 2
0
        private void PaintMap()
        {
            tbMapSize.Text = string.Format("{0}x{1}", scenario.Map.GetMap().GetLength(0), scenario.map.GetMap().GetLength(1));
            pnlMap.Width   = scenario.map.GetMap().GetLength(0);
            pnlMap.Height  = scenario.map.GetMap().GetLength(1);
            if (_showMapMask)
            {
                //ImageBrush brush = new ImageBrush(scenario.Image);
                ImageBrush brush = new ImageBrush(scenario.Map.GetLayerMask(0));
                pnlMap.Background = brush;
            }
            if (_showBackgroundImage)
            {
                try
                {
                    ImageBrush brush = new ImageBrush(new BitmapImage(new Uri(Properties.Settings.Default.ScenarioPath + "image.jpg")));
                    pnlMap.Background = brush;
                }
                catch
                {
                    pnlMap.Background = Brushes.LightPink;
                }
            }
            if ((_showBackgroundImage | _showMapMask) == false)
            {
                pnlMap.Background = Brushes.White;
            }

            for (int i = 0; i < pnlMap.Children.Count; i++)
            {
                if (!(pnlMap.Children[i] is Shape))
                {
                    pnlMap.Children.RemoveAt(i);
                    i--;
                }
            }
            if (_showWalls)
            {
                for (int n = 0; n < scenario.ServicesList.Count; n++)
                {
                    if (scenario.ServicesList[n] is TurnstileService)
                    {
                        var fig = (scenario.ServicesList[n] as TurnstileService).TurnstileGeometry;
                        System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
                        path.Data            = new PathGeometry(new PathFigure[] { fig });
                        path.Stroke          = Brushes.LightGray;
                        path.StrokeThickness = 2.0;
                        pnlMap.Children.Add(path);
                    }
                    if (scenario.ServicesList[n] is QueueService)
                    {
                        foreach (var point in (scenario.ServicesList[n] as QueueService).InputPoints)
                        {
                            System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
                            rect.SetValue(Canvas.LeftProperty, (double)point.X - 1);
                            rect.SetValue(Canvas.TopProperty, (double)point.Y - 1);
                            rect.Width  = point.PointWidth * 2;
                            rect.Height = point.PointHeight * 2;
                            //rect.Stroke = Brushes.Pink;
                            rect.Fill = Brushes.LimeGreen;
                            //rect.StrokeThickness = 2.0D;
                            pnlMap.Children.Add(rect);
                        }
                    }
                }
                for (int n = 0; n < scenario.paintObjectList.Count; n++)
                {
                    PaintObject obj = scenario.paintObjectList[n];
                    if (obj.GetName() == "path")
                    {
                        string data = obj.GetAttributeValue("data");
                        System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
                        path.Data = Geometry.Parse(data);
                        SVSObjectStyle style = obj.GetStyle();
                        path.Fill   = new System.Windows.Media.SolidColorBrush(Color.FromArgb(style.FillColor.A, style.FillColor.R, style.FillColor.G, style.FillColor.B));
                        path.Stroke = new System.Windows.Media.SolidColorBrush(Color.FromArgb(style.BorderColor.A, style.BorderColor.R, style.BorderColor.G, style.BorderColor.B));
                        //path.Stroke = new System.Windows.Media.SolidColorBrush(Colors.Black);
                        path.StrokeThickness = (double)style.BorderSize;
                        System.Drawing.Drawing2D.Matrix m = obj.GetTransformMatrix();
                        Matrix matrix = new Matrix((double)m.Elements[0], (double)m.Elements[1], (double)m.Elements[2], (double)m.Elements[3], (double)m.OffsetX, (double)m.OffsetY);
                        path.RenderTransform = new MatrixTransform(matrix);
                        pnlMap.Children.Add(path);
                    }
                    if (obj.GetName() == "rect")
                    {
                        double         x     = PaintObject.StringToDoubleConvertor(obj.GetAttributeValue("x"));
                        double         y     = PaintObject.StringToDoubleConvertor(obj.GetAttributeValue("y"));
                        double         w     = PaintObject.StringToDoubleConvertor(obj.GetAttributeValue("width"));
                        double         h     = PaintObject.StringToDoubleConvertor(obj.GetAttributeValue("height"));
                        SVSObjectStyle style = obj.GetStyle();

                        Rectangle rect = new Rectangle();
                        rect.SetValue(Canvas.LeftProperty, x);
                        rect.SetValue(Canvas.TopProperty, y);
                        rect.Width           = w;
                        rect.Height          = h;
                        rect.Fill            = new System.Windows.Media.SolidColorBrush(Color.FromArgb(style.FillColor.A, style.FillColor.R, style.FillColor.G, style.FillColor.B));
                        rect.Stroke          = new System.Windows.Media.SolidColorBrush(Color.FromArgb(style.BorderColor.A, style.BorderColor.R, style.BorderColor.G, style.BorderColor.B));
                        rect.StrokeThickness = (double)style.BorderSize;
                        System.Drawing.Drawing2D.Matrix m = obj.GetTransformMatrix();
                        Matrix matrix = new Matrix((double)m.Elements[0], (double)m.Elements[1], (double)m.Elements[2], (double)m.Elements[3], (double)m.OffsetX, (double)m.OffsetY);
                        rect.RenderTransform = new MatrixTransform(matrix);
                        pnlMap.Children.Add(rect);
                    }
                }
            }
        }