コード例 #1
0
 //dont hit test, these are just overlay graphics
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     if (IsHitTestVisible)
         return base.HitTestCore(hitTestParameters);
     else
         return null;
 }
コード例 #2
0
ファイル: CardScroller.cs プロジェクト: jonbonne/OCTGN
 protected override GeometryHitTestResult HitTestCore
         (GeometryHitTestParameters hitTestParameters)
 {
     var geometry = new RectangleGeometry(VisualTreeHelper.GetDescendantBounds(this));
     return new GeometryHitTestResult
      (this, geometry.FillContainsWithDetail(hitTestParameters.HitGeometry));
 }
コード例 #3
0
ファイル: DrawingCanvas.cs プロジェクト: ittray/LocalDemo
 public List<DrawingVisual> GetVisuals(Geometry region)
 {
     hits.Clear();
     GeometryHitTestParameters parameters = new GeometryHitTestParameters(region);
     HitTestResultCallback callback = new HitTestResultCallback(this.HitTestCallback);
     VisualTreeHelper.HitTest(this, null, callback, parameters);
     return hits;
 }
コード例 #4
0
ファイル: HostVisual.cs プロジェクト: JianwenSun/cc
 /// <summary>
 /// HitTestCore
 /// </summary>
 protected override GeometryHitTestResult HitTestCore(
     GeometryHitTestParameters hitTestParameters)
 {
     //
     // HostVisual never reports itself as being hit. To change this
     // behavior clients should derive from HostVisual and override
     // HitTestCore methods.
     //
     return null;
 }
コード例 #5
0
 /// <summary>
 /// HitTestCore
 /// </summary>
 protected override GeometryHitTestResult HitTestCore(
     GeometryHitTestParameters hitTestParameters)
 {
     //
     // HostVisual never reports itself as being hit. To change this
     // behavior clients should derive from HostVisual and override
     // HitTestCore methods.
     //
     return(null);
 }
コード例 #6
0
        /// <summary>
        /// HitTestCore implements precise hit testing against render contents
        /// </summary>
        protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
        {
            if (hitTestParameters == null)
            {
                throw new ArgumentNullException("hitTestParameters");
            }

            if ((_content != null) && GetHitTestBounds().IntersectsWith(hitTestParameters.Bounds))
            {
                IntersectionDetail intersectionDetail;

                intersectionDetail = _content.HitTestGeometry(hitTestParameters.InternalHitGeometry);
                Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated);

                if (intersectionDetail != IntersectionDetail.Empty)
                {
                    return(new GeometryHitTestResult(this, intersectionDetail));
                }
            }

            return(null);
        }
コード例 #7
0
ファイル: DrawingVisual.cs プロジェクト: JianwenSun/cc
        /// <summary>
        /// HitTestCore implements precise hit testing against render contents
        /// </summary>
        protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
        {                   
            if (hitTestParameters == null)
            {
                throw new ArgumentNullException("hitTestParameters");
            }

            if ((_content != null) && GetHitTestBounds().IntersectsWith(hitTestParameters.Bounds))
            {                 
                IntersectionDetail intersectionDetail;

                intersectionDetail = _content.HitTestGeometry(hitTestParameters.InternalHitGeometry);
                Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated);

                if (intersectionDetail != IntersectionDetail.Empty)
                {
                    return new GeometryHitTestResult(this, intersectionDetail);
                }
                
            }

            return null;
        }
