Пример #1
0
 internal static void WheelZoom(this Canvas canvas, WindowData data, double delta)
 {
     data.Zoom += delta;
     canvas.Scale(data.Zoom);
     data.RectangleHasFocus = false;
     Keyboard.Focus(canvas);
 }
Пример #2
0
 internal static void WheelZoom(this Canvas canvas, WindowData data, double delta)
 {
     data.Zoom += delta;
     canvas.Scale(data.Zoom);
     data.RectangleHasFocus = false;
     Keyboard.Focus(canvas);
 }
Пример #3
0
        internal static async Task LoadImage(this Canvas canvas, WindowData data, int imageIndex)
        {
            var image = await Task.Run(delegate
            {
                var im = new BitmapImage(new Uri(data.FileList[imageIndex].FileName));
                im.Freeze();
                return(im);
            });

            data.ScaleX = image.Width / image.PixelWidth;
            data.ScaleY = image.Height / image.PixelHeight;

            //if (image.PixelWidth != FileAccess.imageWidth || image.PixelHeight != FileAccess.imageHeight) throw new Exception();

            var bg = new ImageBrush
            {
                ImageSource = image
            };

            data.WindowTitle = Path.GetFileName(data.FileList[imageIndex].FileName) + " (" + bg.ImageSource.Width + "x" + bg.ImageSource.Height + ")";

            canvas.Background = bg;
            canvas.Width      = bg.ImageSource.Width;
            canvas.Height     = bg.ImageSource.Height;

            canvas.Scale(data.Zoom);

            Keyboard.Focus(canvas);
        }
Пример #4
0
 internal static async Task ChangeRectangle(this Canvas canvas, WindowData data, int offset)
 {
     data.RectangleIndex += offset;
     if (data.RectangleIndex < 0)
     {
         data.FileIndex--;
         if (data.FileIndex < 0)
         {
             data.FileIndex      = 0;
             data.RectangleIndex = 0;
         }
         else
         {
             data.RectangleIndex = data.FileList[data.FileIndex].Rectangles.Count - 1;
         }
         await canvas.LoadImage(data, data.FileIndex);
     }
     else if (data.RectangleIndex >= data.FileList[data.FileIndex].Rectangles.Count)
     {
         data.FileIndex++;
         if (data.FileIndex >= data.FileList.Count)
         {
             data.FileIndex      = data.FileList.Count - 1;
             data.RectangleIndex = data.FileList[data.FileIndex].Rectangles.Count - 1;
         }
         else
         {
             data.RectangleIndex = 0;
         }
         await canvas.LoadImage(data, data.FileIndex);
     }
 }
Пример #5
0
        internal static async Task LoadImage(this Canvas canvas, WindowData data, int imageIndex)
        {
            var image = await Task.Run(delegate
            {
                var im = new BitmapImage(new Uri(data.FileList[imageIndex].FileName));
                im.Freeze();
                return im;
            });

            data.ScaleX = image.Width / image.PixelWidth;
            data.ScaleY = image.Height / image.PixelHeight;

            //if (image.PixelWidth != FileAccess.imageWidth || image.PixelHeight != FileAccess.imageHeight) throw new Exception();

            var bg = new ImageBrush
            {
                ImageSource = image
            };

            data.WindowTitle = Path.GetFileName(data.FileList[imageIndex].FileName) + " (" + bg.ImageSource.Width + "x" + bg.ImageSource.Height + ")";

            canvas.Background = bg;
            canvas.Width = bg.ImageSource.Width;
            canvas.Height = bg.ImageSource.Height;

            canvas.Scale(data.Zoom);

            Keyboard.Focus(canvas);
        }
Пример #6
0
        internal static void RemoveRectangle(this Canvas canvas, WindowData data, int fileIndex, int rectangleIndex)
        {
            var removed = data.FileList[fileIndex].Rectangles[rectangleIndex];

            data.UndoStack.Push(Tuple.Create(fileIndex, removed));
            data.FileList[fileIndex].Rectangles.RemoveAt(rectangleIndex);
            data.RectangleHasFocus = false;
        }
Пример #7
0
        internal static void LoadRectangles(this Canvas canvas, WindowData data, int imageIndex)
        {
            canvas.Children.Clear();

            foreach (var sample in data.FileList[imageIndex].Rectangles)
            {
                canvas.Children.Add(canvas.InitializeShape(sample, new System.Windows.Shapes.Rectangle(), data.ScaleX, data.ScaleY, Brushes.OrangeRed));
            }
        }
Пример #8
0
        internal static void LoadRectangles(this Canvas canvas, WindowData data, int imageIndex)
        {
            canvas.Children.Clear();

            foreach (var sample in data.FileList[imageIndex].Rectangles)
            {
                canvas.Children.Add(canvas.InitializeShape(sample, new System.Windows.Shapes.Rectangle(), data.ScaleX, data.ScaleY, Brushes.OrangeRed));
            }
        }
