Inheritance: SharpVectors.Dom.Svg.Rendering.RenderingNode
        public void DrawImage(GraphicsNode grNode, Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)
        {
            if (_idMapGraphics != null)
            {
                // This handles pointer-events for visibleFill visibleStroke and visible

                /*Brush idBrush = new SolidBrush(grNode.UniqueColor);
                 * GraphicsPath gp = new GraphicsPath();
                 * gp.AddRectangle(destRect);
                 * _idMapGraphics.FillPath(idBrush, gp);*/
                Color       unique      = grNode.UniqueColor;
                float       r           = (float)unique.R / 255;
                float       g           = (float)unique.G / 255;
                float       b           = (float)unique.B / 255;
                ColorMatrix colorMatrix = new ColorMatrix(
                    new float[][] { new float[] { 0f, 0f, 0f, 0f, 0f },
                                    new float[] { 0f, 0f, 0f, 0f, 0f },
                                    new float[] { 0f, 0f, 0f, 0f, 0f },
                                    new float[] { 0f, 0f, 0f, 1f, 0f },
                                    new float[] { r, g, b, 0f, 1f } });
                ImageAttributes ia = new ImageAttributes();
                ia.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                _idMapGraphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, ia);
            }
            _graphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, imageAttributes);
        }
示例#2
0
 internal void _removeColor(Color color,
                            GraphicsNode grNode)
 {
     if (!color.IsEmpty)
     {
         graphicsNodes[color] = null;
         graphicsNodes.Remove(color);
     }
 }
 public void DrawPath(GraphicsNode grNode, Pen pen, GraphicsPath path)
 {
     if (_idMapGraphics != null)
     {
         Pen idPen = new Pen(grNode.UniqueColor, pen.Width);
         _idMapGraphics.DrawPath(idPen, path);
     }
     _graphics.DrawPath(pen, path);
 }
示例#4
0
        public bool HitTest(int x, int y)
        {
            bool hit = false;

            Color        pixel  = idMapRaster.GetPixel(x, y);
            GraphicsNode grNode = _getGraphicsNodeFromColor(pixel);

            if (grNode != null)
            {
                hit = true;
            }

            return(hit);
        }
 public void FillPath(GraphicsNode grNode, Brush brush, GraphicsPath path)
 {
     if (_idMapGraphics != null)
     {
         Brush idBrush = new SolidBrush(grNode.UniqueColor);
         if (grNode.Element is SvgTextContentElement)
         {
             _idMapGraphics.FillRectangle(idBrush, path.GetBounds());
         }
         else
         {
             _idMapGraphics.FillPath(idBrush, path);
         }
     }
     _graphics.FillPath(brush, path);
 }
示例#6
0
/// <summary>
/// Allocate a hit color for the specified graphics node.
/// </summary>
/// <param name="grNode">
/// The <see cref="GraphicsNode">GraphicsNode</see> object for which to
/// allocate a new hit color.
/// </param>
/// <returns>
/// The hit color for the <see cref="GraphicsNode">GraphicsNode</see>
/// object.
/// </returns>
        internal Color _getNextColor(
            GraphicsNode grNode)
        {
            //	TODO: [newhoggy] It looks like there is a potential memory leak here.
            //	We only ever add to the graphicsNodes map, never remove
            //	from it, so it will grow every time this function is called.

            // The counter is used to generate IDs in the range [0,2^24-1]
            // The 24 bits of the counter are interpreted as follows:
            // [red 7 bits | green 7 bits | blue 7 bits |shuffle term 3 bits]
            // The shuffle term is used to define how the remaining high
            // bit is set on each color. The colors are generated in the
            // range [0,127] (7 bits) instead of [0,255]. Then the shuffle term
            // is used to adjust them into the range [0,255].
            // This algorithm has the feature that consecutive ids generate
            // visually distinct colors.
            int id          = counter++; // Zero should be the first color.
            int shuffleTerm = id & 7;
            int r           = 0x7f & (id >> 17);
            int g           = 0x7f & (id >> 10);
            int b           = 0x7f & (id >> 3);

            switch (shuffleTerm)
            {
            case 0:                                  break;

            case 1:                       b |= 0x80; break;

            case 2:            g |= 0x80;            break;

            case 3:            g |= 0x80; b |= 0x80; break;

            case 4: r |= 0x80;                       break;

            case 5: r |= 0x80;            b |= 0x80; break;

            case 6: r |= 0x80; g |= 0x80;            break;

            case 7: r |= 0x80; g |= 0x80; b |= 0x80; break;
            }

            Color color = Color.FromArgb(r, g, b);

            graphicsNodes.Add(color, grNode);

            return(color);
        }
