Versatile Java game engine with pluggable backends (this was used in Rogue, I think)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gamecore/src/mightypork/gamecore/gui/components/input/ClickableComponent.java

50 lines
961 B

10 years ago
package mightypork.gamecore.gui.components.input;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.HasAction;
10 years ago
import mightypork.gamecore.gui.components.InputComponent;
import mightypork.gamecore.input.events.MouseButtonEvent;
import mightypork.gamecore.input.events.MouseButtonHandler;
public abstract class ClickableComponent extends InputComponent implements HasAction, MouseButtonHandler {
10 years ago
protected boolean btnDownOver;
private Action action;
10 years ago
@Override
public void setAction(Action action)
{
this.action = action;
}
10 years ago
protected void triggerAction()
{
if (action != null && isEnabled()) action.run();
}
10 years ago
@Override
public void receive(MouseButtonEvent event)
{
if (!event.isButtonEvent()) return;
10 years ago
if (event.isDown()) {
btnDownOver = event.isOver(this);
}
10 years ago
if (event.isUp()) {
10 years ago
if (btnDownOver && event.isOver(this)) {
triggerAction();
event.consume();
}
10 years ago
btnDownOver = false;
}
}
}