コード例 #1
0
        public async void ZoomCanvas(double zoomMultiplicator)
        {
            double oldCenterX = HexMapCenterX;
            double oldCenterY = HexMapCenterY;

            GetHexMapCanvasDimensionsRequestMessage msg = new GetHexMapCanvasDimensionsRequestMessage();
            var result = await Messenger.Default.SendAsync(msg);

            double oldHexMapCanvasWidth  = result.Result.Item1;
            double oldHexMapCanvasHeight = result.Result.Item2;
            double oldHexMapCanvasX      = oldHexMapCanvasWidth / 2;
            double oldHexMapCanvasY      = oldHexMapCanvasHeight / 2;

            double xMove = oldCenterX - oldHexMapCanvasX;
            double yMove = oldCenterY - oldHexMapCanvasY;

            CellRadius = CellRadius * zoomMultiplicator;

            foreach (var hexViewModel in ListHexViewModel)
            {
                hexViewModel.UpdateCellRadius(CellRadius);
            }

            HexMapCenterX = HexMapDrawingHelper.GetRedrawnHexMapXCenter(CellRadius, Columns);
            HexMapCenterY = HexMapDrawingHelper.GetRedrawnHexMapYCenter(CellRadius, Columns, Rows);

            CenterHexMap();

            MoveCanvas(xMove * zoomMultiplicator, yMove * zoomMultiplicator);
        }
コード例 #2
0
        public override async void ApplyModel(HexMapModel hexMapModel)
        {
            GetHexMapCanvasDimensionsRequestMessage msg = new GetHexMapCanvasDimensionsRequestMessage();
            var result = await Messenger.Default.SendAsync(msg);

            double hexMapCanvasWidth  = result.Result.Item1;
            double hexMapCanvasHeight = result.Result.Item2;

            double cellRadius = HexMapDrawingHelper.GetCellRadius(hexMapCanvasHeight, hexMapCanvasWidth, hexMapModel.Columns, hexMapModel.Rows);

            CellRadius = cellRadius;
            Columns    = hexMapModel.Columns;
            Rows       = hexMapModel.Rows;
            foreach (var hexViewModel in ListHexViewModel)
            {
                hexViewModel.UnsubscribePolygonEvents();
            }
            ListHexViewModel.Clear();
            ListUIElement.Clear();
            foreach (var hexModel in hexMapModel.ListHexModel)
            {
                var hexViewModel = new HexViewModel();
                hexViewModel.ApplyModel(hexModel);
                hexViewModel.InitializeCellRadius(CellRadius);
                ListHexViewModel.Add(hexViewModel);
                foreach (UIElement uiElement in hexViewModel.GetAllUIElements())
                {
                    ListUIElement.Add(uiElement);
                }
            }

            HexMapCenterX = HexMapDrawingHelper.GetRedrawnHexMapXCenter(CellRadius, Columns);
            HexMapCenterY = HexMapDrawingHelper.GetRedrawnHexMapYCenter(CellRadius, Columns, Rows);

            CenterHexMap();
        }