Skip to content

Instantly share code, notes, and snippets.

@telamon
Created March 26, 2012 23:15
Show Gist options
  • Save telamon/2210505 to your computer and use it in GitHub Desktop.
Save telamon/2210505 to your computer and use it in GitHub Desktop.
Custom JoglInputSystem
/**
* Suppress mouse events if they hit panel with id "glassPane"
* unless a MouseDragged gesture is in process to ensure that every MouseClickedEvent that hits
* will be followed by an MouseReleasedEvent even if it's coords do not overlap any other nifty elements.
*/
private final JoglInputSystem inputSystem = new JoglInputSystem() {
boolean niftyBusy=false;
@Override
public void mouseDragged(MouseEvent mouseEvent) {
if (niftyBusy) {
super.mouseDragged(mouseEvent);
}
}
@Override
public void mouseReleased(MouseEvent mouseEvent) {
niftyBusy=false;
super.mouseReleased(mouseEvent);
}
@Override
public void mousePressed(MouseEvent mouseEvent) {
if (checkElementHits(mouseEvent)) {
ControlManager.getSingleton().suppressEvents(true); // Pauses personal App event listener.
niftyBusy = true;
super.mousePressed(mouseEvent);
} else {
ControlManager.getSingleton().suppressEvents(false); // Resumes personal App event listener.
}
}
private boolean checkElementHits(MouseEvent mouseEvent) {
if (nifty != null) {
Element glassPane = nifty.getCurrentScreen().findElementByName("glassPane");
//ArrayList<Element> hits= new ArrayList<>();
//String path ="";
Iterator<Element> iterator = nifty.getCurrentScreen().getRootElement().getDescendants();
Element last = null;
while (iterator.hasNext()) {
Element e = iterator.next();
if (e.isMouseInsideElement(mouseEvent.getX(), mouseEvent.getY())) {
last = e;
// hits.add(e);
// path+= e.getId()+" -> ";
}
}
//System.out.println("Hits: "+hits.size() + "\n" +path);
return (last != null && !glassPane.equals(last));
}
return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment