'MSAGL: How to neutralize the graphics transform in DrawNodeDelegate so that owner drawing can always begin with top left as 0,0?

I am using a NodeBoundaryDelegate to owner-draw my nodes.

Is it possible to neutralize the graphics transform in DrawNodeDelegate so that this owner drawing can always begin with top left of the relevant area as 0,0?

Msagl.Drawing.Node's coordinate system is positive-y-is-north. Winforms is positive-y-is-south.

In my graph (about 100 nodes, laid out very wide from left to right) the leftmost Msagl.Drawing.Node objects usually end up at coordinates like -10,000, -3000.

g.ClipBounds ends up with ranges like {X = -10019.999 Y = -1716.70862 Width = 9519.998 Height = 3755.74536}.

By the time the code reaches DrawNode, g.Transform already is already in some (non-intutive to me) nonzero range like:

[0]   0.0612394959
[1]   0
[2]   0
[3]   0.0612394959
[4]   613.619751
[5]   224.130356

In case it matters, I am also using NodeBoundaryDelegate to hardcode all my node sizes to a fixed size of 500x50.

private bool DrawNode(Microsoft.Msagl.Drawing.Node node, object graphics)
{
    Graphics g = (Graphics)graphics;

    // some kind of g.Transform wizardry here?

    g.DrawString("nodename", Font, Brushes.Red, 0, 0);  // 0,0 should be perfectly aligned
                                                        // at top left corner of drawn node
}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source