Пример #9
0
 internal static void UndoRemoveRectangle(this Canvas canvas, WindowData data, ref int fileIndex, ref int rectangleIndex)
 {
     if (data.UndoStack.Count > 0)
     {
         var removed = data.UndoStack.Pop();
         fileIndex      = removed.Item1;
         rectangleIndex = data.FileList[fileIndex].Rectangles.Count;
         data.FileList[fileIndex].Rectangles.Add(removed.Item2);
     }
 }
Пример #10
0
        internal static void FocusRectangle(this Canvas canvas, WindowData data, int imageIndex, int rectIndex)
        {
            canvas.LayoutTransform = Transform.Identity;
            canvas.LoadRectangles(data, imageIndex);

            var rect = data.FileList[imageIndex].Rectangles[rectIndex];
            canvas.Children.Add(canvas.InitializeShape(rect, new System.Windows.Shapes.Rectangle(), data.ScaleX, data.ScaleY, Brushes.RoyalBlue));
            canvas.Children.Add(canvas.InitializeShape(rect, new Ellipse(), data.ScaleX, data.ScaleY, Brushes.RoyalBlue));

            var scroller = canvas.Parent as ScrollViewer;
            if (scroller != null)
            {
                scroller.ScrollToHorizontalOffset(Math.Max(rect.X - 32, 0) *data.ScaleX);
                scroller.ScrollToVerticalOffset(Math.Max(rect.Y - 32, 0) *data.ScaleY);
            }

            data.WindowTitle = "File " + (data.FileIndex + 1) + "/" + data.FileList.Count + ", Box " + (data.RectangleIndex + 1) + "/" + data.FileList[data.FileIndex].Rectangles.Count;
            data.RectangleHasFocus = true;
        }
Пример #11
0
        internal static void FocusRectangle(this Canvas canvas, WindowData data, int imageIndex, int rectIndex)
        {
            canvas.LayoutTransform = Transform.Identity;
            canvas.LoadRectangles(data, imageIndex);

            var rect = data.FileList[imageIndex].Rectangles[rectIndex];

            canvas.Children.Add(canvas.InitializeShape(rect, new System.Windows.Shapes.Rectangle(), data.ScaleX, data.ScaleY, Brushes.RoyalBlue));
            canvas.Children.Add(canvas.InitializeShape(rect, new Ellipse(), data.ScaleX, data.ScaleY, Brushes.RoyalBlue));

            var scroller = canvas.Parent as ScrollViewer;

            if (scroller != null)
            {
                scroller.ScrollToHorizontalOffset(Math.Max(rect.X - 32, 0) * data.ScaleX);
                scroller.ScrollToVerticalOffset(Math.Max(rect.Y - 32, 0) * data.ScaleY);
            }

            data.WindowTitle       = "File " + (data.FileIndex + 1) + "/" + data.FileList.Count + ", Box " + (data.RectangleIndex + 1) + "/" + data.FileList[data.FileIndex].Rectangles.Count;
            data.RectangleHasFocus = true;
        }
Пример #12
0
        internal static async Task <bool> Click(this Canvas canvas, WindowData data, MouseButton changedButton)
        {
            var handled = false;

            if (changedButton == MouseButton.Left)
            {
                data.FileIndex++;
                data.RectangleIndex    = 0;
                data.RectangleHasFocus = false;
                handled = true;
            }
            else if (changedButton == MouseButton.Right)
            {
                data.FileIndex--;
                data.RectangleIndex    = 0;
                data.RectangleHasFocus = false;
                handled = true;
            }

            if (data.FileIndex < 0)
            {
                data.FileIndex = 0;
            }
            else if (data.FileIndex < data.FileList.Count)
            {
                await canvas.LoadImage(data, data.FileIndex);

                canvas.LoadRectangles(data, data.FileIndex);
            }
            else
            {
                data.FileIndex = data.FileList.Count;
                canvas.Children.Clear();
                canvas.Background = Brushes.SkyBlue;
            }
            return(handled);
        }
Пример #13
0
 internal static void UndoRemoveRectangle(this Canvas canvas, WindowData data, ref int fileIndex, ref int rectangleIndex)
 {
     if (data.UndoStack.Count > 0)
     {
         var removed = data.UndoStack.Pop();
         fileIndex = removed.Item1;
         rectangleIndex = data.FileList[fileIndex].Rectangles.Count;
         data.FileList[fileIndex].Rectangles.Add(removed.Item2);
     }
 }
Пример #14
0
 internal static Rectangle TransformRectangle(this Canvas canvas, WindowData data, Rectangle rectangle, WindowData.Dimension dimension, int amount)
 {
     data.UnsavedChangesPresent = true;
     return canvas.TransformRectangle(rectangle, dimension, amount);
 }
