/// <summary>
        /// The 'Fill' command was executed.
        /// </summary>
        private void FitContent_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            IList nodes = null;

            if (NetworkControl.SelectedNodes.Count > 0)
            {
                nodes = NetworkControl.SelectedNodes;
            }
            else
            {
                nodes = ViewModel.Network.Nodes;
                if (nodes.Count == 0)
                {
                    return;
                }
            }

            SavePrevZoomRect();

            var actualContentRect = DetermineAreaOfNodes(nodes);

            //
            // Inflate the content rect by a fraction of the actual size of the total content area.
            // This puts a nice border around the content we are fitting to the viewport.
            //
            actualContentRect.Inflate(NetworkControl.ActualWidth / 40, NetworkControl.ActualHeight / 40);

            ZoomAndPanControl.AnimatedZoomTo(actualContentRect);
        }
        /// <summary>
        /// When the user has finished dragging out the rectangle the zoom operation is applied.
        /// </summary>
        private void ApplyDragZoomRect()
        {
            //
            // Record the previous zoom level, so that we can jump back to it when the backspace key is pressed.
            //
            SavePrevZoomRect();

            //
            // Retreive the rectangle that the user draggged out and zoom in on it.
            //
            var contentX      = Canvas.GetLeft(DragZoomBorder);
            var contentY      = Canvas.GetTop(DragZoomBorder);
            var contentWidth  = DragZoomBorder.Width;
            var contentHeight = DragZoomBorder.Height;

            ZoomAndPanControl.AnimatedZoomTo(new Rect(contentX, contentY, contentWidth, contentHeight));

            FadeOutDragZoomRect();
        }
