public static EditTimeVisualizer Create(IWpfTextView editor, SyntaxNode node) { var model = EditTimeVisualizerModel.Create(node); if (model.IsValid) { return(Create(editor, model)); } return(null); }
public GazeAdornment(Microsoft.VisualStudio.Text.Editor.IWpfTextView view) { var componentModel = (Microsoft.VisualStudio.ComponentModelHost.IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(Microsoft.VisualStudio.ComponentModelHost.SComponentModel)); Workspace = componentModel.GetService <Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>(); View = view; LayerManager = GazeLayerManager.Get(view); LayerManager.SingletonLayers = new System.Collections.Generic.List <GazeResponseLayer>() { new EllipseInformationalGazeLayerElement(View, Brushes.Red, 5, 5), // show a 5x5 core target that is the discrete X,Y coordinates new EllipseInformationalGazeLayerElement(View, Brushes.Cyan, 100, 100), // show a 100x100 extended target that is the scan area for the gaze targeting system }; EyeTracking.PointAvailable += (sender, e) => Stabilization.AddPoint(e); Stabilization.StabilizedPointAvailable += (sender, e) => { if (_inFlight) { return; } _inFlight = true; // workflow goes here, point should be stabilized coming from point provider try { if (View.VisualElement.Dispatcher.Invoke(() => (View.VisualElement.ActualHeight == 0 || !View.VisualElement.IsInitialized || !View.VisualElement.IsLoaded))) { _inFlight = false; return; // gaze point available before WPF draw is finished } // localize point to our editor view var localPt = View.VisualElement.Dispatcher.Invoke(() => View.VisualElement.PointFromScreen(e)); localPt.X += View.ViewportLeft; localPt.Y += View.ViewportTop; // infer/guess gaze targets var gazedElements = GazeTargeting.GetTargetCandidateTokens(View, Workspace, localPt.X, localPt.Y); // draw singleton layers (coordinate-based) LayerManager.DrawSingletonLayers(localPt.X, localPt.Y); // draw highlights around gazed elements LayerManager.ScrubLayers(); foreach (GazeTarget element in gazedElements.OrderByDescending(el => el.Weight)) { var span = new SnapshotSpan(View.TextSnapshot, element.DefinitionLocation.Start, element.DefinitionLocation.Length); if (!LayerManager.IsTracking(span)) { // gradate opacity of the debug layer based on target weights (on green) LayerManager.Layers.Add(new TextHighlightInformationalGazeLayerElement(View, span, element.Weight)); } var model = EditTimeVisualizerModel.Create(element); if (model != null && model.IsValid) { LayerManager.Layers.Add(new EditTimeVisualizationLayer(View, span, model)); } } LayerManager.Draw(); } catch (Exception ex) { } _inFlight = false; }; }