コード例 #8
0
        internal HitTestResultBehavior HitTestGeometry(
            HitTestFilterCallback filterCallback,
            HitTestResultCallback resultCallback,
            GeometryHitTestParameters geometryParams)
        {
            // we do not need parameter checks because they are done in HitTest()
            Geometry clip = VisualClip;
            if (clip != null)
            {
                // HitTest with a Geometry and a clip should hit test with
                // the intersection of the geometry and the clip, not the entire geometry
                IntersectionDetail intersectionDetail = clip.FillContainsWithDetail(geometryParams.InternalHitGeometry);
                
                Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated);
                if (intersectionDetail == IntersectionDetail.Empty)
                {
                    // bail out if there is a clip and this region is not inside
                    return HitTestResultBehavior.Continue;
                }
            }
            
            //
            // Check if the geometry intersects with our hittest bounds.
            // If not, the Visual is not hit-testable at all.

            if (_bboxSubgraph.IntersectsWith(geometryParams.Bounds))
            {
                //
                // Determine if there is a special filter behavior defined for this
                // Visual.
                //

                HitTestFilterBehavior filter = HitTestFilterBehavior.Continue;

                if (filterCallback != null)
                {
                    filter = filterCallback(this);

                    if (filter == HitTestFilterBehavior.ContinueSkipSelfAndChildren)
                    {
                        return HitTestResultBehavior.Continue;
                    }

                    if (filter == HitTestFilterBehavior.Stop)
                    {
                        return HitTestResultBehavior.Stop;
                    }
                }

                //
                // Hit-test against the children.
                //

                int childCount = VisualChildrenCount;

                if (filter != HitTestFilterBehavior.ContinueSkipChildren)
                {
                    for (int i=childCount-1; i>=0; i--)
                    {
                        Visual child = GetVisualChild(i);
                        if (child != null)
                        {
                            // Hit the scollClip bounds first, which are in the child's outer-space.
                            Rect? scrollClip = ScrollableAreaClipField.GetValue(child);
                            if (scrollClip.HasValue)
                            {
                                // Hit-testing with a Geometry and a clip should hit test with
                                // the intersection of the geometry and the clip, not the entire geometry
                                RectangleGeometry rectClip = new RectangleGeometry(scrollClip.Value);
                                IntersectionDetail intersectionDetail = rectClip.FillContainsWithDetail(geometryParams.InternalHitGeometry);
   
                                Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated);
                                if (intersectionDetail == IntersectionDetail.Empty)
                                {
                                    // Skip child if there is a scrollable clip and this region is not inside it.
                                    continue;
                                }
                            }
                            
                            // Transform the geometry below offset and transform.
                            Matrix inv = Matrix.Identity;
                            inv.Translate(-child._offset.X, -child._offset.Y);

                            Transform childTransform = TransformField.GetValue(child);
                            if (childTransform != null)
                            {
                                Matrix m = childTransform.Value;

                                // If we can't invert the transform, the child is not hitable. This makes sense since
                                // the node's rendered content is degnerated, i.e. does not really take up any space.
                                // Skipping the child by continuing the loop.
                                if (!m.HasInverse)
                                {
                                   continue;
                                }

                                // Inverse the transform.
                                m.Invert();

                                // Multiply the inverse and the offset together.
                                // inv = inv * m;
                                MatrixUtil.MultiplyMatrix(ref inv, ref m);
                            }

                            // Push the transform on the geometry params.
                            geometryParams.PushMatrix(ref inv);

                            // Hit-Test against the children.

                            HitTestResultBehavior result =
                                child.HitTestGeometry(filterCallback, resultCallback, geometryParams);

                            // Pop the transform from the geometry params.

                            geometryParams.PopMatrix();

                            // Process the result.
                            if (result == HitTestResultBehavior.Stop)
                            {
                                return HitTestResultBehavior.Stop;
                            }
                        }
                    }
                }

                //
                // Hit-test against the content of the Visual.
                //

                if (filter != HitTestFilterBehavior.ContinueSkipSelf)
                {
                    GeometryHitTestResult hitResult = HitTestCore(geometryParams);

                    if (hitResult != null)
                    {
                        Debug.Assert(resultCallback != null);

                        return resultCallback(hitResult);
                    }
                }
            }

            return HitTestResultBehavior.Continue;
        }
コード例 #9
0
ファイル: Viewport3DVisual.cs プロジェクト: mind0n/hive
 /// <summary>
 ///     Viewport3DVisual does not yet support Geometry hit testing.
 /// </summary>
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     throw new NotSupportedException(SR.Get(SRID.HitTest_Invalid, typeof(GeometryHitTestParameters).Name, this.GetType().Name));
 }
