private void MainWindow_KeyDown(object sender, KeyRoutedEventArgs args)
        {
            var   ttv          = rect.TransformToVisual(previewElement);
            Point screenCoords = ttv.TransformPoint(new Point(0, 0));

            var   ttvcanvas          = PreviewCanvas.TransformToVisual(grid);
            Point screenCoordscanvas = ttvcanvas.TransformPoint(new Point(0, 0));

            if (args.Key == Windows.System.VirtualKey.Add && rect.ActualWidth <= previewElement.ActualWidth && rect.ActualHeight <= previewElement.ActualHeight)
            {
                rect.Width  = rect.ActualWidth + 10;
                rect.Height = rect.ActualWidth + 10;
            }
            else if (args.Key == Windows.System.VirtualKey.Subtract && rect.Width >= 0)
            {
                rect.Width  = rect.ActualWidth - 10;
                rect.Height = rect.ActualWidth - 10;
            }
            else if (args.Key == Windows.System.VirtualKey.Left && screenCoords.X >= 0)
            {
                rect.Margin = new Thickness(rect.Margin.Left - 10, rect.Margin.Top, rect.Margin.Right + 10, rect.Margin.Bottom);
            }
            else if (args.Key == Windows.System.VirtualKey.Right && screenCoords.X <= screenCoordscanvas.X + PreviewCanvas.Width - rect.Width)
            {
                rect.Margin = new Thickness(rect.Margin.Left + 10, rect.Margin.Top, rect.Margin.Right - 10, rect.Margin.Bottom);
            }
            else if (args.Key == Windows.System.VirtualKey.Up && screenCoords.Y >= 0)
            {
                rect.Margin = new Thickness(rect.Margin.Left, rect.Margin.Top - 10, rect.Margin.Right, rect.Margin.Bottom + 10);
            }
            else if (args.Key == Windows.System.VirtualKey.Down && screenCoords.Y <= screenCoordscanvas.Y + PreviewCanvas.Height - rect.Height)
            {
                rect.Margin = new Thickness(rect.Margin.Left, rect.Margin.Top + 10, rect.Margin.Right, rect.Margin.Bottom - 10);
            }
        }
示例#2
0
        private void ChooseFile_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openJsonFile = new OpenFileDialog())
            {
                openJsonFile.InitialDirectory = "C:\\";
                openJsonFile.Filter           = "json files (*.json)|*.json";
                openJsonFile.RestoreDirectory = true;

                if (openJsonFile.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        Stream fileStream = openJsonFile.OpenFile();
                        this.ReadCurrentSelection(fileStream);
                        fileStream.Close();
                    }
                    catch
                    {
                        MessageBox.Show("json文件格式错误,请检查输入文件。");
                        return;
                    }

                    ///Write the data to the command as well.
                    originCommand.CurrentHouse = this.CurrentHouse;
                    this.CheckCondition();
                    PreviewCanvas.Refresh();
                }
            }
        }
示例#3
0
        private void PreviewCanvas_Paint(object sender, PaintEventArgs e)
        {
            ///Graphic prepare
            myPen = new Pen(Color.Black);
            g     = PreviewCanvas.CreateGraphics();
            g.Clear(Color.White);
            canvasW = PreviewCanvas.Width;
            canvasH = PreviewCanvas.Height;
            ///
            if (CurrentHouse == null)
            {
                return;
            }
            List <A_Wall> walls = CurrentHouse.Floors
                                  .SelectMany(f => f.Walls).ToList();
            List <A_Point> pts = walls.Select(w => w.P1).ToList();

            pts.AddRange(walls.Select(w => w.P2));

            ///Get the range of the house.
            float minX = pts.OrderBy(p => p.X).First().X;
            float minY = pts.OrderBy(p => p.Y).First().Y;
            float maxX = pts.OrderByDescending(p => p.X)
                         .First().X;
            float maxY = pts.OrderByDescending(p => p.Y)
                         .First().Y;

            ///Calculate the transform and scale factor.
            Point toBaseT = Point.Round(new PointF(minX, minY));
            float scaleX  = (maxX - minX) / canvasW;
            float scaleY  = (maxY - minY) / canvasH;
            float scale   = Math.Max(scaleX, scaleY);

            scale = (float)(scale / 0.9);

            foreach (A_Wall wall in walls)
            {
                float  x1 = ((wall.P1.X - minX) / scale) + (canvasW / 20);
                float  y1 = ((wall.P1.Y - minY) / scale) + (canvasH / 20);
                float  x2 = ((wall.P2.X - minX) / scale) + (canvasW / 20);
                float  y2 = ((wall.P2.Y - minY) / scale) + (canvasH / 20);
                PointF p1 = new PointF(x1, y1);
                PointF p2 = new PointF(x2, y2);
                g.DrawLine(myPen, p1, p2);
            }
        }
