Hello
I use to work with GDI Graphics to draw Diagram, normaly the origin of coordinate is 0,0 : Bottom Left
XGraphix and GDI Graphics have the Origin on TOP Left
So when Using a GDI Graphic I set a Transformation Matrix
Code SetTransformMatrix below
But I'm trying do to Similar with
XGraphics like this :
Code:
gfx.TranslateTransform(-offset_x, offset_y, XMatrixOrder.Append);
gfx.ScaleTransform(scaleX, scaleY, XMatrixOrder.Append);
Full code below
Without any succes
What I'm doing wrong ??
Is it possible to invert Origin with Xgraphics
Thanks for any help
Code for GDI : (working well)
Code:
// *************************************************************************
public static Matrix SetTransformMatrix(RectangleF World, SizeF Dest, bool Centered)
{
double map_W = World.Width;
double map_H = World.Height;
double rh = Dest.Height / (map_H);
double rw = Dest.Width / (map_W);
double scaleX = rw;
double scaleY = rh;
double ofY = 0;
double ofX = 0;
ofX = ((Dest.Width / scaleX) - World.Width) / 2;
ofY = ((Dest.Height / scaleY) - World.Height) / 2;
double offset_x = World.X;
double offset_y = World.Y + World.Height;
if (Centered)
{
offset_x -= ofX;
offset_y += ofY;
}
float offset_Xf = (float)offset_x;
float offset_Yf = (float)offset_y;
Matrix m = new Matrix(1.0f,
0.0f,
0.0f,
-1.0f,
0.0f,
0.0f);
m.Translate(-offset_Xf, offset_Yf, MatrixOrder.Append);
m.Scale((float)scaleX, (float)scaleY, MatrixOrder.Append);
return m;
}
Code for Xgraphics : Graph is Upside Down
Code:
internal static void SetTransformMatrix(XRect World, XSize Dest, bool Centered, XGraphics gfx)
{
double map_W = World.Width;
double map_H = World.Height;
double rh = Dest.Height / (map_H);
double rw = Dest.Width / (map_W);
double scaleX = rw;
double scaleY = rh;
double ofY = 0;
double ofX = 0;
ofX = ((Dest.Width / scaleX) - World.Width) / 2;
ofY = ((Dest.Height / scaleY) - World.Height) / 2;
double offset_x = World.X;
double offset_y = -World.Y; // Not good but it shows something upsisde down
gfx.TranslateTransform(-offset_x, offset_y, XMatrixOrder.Append);
gfx.ScaleTransform(scaleX, scaleY, XMatrixOrder.Append);
}