Пример #15
0
 internal static async Task ChangeRectangle(this Canvas canvas, WindowData data, int offset)
 {
     data.RectangleIndex += offset;
     if (data.RectangleIndex < 0)
     {
         data.FileIndex--;
         if (data.FileIndex < 0)
         {
             data.FileIndex = 0;
             data.RectangleIndex = 0;
         }
         else
         {
             data.RectangleIndex = data.FileList[data.FileIndex].Rectangles.Count - 1;
         }
         await canvas.LoadImage(data, data.FileIndex);
     }
     else if (data.RectangleIndex >= data.FileList[data.FileIndex].Rectangles.Count)
     {
         data.FileIndex++;
         if (data.FileIndex >= data.FileList.Count)
         {
             data.FileIndex = data.FileList.Count - 1;
             data.RectangleIndex = data.FileList[data.FileIndex].Rectangles.Count - 1;
         }
         else
         {
             data.RectangleIndex = 0;
         }
         await canvas.LoadImage(data, data.FileIndex);
     }
 }
Пример #16
0
 internal static void RemoveRectangle(this Canvas canvas, WindowData data, int fileIndex, int rectangleIndex)
 {
     var removed = data.FileList[fileIndex].Rectangles[rectangleIndex];
     data.UndoStack.Push(Tuple.Create(fileIndex, removed));
     data.FileList[fileIndex].Rectangles.RemoveAt(rectangleIndex);
     data.RectangleHasFocus = false;
 }
Пример #17
0
 internal static Rectangle TransformRectangle(this Canvas canvas, Rectangle rectangle, WindowData.Dimension dimension, int amount)
 {
     switch (dimension) {
         case WindowData.Dimension.X:
             rectangle.Left += amount;
             break;
         case WindowData.Dimension.Y:
             rectangle.Top += amount;
             break;
         case WindowData.Dimension.Size:
             rectangle.Width += amount;
             rectangle.Height += amount;
             break;
     }
     rectangle = canvas.Rectangle(rectangle);
     return rectangle;
 }
Пример #18
0
        internal static async void KeyPress(this Canvas canvas, WindowData data, KeyEventArgs e, MainWindow mainWindow)
        {
            if (mainWindow.DragLeft || mainWindow.DragRight) return;
            if (data.RectangleHasFocus)
            {
                var step = 2;
                if (e.IsRepeat) step = 4;
                if (e.KeyboardDevice.IsKeyDown(Key.Back))
                {
                    await canvas.ChangeRectangle(data, -1);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Space))
                {
                    await canvas.ChangeRectangle(data, +1);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Left))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.X, -step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Right))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.X, step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Up))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.Y, -step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Down))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.Y, step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.W))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.Size, step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.S))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.Size, -step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Delete) && !e.IsRepeat)
                {
                    canvas.RemoveRectangle(data, data.FileIndex, data.RectangleIndex);

                    data.RectangleHasFocus = false;
                    canvas.LoadRectangles(data, data.FileIndex);
                    e.Handled = true;
                    return;
                }
            }
            else if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl) && e.KeyboardDevice.IsKeyDown(Key.Z) && !e.IsRepeat)
            {
                canvas.UndoRemoveRectangle(data, ref data.FileIndex, ref data.RectangleIndex);
                await canvas.LoadImage(data, data.FileIndex);
            }
            else if (!(e.Key == Key.Space || e.Key == Key.Back))
            {
                return;
            }
            data.RectangleIndex = Math.Min(Math.Max(data.RectangleIndex, 0), data.FileList[data.FileIndex].Rectangles.Count - 1);
            canvas.FocusRectangle(data, data.FileIndex, data.RectangleIndex);
            e.Handled = true;
        }
Пример #19
0
 internal static void DragFinal(this Canvas canvas, WindowData data, Point dragStart, Point dragEnd)
 {
     data.FileList[data.FileIndex].Rectangles.Insert(data.RectangleIndex, canvas.GetRect(data.ScaleY, data.ScaleX, dragStart, dragEnd));
     canvas.FocusRectangle(data, data.FileIndex, data.RectangleIndex);
     data.UnsavedChangesPresent = true;
 }
Пример #20
0
 internal static void DragFinal(this Canvas canvas, WindowData data, Point dragStart, Point dragEnd)
 {
     data.FileList[data.FileIndex].Rectangles.Insert(data.RectangleIndex, canvas.GetRect(data.ScaleY, data.ScaleX, dragStart, dragEnd));
     canvas.FocusRectangle(data, data.FileIndex, data.RectangleIndex);
     data.UnsavedChangesPresent = true;
 }
