Hit detection

TCanvasView::Hit provides simple hit detection. The Hit function takes a point in local coordinates and returns a canvas graphic ID of the hit graphic. TCanvasGraphicID:kInvalidID is returned when there is no hit. The following code fragment is an example override of TCanvasView::Hit.

      TCanvasGraphicID
      TExampleCanvasView::Hit( const TGPoInt& hitLocation ) const
      {
          TCanvasFrontToBackFilter filter;
          TCanvasGraphicHitDetectionFunnel funnel( hitLocation );
          EnumerateGraphics( filter, funnel );
          
          return funnel.GetHitGraphicID();
      }
TCanvasFrontToBackFilter enumerates graphics from front to back. TCanvasGraphicHitDetectionFunnel detects the first hit graphic and remembers it. GetHitGraphic returns the hit graphic.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker