Exemple #1
0
        public static void InitCanvasHandlers()
        {
            var window = Application.Current.MainWindow as Designer;

            window.txtRatio.Text = "1m : " + Settings.Default.PixelMeterRatio + "px";
            window.MapCanvas.PreviewMouseLeftButtonDown += (sender, args) =>
            {
                SelectionFilter.ChangeFilters(null);
                ImageHandler.SelectedImage = null;
                ShapeHandler.SelectedImage = null;
            };

            window.MapCanvas.PreviewMouseMove += (sender, args) =>
            {
                var point = args.GetPosition(window.MapCanvas);
                window.txtCursor.Text       = string.Format("x: {0}px, y: {1}px", (int)point.X, (int)point.Y);
                window.txtCursorMeters.Text = string.Format("x: {0}m, y: {1}m", (point.X / Settings.Default.PixelMeterRatio).ToString("N"), (point.Y / Settings.Default.PixelMeterRatio).ToString("N"));
            };

            window.MapCanvas.MouseWheel += (sender, args) =>
            {
                if (Keyboard.IsKeyDown(Key.LeftAlt) && BaseHandler.ObjectSelected == false)
                {
                    if (args.Delta > 0)
                    {
                        window.TxtMapZoom.Text = (Convert.ToSingle(window.TxtMapZoom.Text) * 1.15).ToString();
                    }
                    else
                    {
                        window.TxtMapZoom.Text = (Convert.ToSingle(window.TxtMapZoom.Text) / 1.15).ToString();
                    }

                    window.PanningCanvas.InvalidateMeasure();
                }
            };
        }
