/// <summary> /// Zooms the specified view with the given factor. /// </summary> /// <param name="viewName">Name of the view.</param> /// <param name="viewRangeName">Name of the view range.</param> /// <param name="factor">The zoom factor.</param> protected bool zoomWithFactor(string viewName, string viewRangeName, double factor) { if (io == null || io.GetView(viewName) as BrailleIOScreen == null) { return(false); } BrailleIOViewRange vr = ((BrailleIOScreen)io.GetView(viewName)).GetViewRange(viewRangeName); bool success = false; if (vr != null) { double oldZoom = vr.GetZoom(); if (oldZoom > 0) { double newZoom = oldZoom * factor; success = zoom(vr, oldZoom, newZoom); } else { return(false); } } else { return(false); } this.io.RefreshDisplay(); return(success); }
/// <summary> /// Zooms the specified view to the given zoom level. /// </summary> /// <param name="viewName">Name of the view.</param> /// <param name="viewRangeName">Name of the view range.</param> /// <param name="zoomLevel">The zoom level.</param> public bool ZoomTo(string viewName, string viewRangeName, double zoomLevel) { if (io == null || io.GetView(viewName) as BrailleIOScreen == null) { return(false); } BrailleIOViewRange vr = ((BrailleIOScreen)io.GetView(viewName)).GetViewRange(viewRangeName); bool success = false; if (vr != null) { var oldZoom = vr.GetZoom(); var newZoom = zoomLevel; success = zoom(vr, oldZoom, newZoom); } else { return(false); } io.RefreshDisplay(); return(success); }
/// <summary> /// Move current view range to the given object. /// For example, this should be used for following the focused object on the pin device. /// </summary> /// <param name="objectBounds">object that should be shown centered on pin device</param> public void MoveToObject(Rectangle boundingBox) { if (boundingBox == null || IsInMinimapMode()) { return; } BrailleIOScreen vs = GetVisibleScreen(); BrailleIOViewRange center = GetActiveCenterView(vs); if (center != null) { // use not whole screen, but open office document position as screen position, because contentWidth and contentHeight of view range is related to this instead of to the whole screen //Rectangle boundingBox = new Rectangle(objectBounds.X, objectBounds.Y, objectBounds.Width, objectBounds.Height); Point centeredScreenPosition = new Point((int)Math.Round(boundingBox.X + boundingBox.Width * 0.5), (int)Math.Round(boundingBox.Y + boundingBox.Height * 0.5)); //Point centeredScreenPosition = new Point(boundingBox.X, boundingBox.Y); Point pinDevicePosition = new Point(0, 0); double zoom = center.GetZoom(); if (zoom != 0) { pinDevicePosition = new Point((int)(Math.Round(centeredScreenPosition.X * -zoom) + ((int)Math.Round(center.ContentBox.Width * 0.5))), (int)(Math.Round(centeredScreenPosition.Y * -zoom) + ((int)Math.Round(center.ContentBox.Height * 0.5)))); //pinDevicePosition = new Point((int)(Math.Round(centeredScreenPosition.X * -zoom)), (int)(Math.Round(centeredScreenPosition.Y * -zoom))); } MoveToPosition(vs.Name, center.Name, pinDevicePosition); } }
/// <summary> /// Check if current view is in print zoom and, therefore, BrailleTextRenderer can be activated. /// </summary> /// <returns></returns> public bool CanBeActivated() { if (_lastView != null && _lastView.GetZoom() == WindowManager.GetPrintZoomLevel()) { return(true); } return(false); }
/// <summary> /// Zooms the specified view by the given factor. /// </summary> /// <param name="vr">The view to change the zoom factor.</param> /// <param name="changeFactor">The change factor for zoom.</param> /// <param name="render">if set to <c>true</c> a new rendering is forced.</param> /// <returns> /// <c>true</c> if the zoom factor of the view was changed successfully. /// </returns> /// <exception cref="System.ArgumentException">Zoom-factor must be not 0! - changeFactor</exception> /// <remarks> /// Views will change their presentation only after calling <see cref="BrailleIOMediator.Instance.RenderDisplay()" />. /// Call the <c>RenderDisplay()</c> function after you have done all your changes to see the results. /// </remarks> public static bool Zoom(BrailleIOViewRange vr, double changeFactor, bool render = false) { if (changeFactor == 0.0) { throw new ArgumentException("Zoom-factor must be not 0!", "changeFactor"); } if (vr != null) { if (vr.GetZoom() > 0) { var oldZoom = vr.GetZoom(); var newZoom = oldZoom * changeFactor; return(ZoomTo(vr, newZoom, render)); } } return(false); }
void zoom(string viewName, string viewRangeName, double factor) { if (IO == null && IO.GetView(viewName) as BrailleIOScreen != null) { return; } // zoom in BrailleIOViewRange vr = ((BrailleIOScreen)IO.GetView(viewName)).GetViewRange(viewRangeName); if (vr != null) { if (vr.GetZoom() > 0) { //TODO: make zoom to center var oldZoom = vr.GetZoom(); var newZoom = oldZoom * factor; var oldvrdin = vr.ViewBox; Point oldcenter = new Point( (int)Math.Round(((double)oldvrdin.Width / 2) + (vr.GetXOffset() * -1)), (int)Math.Round(((double)oldvrdin.Height / 2) + (vr.GetYOffset() * -1)) ); Point newCenter = new Point( (int)Math.Round(oldcenter.X * newZoom / oldZoom), (int)Math.Round(oldcenter.Y * newZoom / oldZoom) ); Point newOffset = new Point( (int)Math.Round((newCenter.X - ((double)oldvrdin.Width / 2)) * -1), (int)Math.Round((newCenter.Y - ((double)oldvrdin.Height / 2)) * -1) ); vr.SetZoom(newZoom); vr.SetXOffset(newOffset.X); vr.SetYOffset(newOffset.Y); } } this. IO.RenderDisplay(); }
/// <summary> /// Set the Zooms factor of the view to the given factor. /// </summary> /// <param name="vr">The view to change the zoom factor.</param> /// <param name="factor">The new zoom-factor.</param> /// <param name="render">if set to <c>true</c> a new rendering is forced.</param> /// <returns> /// <c>true</c> if the zoom factor of the view was changed successfully. /// </returns> /// <exception cref="System.ArgumentException">Zoom-factor must be not 0! - factor</exception> /// <remarks> /// Views will change their presentation only after calling <see cref="BrailleIOMediator.Instance.RenderDisplay()" />. /// Call the <c>RenderDisplay()</c> function after you have done all your changes to see the results. /// </remarks> public static bool ZoomTo(BrailleIOViewRange vr, double factor, bool render = false) { if (factor == 0.0) { throw new ArgumentException("Zoom-factor must be not 0!", "factor"); } if (vr != null) { var oldZoom = vr.GetZoom(); var newZoom = factor; var oldvrdin = vr.ViewBox; Point oldcenter = new Point( (int)Math.Round(((double)oldvrdin.Width / 2) + (vr.GetXOffset() * -1)), (int)Math.Round(((double)oldvrdin.Height / 2) + (vr.GetYOffset() * -1)) ); Point newCenter = new Point( (int)Math.Round(oldcenter.X * newZoom / oldZoom), (int)Math.Round(oldcenter.Y * newZoom / oldZoom) ); Point newOffset = new Point( (int)Math.Round((newCenter.X - ((double)oldvrdin.Width / 2)) * -1), (int)Math.Round((newCenter.Y - ((double)oldvrdin.Height / 2)) * -1) ); vr.SetZoom(newZoom); vr.SetXOffset(newOffset.X); vr.SetYOffset(newOffset.Y); if (render && BrailleIOMediator.Instance != null) { BrailleIOMediator.Instance.RenderDisplay(); } return(oldZoom != vr.GetZoom()); } return(false); }
/// <summary> /// Get zoom level in percentage. Print zoom is defined as 100%. /// </summary> /// <param name="viewName">name of the current BrailleIOScreen</param> /// <param name="viewRangeName">name of the current view range</param> /// <returns>current zoom level in % or Double.NaN if there is no zoom level</returns> public double GetZoomPercentageBasedOnPrintZoom(string viewName, string viewRangeName) { if (io != null && io.GetView(viewName) as BrailleIOScreen != null) { BrailleIOViewRange vr = ((BrailleIOScreen)io.GetView(viewName)).GetViewRange(viewRangeName); if (vr != null) { double zoom = vr.GetZoom(); double zoomPercentage = zoom / GetPrintZoomLevel(); zoomPercentage = (int)(zoomPercentage * 100); zoomPercentage = Math.Round(zoomPercentage / 10, MidpointRounding.AwayFromZero) * 10; // round to 10er values return(zoomPercentage); } } return(Double.NaN); }
/// <summary> /// Synchronize the zoom and x/y offset of the given view range with that of the center view range of the visible screen. /// </summary> /// <param name="vr">view range that should be syncronized with visible center</param> private void syncViewRangeWithVisibleCenterViewRange(BrailleIOViewRange vr) { BrailleIOScreen vs = GetVisibleScreen(); if (!vs.Name.Equals(BS_MINIMAP_NAME)) { BrailleIOViewRange visibleCenterVR = vs.GetViewRange(VR_CENTER_NAME); double zoom = visibleCenterVR.GetZoom(); int x = visibleCenterVR.GetXOffset(); int y = visibleCenterVR.GetYOffset(); if (visibleCenterVR.ContentHeight <= vr.ContentBox.Height && visibleCenterVR.ContentWidth <= vr.ContentBox.Width) { vr.SetZoom(-1); // für Anpassung bei kleinster Zoomstufe } else { vr.SetZoom(zoom); } vr.SetXOffset(x); vr.SetYOffset(y); } }
/// <summary> /// Get position of tap on the screen /// </summary> /// <param name="x">x value of tap (on pin device)</param> /// <param name="y">y value of tap (on pin device)</param> /// <param name="vr">touched view range</param> /// <returns>position on the screen</returns> public Point GetTapPositionOnScreen(double x, double y, BrailleIOViewRange vr) { Point p = GetTapPositionInContent(x, y, vr); if (vr != null && p != null) { double zoom = vr.GetZoom(); if (zoom != 0) { int x_old = p.X; int y_old = p.Y; p = new Point((int)Math.Round(x_old / zoom), (int)Math.Round(y_old / zoom)); if (ScreenObserver != null && ScreenObserver.ScreenPos is Rectangle) { Rectangle sp = (Rectangle)ScreenObserver.ScreenPos; p.X += sp.X; p.Y += sp.Y; } System.Diagnostics.Debug.WriteLine("tap screen position: " + p.ToString()); } } return(p); }
/// <summary> /// Zooms the given view range to the new zoom level and calculates the new offset out of the old center position. /// </summary> /// <param name="vr">view range that should be zoomed</param> /// <param name="oldZoom">old zoom of the view range</param> /// <param name="newZoom">new zoom</param> /// <returns>true, if zoom was successful</returns> private bool zoom(BrailleIOViewRange vr, double oldZoom, double newZoom) { if (vr != null) { Point oldCenter = new Point(); var oldvrdin = vr.ContentBox; bool zoomToShape = false; Point oldOffset = new Point(vr.GetXOffset(), vr.GetYOffset()); // Prüfung auf größte Zoomstufe if (newZoom > vr.MAX_ZOOM_LEVEL) { if (oldZoom == vr.MAX_ZOOM_LEVEL) return false; newZoom = vr.MAX_ZOOM_LEVEL; } // Prüfung auf kleinste Zoomstufe if (vr.ContentBox.Height >= vr.ContentHeight && vr.ContentBox.Width >= vr.ContentWidth) { if (oldZoom >= newZoom) return false; oldCenter = Point.Empty; // central point of focused element as center for zooming if (OoConnector.Instance != null && OoConnector.Instance.Observer != null) { OoShapeObserver shape = OoConnector.Instance.Observer.GetLastSelectedShape(); if (shape != null) { Rectangle shapeBoundingbox = shape.GetRelativeScreenBoundsByDom(); if (shapeBoundingbox != null) { // calculate shape position and size in pins (relative to document boundings on pin device) Point shapePosition = new Point((int)Math.Round(shapeBoundingbox.X * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Y * vr.GetZoom())); Size shapeSize = new Size((int)Math.Round(shapeBoundingbox.Width * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Height * vr.GetZoom())); Point shapeCenter = new Point(shapePosition.X + shapeSize.Width / 2, shapePosition.Y + shapeSize.Height / 2); oldCenter = new Point(shapeCenter.X, shapeCenter.Y); } } } if (oldCenter != Point.Empty) zoomToShape = true; else { oldCenter = new Point( (int)Math.Round(((double)vr.ContentWidth / 2) + (vr.GetXOffset() * -1)), (int)Math.Round(((double)vr.ContentHeight / 2) + (vr.GetYOffset() * -1)) ); } } else { oldCenter = Point.Empty; // central point of focused element as center for zooming if (OoConnector.Instance != null && OoConnector.Instance.Observer != null) { OoShapeObserver shape = OoConnector.Instance.Observer.GetLastSelectedShape(); if (shape != null) { Rectangle shapeBoundingbox = shape.GetRelativeScreenBoundsByDom(); if (shapeBoundingbox != null) { // calculate shape position and size in pins (relative to document boundings on pin device) Point shapePosition = new Point((int)Math.Round(shapeBoundingbox.X * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Y * vr.GetZoom())); Size shapeSize = new Size((int)Math.Round(shapeBoundingbox.Width * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Height * vr.GetZoom())); Point shapeCenter = new Point(shapePosition.X + shapeSize.Width / 2, shapePosition.Y + shapeSize.Height / 2); oldCenter = new Point(shapeCenter.X, shapeCenter.Y); } } } if (oldCenter != Point.Empty) zoomToShape = true; else { // central point of center region as center for zooming oldCenter = new Point( (int)Math.Round(((double)oldvrdin.Width / 2) + (vr.GetXOffset() * -1)), (int)Math.Round(((double)oldvrdin.Height / 2) + (vr.GetYOffset() * -1)) ); } } if (newZoom > 0) { double zoomRatio = newZoom / oldZoom; Point newCenter = new Point( (int)Math.Round(oldCenter.X * zoomRatio), (int)Math.Round(oldCenter.Y * zoomRatio) ); Point newOffset = new Point(); if (zoomToShape) { newOffset = new Point(oldOffset.X + (oldCenter.X - newCenter.X), oldOffset.Y + (oldCenter.Y - newCenter.Y)); } else { newOffset = new Point( (int)Math.Round((newCenter.X - ((double)oldvrdin.Width / 2)) * -1), (int)Math.Round((newCenter.Y - ((double)oldvrdin.Height / 2)) * -1) ); } vr.SetZoom(newZoom); vr.MoveTo(new Point(Math.Min(newOffset.X, 0), Math.Min(newOffset.Y, 0))); } else // set to smallest zoom level { vr.SetZoom(-1); vr.SetXOffset(0); vr.SetYOffset(0); } // check for correct panning if (vr.GetXOffset() > 0) { vr.SetXOffset(0); } if (vr.GetYOffset() > 0) { vr.SetYOffset(0); } if ((vr.ContentWidth + vr.GetXOffset()) < vr.ContentBox.Width) { int maxOffset = Math.Min(0, vr.ContentBox.Width - vr.ContentWidth); vr.SetXOffset(maxOffset); } if ((vr.ContentHeight + vr.GetYOffset()) < vr.ContentBox.Height) { int maxOffset = Math.Min(0, vr.ContentBox.Height - vr.ContentHeight); vr.SetYOffset(maxOffset); } return true; } return false; }
/// <summary> /// Set the content in minimap mode. Thereby the screen capturing bitmap is shown with blinking frame. /// </summary> /// <param name="vr">ViewRange in which minimap content should be shown.</param> /// <param name="e">EventArgs of the screen capturing event.</param> void setMinimapContent(BrailleIOViewRange vr, CaptureChangedEventArgs e) { int width = vr.ContentBox.Width; int height = vr.ContentBox.Height; Bitmap bmp = new Bitmap(width, height); Graphics graph = Graphics.FromImage(bmp); if (screenBeforeMinimap != null) { BrailleIOViewRange imgvr = screenBeforeMinimap.GetViewRange(VR_CENTER_NAME); if (imgvr == null) { return; } int xoffset = imgvr.GetXOffset(); int yoffset = imgvr.GetYOffset(); int imgWidth = imgvr.ContentWidth; int imgHeight = imgvr.ContentHeight; if (imgWidth > 0 && imgHeight > 0) { // calculate image size for minimap (complete image has to fit into view range) int imgScaledWidth = imgWidth; int imgScaledHeight = imgHeight; double scaleFactorX = 1; double scaleFactorY = 1; if (width != 0 && imgScaledWidth > width) { scaleFactorX = (double)imgWidth / (double)width; if (scaleFactorX != 0) { imgScaledWidth = width; imgScaledHeight = (int)(imgHeight / scaleFactorX); } } if (height != 0 && imgScaledHeight > height) { scaleFactorY = (double)imgScaledHeight / (double)height; if (scaleFactorY != 0) { imgScaledHeight = height; imgScaledWidth = (int)(imgScaledWidth / scaleFactorY); } } // calculate scaling factor from original image to minimap image size MinimapScalingFactor = 1 / (scaleFactorX * scaleFactorY); double zoom = imgvr.GetZoom(); if (zoom > 0) { MinimapScalingFactor = MinimapScalingFactor * zoom; } // calculate position and size of the blinking frame int x = Math.Abs(xoffset) * imgScaledWidth / imgWidth; int y = Math.Abs(yoffset) * imgScaledHeight / imgHeight; int frameWidth = width * imgScaledWidth / imgWidth; int frameHeigth = height * imgScaledHeight / imgHeight; // draw scaled image and blinking frame graph.DrawImage(e.Img, 0, 0, imgScaledWidth, imgScaledHeight); Color frameColor = Color.Black; if (!blinkPinsUp) { frameColor = Color.White; } graph.DrawRectangle(new Pen(frameColor, 2), x, y, frameWidth, frameHeigth); vr.SetBitmap(bmp); } } }
/// <summary> /// Determines whether [is elements bounding box visible in view] [the specified view]. /// </summary> /// <param name="view">The view.</param> /// <param name="shape">The shape.</param> /// <returns> /// <c>true</c> if [is elements bounding box visible in view] [the specified view]; otherwise, <c>false</c>. /// </returns> public static bool IsElementsBoundingBoxVisibleInView(BrailleIOViewRange view, OoShapeObserver shape) { if (view != null && shape != null) { return IsElementsBoundingBoxVisibleInView(GetViewPort(view), shape, Math.Max(0.0000001, view.GetZoom())); } return false; }
/// <summary> /// Determines whether [is elements bounding box visible in view] [the specified view]. /// </summary> /// <param name="view">The view.</param> /// <param name="screenPos">The screen pos.</param> /// <returns> /// <c>true</c> if [is elements bounding box visible in view] [the specified view]; otherwise, <c>false</c>. /// </returns> public static bool IsElementsBoundingBoxVisibleInView(BrailleIOViewRange view, Rectangle screenPos) { if (view != null && !screenPos.IsEmpty) { return IsElementsBoundingBoxVisibleInView(GetViewPort(view), screenPos, Math.Max(0.0000001, view.GetZoom())); } return false; }
/// <summary> /// Switch between minimap and currently visible screen. /// </summary> private void toggleMinimap() { BrailleIOScreen vs = GetVisibleScreen(); if (vs != null) { if (vs.Name.Equals(BS_MINIMAP_NAME)) // exit minimap mode { BrailleIOScreen ms = screenBeforeMinimap; if (ms != null) { BrailleIOViewRange ocvr = vs.GetViewRange(VR_CENTER_NAME); BrailleIOViewRange ncvr = ms.GetViewRange(VR_CENTER_NAME); if (ocvr != null && ncvr != null) { syncContrastSettings(ocvr, ncvr); } } io.HideView(vs.Name); io.ShowView(ms.Name); SetDetailRegionContent(GetLastDetailRegionContent()); } else // show minimap { screenBeforeMinimap = vs; BrailleIOScreen ms = io.GetView(BS_MINIMAP_NAME) as BrailleIOScreen; if (ms != null) { BrailleIOViewRange ocvr = vs.GetViewRange(VR_CENTER_NAME); BrailleIOViewRange ncvr = ms.GetViewRange(VR_CENTER_NAME); if (ocvr != null && ncvr != null) { syncContrastSettings(ocvr, ncvr); } } io.HideView(vs.Name); io.ShowView(BS_MINIMAP_NAME); BrailleIOViewRange vr = vs.GetViewRange(VR_CENTER_NAME); if (vr != null) { SetDetailRegionContent(LL.GetTrans("tangram.lector.wm.zooming.current.short", ((int)(vr.GetZoom() * 100)).ToString())); } } } }
/// <summary> /// Get position of tap on the screen /// </summary> /// <param name="x">x value of tap (on pin device)</param> /// <param name="y">y value of tap (on pin device)</param> /// <param name="vr">touched view range</param> /// <returns>position on the screen</returns> public Point GetTapPositionOnScreen(double x, double y, BrailleIOViewRange vr) { Point p = GetTapPositionInContent(x, y, vr); if (vr != null && p != null) { double zoom = vr.GetZoom(); if (zoom != 0) { int x_old = p.X; int y_old = p.Y; p = new Point((int)Math.Round(x_old / zoom), (int)Math.Round(y_old / zoom)); if (ScreenObserver != null && ScreenObserver.ScreenPos is Rectangle) { Rectangle sp = (Rectangle)ScreenObserver.ScreenPos; p.X += sp.X; p.Y += sp.Y; } System.Diagnostics.Debug.WriteLine("tap screen position: " + p.ToString()); } } return p; }
/// <summary> /// Determines whether [is elements bounding box visible in view] [the specified view]. /// </summary> /// <param name="view">The view.</param> /// <param name="screenPos">The screen pos.</param> /// <returns> /// <c>true</c> if [is elements bounding box visible in view] [the specified view]; otherwise, <c>false</c>. /// </returns> public static bool IsElementsBoundingBoxVisibleInView(BrailleIOViewRange view, Rectangle screenPos) { if (view != null && !screenPos.IsEmpty) { return(IsElementsBoundingBoxVisibleInView(GetViewPort(view), screenPos, Math.Max(0.0000001, view.GetZoom()))); } return(false); }
/// <summary> /// Zooms the given view range to the new zoom level and calculates the new offset out of the old center position. /// </summary> /// <param name="vr">view range that should be zoomed</param> /// <param name="oldZoom">old zoom of the view range</param> /// <param name="newZoom">new zoom</param> /// <returns>true, if zoom was successful</returns> private bool zoom(BrailleIOViewRange vr, double oldZoom, double newZoom) { if (vr != null) { Point oldCenter = new Point(); var oldvrdin = vr.ContentBox; bool zoomToShape = false; Point oldOffset = new Point(vr.GetXOffset(), vr.GetYOffset()); // Prüfung auf größte Zoomstufe if (newZoom > vr.MAX_ZOOM_LEVEL) { if (oldZoom == vr.MAX_ZOOM_LEVEL) { return(false); } newZoom = vr.MAX_ZOOM_LEVEL; } // Prüfung auf kleinste Zoomstufe if (vr.ContentBox.Height >= vr.ContentHeight && vr.ContentBox.Width >= vr.ContentWidth) { if (oldZoom >= newZoom) { return(false); } oldCenter = Point.Empty; // central point of focused element as center for zooming if (OoConnector.Instance != null && OoConnector.Instance.Observer != null) { OoShapeObserver shape = OoConnector.Instance.Observer.GetLastSelectedShape(); if (shape != null) { Rectangle shapeBoundingbox = shape.GetRelativeScreenBoundsByDom(); if (shapeBoundingbox != null) { // calculate shape position and size in pins (relative to document boundings on pin device) Point shapePosition = new Point((int)Math.Round(shapeBoundingbox.X * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Y * vr.GetZoom())); Size shapeSize = new Size((int)Math.Round(shapeBoundingbox.Width * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Height * vr.GetZoom())); Point shapeCenter = new Point(shapePosition.X + shapeSize.Width / 2, shapePosition.Y + shapeSize.Height / 2); oldCenter = new Point(shapeCenter.X, shapeCenter.Y); } } } if (oldCenter != Point.Empty) { zoomToShape = true; } else { oldCenter = new Point( (int)Math.Round(((double)vr.ContentWidth / 2) + (vr.GetXOffset() * -1)), (int)Math.Round(((double)vr.ContentHeight / 2) + (vr.GetYOffset() * -1)) ); } } else { oldCenter = Point.Empty; // central point of focused element as center for zooming if (OoConnector.Instance != null && OoConnector.Instance.Observer != null) { OoShapeObserver shape = OoConnector.Instance.Observer.GetLastSelectedShape(); if (shape != null) { Rectangle shapeBoundingbox = shape.GetRelativeScreenBoundsByDom(); if (shapeBoundingbox != null) { // calculate shape position and size in pins (relative to document boundings on pin device) Point shapePosition = new Point((int)Math.Round(shapeBoundingbox.X * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Y * vr.GetZoom())); Size shapeSize = new Size((int)Math.Round(shapeBoundingbox.Width * vr.GetZoom()), (int)Math.Round(shapeBoundingbox.Height * vr.GetZoom())); Point shapeCenter = new Point(shapePosition.X + shapeSize.Width / 2, shapePosition.Y + shapeSize.Height / 2); oldCenter = new Point(shapeCenter.X, shapeCenter.Y); } } } if (oldCenter != Point.Empty) { zoomToShape = true; } else { // central point of center region as center for zooming oldCenter = new Point( (int)Math.Round(((double)oldvrdin.Width / 2) + (vr.GetXOffset() * -1)), (int)Math.Round(((double)oldvrdin.Height / 2) + (vr.GetYOffset() * -1)) ); } } double zoomDivRatio = newZoom / oldZoom; if (newZoom > 0 && (vr.ContentBox.Height <= vr.ContentHeight * zoomDivRatio || vr.ContentBox.Width <= vr.ContentWidth * zoomDivRatio)) { Point newCenter = new Point( (int)Math.Round(oldCenter.X * zoomDivRatio), (int)Math.Round(oldCenter.Y * zoomDivRatio) ); Point newOffset = new Point(); if (zoomToShape) { newOffset = new Point(oldOffset.X + (oldCenter.X - newCenter.X), oldOffset.Y + (oldCenter.Y - newCenter.Y)); } else { newOffset = new Point( (int)Math.Round((newCenter.X - ((double)oldvrdin.Width / 2)) * -1), (int)Math.Round((newCenter.Y - ((double)oldvrdin.Height / 2)) * -1) ); } vr.SetZoom(newZoom); vr.MoveTo(new Point(Math.Min(newOffset.X, 0), Math.Min(newOffset.Y, 0))); } else // set to smallest zoom level { vr.SetZoom(-1); vr.SetXOffset(0); vr.SetYOffset(0); } // check for correct panning if (vr.GetXOffset() > 0) { vr.SetXOffset(0); } if (vr.GetYOffset() > 0) { vr.SetYOffset(0); } if ((vr.ContentWidth + vr.GetXOffset()) < vr.ContentBox.Width) { int maxOffset = Math.Min(0, vr.ContentBox.Width - vr.ContentWidth); vr.SetXOffset(maxOffset); } if ((vr.ContentHeight + vr.GetYOffset()) < vr.ContentBox.Height) { int maxOffset = Math.Min(0, vr.ContentBox.Height - vr.ContentHeight); vr.SetYOffset(maxOffset); } return(true); } return(false); }
/// <summary> /// Determines whether [is elements bounding box visible in view] [the specified view]. /// </summary> /// <param name="view">The view.</param> /// <param name="shape">The shape.</param> /// <returns> /// <c>true</c> if [is elements bounding box visible in view] [the specified view]; otherwise, <c>false</c>. /// </returns> public static bool IsElementsBoundingBoxVisibleInView(BrailleIOViewRange view, OoShapeObserver shape) { if (view != null && shape != null) { return(IsElementsBoundingBoxVisibleInView(GetViewPort(view), shape, Math.Max(0.0000001, view.GetZoom()))); } return(false); }