示例#7
0
        /// <summary>
        /// Generates a new <see cref="RenderingNode">RenderingNode</see> that
        /// corresponds to the given <see cref="XmlElement">XmlElement</see>.
        /// </summary>
        /// <param name="node">
        /// The <see cref="XmlElement">XmlElement</see> node for which to generate
        /// a new <see cref="RenderingNode">RenderingNode</see> object.
        /// </param>
        /// <returns>
        /// The generated <see cref="RenderingNode">RenderingNode</see> that
        /// corresponds to the given <see cref="XmlElement">XmlElement</see>.
        /// </returns>
        public RenderingNode GetRenderingNode(
            ISvgElement node)
        {
            SvgElement    svgNode = (SvgElement)node;
            string        name    = svgNode.NamespaceURI + ":" + svgNode.LocalName;
            RenderingNode result;

            if (nodeByTagName.ContainsKey(name))
            {
                object[] args = new object[] { svgNode };
                result = (RenderingNode)nodeByTagName.CreateInstance(name, args);
            }
            else if (node is ISharpGDIPath)
            {
                result = new GDIPathGraphicsNode(svgNode);
            }
            else
            {
                result = new GraphicsNode(svgNode);
            }

            return(result);
        }
示例#8
0
 public void FillPath(GraphicsNode grNode, Brush brush, GraphicsPath path )
 {
     if(_idMapGraphics != null)
     {
         Brush idBrush = new SolidBrush(grNode.UniqueColor);
         if(grNode.Element is SvgTextContentElement)
         {
             _idMapGraphics.FillRectangle(idBrush, path.GetBounds());
         }
         else
         {
             _idMapGraphics.FillPath(idBrush, path);
         }
     }
     _graphics.FillPath(brush, path);
 }
示例#9
0
 public void DrawPath(GraphicsNode grNode, Pen pen, GraphicsPath path)
 {
     if(_idMapGraphics != null)
     {
         Pen idPen = new Pen(grNode.UniqueColor, pen.Width);
         _idMapGraphics.DrawPath(idPen, path);
     }
     _graphics.DrawPath(pen, path);
 }
示例#10
0
 public void DrawImage(GraphicsNode grNode, Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit graphicsUnit, ImageAttributes imageAttributes)
 {
     if(_idMapGraphics != null)
       {
     // This handles pointer-events for visibleFill visibleStroke and visible
     /*Brush idBrush = new SolidBrush(grNode.UniqueColor);
     GraphicsPath gp = new GraphicsPath();
     gp.AddRectangle(destRect);
     _idMapGraphics.FillPath(idBrush, gp);*/
     Color unique = grNode.UniqueColor;
     float r = (float)unique.R / 255;
     float g = (float)unique.G / 255;
     float b = (float)unique.B / 255;
     ColorMatrix colorMatrix = new ColorMatrix(
       new float[][] { new float[] {0f, 0f, 0f, 0f, 0f},
                   new float[] {0f, 0f, 0f, 0f, 0f},
                   new float[] {0f, 0f, 0f, 0f, 0f},
                   new float[] {0f, 0f, 0f, 1f, 0f},
                   new float[] {r,  g,  b,  0f, 1f} });
     ImageAttributes ia = new ImageAttributes();
     ia.SetColorMatrix(colorMatrix,ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
     _idMapGraphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, ia);
       }
       _graphics.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, graphicsUnit, imageAttributes);
 }
