private void ResizeDisplayViewport( DragDeltaEventArgs e, ResizeEdge relativeTo ) { // get the existing viewport rect and scale Rect viewportRect = _viewFinderDisplay.ViewportRect; double scale = _viewFinderDisplay.Scale; // ensure that we stay within the bounds of the VisualBrush double x = Math.Max( _resizeViewportBounds.Left, Math.Min( _resizeDraggingPoint.X + e.HorizontalChange, _resizeViewportBounds.Right ) ); double y = Math.Max( _resizeViewportBounds.Top, Math.Min( _resizeDraggingPoint.Y + e.VerticalChange, _resizeViewportBounds.Bottom ) ); // get the selected region in the coordinate space of the content Point anchorPoint = new Point( _resizeAnchorPoint.X / scale, _resizeAnchorPoint.Y / scale ); Vector newRegionVector = new Vector( ( x - _resizeAnchorPoint.X ) / scale / _viewboxFactor, ( y - _resizeAnchorPoint.Y ) / scale / _viewboxFactor ); Rect region = new Rect( anchorPoint, newRegionVector ); // now translate the region from the coordinate space of the content // to the coordinate space of the content presenter region = new Rect( _content.TranslatePoint( region.TopLeft, _contentPresenter ), _content.TranslatePoint( region.BottomRight, _contentPresenter ) ); // calculate actual scale value double aspectX = _content.DesiredSize.Width / region.Width; double aspectY = _content.DesiredSize.Height / region.Height; scale = aspectX < aspectY ? aspectX : aspectY; // scale relative to the anchor point this.ZoomTo( scale, anchorPoint, false, false ); }
protected void OnMouseLeftUp(MouseEventArgs e) { dragging = false; resizeEdge = ResizeEdge.None; }
protected void OnMouseLeftDown(MouseEventArgs e) { Vector2 mousePosition = GetPositionInScene(new Vector2(e.Location)); // unselect all items foreach (ObsSceneItem item in scene.Items) item.Selected = false; const float edgeSize = 0.01f; // select item under the mouse cursor using (ObsSceneItem mouseItem = GetItemAtPosition(mousePosition, edgeSize)) { if (mouseItem == null || dragging) return; mouseItem.Selected = true; Vector3 transformedPos = Vector3.GetTransform( new Vector3(mousePosition), mouseItem.BoxTransform.GetInverse()); bool edgeTop = transformedPos.y <= edgeSize; bool edgeBottom = transformedPos.y >= 1.0f-edgeSize; bool edgeLeft = transformedPos.x <= edgeSize; bool edgeRight = transformedPos.x >= 1.0f-edgeSize; bool center = !edgeTop && !edgeBottom && !edgeLeft && !edgeRight; if (center) { resizeEdge = ResizeEdge.None; Cursor.Current = Cursors.Hand; dragging = true; dragLastPosition = mousePosition; dragStartPosition = mousePosition; } else { dragLastPosition = mousePosition; dragStartPosition = mousePosition; itemLastPosition = mouseItem.Position; itemLastBounds = mouseItem.Bounds; resizeEdge = ResizeEdge.None; if (edgeTop) { Cursor.Current = Cursors.SizeNS; resizeEdge |= ResizeEdge.Top; } else if (edgeBottom) { Cursor.Current = Cursors.SizeNS; resizeEdge |= ResizeEdge.Bottom; } if (edgeLeft) { Cursor.Current = Cursors.SizeWE; resizeEdge |= ResizeEdge.Left; } else if (edgeRight) { Cursor.Current = Cursors.SizeWE; resizeEdge |= ResizeEdge.Right; } } if (mouseItem == hoveredItem) SetHoveredItem(null); } }
private void ResizeDisplayViewport(DragDeltaEventArgs e, ResizeEdge relativeTo) { return;// NOT IMPLEMENTED // get the existing viewport rect and scale /* var viewportRect = _viewFinderDisplay.ViewportRect; var scale = _viewFinderDisplay.Scale; // ensure that we stay within the bounds of the VisualBrush var x = Math.Max(_resizeViewportBounds.Left, Math.Min(_resizeDraggingPoint.X + e.HorizontalChange, _resizeViewportBounds.Right)); var y = Math.Max(_resizeViewportBounds.Top, Math.Min(_resizeDraggingPoint.Y + e.VerticalChange, _resizeViewportBounds.Bottom)); // get the selected region in the coordinate space of the content var anchorPoint = new Point(_resizeAnchorPoint.X / scale, _resizeAnchorPoint.Y / scale); var newRegionVector = new Vector((x - _resizeAnchorPoint.X) / scale / _viewboxFactor, (y - _resizeAnchorPoint.Y) / scale / _viewboxFactor); var region2 = new Rect(anchorPoint, newRegionVector); // now translate the region from the coordinate space of the content // to the coordinate space of the content presenter var region = new Rect( (Content as UIElement).TranslatePoint(region2.TopLeft, _presenter), (Content as UIElement).TranslatePoint(region2.BottomRight, _presenter)); // calculate actual scale value var aspectX = RenderSize.Width / region.Width; var aspectY = RenderSize.Height / region.Height; scale = aspectX < aspectY ? aspectX : aspectY; // scale relative to the anchor point ZoomToInternal(region2); */ }
protected void OnMouseLeftDown(MouseEventArgs e) { Vector2 mousePosition = GetPositionInScene(new Vector2(e.Location)); // unselect all items foreach (ObsSceneItem item in scene.Items) { item.Selected = false; } const float edgeSize = 0.01f; // select item under the mouse cursor using (ObsSceneItem mouseItem = GetItemAtPosition(mousePosition, edgeSize)) { if (mouseItem == null || dragging) { return; } mouseItem.Selected = true; Vector3 transformedPos = Vector3.GetTransform( new Vector3(mousePosition), mouseItem.BoxTransform.GetInverse()); bool edgeTop = transformedPos.y <= edgeSize; bool edgeBottom = transformedPos.y >= 1.0f - edgeSize; bool edgeLeft = transformedPos.x <= edgeSize; bool edgeRight = transformedPos.x >= 1.0f - edgeSize; bool center = !edgeTop && !edgeBottom && !edgeLeft && !edgeRight; if (center) { resizeEdge = ResizeEdge.None; Cursor.Current = Cursors.Hand; dragging = true; dragLastPosition = mousePosition; dragStartPosition = mousePosition; } else { dragLastPosition = mousePosition; dragStartPosition = mousePosition; itemLastPosition = mouseItem.Position; itemLastBounds = mouseItem.Bounds; resizeEdge = ResizeEdge.None; if (edgeTop) { Cursor.Current = Cursors.SizeNS; resizeEdge |= ResizeEdge.Top; } else if (edgeBottom) { Cursor.Current = Cursors.SizeNS; resizeEdge |= ResizeEdge.Bottom; } if (edgeLeft) { Cursor.Current = Cursors.SizeWE; resizeEdge |= ResizeEdge.Left; } else if (edgeRight) { Cursor.Current = Cursors.SizeWE; resizeEdge |= ResizeEdge.Right; } } if (mouseItem == hoveredItem) { SetHoveredItem(null); } } }