/// <summary> /// Returns a value indicating whether a point is inside the bounding box of the element. /// </summary> /// <param name="element"></param> /// <param name="pointRelativeToElement"></param> /// <returns></returns> public static bool ContainsPoint(this FrameworkElement element, Point pointRelativeToElement) { //TODO: Silverlight allows more complex geometries than Rectangle. Rect rect = new Rect { X = 0, Y = 0, Width = element.ActualWidth, Height=element.ActualHeight }; return rect.Contains(pointRelativeToElement); }
/// <summary> /// Return wheter the mouse is over a control /// </summary> /// <param name="s"></param> /// <param name="e"></param> /// <returns>True if the mouse is over a control, false otherwise</returns> internal static bool IsMouseOver(FrameworkElement s, System.Windows.Input.MouseEventArgs e) { Rect bounds = new Rect(0, 0, s.ActualWidth, s.ActualHeight); if (bounds.Contains(e.GetPosition(s))) return true; return false; }
public static bool LineIntersectsRect(Point p1, Point p2, Rect r) { return LineIntersectsLine(p1, p2, new Point(r.X, r.Y), new Point(r.X + r.Width, r.Y)) || LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y), new Point(r.X + r.Width, r.Y + r.Height)) || LineIntersectsLine(p1, p2, new Point(r.X + r.Width, r.Y + r.Height), new Point(r.X, r.Y + r.Height)) || LineIntersectsLine(p1, p2, new Point(r.X, r.Y + r.Height), new Point(r.X, r.Y)) || (r.Contains(p1) && r.Contains(p2)); }
private static bool IsInView(FrameworkElement element, FrameworkElement container) { if (element == null || element.Visibility == Visibility.Collapsed) { return false; } var bounds = element.TransformToVisual(container).TransformBounds(new Rect(0, 0, element.ActualWidth, element.ActualHeight)); var rect = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight); return rect.Contains(new Point(bounds.X, bounds.Y)) || rect.Contains(new Point(bounds.X, bounds.Y + bounds.Height)); }
private bool IsItemVisible(FrameworkElement element, FrameworkElement container) { if (!element.IsVisible) { return(false); } System.Windows.Rect bounds = element.TransformToAncestor(container).TransformBounds(new System.Windows.Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight)); var rect = new System.Windows.Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight); return(rect.Contains(bounds.TopLeft) || rect.Contains(bounds.BottomRight)); }
private static bool FitIntoScreen(Rect workArea, Rect formSize, out Rect newFormSize) { var hasChanged = false; newFormSize = formSize == Rect.Empty ? new Rect() : formSize; if (!workArea.Contains(formSize)) { // limiting size guarantees form fits into screen newFormSize.Width = Math.Min(newFormSize.Width, workArea.Width); newFormSize.Height = Math.Min(newFormSize.Height, workArea.Height); if (newFormSize.Right > workArea.Right) { newFormSize.Offset(workArea.Right - newFormSize.Right, 0); hasChanged = true; } else if (newFormSize.Left < workArea.Left) { newFormSize.Offset(workArea.Left - newFormSize.Left, 0); hasChanged = true; } if (newFormSize.Top < workArea.Top) { newFormSize.Offset(0, workArea.Top - newFormSize.Top); hasChanged = true; } else if (newFormSize.Bottom > workArea.Bottom) { newFormSize.Offset(0, workArea.Bottom - newFormSize.Bottom); hasChanged = true; } } return hasChanged; }
public static bool detCursorSelection(Canvas rel, Point relPos, out UIElement result) { var list = new System.Collections.Generic.SortedList<int, UIElement>(); foreach (UIElement ue in rel.Children) { var ta = ue.TransformToAncestor(rel); var p = ta.Transform(new Point(0, 0)); var r = new Rect(p, ue.RenderSize); if (r.Contains(relPos)) try { list.Add(Canvas.GetZIndex(ue), ue); } catch (Exception) { } } if (list.Count != 0) { var pr = list.Keys.Max(); result = list[pr]; return true; } else { result = null; return false; } }
public StateStationActivityVm GetUnderlyingStateStationActivity(Point mouse) { var states = _parentWindowVm.States.Where(x => x.ShowDetails && x.Config != null); foreach (var state in states) { TreeItemVm station; if(_parentWindowVm.ShowAllMachines) { station = state.Config.ContentsList.SingleOrDefault(x => x.IsExpanded); } else { station = state.Config.ContentsList.SingleOrDefault(x => x.IsExpanded && (x.Containment as StationVm).StationMachines.Any(y => y.Machine.Id == this.ContentData.Id)); } if (station == null) continue; var activity = station.ContentsList.SingleOrDefault(x => x.IsExpanded) as StateStationActivityVm; if (activity == null) continue; if (activity.ContentsList.Any(ssa => ssa.Containment.Id == ContentData.Id && !ssa.IsDropIndicator)) continue; Rect r = new Rect(state.Location.X, state.Location.Y, state.Width, state.Height); if (r.Contains(mouse.X, mouse.Y)) return activity; } return null; }
private void TickDragScroll(object sender, EventArgs e) { bool isDone = true; if (this.IsLoaded) { Rect bounds = new Rect(RenderSize); Point p = MouseUtilities.GetMousePosition(this); if (bounds.Contains(p)) { if (p.Y < s_dragMargin) { DragScroll(DragDirection.Up); isDone = false; } else if (p.Y > RenderSize.Height - s_dragMargin) { DragScroll(DragDirection.Down); isDone = false; } } } if (isDone) { CancelDrag(); } }
protected override void OnManipulationDelta(System.Windows.Input.ManipulationDeltaEventArgs e) { Rectangle rectToMove = e.OriginalSource as Rectangle; Matrix rectsMatrix = ((MatrixTransform)rectToMove.RenderTransform).Matrix; rectsMatrix.RotateAt(e.DeltaManipulation.Rotation, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.X, e.ManipulationOrigin.X, e.ManipulationOrigin.Y); rectsMatrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); rectToMove.RenderTransform = new MatrixTransform(rectsMatrix); Rect containingRect = new Rect(((FrameworkElement)e.ManipulationContainer).RenderSize); Rect shapeBounds = rectToMove.RenderTransform.TransformBounds( new Rect(rectToMove.RenderSize)); if (e.IsInertial && !containingRect.Contains(shapeBounds)) { e.Complete(); } e.Handled = true; //base.OnManipulationDelta(e); }
public int[] GetPointsInRect(Rect rect) { var query = from i in Enumerable.Range(0, points.Count) where rect.Contains(points[i]) select i; return query.ToArray(); }
public static bool IsContained(this Rect @this, Rect other, int tolerance) { other = new Rect(other.X - tolerance, other.Y - tolerance, other.Width + (tolerance * 2), other.Height + (tolerance * 2)); return other.Contains(@this); }
public override Cursor GetCursor(Point point, double actualWidht, double actualHeight) { var topLeft = new Rect(0, 0, EdgeSize - GlowSize, actualHeight); var topRight = new Rect(actualWidht - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, actualHeight); return topLeft.Contains(point) ? Cursors.SizeNWSE : topRight.Contains(point) ? Cursors.SizeNESW : Cursors.SizeNS; }
public override HitTestValues GetHitTestValue(Point point, double actualWidht, double actualHeight) { var topLeft = new Rect(0, 0, EdgeSize - GlowSize, actualHeight); var topRight = new Rect(actualWidht - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, actualHeight); return topLeft.Contains(point) ? HitTestValues.HTTOPLEFT : topRight.Contains(point) ? HitTestValues.HTTOPRIGHT : HitTestValues.HTTOP; }
public override HitTestValues GetHitTestValue(Point point, double actualWidht, double actualHeight) { var bottomLeft = new Rect(0, 0, EdgeSize - GlowSize, actualHeight); var bottomRight = new Rect(actualWidht - EdgeSize + GlowSize, 0, EdgeSize - GlowSize, actualHeight); return bottomLeft.Contains(point) ? HitTestValues.HTBOTTOMLEFT : bottomRight.Contains(point) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTBOTTOM; }
public override HitTestValues GetHitTestValue(Point point, double actualWidht, double actualHeight) { var leftTop = new Rect(0, 0, actualWidht, EdgeSize); var leftBottom = new Rect(0, actualHeight - EdgeSize, actualWidht, EdgeSize); return leftTop.Contains(point) ? HitTestValues.HTTOPLEFT : leftBottom.Contains(point) ? HitTestValues.HTBOTTOMLEFT : HitTestValues.HTLEFT; }
public static bool ContainsPoint(this UserControl uc,Point p) { double x = Canvas.GetLeft(uc); double y = Canvas.GetTop(uc); double width = uc.Width; double height = uc.Height; Rect r = new Rect(x, y, width, height); return r.Contains(p); }
public override HitTestValues GetHitTestValue(Point point, double actualWidht, double actualHeight) { var rightTop = new Rect(0, 0, actualWidht, EdgeSize); var rightBottom = new Rect(0, actualHeight - EdgeSize, actualWidht, EdgeSize); return rightTop.Contains(point) ? HitTestValues.HTTOPRIGHT : rightBottom.Contains(point) ? HitTestValues.HTBOTTOMRIGHT : HitTestValues.HTRIGHT; }
public override Cursor GetCursor(Point point, double actualWidht, double actualHeight) { var rightTop = new Rect(0, 0, actualWidht, EdgeSize); var rightBottom = new Rect(0, actualHeight - EdgeSize, actualWidht, EdgeSize); return rightTop.Contains(point) ? Cursors.SizeNESW : rightBottom.Contains(point) ? Cursors.SizeNWSE : Cursors.SizeWE; }
public static bool IsMouseMoveDrag( Point initialPosition, Point currentPosition ) { Rect dragRect = new Rect( initialPosition.X - SystemParameters.MinimumHorizontalDragDistance, initialPosition.Y - SystemParameters.MinimumVerticalDragDistance, SystemParameters.MinimumHorizontalDragDistance * 2, SystemParameters.MinimumVerticalDragDistance * 2 ); return !dragRect.Contains( currentPosition ); }
private Point? hitTestAxis(Point point) { var margin = 2.5; foreach (var pt in LinkPolyLine.Points) { var r = new Rect(pt.X - margin, pt.Y - margin, margin * 2, margin * 2); if (r.Contains(point)) return pt; } return null; }
internal DockPaneBase GetChildAtPoint(Point point) { var pane = ((DockBayLayoutEngine)LayoutEngine).OwnNodes .Select(l => (DockPaneBase)l.Target).FirstOrDefault(p => { var pt = p.TranslatePoint(new Point(p.ContentLeft, p.ContentTop), this); var rect = new Rect(pt, new Size(p.ContentWidth, p.ContentHeight)); return rect.Contains(point); }); return pane; }
public void MoveTo(Point to) { position = to; position.Offset(-3, -1); InvalidateArrange(); // If we were given a clip visual, hide the triangle, which are totally outside of it if (ClippingVisual != null) { var clipping = new Rect( ClippingVisual.PointToScreen(new Point(-4, -4)), ClippingVisual.PointToScreen(new Point(ClippingVisual.ActualWidth + 4, ClippingVisual.ActualHeight + 4))); var testPt = PointToScreen(position); topTriangle.Visibility = clipping.Contains(testPt) ? Visibility.Visible : Visibility.Collapsed; testPt = PointToScreen(new Point(position.X, position.Y + Height + 2)); bottomTriangle.Visibility = clipping.Contains(testPt) ? Visibility.Visible : Visibility.Collapsed; } (Parent as AdornerLayer).Update(); }
private void UpdateSelection() { Rect rubberBand = new Rect(StartPoint.Value, endPoint.Value); foreach (DesignerItem designerItem in DesignerCanvas.Items) if (designerItem.IsEnabled) { Rect itemRect = designerItem.ContentBounds; designerItem.IsSelected = rubberBand.Contains(itemRect); //Rect itemBounds = designerItem.TransformToAncestor(DesignerCanvas).TransformBounds(itemRect); //designerItem.IsSelected = rubberBand.Contains(itemBounds); } }
/// <summary> /// Determines whether the specified element contains the point. /// </summary> /// <param name="element">This FrameworkElement.</param> /// <param name="point">The point to check.</param> /// <param name="origin">Relative origin (optional).</param> /// <returns><c>true</c> if the specified element contains the point; otherwise, <c>false</c>.</returns> public static bool ContainsPoint(this FrameworkElement element, Point point, UIElement origin = null) { bool result = false; if (element != null) { Point elementOrigin = (origin == null) ? new Point(0, 0) : element.GetRelativePosition(origin); Rect rect = new Rect(elementOrigin, new Size(element.ActualWidth, element.ActualHeight)); result = rect.Contains(point); } return result; }
public static bool inRectangle(double x, double y) { Rect theRectangle = new Rect(); theRectangle.Location = new Point(1, -1); theRectangle.Size = new Size(6, 2); bool doesContain = theRectangle.Contains(new Point((double)x, (double)y)); return doesContain; }
public virtual UIItemCollection ItemsWithin(Rect bounds, ActionListener actionListener) { var collection = new UIItemCollection(); List<AutomationElement> descendants = Finder.Descendants(AutomationSearchCondition.All); foreach (AutomationElement automationElement in descendants) { if (!bounds.Contains(automationElement.Current.BoundingRectangle)) continue; var factory = new DictionaryMappedItemFactory(); collection.Add(factory.Create(automationElement, actionListener)); } return collection; }
public StateConfigVm GetUnderlyingStateConfig(Point mouse) { var states = _parentWindowVm.States.Where(x => x.ShowDetails && x.Config != null); foreach (var state in states) { if (state.Config.ContentsList.Any(s => s.Containment.Id == ContentData.Id && !s.IsDropIndicator)) continue; Rect r = new Rect(state.Location.X, state.Location.Y, state.Width, state.Height); if (r.Contains(mouse.X, mouse.Y)) return state.Config; } return null; }
private void Slider_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { var slider = (Slider)sender; if (slider.IsMouseCaptured) { // If the point is outside of the control, clear the hover state. Rect rcSlider = new Rect(0, 0, slider.ActualWidth, slider.ActualHeight); if (!rcSlider.Contains(e.GetPosition(slider))) { VisualStateManager.GoToState((FrameworkElement)sender, "Normal", true); } ((Slider)sender).ReleaseMouseCapture(); e.Handled = true; } }
public StateStationVm GetUnderlyingStateStation(Point mouse) { var states = _parentWindowVm.States.Where(x => x.ShowDetails && x.Config != null); foreach (var state in states) { var station = state.Config.ContentsList.SingleOrDefault(x => x.IsExpanded) as StateStationVm; if (station == null) continue; /*if (station.ContentsList.Any(ss => ss.Containment.Id == ContentData.Id && !ss.IsDropIndicator)) continue;*/ Rect r = new Rect(state.Location.X, state.Location.Y, state.Width, state.Height); if (r.Contains(mouse.X, mouse.Y)) return station; } return null; }
void LayoutRoot_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { Point pos = e.GetPosition(this); var transform = ContentLayout.TransformToVisual(LayoutRoot); var origin = transform.Transform(new Point(0,0)); Rect r = new Rect(origin.X, origin.Y, ContentLayout.Width, ContentLayout.Height); if (!r.Contains(pos)) { var p = this.Parent as Popup; if (p != null) { p.Child = null; p.IsOpen = false; } } }
protected override void OnPreviewTouchDown(TouchEventArgs e) { base.OnPreviewTouchDown(e); var expandRect = new System.Windows.Rect(this.Width * 0.9, 50, ExpandBitmap.PixelWidth, ExpandBitmap.PixelHeight); if (expandRect.Contains(e.GetTouchPoint(this).Position)) { this.IsManipulationEnabled = !this.IsManipulationEnabled; if (IsManipulationEnabled) { BeginTransform(); } else { EndTransform(); } e.Handled = true; } }
/// <summary> /// Common hittest method that invoked by both touch event handler and mouse event handler. /// </summary> /// <param name="point">The touched/clicked point</param> private void DoHitTest(Point point) { if (this._dataCenters != null) { VisualTreeHelper.HitTest(this.viewport, null, new HitTestResultCallback(target => { RayMeshGeometry3DHitTestResult result = target as RayMeshGeometry3DHitTestResult; if (result != null) { // Calculate the hit point using barycentric coordinates formula: // p = p1 * w1 + p2 * w2 + p3 * w3. // For more information, please refer to http://en.wikipedia.org/wiki/Barycentric_coordinates_%28mathematics%29. Point p1 = result.MeshHit.TextureCoordinates[result.VertexIndex1]; Point p2 = result.MeshHit.TextureCoordinates[result.VertexIndex2]; Point p3 = result.MeshHit.TextureCoordinates[result.VertexIndex3]; double hitX = p1.X * result.VertexWeight1 + p2.X * result.VertexWeight2 + p3.X * result.VertexWeight3; double hitY = p1.Y * result.VertexWeight1 + p2.Y * result.VertexWeight2 + p3.Y * result.VertexWeight3; Point pointHit = new Point(hitX * _imageWidth, hitY * _imageHeight); // If a data center circle is hit, display the information. foreach (DataCenter dc in this._dataCenters) { System.Windows.Rect bound = new System.Windows.Rect(dc.Bound.X, dc.Bound.Y, dc.Bound.Width, dc.Bound.Height); if (bound.Contains(pointHit)) { this.InfoTextBox.Text = "You've just touched the " + dc.Name + " data center!"; Storyboard sb = this.Resources["sb"] as Storyboard; if (sb != null) { sb.Begin(); } return(HitTestResultBehavior.Stop); } } } return(HitTestResultBehavior.Continue); }), new PointHitTestParameters(point)); } }
private void UpdateOpacityMask(UIElement uieChild) { if (uieChild == null) { return; } System.Windows.Rect scrollViewerRectangle = this.GetScrollViewerRectangle(); if (scrollViewerRectangle == System.Windows.Rect.Empty) { return; } System.Windows.Rect childRectangle = this.GetChildRectangle(uieChild); if (scrollViewerRectangle.Contains(childRectangle)) { uieChild.OpacityMask = null; return; } double num = this.PartlyVisiblePortion_OverflowToLeft(uieChild); double num2 = this.PartlyVisiblePortion_OverflowToRight(uieChild); if (num < 1.0 && num2 < 1.0) { uieChild.OpacityMask = new LinearGradientBrush(ScrollableTabPanel._gscOpacityMaskStops_TransparentOnLeftAndRight, new System.Windows.Point(0.0, 0.0), new System.Windows.Point(1.0, 0.0)); return; } if (num < 1.0) { uieChild.OpacityMask = new LinearGradientBrush(ScrollableTabPanel._gscOpacityMaskStops_TransparentOnLeft, new System.Windows.Point(1.0 - num, 0.0), new System.Windows.Point(1.0, 0.0)); return; } if (num2 < 1.0) { uieChild.OpacityMask = new LinearGradientBrush(ScrollableTabPanel._gscOpacityMaskStops_TransparentOnRight, new System.Windows.Point(0.0, 0.0), new System.Windows.Point(num2, 0.0)); return; } uieChild.OpacityMask = null; }
bool CheckMouseInSensitiveArea(double x, double y) { return(DockedSensitiveArea.Contains(new Point(x, y))); }
private void DoRender(IntPtr pIDXGISurface, bool dunnoWhatThisIsFor) { if (pIDXGISurface != m_pIDXGISurfacePreviousNoRef) { m_pIDXGISurfacePreviousNoRef = pIDXGISurface; // Create the render target Surface dxgiSurface = new Surface(pIDXGISurface); SurfaceDescription sd = dxgiSurface.Description; RenderTargetProperties rtp = new RenderTargetProperties( RenderTargetType.Default, new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied), 96, 96, // Force bitmap rendering if you want it to work on remote desktop connections RenderTargetUsage.None, FeatureLevel.Level_DEFAULT); try { _renderTarget = new RenderTarget(_d2dFactory, dxgiSurface, rtp); } catch (Exception) { return; } // Clear the surface to transparent //_renderTarget.BeginDraw(); //_renderTarget.Clear(new ColorF(1, 1, 1, 0)); //_renderTarget.EndDraw(); _isValid = true; } if (PrimitiveTransform == null || PrimitiveList == null) { return; } _renderTarget.BeginDraw(); _renderTarget.Clear(new SharpDX.Mathematics.Interop.RawColor4(1, 1, 1, 0)); foreach (IChartRendererD2D primitive in PrimitiveList) { primitive.RenderFilledElements(this, ChartDataRange, PrimitiveTransform); } foreach (IChartRendererD2D primitive in PrimitiveList) { primitive.RenderUnfilledElements(this, ChartDataRange, PrimitiveTransform); } // Now render the points System.Windows.Rect bounds = new System.Windows.Rect(-3, -3, _canvasRect.Width + 6, _canvasRect.Height + 6); foreach (ChartPrimitive primitive in PrimitiveList) { if (primitive.ShowPoints) { var brush = new SolidColorBrush(RenderTarget, primitive.PointColor.ToD2D()); Ellipse ellipse = new Ellipse(new SharpDX.Mathematics.Interop.RawVector2(0, 0), 2, 2); foreach (Point point in primitive.Points) { Point transformedPoint = PrimitiveTransform.Transform(point); if (bounds.Contains(transformedPoint)) { ellipse.Point = transformedPoint.ToD2D(); RenderTarget.DrawEllipse(ellipse, brush, 1); } } } } _renderTarget.EndDraw(); }
private void CheckMouseOver(object?sender, EventArgs e) { if (this.mouseOverWindows.Count == 0) { return; } bool isOver = false; IEnumerable <Window> windows = this.mouseOverWindows.Where(w => w.IsVisible && w.Opacity > 0); Point?cursor = null; // Window.IsMouseOver is false if the mouse is over the window border, check if that's the case. foreach (Window window in windows) { if (window.IsMouseOver) { isOver = true; break; } cursor ??= PresentationSource.FromVisual(window)?.CompositionTarget.TransformFromDevice .Transform(WindowMovement.GetCursorPos()); if (cursor is not null) { System.Windows.Rect rc = window.GetRect(); rc.Inflate(10, 10); if (rc.Contains(cursor.Value)) { isOver = true; if (this.mouseTimer is null) { // Keep an eye on the current position. this.mouseTimer = new DispatcherTimer(DispatcherPriority.Input) { Interval = TimeSpan.FromMilliseconds(100), }; this.mouseTimer.Tick += this.CheckMouseOver; this.mouseTimer.Start(); } break; } } } if (!isOver) { this.mouseTimer?.Stop(); this.mouseTimer = null; } if (this.mouseOver != isOver) { this.mouseOver = isOver; if (isOver) { this.MouseEnter?.Invoke(sender, new EventArgs()); } else { this.MouseLeave?.Invoke(sender, new EventArgs()); } } }