Esempio n. 1
0
        private void CreateVisualRepresentation()
        {
            int width       = LocalFloorPlan.Width;
            int height      = LocalFloorPlan.Height;
            int floorAmount = LocalFloorPlan.FloorAmount;

            _floorContainer = new Grid[floorAmount];

            for (int z = 0; z < floorAmount; z++)
            {
                Grid container = new Grid()
                {
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top
                };
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        Rectangle figure = new Rectangle
                        {
                            Height = TileSize,
                            Width  = TileSize,
                            Fill   = new SolidColorBrush(Colors.White),
                            Tag    = Coordinate(x, y, z), /* Makes binding rectangles to buildingblocks easier */
                            Margin = new Thickness(0, 0, x * TileSize * 2 + x, y * TileSize * 2 + y)
                        };

                        if (LocalFloorPlan.Tiles[Coordinate(x, y, z)].Type != Tile.Types.Free)
                        {
                            ColorizeBuildingBlock(figure, LocalFloorPlan.Tiles[Coordinate(x, y, z)].Type);
                        }

                        BuildingBlock current = (LocalFloorPlan.Tiles[Coordinate(x, y, z)] as BuildingBlock);
                        current.Figure              = figure;
                        figure.ToolTip              = current.ToString();
                        figure.MouseLeftButtonDown += OnBuildingBlockClick;


                        AllRectangles.Add(Coordinate(x, y, z), figure);
                        container.Children.Add(figure);
                    }
                }
                _floorContainer[z] = container;
            }

            VisualContainer.Children.Add(_floorContainer[0]);
        }
Esempio n. 2
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0)
            {
                throw new ArgumentException("Size must be positive");
            }

            Rectangle currRect;

            CloudSpiral = new Spiral(0.5, Center).GetEnumerator();
            for (;;)
            {
                currRect = new Rectangle(GetPossiblePointForRectCenter(rectangleSize), rectangleSize);
                if (!AllRectangles.Any(rect => rect.IntersectsWith(currRect)))
                {
                    break;
                }
            }
            AllRectangles.Add(currRect);
            return(currRect);
        }