Before I say anything else, I do realize that there are numerous threads on this topic, but I haven't been able to fix my problem.
Okay. Well, here's my problem. I'm writing a map editor for the game that I'm working on, and the map is oftentimes much larger than the view area. (I'm working on a zoom feature, but that's a different problem...) I have a diamond shaped vector graphic that I'm drawing, and I need it to be moveable. I can get it to move, but it doesn't move relative to the mouse movement, it only moves the origin of the painting to the mouse location, then moves in the same direction as the mouse, but in increasing large increments...
If anyone knows of a solution for this problem, please let me know, Thank you!
Here's the code I have:
// This is located in the Map class that controls drawing and such
public java.awt.Point getDrawLocation(){
return new java.awt.Point(startX, startY);
}
Point originalLoc;
public void setOrigLoc(Point p){
originalLoc = p;
}
public void setDrawLocation(java.awt.Point current){
startX = (int)current.getX();
startY = (int)current.getY();
startX = (int)(current.getX()+(startX - originalLoc.getX()));
startY = (int)(current.getY()+(startY - originalLoc.getY()));
// startX = (int)(originalLoc.getX()+(current.getX()-originalLoc.getX()));
// startY = (int)(originalLoc.getY()+(current.getY()-originalLoc.getY()));
}
// This is in the EditableMap class which extends Map (It should
// probably be in the Map class though.......)
Point mouseStart, mouseEnd;
public void mousePressed(MouseEvent e){
mouseStart = e.getPoint();
this.setOrigLoc(mouseStart);
dragging = true;
}
public void mouseReleased(MouseEvent e){
mouseEnd = e.getPoint();
dragging = false;
int a = Math.abs((int)(mouseEnd.getX()-mouseStart.getX()));
int b = Math.abs((int)(mouseEnd.getY()-mouseStart.getY()));
if(Math.sqrt(a*a+b*b)>3){
// this.setDrawLocation(mouseEnd);
}else{
this.findAndSelectTile(e.getX(), e.getY());
}
e.getComponent().repaint();
}
public void mouseClicked(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseDragged(MouseEvent e){
Point current = e.getPoint();
this.setDrawLocation(current);
e.getComponent().repaint();
}
public void mouseMoved(MouseEvent e){}