Skip to content

Commit

Permalink
Provide overload method to set mouse cursor location with Align and V…
Browse files Browse the repository at this point in the history
…align parameters instead of absolute offset values.
  • Loading branch information
nightm4re94 committed Dec 16, 2019
1 parent eaa98c7 commit 949be86
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/de/gurkenlabs/litiengine/graphics/MouseCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;

import de.gurkenlabs.litiengine.Align;
import de.gurkenlabs.litiengine.Valign;
import de.gurkenlabs.litiengine.input.Input;
import de.gurkenlabs.litiengine.input.Mouse;

Expand All @@ -21,15 +23,15 @@ public final class MouseCursor implements IRenderable {
private int offsetY;

private boolean visible;

public MouseCursor() {
this.visible = true;
}

@Override
public void render(Graphics2D g) {
if (this.isVisible()) {
final Point2D locationWithOffset = new Point2D.Double(Input.mouse().getLocation().getX() - this.getOffsetX(), Input.mouse().getLocation().getY() - this.getOffsetY());
final Point2D locationWithOffset = new Point2D.Double(Input.mouse().getLocation().getX() + this.getOffsetX(), Input.mouse().getLocation().getY() + this.getOffsetY());
ImageRenderer.renderTransformed(g, this.getImage(), locationWithOffset, this.getTransform());
}
}
Expand Down Expand Up @@ -61,21 +63,18 @@ public boolean isVisible() {
}

public void set(final Image img) {
this.image = img;
if (this.image != null) {
this.setOffsetX(-(this.image.getWidth(null) / 2));
this.setOffsetY(-(this.image.getHeight(null) / 2));
} else {
this.setOffsetX(0);
this.setOffsetY(0);
}
this.set(img, Align.LEFT, Valign.TOP);
}

public void set(final Image img, final int offsetX, final int offsetY) {
this.set(img);
this.image = img;
this.setOffset(offsetX, offsetY);
}

public void set(final Image img, Align hAlign, Valign vAlign) {
this.set(img, -(int) (hAlign.portion * img.getWidth(null)), -(int) (vAlign.portion * img.getHeight(null)));
}

public void setOffset(final int x, final int y) {
this.setOffsetX(x);
this.setOffsetY(y);
Expand Down

0 comments on commit 949be86

Please sign in to comment.