Пример #21
0
 internal static void DragIntermediate(this Canvas canvas, WindowData data, Point dragStart, Point dragEnd)
 {
     canvas.Children.Clear();
     canvas.Children.Add(canvas.InitializeShape(canvas.GetRect(data.ScaleY, data.ScaleX, dragStart, dragEnd), new System.Windows.Shapes.Rectangle(), data.ScaleX, data.ScaleY, Brushes.RoyalBlue));
     data.WindowTitle = dragStart.X + "," + dragStart.Y + " - " + canvas.GetRect(data.ScaleY, data.ScaleX, dragStart, dragEnd).X + "," + canvas.GetRect(data.ScaleY, data.ScaleX, dragStart, dragEnd).Y;
 }
Пример #22
0
        internal static async void KeyPress(this Canvas canvas, WindowData data, KeyEventArgs e, MainWindow mainWindow)
        {
            if (mainWindow.DragLeft || mainWindow.DragRight)
            {
                return;
            }
            if (data.RectangleHasFocus)
            {
                var step = 2;
                if (e.IsRepeat)
                {
                    step = 4;
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Back))
                {
                    await canvas.ChangeRectangle(data, -1);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Space))
                {
                    await canvas.ChangeRectangle(data, +1);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Left))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.X, -step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Right))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.X, step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Up))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.Y, -step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Down))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.Y, step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.W))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.Size, step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.S))
                {
                    data.FileList[data.FileIndex].Rectangles[data.RectangleIndex] = canvas.TransformRectangle(data.FileList[data.FileIndex].Rectangles[data.RectangleIndex], WindowData.Dimension.Size, -step);
                }
                if (e.KeyboardDevice.IsKeyDown(Key.Delete) && !e.IsRepeat)
                {
                    canvas.RemoveRectangle(data, data.FileIndex, data.RectangleIndex);

                    data.RectangleHasFocus = false;
                    canvas.LoadRectangles(data, data.FileIndex);
                    e.Handled = true;
                    return;
                }
            }
            else if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl) && e.KeyboardDevice.IsKeyDown(Key.Z) && !e.IsRepeat)
            {
                canvas.UndoRemoveRectangle(data, ref data.FileIndex, ref data.RectangleIndex);
                await canvas.LoadImage(data, data.FileIndex);
            }
            else if (!(e.Key == Key.Space || e.Key == Key.Back))
            {
                return;
            }
            data.RectangleIndex = Math.Min(Math.Max(data.RectangleIndex, 0), data.FileList[data.FileIndex].Rectangles.Count - 1);
            canvas.FocusRectangle(data, data.FileIndex, data.RectangleIndex);
            e.Handled = true;
        }
Пример #23
0
 internal static Rectangle TransformRectangle(this Canvas canvas, WindowData data, Rectangle rectangle, WindowData.Dimension dimension, int amount)
 {
     data.UnsavedChangesPresent = true;
     return(canvas.TransformRectangle(rectangle, dimension, amount));
 }
Пример #24
0
 public MainWindow()
 {
     InitializeComponent();
     _data = new WindowData(this);
 }
Пример #25
0
 public MainWindow()
 {
     InitializeComponent();
     _data = new WindowData(this);
 }
Пример #26
0
        internal static async Task<bool> Click(this Canvas canvas, WindowData data, MouseButton changedButton)
        {
            var handled = false;
            if (changedButton == MouseButton.Left)
            {
                data.FileIndex++;
                data.RectangleIndex = 0;
                data.RectangleHasFocus = false;
                handled = true;
            }
            else if (changedButton == MouseButton.Right)
            {
                data.FileIndex--;
                data.RectangleIndex = 0;
                data.RectangleHasFocus = false;
                handled = true;
            }

            if (data.FileIndex < 0)
            {
                data.FileIndex = 0;
            }
            else if (data.FileIndex < data.FileList.Count)
            {
                await canvas.LoadImage(data, data.FileIndex);
                canvas.LoadRectangles(data, data.FileIndex);
            }
            else
            {
                data.FileIndex = data.FileList.Count;
                canvas.Children.Clear();
                canvas.Background = Brushes.SkyBlue;
            }
            return handled;
        }
Пример #27
0
 internal static void DragIntermediate(this Canvas canvas, WindowData data, Point dragStart, Point dragEnd)
 {
     canvas.Children.Clear();
     canvas.Children.Add(canvas.InitializeShape(canvas.GetRect(data.ScaleY, data.ScaleX, dragStart, dragEnd), new System.Windows.Shapes.Rectangle(), data.ScaleX, data.ScaleY, Brushes.RoyalBlue));
     data.WindowTitle = dragStart.X + "," + dragStart.Y + " - " + canvas.GetRect(data.ScaleY, data.ScaleX, dragStart, dragEnd).X + "," + canvas.GetRect(data.ScaleY, data.ScaleX, dragStart, dragEnd).Y;
 }