This relates to the request for a visibility test in #3846, the problem being that getTransform().transform(x,y)
doesn't produce the correct results (so codename1 differs from standard java in a documented API)
So this is somewhere between a bug report for an eternal bug, and a RFE that that might break
some user code by fixing such a longstanding problem.
Here's a calculation with several fudge factors that I think works.
int actualX=0; // set the the absolute x of the window
int actualY=0; // set to the absoluteY of the window
public Point transform(Graphics gc,int x,int y)
{ if(from==null) { from = new float[3]; }
if(to==null) { to = new float[3]; }
if(pt==null) { pt = new Point(0,0); }
int tx = gc.getTranslateX();
int ty = gc.getTranslateY();
from[0] = x+tx;
from[1] = y+ty;
Transform tr = gc.getTransform();
tr.transformPoint(from,to);
float fudgeY = actualY;
float fudgeX = actualX;
pt.setX((int)(to[0]-fudgeX));
pt.setY((int)(to[1]-fudgeY));
return pt;
}
I believe that changing the logic that uses graphics.transform is onerous, but graphics.getTransform()
is defined to return a copy, so you're free to construct a copy with the appropriate fudge factors builtin.
This relates to the request for a visibility test in #3846, the problem being that getTransform().transform(x,y)
doesn't produce the correct results (so codename1 differs from standard java in a documented API)
So this is somewhere between a bug report for an eternal bug, and a RFE that that might break
some user code by fixing such a longstanding problem.
Here's a calculation with several fudge factors that I think works.
int actualX=0; // set the the absolute x of the window
int actualY=0; // set to the absoluteY of the window
public Point transform(Graphics gc,int x,int y)
{ if(from==null) { from = new float[3]; }
if(to==null) { to = new float[3]; }
if(pt==null) { pt = new Point(0,0); }
int tx = gc.getTranslateX();
int ty = gc.getTranslateY();
from[0] = x+tx;
from[1] = y+ty;
Transform tr = gc.getTransform();
tr.transformPoint(from,to);
float fudgeY = actualY;
float fudgeX = actualX;
pt.setX((int)(to[0]-fudgeX));
pt.setY((int)(to[1]-fudgeY));
return pt;
}
I believe that changing the logic that uses graphics.transform is onerous, but graphics.getTransform()
is defined to return a copy, so you're free to construct a copy with the appropriate fudge factors builtin.