private static bool _HitTestTriangleFansResult(DataPair pair, LazyArray <Point3F, PointF> pointsTransformed, RectF rectInWpf, bool isFullContain, ref bool flag1, ref bool flag2) { var stopCond = false; var pt1 = pointsTransformed[pair.Start]; for (int i = 2; i < pair.Count; i++) { var pt2 = pointsTransformed[i - 1 + pair.Start]; var pt3 = pointsTransformed[i + pair.Start]; var triangle = new Triangle(pt1, pt2, pt3); if (!isFullContain) { if (rectInWpf.Contains(triangle.P1) || rectInWpf.Contains(triangle.P2) || rectInWpf.Contains(triangle.P3) || triangle.IsPointInside(rectInWpf.TopLeft) || triangle.IsPointInside(rectInWpf.TopRight) || triangle.IsPointInside(rectInWpf.BottomLeft) || triangle.IsPointInside(rectInWpf.BottomRight)) { flag1 = true; stopCond = true; break; } } else { if (!triangle.IsCompletelyInside(rectInWpf)) { flag2 = false; stopCond = true; break; } } } return(stopCond); }
private static bool _HitTestTrianglesResult(IHitTestSource model, DataPair pair, LazyArray <Point3F, PointF> pointsTransformed, RectF rectInWpf, bool isFullContain, ref bool flag1, ref bool flag2) { var stopCond = false; var stride = model.Mode == GLPrimitiveMode.GL_TRIANGLES ? 3 : 1; for (int i = 0; i < pair.Count - 2; i += stride) { var pt1 = pointsTransformed[i + pair.Start]; var pt2 = pointsTransformed[i + 1 + pair.Start]; var pt3 = pointsTransformed[i + 2 + pair.Start]; var triangle = new Triangle(pt1, pt2, pt3); if (!isFullContain) { if (rectInWpf.Contains(triangle.P1) || rectInWpf.Contains(triangle.P2) || rectInWpf.Contains(triangle.P3) || triangle.IsPointInside(rectInWpf.TopLeft) || triangle.IsPointInside(rectInWpf.TopRight) || triangle.IsPointInside(rectInWpf.BottomLeft) || triangle.IsPointInside(rectInWpf.BottomRight)) { flag1 = true; stopCond = true; break; } } else { if (!triangle.IsCompletelyInside(rectInWpf)) { flag2 = false; stopCond = true; break; } } } return(stopCond); }
private static bool _HitTestPointResult(DataPair pair, LazyArray <Point3F, PointF> pointsTransformed, RectF rectInWpf, bool isFullContain, float sensity, ref bool flag1, ref bool flag2) { var stopCond = false; for (int i = 0; i < pair.Count; i++) { var pt = pointsTransformed[i + pair.Start]; if (!isFullContain) { if (rectInWpf.Contains(pt, sensity)) { flag1 = true; stopCond = true; break; } } else { var rect = new RectF(pt, pt); rect.Extents(sensity); if (!rectInWpf.Contains(rect)) { flag2 = false; stopCond = true; break; } } } return(stopCond); }
private TouchableSpan GetTouchableSpan(TextView textView, ISpannable span, MotionEvent e) { var x = (int)e.GetX(); var y = (int)e.GetY(); x -= textView.TotalPaddingLeft; y -= textView.TotalPaddingTop; x += textView.ScrollX; y += textView.ScrollY; var touchedLine = textView.Layout.GetLineForVertical(y); var touchOffset = textView.Layout.GetOffsetForHorizontal(touchedLine, x); _touchBounds.Left = textView.Layout.GetLineLeft(touchedLine); _touchBounds.Top = textView.Layout.GetLineTop(touchedLine); _touchBounds.Right = textView.Layout.GetLineRight(touchedLine); _touchBounds.Bottom = textView.Layout.GetLineBottom(touchedLine); TouchableSpan touchableSpan = null; if (_touchBounds.Contains(x, y)) { var spans = span.GetSpans(touchOffset, touchOffset, Java.Lang.Class.FromType(typeof(TouchableSpan))); touchableSpan = spans.Length > 0 ? (TouchableSpan)spans[0] : null; } return(touchableSpan); }
protected virtual bool OnHitTest(RectF box, Vector2 position, ref HitTestState state) { if (Intangible) { return(false); } if (state.Options.AcceptsMouseInput.HasValue && (AcceptsMouseInput != state.Options.AcceptsMouseInput.Value)) { return(false); } if (state.Options.AcceptsFocus.HasValue && (AcceptsFocus != state.Options.AcceptsFocus.Value)) { return(false); } if (state.Options.RequiresInput && !Enabled) { return(false); } if (!box.Contains(position)) { return(false); } state.Result = this; return(true); }
public bool OnSingleTapConfirmed(Android.Views.MotionEvent e) { if (this.photoViewAttacher == null) { return(false); } ImageView imageView = photoViewAttacher.GetImageView(); if (null != photoViewAttacher.GetOnPhotoTapListener()) { RectF displayRect = photoViewAttacher.GetDisplayRect(); if (null != displayRect) { float x = e.GetX(), y = e.GetY(); if (displayRect.Contains(x, y)) { float xResult = (x - displayRect.Left) / displayRect.Width(); float yResult = (y - displayRect.Top) / displayRect.Height(); photoViewAttacher.GetOnPhotoTapListener().OnPhotoTap(imageView, xResult, yResult); return(true); } } } if (null != photoViewAttacher.GetOnViewTapListener()) { photoViewAttacher.GetOnViewTapListener().OnViewTap(imageView, e.GetX(), e.GetY()); } return(false); }
public bool OnClick(float x, float y) { if (clickRegion != null && clickRegion.Contains(x, y)) { listenerHelper.OnCliCk(pos); return(true); } return(false); }
public bool OnClick(float x, float y) { if (_clickRegion != null && _clickRegion.Contains(x, y)) { Listener?.OnClick(Id, _pos); return(true); } return(false); }
public override void OnTouchDown(GPoint point) { PointF touchPoint = new PointF((float)point.X, (float)point.Y); if (_indicatorRect.Contains(touchPoint)) { View.Text = string.Empty; } }
public override bool OnTouchEvent(TextView widget, ISpannable buffer, MotionEvent e) { if (e.Action == MotionEventActions.Up) { int touchX = (int)e.GetX(); int touchY = (int)e.GetY(); var layout = widget.Layout; int touchedLine = widget.Layout.GetLineForVertical(touchY); int touchOffset = widget.Layout.GetOffsetForHorizontal(touchedLine, touchX); _touchedLineBounds.Left = layout.GetLineLeft(touchedLine); _touchedLineBounds.Top = layout.GetLineTop(touchedLine); _touchedLineBounds.Right = layout.GetLineWidth(touchedLine) + _touchedLineBounds.Left; _touchedLineBounds.Bottom = layout.GetLineBottom(touchedLine); if (_touchedLineBounds.Contains(touchX, touchY)) { object[] spans = buffer.GetSpans(touchOffset, touchOffset, Java.Lang.Class.FromType(typeof(ClickableSpan))); foreach (object span in spans) { if (span is URLSpan) { var spanTarget = (URLSpan)span; if (LinkClicked != null) { switch (spanTarget.URL.Split(':')[0]) { case "taxonid": LinkClicked(widget, new TaxonLinkClickedEventArgs() { TaxonId = int.Parse(spanTarget.URL.Replace("taxonid://", "")) }); break; case "http": case "https": Launcher.OpenAsync(new Uri(spanTarget.URL)); break; } return(true); } } } } return(base.OnTouchEvent(widget, buffer, e)); } else { return(false); } }
public override bool OnTouchEvent(MotionEvent e) { switch (e.ActionMasked) { case MotionEventActions.Down: var x = e.GetX(); var y = e.GetY(); if (rectBar.Contains(x, y)) { if (!rectTouch.Contains(x, y)) { position = (float)Math.Max(0f, Math.Min(1f, (x - rectTouch.Width() / 2) / maxMovement)); } touchX = x; OnBeginTracking?.Invoke(); ShowLabel(metaballRiseDistance); this.Parent.RequestDisallowInterceptTouchEvent(true); return(true); } else { return(false); } case MotionEventActions.Move: var newPos = Math.Max(0f, Math.Min(1f, position + (e.GetX() - touchX) / maxMovement)); System.Diagnostics.Debug.WriteLine("TouchX: " + touchX + "/E.X: " + e.GetX()); touchX = e.GetX(); System.Diagnostics.Debug.WriteLine("Old: " + position + "/New: " + newPos); UpdatePosition((float)newPos); return(true); case MotionEventActions.Up: case MotionEventActions.Cancel: touchX = 0f; OnEndTracking?.Invoke(); HideLabel(); PerformClick(); this.Parent.RequestDisallowInterceptTouchEvent(false); return(true); default: return(false); } ; }
public override void OnTouchUp(GPoint point) { var touchDownPoint = new PointF((float)point.X, (float)point.Y); if (_minusRect.Contains(touchDownPoint) && _pressed) { View.Value -= View.Increment; } if (_plusRect.Contains(touchDownPoint) && _pressed) { View.Value += View.Increment; } _minusRippleEffect.OnTouchUp(point); _plusRippleEffect.OnTouchUp(point); _pressed = false; }
/** * Determines the touched location inside the TextView's text and returns the ClickableSpan found under it (if any). * * @return The touched ClickableSpan or null. */ protected ClickableSpanWithText FindClickableSpanUnderTouch(TextView textView, ISpannable text, MotionEvent e) { // So we need to find the location in text where touch was made, regardless of whether the TextView // has scrollable text. That is, not the entire text is currently visible. var touchX = (int)e.GetX(); var touchY = (int)e.GetY(); // Ignore padding. touchX -= textView.TotalPaddingLeft; touchY -= textView.TotalPaddingTop; // Account for scrollable text. touchX += textView.ScrollX; touchY += textView.ScrollY; var layout = textView.Layout; var touchedLine = layout.GetLineForVertical(touchY); var touchOffset = layout.GetOffsetForHorizontal(touchedLine, touchX); _touchedLineBounds.Left = layout.GetLineLeft(touchedLine); _touchedLineBounds.Top = layout.GetLineTop(touchedLine); _touchedLineBounds.Right = layout.GetLineWidth(touchedLine) + _touchedLineBounds.Left; _touchedLineBounds.Bottom = layout.GetLineBottom(touchedLine); if (_touchedLineBounds.Contains(touchX, touchY)) { // Find any ClickableSpan that lies under the touched area var spans = text.GetSpans(touchOffset, touchOffset, SpanClass); foreach (var span in spans) { if (span is ClickableSpan) { return(ClickableSpanWithText.OfSpan(textView, span as ClickableSpan)); } } // No ClickableSpan found under the touched location. return(null); } // Touch lies outside the line's horizontal bounds where no spans should exist. return(null); }
private static bool _HitTestLinesResult(IHitTestSource model, DataPair pair, LazyArray <Point3F, PointF> pointsTransformed, RectF rectInWpf, bool isFullContain, float sensity, ref bool flag1, ref bool flag2) { var stopCond = false; var cond = pair.Count - 1; var stride = model.Mode == GLPrimitiveMode.GL_LINES ? 2 : 1; var limit = model.Mode == GLPrimitiveMode.GL_LINE_LOOP ? pair.Count : pair.Count - 1; for (int i = 0; i < limit; i += stride) { var index1 = i + pair.Start; var index2 = i + 1 + pair.Start; if (i == cond) { index2 = 0; } var pt1 = pointsTransformed[index1]; var pt2 = pointsTransformed[index2]; var line = new Line(pt1, pt2); var bounds = line.GetBounds(); bounds.Extents(sensity); if (!isFullContain) { if (bounds.IntersectsWith(rectInWpf) && line.HitTest(rectInWpf, sensity)) { flag1 = true; stopCond = true; break; } } else { if (!rectInWpf.Contains(bounds)) { flag2 = false; stopCond = true; break; } } } return(stopCond); }
public List <T> GetComponentsInRect(RectF rect) { List <Point> chunksToCheck = GetChunksInRect(rect); List <T> retList = new List <T>(); foreach (Point chunkPos in chunksToCheck) { if (chunks_.ContainsKey(chunkPos) && chunks_[chunkPos] != null)//TODO use out value { foreach (T component in chunks_[chunkPos]) { if (rect.Contains(component.entity.Position)) { retList.Add(component); } } } } return(retList); }
private bool MoveTrackersIfNeeded(MotionEvent e) { if (_startTouchPoint == null) { return(false); } var update = false; var startX = _startTouchPoint.X; var startY = _startTouchPoint.Y; if (_hueRect.Contains(startX, startY)) { _lastTouchedPanel = PanelHue; _hue = PointToHue(e.GetY()); update = true; } else if (_satValRect.Contains(startX, startY)) { _lastTouchedPanel = PanelSatVal; var result = PointToSatVal(e.GetX(), e.GetY()); _sat = result[0]; _val = result[1]; update = true; } else if (_alphaRect != null && _alphaRect.Contains(startX, startY)) { _lastTouchedPanel = PanelAlpha; _alpha = PointToAlpha((int)e.GetX()); update = true; } return(update); }
internal void DrawRippleEffect(ICanvas canvas, RectF dirtyRect, IButton button) { if (dirtyRect.Contains(TouchPoint)) { canvas.SaveState(); canvas.ClipRectangle(dirtyRect); canvas.FillColor = Material.Color.White.ToColor().WithAlpha(0.75f); canvas.Alpha = 0.25f; float minimumRippleEffectSize = 0.0f; var rippleEffectSize = minimumRippleEffectSize.Lerp(dirtyRect.Width, AnimationPercent); canvas.FillCircle((float)TouchPoint.X, (float)TouchPoint.Y, rippleEffectSize); canvas.RestoreState(); } }
public override bool OnTouchEvent(MotionEvent e) { if (mController.IsIgnoringTouchEvents) { return(false); } // Prevent ray cast of touch events to actions container GetHitRect(mHitRect); mHitRect.Offset(-ScrollX, -ScrollY); // Applying effects mEffectedHitRect.Set(mHitRect); mController.EffectsMatrix.MapRect(mEffectedHitRect); if (mEffectedHitRect.Contains((int)e.GetX(), (int)e.GetY())) { return(true); } return(base.OnTouchEvent(e)); }
//TODO: Step 5 - Subscribe to touch events in the view public override bool OnTouchEvent(MotionEvent ev) { Log.Debug(GetType().FullName, "Number of touches: {0}", ev.PointerCount); Log.Debug(GetType().FullName, "Touch Type: {0}", ev.Action); float width = _icon.IntrinsicWidth, height = _icon.IntrinsicHeight; //TODO: Step 6 - Detect scale events _scaleDetector.OnTouchEvent(ev); MotionEventActions action = ev.Action & MotionEventActions.Mask; int pointerIndex; switch (action) { case MotionEventActions.Down: _lastTouchX = ev.GetX(); _lastTouchY = ev.GetY(); _activePointerId = ev.GetPointerId(0); break; case MotionEventActions.Move: pointerIndex = ev.FindPointerIndex(_activePointerId); float x = ev.GetX(pointerIndex); float y = ev.GetY(pointerIndex); if (!_scaleDetector.IsInProgress) { // Only move the ScaleGestureDetector isn't already processing a gesture. float deltaX = x - _lastTouchX; float deltaY = y - _lastTouchY; _posX += deltaX; _posY += deltaY; Invalidate(); } _lastTouchX = x; _lastTouchY = y; break; case MotionEventActions.Up: case MotionEventActions.Cancel: // This events occur when something cancels the gesture (for example the // activity going in the background) or when the pointer has been lifted up. // We no longer need to keep track of the active pointer. _activePointerId = InvalidPointerId; break; case MotionEventActions.PointerUp: // We only want to update the last touch position if the the appropriate pointer // has been lifted off the screen. pointerIndex = (int)(ev.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift; int pointerId = ev.GetPointerId(pointerIndex); if (pointerId == _activePointerId) { // This was our active pointer going up. Choose a new // action pointer and adjust accordingly int newPointerIndex = pointerIndex == 0 ? 1 : 0; _lastTouchX = ev.GetX(newPointerIndex); _lastTouchY = ev.GetY(newPointerIndex); _activePointerId = ev.GetPointerId(newPointerIndex); } break; } //Determine if the image is within the touch area if (Math.Abs(_scaleFactor - 1.0f) > 0.001) { width *= _scaleFactor; height *= _scaleFactor; } var rc = new RectF(_posX, _posY, _posX + width, _posY + height); float touchX = ev.GetX(), touchY = ev.GetY(); bool contains = rc.Contains(touchX, touchY); Log.Debug(GetType().FullName, "{0} - ({1},{2}) - CONTAINS: {3}", rc, touchX, touchY, contains); return(true); }
private void HandleClick(float x, float y) { Log.Debug(TAG, $"Click at ({x}, {y})"); if (location == null || currentSubLocationIndex < 0) { return; } SubLocation subLoc = (SubLocation)location.SubLocations[currentSubLocationIndex]; if (subLoc == null) { return; } if (pinPoint != null) { if (pinPointRect != null && pinPointRect.Contains(x, y)) { targetPoint = pinPoint; targetVenue = null; pinPoint = null; pinPointRect = null; DemoApp.Navigation.SetTarget(targetPoint); backView.Visibility = ViewStates.Visible; return; } CancelPin(); return; } if (selectedVenue != null) { if (selectedVenueRect != null && selectedVenueRect.Contains(x, y)) { targetVenue = selectedVenue; targetPoint = null; DemoApp.Navigation.SetTarget(new LocationPoint(location.Id, subLoc.Id, targetVenue.X, targetVenue.Y)); backView.Visibility = ViewStates.Visible; } CancelVenue(); return; } // Check if we touched venue selectedVenue = GetVenueAt(x, y); selectedVenueRect = new RectF(); // Check if we touched zone if (selectedVenue == null) { Zone Z = getZoneAt(x, y); if (Z != null) { selectedZone = (selectedZone == Z) ? null : Z; } } Refresh(); }
// Test if the suggested size fits the control boundaries public int OnTestSize(int suggestedSize, RectF availableSpace) { RectF textRect = new RectF(); paint.TextSize = suggestedSize; ITransformationMethod transformationMethod = targetControl.TransformationMethod; string text = null; if (transformationMethod != null) { text = transformationMethod.GetTransformation(targetControl.Text, targetControl); } // If text is null, use the value from Text object if (text == null) { text = targetControl.Text; } bool singleLine = targetControl.MaxLines == 1; if (singleLine) { textRect.Bottom = paint.FontSpacing; textRect.Right = paint.MeasureText(text); } else { StaticLayout layout = new StaticLayout(text, paint, widthLimit, Alignment.AlignNormal, spacingMult, spacingAdd, true); if (targetControl.MaxLines != NO_LINE_LIMIT && layout.LineCount > targetControl.MaxLines) { return(1); } textRect.Bottom = layout.Height; int maxWidth = -1; int lineCount = layout.LineCount; for (int i = 0; i < lineCount; i++) { int end = layout.GetLineEnd(i); if (i < lineCount - 1 && end > 0 && !IsValidWordWrap(text[end - 1], text[end])) { return(1); } if (maxWidth < layout.GetLineRight(i) - layout.GetLineLeft(i)) { maxWidth = (int)layout.GetLineRight(i) - (int)layout.GetLineLeft(i); } } textRect.Right = maxWidth; } textRect.OffsetTo(0, 0); if (availableSpace.Contains(textRect)) { return(-1); } return(1); }
private void RasterizeDebugOverlays(ref UIOperationContext context, ref RasterizePassSet passSet, RectF rect) { if (!ShowDebugBoxes && !ShowDebugBreakMarkers && !ShowDebugMargins && !ShowDebugPadding && !ShowDebugBoxesForLeavesOnly) { return; } var mouseIsOver = rect.Contains(context.MousePosition); var alpha = mouseIsOver ? 1.0f : 0.5f; // HACK: Show outlines for controls that don't have any children or contain the mouse position var isLeaf = (((this as IControlContainer)?.Children?.Count ?? 0) == 0) || mouseIsOver; int?layer = null; if (ShowDebugBoxes || (ShowDebugBoxesForLeavesOnly && isLeaf)) { passSet.Above.RasterizeRectangle( rect.Position, rect.Extent, 0f, 1f, Color.Transparent, Color.Transparent, GetDebugBoxColor(context.Depth) * alpha, layer: layer ); } if (!context.Layout.TryGetFlags(LayoutKey, out ControlFlags flags)) { return; } if (ShowDebugMargins) { RasterizeDebugMargins(ref context, ref passSet, ref rect, context.Layout.GetMargins(LayoutKey), 1f, Color.Green, layer); } if (ShowDebugPadding) { RasterizeDebugMargins(ref context, ref passSet, ref rect, context.Layout.GetPadding(LayoutKey), -1f, Color.Yellow, layer); } if (ShowDebugBreakMarkers && mouseIsOver && flags.IsBreak()) { rect = new RectF( new Vector2(rect.Left - 1.5f, rect.Center.Y - 7.5f), new Vector2(6.5f, 15) ); var facingRight = false; Vector2 a = !facingRight ? rect.Extent : rect.Position, b = !facingRight ? new Vector2(rect.Position.X, rect.Center.Y) : new Vector2(rect.Extent.X, rect.Center.Y), c = !facingRight ? new Vector2(rect.Extent.X, rect.Position.Y) : new Vector2(rect.Position.X, rect.Extent.Y); var arrowColor = flags.IsFlagged(ControlFlags.Layout_ForceBreak) ? Color.White : Color.Yellow; passSet.Above.RasterizeTriangle( a, b, c, radius: 0f, outlineRadius: 1f, innerColor: arrowColor * alpha, outerColor: arrowColor * alpha, outlineColor: Color.Black * (alpha * 0.8f) ); } }
private bool isInStickerArea(Sticker sticker, MotionEvent e) { RectF dst = sticker.getSrcImageBound(); return(dst.Contains(e.GetX(), e.GetY())); }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { MouseState mouseState = Mouse.GetState(); #region Graph Rendering Demo _graphs["First Graph"].UpdateGraph((float)Math.Sin(gameTime.TotalGameTime.TotalSeconds) * 50f + 50f); _graphs["Second Graph"].UpdateGraph((float)Math.Sin(gameTime.TotalGameTime.TotalSeconds) * 50f); _graphs["Third Graph"].UpdateGraph((float)Math.Sin(gameTime.TotalGameTime.TotalMilliseconds) * 1f); _graphs["Mouse X Graph"].UpdateGraph((float)mouseState.X); _graphs["Mouse Y Graph"].UpdateGraph((float)mouseState.Y); #endregion #region Animated Sprite Sheet Demo Random rand = new Random(); _explosionRect = new RectF(ScreenManager.GraphicsDevice.Viewport.Width * 0.5f + ScreenManager.GraphicsDevice.Viewport.Width * 0.02f, ScreenManager.GraphicsDevice.Viewport.Height * 0.04f, ScreenManager.GraphicsDevice.Viewport.Width * 0.5f - ScreenManager.GraphicsDevice.Viewport.Width * 0.04f, ScreenManager.GraphicsDevice.Viewport.Height * 0.25f); float size = (float)rand.NextDouble() * 64f + 32f; if (_explosionRect.Contains(new Vector2(mouseState.X, mouseState.Y))) { int k = rand.Next(8); for (int i = 0; i < 16; i++) { _explosionFrames.Add(new RectF(((float)i * 64f) / 1024f, k * 64f / 512f, 62f / 1024f, 62f / 512f)); } Quad quad = new Quad(new Vector2(mouseState.X + (float)(rand.NextDouble() * 50f) - 50f, mouseState.Y + (float)(rand.NextDouble() * 50f) - 50f), 0, size, size, 1.0f, 0.5f, _explostionTextureIndex, Color.White, true); quad.Frames = new List <RectF>(_explosionFrames); quad.AutoLoop = true; _explosionQuads.Add(quad); _explosionFrames.Clear(); } for (int i = 0; i < _explosionQuads.Count; i++) { _explosionQuads[i].CurrentFrame++; if (_explosionQuads.Count > 30) { _explosionQuads.RemoveAt(0); } if (_explosionQuads.Count > 0) { ScreenManager.QuadRenderEngine.Submit(_explosionQuads[i]); } } #endregion base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); }
public void ContainsPoint() { Assert.IsTrue(rectD.Contains(rectD.TopLeft)); Assert.IsTrue(rectD.Contains(rectD.TopRight)); Assert.IsTrue(rectD.Contains(rectD.BottomLeft)); Assert.IsTrue(rectD.Contains(rectD.BottomRight)); Assert.IsTrue(rectD.Contains(3, 4)); Assert.IsFalse(rectD.Contains(0, 1)); Assert.IsTrue(rectF.Contains(rectF.TopLeft)); Assert.IsTrue(rectF.Contains(rectF.TopRight)); Assert.IsTrue(rectF.Contains(rectF.BottomLeft)); Assert.IsTrue(rectF.Contains(rectF.BottomRight)); Assert.IsTrue(rectF.Contains(3, 4)); Assert.IsFalse(rectF.Contains(0, 1)); Assert.IsTrue(rectI.Contains(rectI.TopLeft)); Assert.IsFalse(rectI.Contains(rectI.TopRight)); Assert.IsFalse(rectI.Contains(rectI.BottomLeft)); Assert.IsFalse(rectI.Contains(rectI.BottomRight)); Assert.IsTrue(rectI.Contains(3, 4)); Assert.IsFalse(rectI.Contains(0, 1)); }
private static bool _HitTest(GLPanel3D viewport, RectF rectInWpf, IHitTestSource model, List <RectHitResult> results, bool isFullContain) { if (model is GLModel3DGroup) { var group = model as GLModel3DGroup; if (isFullContain) { foreach (var child in group.Children) { if (!_HitTest(viewport, rectInWpf, child, results, isFullContain)) { return(false); } } if (model.Parent == null) { results.Add(new RectHitResult(model)); } return(true); } else { foreach (var child in group.Children) { if (_HitTest(viewport, rectInWpf, child, results, isFullContain)) { return(true); } } return(false); } } else { //var meshModel = model as GLMeshModel3D; var bounds3D = model.Bounds; var bounds2D = Math3DHelper.Transform(bounds3D, viewport); var sensity = model.Mode == GLPrimitiveMode.GL_POINTS ? model.PointSize / 2 : model.LineWidth; switch (model.Mode) { case GLPrimitiveMode.GL_POINTS: case GLPrimitiveMode.GL_LINES: case GLPrimitiveMode.GL_LINE_LOOP: case GLPrimitiveMode.GL_LINE_STRIP: if (!bounds2D.IsEmpty) { bounds2D.Extents(sensity); } break; } if ((isFullContain && bounds2D.IsEmpty) || rectInWpf.Contains(bounds2D)) { if (!isFullContain || model.Parent == null) { results.Add(new RectHitResult(model)); } return(true); } else { if (!rectInWpf.IntersectsWith(bounds2D)) { return(false); } var flag1 = false; var flag2 = true; var pointsTransformed = new LazyArray <Point3F, PointF>(model.GetHitTestPoints(), p => viewport.Point3DToPointInWpf(p)); switch (model.Mode) { case GLPrimitiveMode.GL_POINTS: { if (model.Pairs == null) { _HitTestPointResult(new DataPair(0, pointsTransformed.Length), pointsTransformed, rectInWpf, isFullContain, sensity, ref flag1, ref flag2); } else { foreach (var pair in model.Pairs) { if (_HitTestPointResult(pair, pointsTransformed, rectInWpf, isFullContain, sensity, ref flag1, ref flag2)) { break; } } } } break; case GLPrimitiveMode.GL_LINES: case GLPrimitiveMode.GL_LINE_LOOP: case GLPrimitiveMode.GL_LINE_STRIP: { if (model.Pairs == null) { _HitTestLinesResult(model, new DataPair(0, pointsTransformed.Length), pointsTransformed, rectInWpf, isFullContain, sensity, ref flag1, ref flag2); } else { foreach (var pair in model.Pairs) { if (_HitTestLinesResult(model, pair, pointsTransformed, rectInWpf, isFullContain, sensity, ref flag1, ref flag2)) { break; } } } } break; case GLPrimitiveMode.GL_TRIANGLES: case GLPrimitiveMode.GL_TRIANGLE_STRIP: { if (model.Pairs == null) { _HitTestTrianglesResult(model, new DataPair(0, pointsTransformed.Length), pointsTransformed, rectInWpf, isFullContain, ref flag1, ref flag2); } else { foreach (var pair in model.Pairs) { if (_HitTestTrianglesResult(model, pair, pointsTransformed, rectInWpf, isFullContain, ref flag1, ref flag2)) { break; } } } } break; case GLPrimitiveMode.GL_TRIANGLE_FAN: { if (model.Pairs == null) { _HitTestTriangleFansResult(new DataPair(0, pointsTransformed.Length), pointsTransformed, rectInWpf, isFullContain, ref flag1, ref flag2); } else { foreach (var pair in model.Pairs) { if (_HitTestTriangleFansResult(pair, pointsTransformed, rectInWpf, isFullContain, ref flag1, ref flag2)) { break; } } } } break; } if (flag1 && !isFullContain) { results.Add(new RectHitResult(model)); return(true); } else if (flag2 && isFullContain) { if (model.Parent == null) { results.Add(new RectHitResult(model)); } return(true); } return(false); } } }