コード例 #10
0
ファイル: Schema.cs プロジェクト: giapdangle/X13.Host
    private uiItem GetVisual(double x, double y) {
      int gs=LogramView.CellSize;

      List<uiItem> objs=new List<uiItem>();
      GeometryHitTestParameters parameters=new GeometryHitTestParameters(new RectangleGeometry(new Rect(x-gs/4, y-gs/4, gs/2, gs/2)));
      VisualTreeHelper.HitTest(this, null, new HitTestResultCallback((hr) => {
        var rez=(GeometryHitTestResult)hr;
        var vis=hr.VisualHit as uiItem;
        if(vis!=null) {
          objs.Add(vis);
        }
        return HitTestResultBehavior.Continue;
      }), parameters);
      uiItem ret=null;
      if(objs.Count>0) {
        ret=objs.FirstOrDefault(z => z is uiPin);
        if(ret==null) {
          ret=objs.FirstOrDefault(z => z is uiWire);
          if(ret==null) {
            ret=objs.FirstOrDefault(z => z is SchemaElement);
          }
        }
      }
      return ret;
    }
コード例 #11
0
ファイル: Schema.cs プロジェクト: giapdangle/X13.Host
    protected override void OnMouseUp(MouseButtonEventArgs e) {
      int gs=LogramView.CellSize;
      if(e.ChangedButton==MouseButton.Right && e.RightButton==MouseButtonState.Released) {
        Topic cur;
        TopicView tv;
        if(_mSelected!=null) {
          var cm=(this.Parent as Grid).ContextMenu;
          cm.Items.Clear();
          MenuItem mi=new MenuItem();
          mi.Header="Copy";
          mi.Click+=new RoutedEventHandler(mi_Copy);
          cm.Items.Add(mi);
          cm.IsOpen=true;
        } else if(selected!=null && (cur=selected.GetModel())!=null && (tv=TopicView.root.Get(cur, true))!=null) {
          var cm=(this.Parent as Grid).ContextMenu;
          var actions=tv.GetActions();
          cm.Items.Clear();

          ItemCollection items;
          for(int i=0; i<actions.Count; i++) {
            switch(actions[i].action) {
            case ItemAction.addToLogram:
            case ItemAction.createBoolMask:
            case ItemAction.createDoubleMask:
            case ItemAction.createLongMask:
            case ItemAction.createNodeMask:
            case ItemAction.createStringMask:
            case ItemAction.createByteArrMask:
            case ItemAction.open:
              continue;
            }
            items=cm.Items;
            string[] lvls=actions[i].menuItem.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            for(int j=0; j<lvls.Length; j++) {
              MenuItem mi = DataStorageView.FindMenuItem(items, lvls[j]);
              if(mi==null) {
                mi=new MenuItem();
                mi.Header=lvls[j];
                mi.DataContext=tv;
                items.Add(mi);
              }

              if(j==lvls.Length-1) {
                mi.Tag=actions[i];
                mi.Click+=new RoutedEventHandler(mi_Click);
                mi.ToolTip=actions[i].description;
              }
              items=mi.Items;
            }
          }
          if(cur.valueType==typeof(PiStatement)) {
            MenuItem mi=new MenuItem();
            mi.Header="Copy";
            mi.Click+=new RoutedEventHandler(mi_Copy);
            cm.Items.Add(mi);
          } else if(selected is uiPin) {
            MenuItem mi=new MenuItem();
            mi.Header="Trace";
            mi.Click+=new RoutedEventHandler(mi_Trace);
            cm.Items.Add(mi);
          }
          if(cm.Items.Count>0) {
            cm.IsOpen=true;
          }
        } else if(Clipboard.ContainsText()) {
          var cm=(this.Parent as Grid).ContextMenu;
          cm.Items.Clear();
          MenuItem mi=new MenuItem();
          mi.Header="Paste";
          mi.Click+=new RoutedEventHandler(mi_Paste);
          cm.Items.Add(mi);
          cm.IsOpen=true;
        }
        return;
      } else if(e.ChangedButton==MouseButton.Left && e.LeftButton==MouseButtonState.Released) {
        if(_mSelected!=null && _mSelected.Length>0) {
          var cp=e.GetPosition(this);
          double r=0, d=0;
          foreach(var el in _mSelected.Where(z => !(z is uiTracer))) {
            if(move) {
              el.SetLocation(new Vector(el.OriginalLocation.X+(cp.X-ScreenStartPoint.X), el.OriginalLocation.Y+(cp.Y-ScreenStartPoint.Y)), true);
              d=Math.Max(d, el.Offset.Y+el.ContentBounds.Bottom);
              r=Math.Max(r, el.Offset.X+el.ContentBounds.Right);
            }
            el.Select(false);
          }
          _mSelected=null;
          if(move) {
            if(d+gs>this.Height) {
              model.Get<long>("_height").value=1+(int)(d)/gs;
            }
            if(r+gs>this.Width) {
              model.Get<long>("_width").value=1+(int)(r)/gs;
            }
          }
        }
        if(IsMouseCaptured) {
          Cursor = Cursors.Arrow;
          ReleaseMouseCapture();
        } else if(selected!=null) {
          SchemaElement el;
          uiWire w;
          var cp=e.GetPosition(this);
          if((el=selected as SchemaElement)!=null && move) {
            el.SetLocation(new Vector(el.OriginalLocation.X+(cp.X-ScreenStartPoint.X), el.OriginalLocation.Y+(cp.Y-ScreenStartPoint.Y)), true);
            if(selected.Offset.Y+selected.ContentBounds.Bottom+gs>this.Height) {
              model.Get<long>("_height").value=1+(int)(selected.Offset.Y+selected.ContentBounds.Bottom)/gs;
            }
            if(selected.Offset.X+selected.ContentBounds.Right+gs>this.Width) {
              model.Get<long>("_width").value=1+(int)(selected.Offset.X+selected.ContentBounds.Right)/gs;
            }
          } else if((w=selected as uiWire)!=null && w.GetModel()==null) {
            uiPin finish=GetVisual(cp.X, cp.Y) as uiPin;
            if(finish!=null && finish!=w.A) {
              w.SetFinish(finish);
            } else {
              this.DeleteVisual(w);
            }
          }
        } else if(_multipleSelection) {
          var cp=e.GetPosition(this);
          _multipleSelection=false;
          base.RemoveVisualChild(_mSelectVisual);
          var objs=new List<SchemaElement>();
          GeometryHitTestParameters parameters;
          {
            double l, t, w, h;
            if(cp.X-ScreenStartPoint.X<0) {
              l=cp.X;
              w=ScreenStartPoint.X-cp.X;
            } else {
              l=ScreenStartPoint.X;
              w=cp.X-ScreenStartPoint.X;
            }
            if(cp.Y-ScreenStartPoint.Y<0) {
              t=cp.Y;
              h=ScreenStartPoint.Y-cp.Y;
            } else {
              t=ScreenStartPoint.Y;
              h=cp.Y-ScreenStartPoint.Y;
            }
            parameters=new GeometryHitTestParameters(new RectangleGeometry(new Rect(l, t, w, h)));
          }

          VisualTreeHelper.HitTest(this, null, new HitTestResultCallback((hr) => {
            var rez=(GeometryHitTestResult)hr;
            var vis=hr.VisualHit as SchemaElement;
            if(vis!=null && rez.IntersectionDetail==IntersectionDetail.FullyInside) {
              objs.Add(vis);
            }
            return HitTestResultBehavior.Continue;
          }), parameters);
          if(objs.Count>0) {
            if(objs.Count==1) {
              selected=objs[0];
            } else {
              _mSelected=objs.ToArray();
              foreach(var el in _mSelected) {
                el.Select(true);
              }
            }
          }
        } else {
          base.OnMouseUp(e);
        }
        move=false;
      } else {
        base.OnMouseUp(e);
      }
    }