示例#4
0
 private void MainCanvas_CanvasScroll(object sender, EventArgs e)
 {
     EndInput();
     PreviewCanvas.Invalidate();
 }
        private void ViewportOperations(Windows.System.VirtualKey args)
        {
            var   ttv          = rect.TransformToVisual(grid);
            Point screenCoords = ttv.TransformPoint(new Point(0, 0));

            var   ttvcanvas          = PreviewCanvas.TransformToVisual(grid);
            Point screenCoordscanvas = ttvcanvas.TransformPoint(new Point(0, 0));

            if (args == Windows.System.VirtualKey.Add && rect.ActualWidth + 10 <= previewElement.ActualWidth && rect.ActualHeight <= previewElement.ActualHeight)
            {
                rect.Width  = rect.ActualWidth + 10;
                rect.Height = rect.ActualWidth + 10;
            }
            else if (args == Windows.System.VirtualKey.Subtract && rect.Width - 10 >= 0)
            {
                rect.Width  = rect.ActualWidth - 10;
                rect.Height = rect.ActualWidth - 10;
            }
            else if (args == Windows.System.VirtualKey.Left && screenCoords.X - 10 >= 0 && screenCoords.X > screenCoordscanvas.X)
            {
                rect.Margin = new Thickness(rect.Margin.Left - 10, rect.Margin.Top, rect.Margin.Right + 10, rect.Margin.Bottom);
            }
            else if (args == Windows.System.VirtualKey.Right && screenCoords.X + 10 <= screenCoordscanvas.X + PreviewCanvas.Width - rect.ActualWidth)
            {
                var pending = (screenCoordscanvas.X + PreviewCanvas.Width - rect.ActualWidth) - (screenCoords.X + 10 + rect.ActualWidth);
                if (pending < 10 && pending >= 0)
                {
                    //edge case
                    rect.Margin = new Thickness(rect.Margin.Left + pending, rect.Margin.Top, rect.Margin.Right - pending, rect.Margin.Bottom);
                }
                else
                {
                    rect.Margin = new Thickness(rect.Margin.Left + 10, rect.Margin.Top, rect.Margin.Right - 10, rect.Margin.Bottom);
                }
            }
            else if (args == Windows.System.VirtualKey.Up && screenCoords.Y - 10 >= 0 && screenCoords.Y > screenCoordscanvas.Y)
            {
                var pending = screenCoords.Y - 10;
                if (pending < 10)
                {
                    rect.Margin = new Thickness(rect.Margin.Left, rect.Margin.Top - pending, rect.Margin.Right, rect.Margin.Bottom + pending);
                }
                else
                {
                    rect.Margin = new Thickness(rect.Margin.Left, rect.Margin.Top - 10, rect.Margin.Right, rect.Margin.Bottom + 10);
                }
            }
            else if (args == Windows.System.VirtualKey.Down && screenCoords.Y + 10 <= screenCoordscanvas.Y + PreviewCanvas.Height - rect.ActualHeight)
            {
                var pending = (screenCoordscanvas.Y + PreviewCanvas.Height - rect.ActualHeight) - (screenCoords.Y + 10 + rect.ActualHeight);
                if (pending < 10 && pending >= 0)
                {
                    //edge case
                    rect.Margin = new Thickness(rect.Margin.Left, rect.Margin.Top + pending, rect.Margin.Right, rect.Margin.Bottom - pending);
                }
                else
                {
                    rect.Margin = new Thickness(rect.Margin.Left, rect.Margin.Top + 10, rect.Margin.Right, rect.Margin.Bottom - 10);
                }
            }
        }
示例#6
0
 private void CmdReadJsonForm_SizeChanged(object sender, EventArgs e)
 {
     PreviewCanvas.Refresh();
 }