示例#11
0
        /// <summary>
        /// Processes mouse events.
        /// </summary>
        /// <param name="type">
        /// A string describing the type of mouse event that occured.
        /// </param>
        /// <param name="e">
        /// The <see cref="MouseEventArgs">MouseEventArgs</see> that contains
        /// the event data.
        /// </param>
        public void OnMouseEvent(string type, int x, int y)
        {
            if (idMapRaster != null)
            {
                try
                {
                    Color        pixel  = idMapRaster.GetPixel(x, y);
                    GraphicsNode grNode = _getGraphicsNodeFromColor(pixel);

                    if (grNode != null)
                    {
                        SvgElement   grElement = (SvgElement)grNode.Element;
                        IEventTarget target;
                        if (grElement.ElementInstance != null)
                        {
                            target = grElement.ElementInstance as IEventTarget;
                        }
                        else
                        {
                            target = grElement as IEventTarget;
                        }

                        if (target != null)
                        {
                            switch (type)
                            {
                            case "mousemove":
                            {
                                if (currentTarget == target)
                                {
                                    target.DispatchEvent(new MouseEvent(
                                                             EventType.MouseMove, true, false,
                                                             null, // todo: put view here
                                                             0,    // todo: put detail here
                                                             x, y, x, y,
                                                             false, false, false, false,
                                                             0, null, false));
                                }
                                else
                                {
                                    if (currentTarget != null)
                                    {
                                        currentTarget.DispatchEvent(new MouseEvent(
                                                                        EventType.MouseOut, true, false,
                                                                        null, // todo: put view here
                                                                        0,    // todo: put detail here
                                                                        x, y, x, y,
                                                                        false, false, false, false,
                                                                        0, null, false));
                                    }

                                    target.DispatchEvent(new MouseEvent(
                                                             EventType.MouseOver, true, false,
                                                             null, // todo: put view here
                                                             0,    // todo: put detail here
                                                             x, y, x, y,
                                                             false, false, false, false,
                                                             0, null, false));
                                }
                                break;
                            }

                            case "mousedown":
                                target.DispatchEvent(new MouseEvent(
                                                         EventType.MouseDown, true, false,
                                                         null, // todo: put view here
                                                         0,    // todo: put detail here
                                                         x, y, x, y,
                                                         false, false, false, false,
                                                         0, null, false));
                                currentDownTarget = target;
                                currentDownX      = x;
                                currentDownY      = y;
                                break;

                            case "mouseup":
                                target.DispatchEvent(new MouseEvent(
                                                         EventType.MouseUp, true, false,
                                                         null, // todo: put view here
                                                         0,    // todo: put detail here
                                                         x, y, x, y,
                                                         false, false, false, false,
                                                         0, null, false));
                                if (/*currentDownTarget == target &&*/ Math.Abs(currentDownX - x) < 5 && Math.Abs(currentDownY - y) < 5)
                                {
                                    target.DispatchEvent(new MouseEvent(
                                                             EventType.Click, true, false,
                                                             null, // todo: put view here
                                                             0,    // todo: put detail here
                                                             x, y, x, y,
                                                             false, false, false, false,
                                                             0, null, false));
                                }
                                currentDownTarget = null;
                                currentDownX      = 0;
                                currentDownY      = 0;
                                break;
                            }
                            currentTarget = target;
                        }
                        else
                        {
                            // jr patch
                            if (currentTarget != null && type == "mousemove")
                            {
                                currentTarget.DispatchEvent(new MouseEvent(
                                                                EventType.MouseOut, true, false,
                                                                null, // todo: put view here
                                                                0,    // todo: put detail here
                                                                x, y, x, y,
                                                                false, false, false, false,
                                                                0, null, false));
                            }
                            currentTarget = null;
                        }
                    }
                    else
                    {
                        // jr patch
                        if (currentTarget != null && type == "mousemove")
                        {
                            currentTarget.DispatchEvent(new MouseEvent(
                                                            EventType.MouseOut, true, false,
                                                            null, // todo: put view here
                                                            0,    // todo: put detail here
                                                            x, y, x, y,
                                                            false, false, false, false,
                                                            0, null, false));
                        }
                        currentTarget = null;
                    }
                }
                catch
                {
                }
            }
        }