예제 #3
0
        private void TriggerEvent(string cmd, object o)
        {
            try
            {
                switch (cmd)
                {
                case WindowsCmdConsts.Next_Image:
                    if (ImageLIst.SelectedIndex <
                        ImageLIst.Items.Count - 1)
                    {
                        FileItem item =
                            ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            int ind = ImageLIst.Items.IndexOf(item);
                            ImageLIst.SelectedIndex = ind + 1;
                        }
                        item = ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            ImageLIst.ScrollIntoView(item);
                        }
                    }
                    break;

                case WindowsCmdConsts.Prev_Image:
                    if (ImageLIst.SelectedIndex > 0)
                    {
                        FileItem item =
                            ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            int ind = ImageLIst.Items.IndexOf(item);
                            ImageLIst.SelectedIndex = ind - 1;
                        }
                        item = ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            ImageLIst.ScrollIntoView(item);
                        }
                    }
                    break;

                case WindowsCmdConsts.Like_Image:
                    if (ImageLIst.SelectedItem != null)
                    {
                        FileItem item = null;
                        if (o != null)
                        {
                            item = ServiceProvider.Settings.DefaultSession.GetByName(o as string);
                        }
                        else
                        {
                            item = ImageLIst.SelectedItem as FileItem;
                        }
                        if (item != null)
                        {
                            item.IsLiked = !item.IsLiked;
                        }
                    }
                    break;

                case WindowsCmdConsts.Unlike_Image:
                    if (ImageLIst.SelectedItem != null)
                    {
                        FileItem item = null;
                        if (o != null)
                        {
                            item =
                                ServiceProvider.Settings.DefaultSession
                                .GetByName(o as string);
                        }
                        else
                        {
                            item = ImageLIst.SelectedItem as FileItem;
                        }
                        if (item != null)
                        {
                            item.IsUnLiked = !item.IsUnLiked;
                        }
                    }
                    break;

                case WindowsCmdConsts.Del_Image:
                {
                    DeleteItem();
                }
                break;

                case WindowsCmdConsts.Select_Image:
                    FileItem fileItem = o as FileItem;
                    if (fileItem != null)
                    {
                        ImageLIst.SelectedValue = fileItem;
                        ImageLIst.ScrollIntoView(fileItem);
                    }
                    break;

                case WindowsCmdConsts.Refresh_Image:
                    RefreshImage();
                    break;

                case WindowsCmdConsts.Zoom_Image_Fit:
                    ZoomAndPanControl.AnimatedScaleToFit();
                    break;

                case WindowsCmdConsts.Zoom_Image_100:
                    ZoomToFocus();
                    LoadFullRes();
                    ZoomAndPanControl.AnimatedZoomTo(1.0);
                    break;

                case WindowsCmdConsts.Zoom_Image_200:
                    ZoomToFocus();
                    LoadFullRes();
                    ZoomAndPanControl.AnimatedZoomTo(2.0);
                    break;

                case WindowsCmdConsts.RotateLeft:
                {
                    FileItem item =
                        ImageLIst.SelectedItem as FileItem;
                    if (item != null)
                    {
                        item.Rotation--;
                    }
                }
                break;

                case WindowsCmdConsts.RotateRight:
                {
                    FileItem item =
                        ImageLIst.SelectedItem as FileItem;
                    if (item != null)
                    {
                        item.Rotation++;
                    }
                }
                break;
                }
                if (cmd.StartsWith(WindowsCmdConsts.ZoomPoint))
                {
                    if (ZoomAndPanControl != null && cmd.Contains("_"))
                    {
                        var vals = cmd.Split('_');
                        if (vals.Count() > 2)
                        {
                            double x;
                            double y;
                            double.TryParse(vals[1], out x);
                            double.TryParse(vals[2], out y);
                            if (cmd.EndsWith("!"))
                            {
                                ZoomAndPanControl.SnapToRation(x, y);
                            }
                            else
                            {
                                ZoomAndPanControl.AnimatedSnapToRation(x, y);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Log.Error("Unable to process event ", exception);
            }
        }
예제 #4
0
        private void Trigger_Event(string cmd, object o)
        {
            ImageLIst.Dispatcher.Invoke(new Action(delegate
            {
                switch (cmd)
                {
                case WindowsCmdConsts.Next_Image:
                    if (ImageLIst.SelectedIndex <
                        ImageLIst.Items.Count - 1)
                    {
                        FileItem item =
                            ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            int ind = ImageLIst.Items.IndexOf(item);
                            ImageLIst.SelectedIndex = ind + 1;
                        }
                        item = ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            ImageLIst.ScrollIntoView(item);
                        }
                    }
                    break;

                case WindowsCmdConsts.Prev_Image:
                    if (ImageLIst.SelectedIndex > 0)
                    {
                        FileItem item =
                            ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            int ind = ImageLIst.Items.IndexOf(item);
                            ImageLIst.SelectedIndex = ind - 1;
                        }
                        item = ImageLIst.SelectedItem as FileItem;
                        if (item != null)
                        {
                            ImageLIst.ScrollIntoView(item);
                        }
                    }
                    break;

                case WindowsCmdConsts.Like_Image:
                    if (ImageLIst.SelectedItem != null)
                    {
                        FileItem item = null;
                        if (o != null)
                        {
                            item = ServiceProvider.Settings.DefaultSession.GetByName(o as string);
                        }
                        else
                        {
                            item = ImageLIst.SelectedItem as FileItem;
                        }
                        if (item != null)
                        {
                            item.IsLiked = !item.IsLiked;
                        }
                    }
                    break;

                case WindowsCmdConsts.Unlike_Image:
                    if (ImageLIst.SelectedItem != null)
                    {
                        FileItem item = null;
                        if (o != null)
                        {
                            item =
                                ServiceProvider.Settings.DefaultSession
                                .GetByName(o as string);
                        }
                        else
                        {
                            item = ImageLIst.SelectedItem as FileItem;
                        }
                        if (item != null)
                        {
                            item.IsUnLiked = !item.IsUnLiked;
                        }
                    }
                    break;

                case WindowsCmdConsts.Del_Image:
                    {
                        DeleteItem();
                    }
                    break;

                case WindowsCmdConsts.Select_Image:
                    FileItem fileItem = o as FileItem;
                    if (fileItem != null)
                    {
                        ImageLIst.SelectedValue = fileItem;
                        ImageLIst.ScrollIntoView(fileItem);
                    }
                    break;

                case WindowsCmdConsts.Refresh_Image:
                    if (!_worker.IsBusy)
                    {
                        _worker.RunWorkerAsync(false);
                    }
                    break;

                case WindowsCmdConsts.Zoom_Image_Fit:
                    ZoomAndPanControl.AnimatedScaleToFit();
                    break;

                case WindowsCmdConsts.Zoom_Image_100:
                    LoadFullRes();
                    ZoomAndPanControl.AnimatedZoomTo(1.0);
                    break;

                case WindowsCmdConsts.Zoom_Image_200:
                    LoadFullRes();
                    ZoomAndPanControl.AnimatedZoomTo(2.0);
                    break;
                }
                if (cmd.StartsWith(WindowsCmdConsts.ZoomPoint))
                {
                    if (ZoomAndPanControl != null && cmd.Contains("_"))
                    {
                        var vals = cmd.Split('_');
                        if (vals.Count() > 2)
                        {
                            double x;
                            double y;
                            double.TryParse(vals[1], out x);
                            double.TryParse(vals[2], out y);
                            if (cmd.EndsWith("!"))
                            {
                                ZoomAndPanControl.SnapToRation(x, y);
                            }
                            else
                            {
                                ZoomAndPanControl.AnimatedSnapToRation(x, y);
                            }
                        }
                    }
                }
            }));
        }
        /// <summary>
        /// Jump back to the previous zoom level.
        /// </summary>
        private void JumpBackToPrevZoom()
        {
            ZoomAndPanControl.AnimatedZoomTo(_prevZoomScale, _prevZoomRect);

            ClearPrevZoomRect();
        }
        /// <summary>
        /// The 'OneHundredPercent' command was executed.
        /// </summary>
        private void OneHundredPercent_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            SavePrevZoomRect();

            ZoomAndPanControl.AnimatedZoomTo(1.0);
        }