/// <summary> /// Move the given view range to the given offset position. /// </summary> /// <param name="viewName">name of the view</param> /// <param name="viewRangeName">name of the view range</param> /// <param name="offset">new offset position</param> /// <returns>true, if view range was moved successfully</returns> public bool MoveToPosition(string viewName, string viewRangeName, Point offset) { if (io == null && io.GetView(viewName) as BrailleIOScreen != null) { return(false); } BrailleIOViewRange vr = ((BrailleIOScreen)io.GetView(viewName)).GetViewRange(viewRangeName); if (vr == null) { return(false); } vr.MoveTo(offset); return(true); }
/// <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> /// 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; }