コード例 #12
0
        public List<DependencyObject> HitTest(Visual visual, IPoint point, double radius)
        {
            var elements = new List<DependencyObject>();
            var elippse = new EllipseGeometry()
            {
                RadiusX = radius,
                RadiusY = radius,
                Center = new Point(point.X, point.Y),
            };

            var hitTestParams = new GeometryHitTestParameters(elippse);
            var resultCallback = new HitTestResultCallback(result => HitTestResultBehavior.Continue);

            var filterCallback = new HitTestFilterCallback(
                element =>
                {
                    elements.Add(element);
                    return HitTestFilterBehavior.Continue;
                });

            VisualTreeHelper.HitTest(visual, filterCallback, resultCallback, hitTestParams);

            return elements;
        }
コード例 #13
0
        public IEnumerable<IElement> HitTest(IRect rect)
        {
            var canvas = this;
            var r = new Rect(new Point(rect.X1, rect.Y1), new Point(rect.X2, rect.Y2));
            var selectedElements = new List<DependencyObject>();
            var rectangle = new RectangleGeometry(r, 0.0, 0.0);
            var hitTestParams = new GeometryHitTestParameters(rectangle);
            var resultCallback = new HitTestResultCallback(result => HitTestResultBehavior.Continue);

            var filterCallback = new HitTestFilterCallback(
                element =>
                {
                    if (VisualTreeHelper.GetParent(element) == canvas)
                        selectedElements.Add(element);

                    return HitTestFilterBehavior.Continue;
                });

            VisualTreeHelper.HitTest(canvas, filterCallback, resultCallback, hitTestParams);

            return selectedElements.Cast<IElement>();
        }