示例#12
0
 internal void _removeColor(Color color,
                        GraphicsNode grNode)
 {
     if (!color.IsEmpty)
     {
     graphicsNodes[color] = null;
     graphicsNodes.Remove(color);
     }
 }
示例#13
0
        /// <summary>
        /// Allocate a hit color for the specified graphics node.
        /// </summary>
        /// <param name="grNode">
        /// The <see cref="GraphicsNode">GraphicsNode</see> object for which to
        /// allocate a new hit color.
        /// </param>
        /// <returns>
        /// The hit color for the <see cref="GraphicsNode">GraphicsNode</see>
        /// object.
        /// </returns>
        internal Color _getNextColor(
    GraphicsNode grNode)
        {
            //	TODO: [newhoggy] It looks like there is a potential memory leak here.
            //	We only ever add to the graphicsNodes map, never remove
            //	from it, so it will grow every time this function is called.

            // The counter is used to generate IDs in the range [0,2^24-1]
            // The 24 bits of the counter are interpreted as follows:
            // [red 7 bits | green 7 bits | blue 7 bits |shuffle term 3 bits]
            // The shuffle term is used to define how the remaining high
            // bit is set on each color. The colors are generated in the
            // range [0,127] (7 bits) instead of [0,255]. Then the shuffle term
            // is used to adjust them into the range [0,255].
            // This algorithm has the feature that consecutive ids generate
            // visually distinct colors.
            int id = counter++; // Zero should be the first color.
            int shuffleTerm = id & 7;
            int r = 0x7f & (id >> 17);
            int g = 0x7f & (id >> 10);
            int b = 0x7f & (id >> 3);

            switch (shuffleTerm)
            {
            case 0:                                  break;
            case 1:                       b |= 0x80; break;
            case 2:            g |= 0x80;            break;
            case 3:            g |= 0x80; b |= 0x80; break;
            case 4: r |= 0x80;                       break;
            case 5: r |= 0x80;            b |= 0x80; break;
            case 6: r |= 0x80; g |= 0x80;            break;
            case 7: r |= 0x80; g |= 0x80; b |= 0x80; break;
            }

            Color color = Color.FromArgb(r, g, b);

            graphicsNodes.Add(color, grNode);

            return color;
        }
示例#14
0
        /// <summary>
        /// Generates a new <see cref="RenderingNode">RenderingNode</see> that
        /// corresponds to the given <see cref="XmlElement">XmlElement</see>.
        /// </summary>
        /// <param name="node">
        /// The <see cref="XmlElement">XmlElement</see> node for which to generate
        /// a new <see cref="RenderingNode">RenderingNode</see> object.
        /// </param>
        /// <returns>
        /// The generated <see cref="RenderingNode">RenderingNode</see> that
        /// corresponds to the given <see cref="XmlElement">XmlElement</see>.
        /// </returns>
        public RenderingNode GetRenderingNode(
        ISvgElement node)
        {
            SvgElement svgNode = (SvgElement)node;
            string name = svgNode.NamespaceURI + ":" + svgNode.LocalName;
            RenderingNode result;

            if (nodeByTagName.ContainsKey(name))
            {
            object[] args = new object[] {svgNode};
            result = (RenderingNode) nodeByTagName.CreateInstance(name, args);
            }
            else if (node is ISharpGDIPath)
            {
            result = new GDIPathGraphicsNode(svgNode);
            }
            else
            {
            result = new GraphicsNode(svgNode);
            }

            return result;
        }