Exemple #2
0
        public Designer()
        {
            InitializeComponent();

            CanvasHandler.InitCanvasHandlers();

            Closing += (sender, args) => { Settings.Default.Save(); };

            PreviewKeyDown += (sender, e) =>
            {
                if (BaseHandler.ObjectSelected)
                {
                    //-- #######################################
                    //-- Copy
                    //-- #######################################
                    if (e.Key == Key.C && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                    {
                        if (ImageHandler.SelectedImage != null)
                        {
                            var img         = ImageHandler.SelectedImage;
                            var savedObject = XamlWriter.Save(img);

                            // Load the XamlObject
                            var stringReader = new StringReader(savedObject);
                            var xmlReader    = XmlReader.Create(stringReader);
                            CopyTarget = (Canvas)XamlReader.Load(xmlReader);
                        }
                        if (ShapeHandler.SelectedImage != null)
                        {
                            var img         = ShapeHandler.SelectedImage;
                            var savedObject = XamlWriter.Save(img);

                            // Load the XamlObject
                            var stringReader = new StringReader(savedObject);
                            var xmlReader    = XmlReader.Create(stringReader);
                            CopyTarget = (Viewbox)XamlReader.Load(xmlReader);
                        }
                    }

                    //-- #######################################
                    //-- Paste
                    //-- #######################################
                    if (e.Key == Key.V && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                    {
                        var canvas = CopyTarget as Canvas;
                        if (canvas != null)
                        {
                            ImageHandler.AddImageToCanvas(ref canvas);

                            var position = Mouse.GetPosition(MapCanvas);
                            Canvas.SetTop(CopyTarget, position.Y);
                            Canvas.SetLeft(CopyTarget, position.X);
                            ImageHandler.SelectedImage = canvas;
                            SelectionFilter.ChangeFilters(CopyTarget);

                            var savedObject = XamlWriter.Save(CopyTarget);

                            // Load the XamlObject
                            var stringReader = new StringReader(savedObject);
                            var xmlReader    = XmlReader.Create(stringReader);
                            CopyTarget = (Canvas)XamlReader.Load(xmlReader);
                        }
                        var grid = CopyTarget as Viewbox;
                        if (grid != null)
                        {
                            ShapeHandler.AddImageToCanvas(ref grid);

                            var position = Mouse.GetPosition(MapCanvas);
                            Canvas.SetTop(CopyTarget, position.Y);
                            Canvas.SetLeft(CopyTarget, position.X);
                            ShapeHandler.SelectedImage = grid;
                            SelectionFilter.ChangeFilters(CopyTarget);

                            var savedObject = XamlWriter.Save(CopyTarget);

                            // Load the XamlObject
                            var stringReader = new StringReader(savedObject);
                            var xmlReader    = XmlReader.Create(stringReader);
                            CopyTarget = (Viewbox)XamlReader.Load(xmlReader);
                        }
                    }
                    //-- #######################################
                    //-- Delete
                    //-- #######################################
                    if (e.Key == Key.Delete)
                    {
                        if (ImageHandler.SelectedImage != null)
                        {
                            MapCanvas.Children.Remove(ImageHandler.SelectedImage);
                        }

                        if (ShapeHandler.SelectedImage != null)
                        {
                            MapCanvas.Children.Remove(ShapeHandler.SelectedImage);
                        }
                    }
                }
            };
        }
Exemple #3
0
        public static void InitImageHandlers(ref Canvas layer)
        {
            var window    = Application.Current.MainWindow as Designer;
            var uiElement = layer as UIElement;

            layer.MouseDown += (sender, args) =>
            {
                firstPoint = args.GetPosition(window);
                var img = sender as Canvas;
                img.CaptureMouse();
                SelectedImage = img;
                SelectionFilter.ChangeFilters(sender);
            };

            layer.PreviewMouseMove += (sender, args) =>
            {
                var img = SelectedImage as UIElement;
                if (args.LeftButton == MouseButtonState.Pressed && img != null)
                {
                    //-- Create Temp Point
                    var temp = args.GetPosition(window);
                    var res  = new Point(firstPoint.X - temp.X, firstPoint.Y - temp.Y);

                    //-Update image location
                    Canvas.SetLeft(img, Canvas.GetLeft(img) - res.X);
                    Canvas.SetTop(img, Canvas.GetTop(img) - res.Y);
                    window.SelectedLayerX.Text = (Canvas.GetLeft(img) / 50.0).ToString("N") + "m, ";
                    window.SelectedLayerY.Text = (Canvas.GetTop(img) / 50.0).ToString("N") + "m";
                    Console.WriteLine(Canvas.GetLeft(img) - res.X);

                    //-- update first point
                    firstPoint = temp;
                }
            };

            layer.PreviewMouseUp += (sender, args) =>
            {
                var img = sender as Canvas;
                img.ReleaseMouseCapture();
            };

            layer.PreviewMouseWheel += (sender, args) =>
            {
                var img   = sender as Canvas;
                var mat   = img.RenderTransform.Value;
                var mouse = args.GetPosition(img);

                if (Keyboard.IsKeyDown(Key.LeftCtrl))
                {
                    if (args.Delta > 0)
                    {
                        mat.RotateAtPrepend(2, mouse.X, mouse.Y);
                    }
                    else
                    {
                        mat.RotateAtPrepend(-2, mouse.X, mouse.Y);
                    }
                }

                img.RenderTransform = new MatrixTransform(mat);
            };

            layer.SizeChanged += (sender, args) =>
            {
                if (SelectedImage != null)
                {
                    window.SelectedLayerWidth.Text  = (SelectedImage.ActualHeight / 50.0).ToString("N") + "m, ";
                    window.SelectedLayerHeight.Text = (SelectedImage.ActualWidth / 50.0).ToString("N") + "m";
                }
            };

            //combo box
            window.SelectedImageStretch.SelectionChanged += (sender, args) =>
            {
                if (SelectedImage != null)
                {
                    switch (window.SelectedImageStretch.SelectedIndex)
                    {
                    case 0:
                        (SelectedImage.Background as ImageBrush).Stretch = Stretch.Uniform;
                        break;

                    case 1:
                        (SelectedImage.Background as ImageBrush).Stretch = Stretch.UniformToFill;
                        break;

                    case 2:
                        (SelectedImage.Background as ImageBrush).Stretch = Stretch.Fill;
                        break;

                    case 3:
                        (SelectedImage.Background as ImageBrush).Stretch = Stretch.None;
                        break;
                    }
                }
            };
        }