コード例 #14
0
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters) {
     return null;
 }
コード例 #15
0
ファイル: MainWindowShell.xaml.cs プロジェクト: abordt/Viking
        protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
        {
            GeometryHitTestResult r = base.HitTestCore(hitTestParameters);
            if (r == null)
                return r;

            ContentControl control = r.VisualHit as ContentControl;
            if (control == null)
                return r;

            System.Diagnostics.Trace.WriteLine(control.Name + " was hit");

            return r;
        }
コード例 #16
0
        /// <summary>
        /// HitTestCore implements whether we have hit the bounds of this visual.
        /// </summary>
        protected virtual GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
        {
            if (hitTestParameters == null)
            {
                throw new ArgumentNullException("hitTestParameters");
            }

            IntersectionDetail intersectionDetail;

            RectangleGeometry contentGeometry = new RectangleGeometry(GetHitTestBounds());

            intersectionDetail = contentGeometry.FillContainsWithDetail(hitTestParameters.InternalHitGeometry);
            Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated);

            if (intersectionDetail != IntersectionDetail.Empty)
            {
                return new GeometryHitTestResult(this, intersectionDetail);
            }


            return null;
        }
コード例 #17
0
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     // Do something similar here, possibly checking every pixel within
     // the hitTestParameters.HitGeometry.Bounds rectangle
     return base.HitTestCore(hitTestParameters);
 }
コード例 #18
0
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
   return default(GeometryHitTestResult);
 }
コード例 #19
0
ファイル: TextVisual.cs プロジェクト: JeongPyoHam/Gabang
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     return base.HitTestCore(hitTestParameters);
 }
コード例 #20
0
 protected virtual GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters);
コード例 #21
0
 protected override GeometryHitTestResult HitTestCore( GeometryHitTestParameters hitTestParameters )
 {
     return IsHitTestVisible ? base.HitTestCore( hitTestParameters ) : null;
 }
コード例 #22
0
        public IEnumerable<IElement> HitTest(IPoint point, double radius)
        {
            var canvas = this;
            var selectedElements = new List<DependencyObject>();
            var elippse = new EllipseGeometry() { RadiusX = radius, RadiusY = radius, Center = new Point(point.X, point.Y) };
            var hitTestParams = new GeometryHitTestParameters(elippse);
            var resultCallback = new HitTestResultCallback(result => HitTestResultBehavior.Continue);

            var filterCallback = new HitTestFilterCallback(
                element =>
                {
                    if (VisualTreeHelper.GetParent(element) == canvas)
                        selectedElements.Add(element);

                    return HitTestFilterBehavior.Continue;
                });

            VisualTreeHelper.HitTest(canvas, filterCallback, resultCallback, hitTestParams);

            return selectedElements.Cast<IElement>();
        }
コード例 #23
0
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     return new GeometryHitTestResult(this, IntersectionDetail.FullyContains);
 }
コード例 #24
0
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     return(default(GeometryHitTestResult));
 }
コード例 #25
0
 protected virtual new GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     return(default(GeometryHitTestResult));
 }
コード例 #26
0
 protected virtual new GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
   return default(GeometryHitTestResult);
 }
コード例 #27
0
ファイル: SharpDXHost.cs プロジェクト: tomba/dwarrowdelf
 protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     throw new NotImplementedException();
 }
コード例 #28
0
ファイル: Visual.cs プロジェクト: stanasse/olive
 protected virtual GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
 {
     throw new NotImplementedException();
 }