Node with soft "shadow" in all directions

Hi,

is it possible to customize the node shadow?
GoDiagram default:

The node should have a soft “shadow” in all directions like in the following picture:

Another example are the Windows 10 explorer windows, that have also the soft shadow in all directions.

How could I do this with GoDiagram?

thank you very much

Igor

Well, those shadows weren’t cool when GoDiagram was invented… hmmmm.

What node class are you using? There may be a way to play games with ShadowPen.

:-D
I’m using the GoGeneralNode.

Well, then Pen hack didn’t work, you need a shape gradient to get the fuzzy edge.

Are you using visible input / output ports? How do you want them integrated into the shadow? Can you show me what your nodes look like now?

OK, the way the gradients work, this is going to be really tricky and / or expensive at run time. So, I went back to the Pen strategy.

Not bad, and playing with width and pen color and pen alpha might improve it.

and… it’s real simple.

  [Serializable]
  public class GoDrawingShadow : GoDrawing
  {
    static float shadowWidth = 2;

    public GoDrawingShadow(GoFigure f) : base(f) { }

    public override RectangleF ExpandPaintBounds(RectangleF rect, GoView view)
    {
      InflateRectx(ref rect, shadowWidth, shadowWidth);
      return rect;
    }

    internal static void InflateRectx(ref RectangleF a, float w, float h)
    {
      a.X -= w;
      a.Width += w * 2;
      a.Y -= h;
      a.Height += h * 2;
    }

    public override Pen GetShadowPen(GoView view, float width)
    {
      Pen pen = new Pen(Color.FromArgb(60, Color.Gray), shadowWidth * 2);
      return pen;
    }
  }

and in your GoGeneralNode class, you’d have to override CreateIcon to create this class of GoDrawing object.

and set the Pen of the Icon to be a little darker than the shadow… something like:

pen = new Pen(Color.FromArgb(80, Color.Gray), 1);

and one more thing… set the view.ShadowOffset = new SizeF(0, 0);

ok I’ve tried to built my own sample, but it has no effect in my application.
What am I doing wrong?

public class ShadowNode : GoGeneralNode
{
    public ShadowNode()
    {
        Initialize(null,null,null,null,0,0);
        this.Size = new SizeF(100,25);
        this.Text = "Shadow Node";
    }
    protected override GoObject CreateIcon(ResourceManager res, string iconname)
    {
        GoDrawing rectangle = new GoDrawing(GoFigure.Rectangle);
        rectangle.Pen = new Pen(Color.FromArgb(80, Color.Gray), 1);
        return rectangle;
    }
}

[Serializable]
public class GoDrawingShadow : GoDrawing
{
    static float shadowWidth = 2;

    public GoDrawingShadow(GoFigure f) : base(f) { }

    public override RectangleF ExpandPaintBounds(RectangleF rect, GoView view)
    {
        InflateRectx(ref rect, shadowWidth, shadowWidth);
        return rect;
    }

    internal static void InflateRectx(ref RectangleF a, float w, float h)
    {
        a.X -= w;
        a.Width += w * 2;
        a.Y -= h;
        a.Height += h * 2;
    }

    public override Pen GetShadowPen(GoView view, float width)
    {
        Pen pen = new Pen(Color.FromArgb(60, Color.Gray), shadowWidth * 2);
        return pen;
    }
}


 public class BaseView :GoView
    {
        public BaseView()
        {
            ShadowOffset = new SizeF(0, 0);
        }
    }

You aren’t creating your new GoDrawingShadow object…

    protected override GoObject CreateIcon(ResourceManager res, string iconname)
    {
        **GoDrawingShadow** rectangle = new **GoDrawingShadow**(GoFigure.Rectangle);
        rectangle.Pen = new Pen(Color.FromArgb(80, Color.Gray), 1);
        return rectangle;
    }

ok I’ve changed this in my code, but still no effect.
Could I send you my project?

Set a breakpoint at the CreateIcon to see if it is getting called. If it isn’t, it may be the wrong Initialize you are calling.

ok I’ve set the shadowWidth to 2000.
The shadow is visible now, but only when I drag the node with the mouse.
The node has the default appearance again when you release the mouse button.

Well, that doesn’t make any sense. Make the pen a different color (like Pink) so that you see the brush and pen as distinct colors. there may be some clue in that.

If you can’t figure it out, package it up in a minimal sample you can send to me.

Ok I’ve packed the solution in a zip file. How could I send it to you?
Here I can unfortunately only upload images.

godiagram at our domain.

The only-when-dragging is an artifact of the default dragging mode.

view.DragsRealtime = true;

fixes that.

and I’ve tweaked the Pen settings a bit here:

  public class ShadowNode : GoGeneralNode
  {
    public ShadowNode()
    {
      Initialize(null, null, null, null, 0, 0);
      this.Size = new SizeF(100, 25);
      this.Text = "Shadow Node";
      this.Shadowed = true;
    }
    protected override GoObject CreateIcon(ResourceManager res, string iconname)
    {
      GoDrawingShadow rectangle = new GoDrawingShadow(GoFigure.Rectangle);
      rectangle.Pen = new Pen(Color.FromArgb(80, Color.Gray), 1);
      rectangle.Pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
      return rectangle;
    }
  }

  [Serializable]
  public class GoDrawingShadow : GoDrawing
  {
    static float shadowWidth = 2;

    public GoDrawingShadow(GoFigure f) : base(f) { }

    public override RectangleF ExpandPaintBounds(RectangleF rect, GoView view)
    {
      InflateRectx(ref rect, shadowWidth, shadowWidth);
      return rect;
    }

    internal static void InflateRectx(ref RectangleF a, float w, float h)
    {
      a.X -= w;
      a.Width += w * 2;
      a.Y -= h;
      a.Height += h * 2;
    }

    public override Pen GetShadowPen(GoView view, float width)
    {
      Pen pen = new Pen(Color.FromArgb(50, Color.Gray), shadowWidth * 1);
      pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Outset;
      return pen;
    }
  }