package sk.paz1a.practicals.task5;
import java.awt.event.MouseEvent;
import sk.upjs.jpaz2.Turtle;
import sk.upjs.jpaz2.WinPane;
public class GrafickyEditor extends WinPane {
private Turtle artist;
private boolean jeStlaceneLaveTlacidloMysi;
public GrafickyEditor() {
artist = new Turtle();
this.add(artist);
}
@Override
protected void onMouseClicked(int x, int y, MouseEvent detail) {
artist.setPosition(x, y);
}
@Override
protected void onMouseMoved(int x, int y, MouseEvent detail) {
if (detail.isAltDown()) {
artist.setDirectionTowards(x, y);
double xStart = artist.getX();
double yStart = artist.getY();
artist.moveTo(x, y);
artist.setPosition(xStart, yStart);
}
}
@Override
protected void onMousePressed(int x, int y, MouseEvent detail) {
if (detail.getButton() == MouseEvent.BUTTON1) {
jeStlaceneLaveTlacidloMysi = true;
System.out.println("stlacene");
}
}
@Override
protected void onMouseDragged(int x, int y, MouseEvent detail) {
System.out.println("taha sa");
if (jeStlaceneLaveTlacidloMysi) {
artist.moveTo(x, y);
}
}
@Override
protected void onMouseReleased(int x, int y, MouseEvent detail) {
if (detail.getButton() == MouseEvent.BUTTON1) {
jeStlaceneLaveTlacidloMysi = false;
System.out.println("uvolnene");
}
}
}