/// <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(); }
protected void zoomAndPanControl_MouseWheel(object sender, MouseWheelEventArgs e) { e.Handled = true; if (e.Delta > 0) { Point curContentMousePoint = e.GetPosition(content); ZoomIn(curContentMousePoint); } else if (e.Delta < 0) { Point curContentMousePoint = e.GetPosition(content); ZoomOut(curContentMousePoint); } if (ZoomAndPanControl.ContentScale > ZoomAndPanControl.FitScale()) { LoadFullRes(); LayoutViewModel.FreeZoom = true; } }
private void SimulateStep(TimeSpan timeStep, DrawingContext dc) { TimeSpan deltaTime = timeStep; if (zoomAndPanControl == null) { zoomAndPanControl = this.FindAncestor <ZoomAndPanControl>(); } diagram.Simulate( Math.Min(deltaTime.TotalSeconds, 0.1), diagram.ZoomAndPanViewModel.ContentWidth, diagram.ZoomAndPanViewModel.ContentHeight ); DrawLinks(dc); if (ShowForces) { DrawForces(dc); } }
// Event raised on mouse up in the ZoomAndPanControl public static void MouseUp(object sender, MouseButtonEventArgs e, ZoomAndPanControl z) { if (mouseHandlingMode != MouseHandlingMode.None) { if (mouseHandlingMode == MouseHandlingMode.Zooming) { if (mouseButtonDown == MouseButton.Left) { // Shift + left-click zooms in on the content. ZoomIn(z, origContentMouseDownPoint); } else if (mouseButtonDown == MouseButton.Right) { // Shift + left-click zooms out from the content. ZoomOut(z, origContentMouseDownPoint); } } z.ReleaseMouseCapture(); mouseHandlingMode = MouseHandlingMode.None; e.Handled = true; } }
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); } } } } })); }
private void ZoomAndPanControl_ContentScaleChanged(object sender, EventArgs e) { GeneratePreview(); LayoutViewModel.FreeZoom = ZoomAndPanControl.ContentScale > ZoomAndPanControl.FitScale(); }
private void OnGraphControlMouseWheel(object sender, MouseWheelEventArgs e) { ZoomAndPanControl.ZoomAboutPoint(ZoomAndPanControl.ContentScale + e.Delta / 1000.0f, e.GetPosition(GraphControl)); e.Handled = true; }
// Zoom in/out centered on the specified point (in content coordinates). public static void ZoomAboutPoint(double newContentScale, Point contentZoomFocus, ZoomAndPanControl z) { newContentScale = Math.Min(Math.Max(newContentScale, z.MinContentScale), z.MaxContentScale); double screenSpaceZoomOffsetX = (contentZoomFocus.X - z.ContentOffsetX) * z.ContentScale; double screenSpaceZoomOffsetY = (contentZoomFocus.Y - z.ContentOffsetY) * z.ContentScale; double contentSpaceZoomOffsetX = screenSpaceZoomOffsetX / newContentScale; double contentSpaceZoomOffsetY = screenSpaceZoomOffsetY / newContentScale; double newContentOffsetX = contentZoomFocus.X - contentSpaceZoomOffsetX; double newContentOffsetY = contentZoomFocus.Y - contentSpaceZoomOffsetY; z.ContentScale = newContentScale; z.ContentOffsetX = newContentOffsetX; z.ContentOffsetY = newContentOffsetY; }
private void worker_DoWork(object sender, DoWorkEventArgs e) { var item = ServiceProvider.Settings.SelectedBitmap.FileItem; bool fullres = e.Argument is bool && (bool)e.Argument; ServiceProvider.Settings.SelectedBitmap.DisplayImage = BitmapLoader.Instance.LoadImage(ServiceProvider.Settings.SelectedBitmap.FileItem, fullres); ServiceProvider.Settings.SelectedBitmap.Notify(); ServiceProvider.Settings.ImageLoading = false; GC.Collect(); ZoomAndPanControl.ScaleToFit(); //if (ServiceProvider.Settings.SelectedBitmap.FileItem == null) // return; ////bool fullres = e.Argument is bool && (bool) e.Argument ||LayoutViewModel.ZoomFit ////bool fullres = !LayoutViewModel.ZoomFit; //bool fullres = e.Argument is bool && (bool)e.Argument; //if ((!File.Exists(item.LargeThumb) && item.IsJpg && File.Exists(item.FileName))) //{ // try // { // PhotoUtils.WaitForFile(item.FileName); // //ServiceProvider.Settings.SelectedBitmap.DisplayImage = (WriteableBitmap)BitmapLoader.Instance.LoadImage(item.FileName, BitmapLoader.LargeThumbSize,0); // } // catch (Exception ex) // { // Log.Error("Unable to load fast preview", ex); // } //} //ServiceProvider.Settings.ImageLoading = fullres || !ServiceProvider.Settings.SelectedBitmap.FileItem.IsLoaded; //if (ServiceProvider.Settings.SelectedBitmap.FileItem.Loading) //{ // while (ServiceProvider.Settings.SelectedBitmap.FileItem.Loading) // { // Thread.Sleep(10); // } //} //else //{ // BitmapLoader.Instance.GenerateCache(ServiceProvider.Settings.SelectedBitmap.FileItem); //} //if (!ServiceProvider.Settings.SelectedBitmap.FileItem.HaveHistogramReady()) // ServiceProvider.QueueManager.Add(new QueueItemFileItem // { // FileItem = ServiceProvider.Settings.SelectedBitmap.FileItem, // Generate = QueueType.Histogram // }); //ServiceProvider.Settings.SelectedBitmap.DisplayImage = BitmapLoader.Instance.LoadImage(ServiceProvider.Settings.SelectedBitmap.FileItem, fullres); //ServiceProvider.Settings.SelectedBitmap.Notify(); //BitmapLoader.Instance.SetData(ServiceProvider.Settings.SelectedBitmap, // ServiceProvider.Settings.SelectedBitmap.FileItem); ////Calling Capture Level Graph ////PathUpdate.getInstance().CaptureLevelGraphVM.ImagePath = item.FileName; //BitmapLoader.Highlight(ServiceProvider.Settings.SelectedBitmap, // ServiceProvider.Settings.HighlightUnderExp, // ServiceProvider.Settings.HighlightOverExp); //ServiceProvider.Settings.SelectedBitmap.FullResLoaded = fullres; //ServiceProvider.Settings.ImageLoading = false; //GC.Collect(); //Dispatcher.BeginInvoke(new Action(OnImageLoaded)); }
/// <summary> /// Zoom the viewport out, centering on the specified point (in content coordinates). /// </summary> private void ZoomOut(Point contentZoomCenter) => ZoomAndPanControl.ZoomAboutPoint(ZoomAndPanControl.ContentScale - 0.1, contentZoomCenter);
/// <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); }
/// <summary> /// The 'Fill' command was executed. /// </summary> private void Fill_Executed(object sender, ExecutedRoutedEventArgs e) { SavePrevZoomRect(); ZoomAndPanControl.AnimatedScaleToFit(); }
private void CvZoomOut(Point point) { ZoomAndPanControl.ZoomAboutPoint(ZoomAndPanControl.ContentScale - 0.1, point); }
private void Fullscreen_OnLoaded(object sender, RoutedEventArgs e) { ZoomAndPanControl.AnimatedScaleToFit(); }
/// <summary> /// Zoom the viewport in, centering on the specified point (in content coordinates). /// </summary> private void ZoomIn(Point contentZoomCenter) { ZoomAndPanControl.ZoomAboutPoint(ZoomAndPanControl.ContentScale + 0.1, contentZoomCenter); }
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.SelectAll_Image: { ServiceProvider.Settings.DefaultSession.SelectAll(); } 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.ScaleToFit(); break; case WindowsCmdConsts.Zoom_Image_60: ZoomToFocus(); LoadFullRes(); ZoomAndPanControl.ZoomTo(0.6); break; case WindowsCmdConsts.Zoom_Image_100: ZoomToFocus(); LoadFullRes(); ZoomAndPanControl.ZoomTo(1.0); break; case WindowsCmdConsts.Zoom_Image_200: ZoomToFocus(); LoadFullRes(); ZoomAndPanControl.ZoomTo(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; case WindowsCmdConsts.ViewExternal: OpenInExternalViewer(); break; case WindowsCmdConsts.ViewExplorer: OpenInExplorer(); break; case WindowsCmdConsts.RefreshDisplay: if (LayoutViewModel.ZoomIndex == 0) { ZoomAndPanControl.ScaleToFit(); } 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); } }
// Zoom the viewport in by a small increment public static void ZoomIn(ZoomAndPanControl z, Point contentZoomCenter) { z.ZoomAboutPoint(z.ContentScale + 0.1, contentZoomCenter); }