示例#1
0
        /// <summary>
        /// Stroke Invalidated event handler
        /// </summary>
        private void OnStrokeInvalidated(object sender, EventArgs eventArgs)
        {
            System.Diagnostics.Debug.Assert(_strokes.IndexOf(sender as Stroke) != -1);

            // Find the visual associated with the changed stroke.
            StrokeVisual visual;
            Stroke       stroke = (Stroke)sender;

            if (_visuals.TryGetValue(stroke, out visual) == false)
            {
                throw new System.ArgumentException(SR.Get(SRID.UnknownStroke1));
            }

            // The original value of IsHighligher and Color are cached in StrokeVisual.
            // if (IsHighlighter value changed or (IsHighlighter == true and not changed and color changed)
            // detach and re-attach the corresponding visual;
            // otherwise Invalidate the corresponding StrokeVisual
            if (visual.CachedIsHighlighter != stroke.DrawingAttributes.IsHighlighter ||
                (stroke.DrawingAttributes.IsHighlighter &&
                 StrokeRenderer.GetHighlighterColor(visual.CachedColor) != StrokeRenderer.GetHighlighterColor(stroke.DrawingAttributes.Color)))
            {
                // The change requires reparenting the visual in the tree.
                DetachVisual(visual);
                AttachVisual(visual, false /*buildingStrokeCollection*/);

                // Update the cached values
                visual.CachedIsHighlighter = stroke.DrawingAttributes.IsHighlighter;
                visual.CachedColor         = stroke.DrawingAttributes.Color;
            }
            // Update the visual.
            visual.Update();
        }
示例#2
0
        /// <summary>
        /// Finds a container for a new visual based on the drawing attributes
        /// of the stroke rendered into that visual.
        /// </summary>
        /// <param name="drawingAttributes">drawing attributes</param>
        /// <returns>visual</returns>
        private ContainerVisual GetContainerVisual(DrawingAttributes drawingAttributes)
        {
            System.Diagnostics.Debug.Assert(drawingAttributes != null);

            HighlighterContainerVisual hcVisual;

            if (drawingAttributes.IsHighlighter)
            {
                // For a highlighter stroke, the color.A is neglected.
                Color color = StrokeRenderer.GetHighlighterColor(drawingAttributes.Color);
                if ((_highlighters == null) || (_highlighters.TryGetValue(color, out hcVisual) == false))
                {
                    if (_highlighters == null)
                    {
                        _highlighters = new Dictionary <Color, HighlighterContainerVisual>();
                    }

                    hcVisual         = new HighlighterContainerVisual(color);
                    hcVisual.Opacity = StrokeRenderer.HighlighterOpacity;
                    _highlightersRoot.Children.Add(hcVisual);

                    _highlighters.Add(color, hcVisual);
                }
                else if (VisualTreeHelper.GetParent(hcVisual) == null)
                {
                    _highlightersRoot.Children.Add(hcVisual);
                }
                return(hcVisual);
            }
            else
            {
                return(_regularInkVisuals);
            }
        }
示例#3
0
        /// <summary>
        /// Render the StrokeCollection under the specified DrawingContext.
        /// </summary>
        /// <param name="context"></param>
        public void Draw(DrawingContext context)
        {
            if (null == context)
            {
                throw new System.ArgumentNullException("context");
            }

            //The verification of UI context affinity is done in Stroke.Draw()

            List <Stroke> solidStrokes = new List <Stroke>();
            Dictionary <Color, List <Stroke> > highLighters = new Dictionary <Color, List <Stroke> >();

            for (int i = 0; i < this.Count; i++)
            {
                Stroke        stroke = this[i];
                List <Stroke> strokes;
                if (stroke.DrawingAttributes.IsHighlighter)
                {
                    // It's very important to override the Alpha value so that Colors of the same RGB vale
                    // but different Alpha would be in the same list.
                    Color color = StrokeRenderer.GetHighlighterColor(stroke.DrawingAttributes.Color);
                    if (highLighters.TryGetValue(color, out strokes) == false)
                    {
                        strokes = new List <Stroke>();
                        highLighters.Add(color, strokes);
                    }
                    strokes.Add(stroke);
                }
                else
                {
                    solidStrokes.Add(stroke);
                }
            }

            foreach (List <Stroke> strokes in highLighters.Values)
            {
                context.PushOpacity(StrokeRenderer.HighlighterOpacity);
                try
                {
                    foreach (Stroke stroke in strokes)
                    {
                        stroke.DrawInternal(context, StrokeRenderer.GetHighlighterAttributes(stroke, stroke.DrawingAttributes),
                                            false /*Don't draw selected stroke as hollow*/);
                    }
                }
                finally
                {
                    context.Pop();
                }
            }

            foreach (Stroke stroke in solidStrokes)
            {
                stroke.DrawInternal(context, stroke.DrawingAttributes, false /*Don't draw selected stroke as hollow*/);
            }
        }