Strange divergency of mouse coords and Image


#1

I tried a pixmap editor component and ran into strange offsets

Component has a private Image of same size as component

here is what i do

void PixMain::mouseDown (const MouseEvent &e){
svedPt.setXY(e.x,e.y);
}
void PixMain::mouseDrag(const MouseEvent &e){
Graphics g(*canvas);
float mx = (float) e.x;
float my = (float) e.y;
float omx = svedPt.getX();
float omy = svedPt.getY();
if( (my != omy) || (mx != omx)) {
g.lineTo(mx,my);
repaint();
svedPt.setXY(mx, my);
}
}

then:

void PixMain::paint (Graphics& g)
{
g.drawImage(canvas,0,
0,
getWidth(),
getHeight(),
0,
0,
canvas->getWidth(),
canvas->getHeight());
}

But what happens is, that the farther I move from topleft corner, the more mouse cursor and drawn line differ. Looks like a multiplicative factor being applied.

Jules: What is happening here?

Thanks


#2

Right… So you reckon the image is the same size as the component. How much do you want to bet on that?


#3

can this be misunderstood?

canvas = new Image(Image::RGB, getWidth(), getHeight(), false);


#4

oops !

void PixMain::paint (Graphics& g)
{
g.drawImage(canvas,0,
0,
getWidth(),
getHeight(),
0,
0,
getWidth(), <----------- this did the job
getHeight());
}


#5

Or just use drawImageAt (canvas, 0, 0)…


#6