com.jme3.input.event.MouseButtonEvent Java Examples

The following examples show how to use com.jme3.input.event.MouseButtonEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InputSystemJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void forwardEvents(NiftyInputConsumer nic) {
    int queueSize = inputQueue.size();

    for (int i = 0; i < queueSize; i++){
        InputEvent evt = inputQueue.get(i);
        if (evt instanceof MouseMotionEvent){
            onMouseMotionEventQueued( (MouseMotionEvent)evt, nic);
        }else if (evt instanceof MouseButtonEvent){
            onMouseButtonEventQueued( (MouseButtonEvent)evt, nic);
        }else if (evt instanceof KeyInputEvent){
            onKeyEventQueued( (KeyInputEvent)evt, nic);
        }
    }

    inputQueue.clear();
}
 
Example #2
Source File: SelectionState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onMouseButtonEvent( MouseButtonEvent evt ) {
    if( !isEnabled() ) {
        return;
    }
    if( evt.isPressed() ) {
        // Save the location for later
        clickStart.set(evt.getX(), evt.getY());
    } else if( evt.isReleased() ) {
        
        Vector2f click = new Vector2f(evt.getX(), evt.getY());
        if( click.distanceSquared(clickStart) < clickRadiusSq ) {
            processClickEvent(click, evt);
        }  
    }
}
 
Example #3
Source File: IosInputHandler.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void update() {
     logger.log(Level.FINE, "InputEvent update : {0}",
            new Object[]{listener});
   if (listener != null) {
        InputEvent inputEvent;

        while ((inputEvent = inputEventQueue.poll()) != null) {
            if (inputEvent instanceof TouchEvent) {
                listener.onTouchEvent((TouchEvent)inputEvent);
            } else if (inputEvent instanceof MouseButtonEvent) {
                listener.onMouseButtonEvent((MouseButtonEvent)inputEvent);
            } else if (inputEvent instanceof MouseMotionEvent) {
                listener.onMouseMotionEvent((MouseMotionEvent)inputEvent);
            } else if (inputEvent instanceof KeyInputEvent) {
                listener.onKeyEvent((KeyInputEvent)inputEvent);
            }
        }
    }
}
 
Example #4
Source File: AndroidTouchInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void update() {
    if (listener != null) {
        InputEvent inputEvent;

        while ((inputEvent = inputEventQueue.poll()) != null) {
            if (inputEvent instanceof TouchEvent) {
                listener.onTouchEvent((TouchEvent)inputEvent);
            } else if (inputEvent instanceof MouseButtonEvent) {
                listener.onMouseButtonEvent((MouseButtonEvent)inputEvent);
            } else if (inputEvent instanceof MouseMotionEvent) {
                listener.onMouseMotionEvent((MouseMotionEvent)inputEvent);
            } else if (inputEvent instanceof KeyInputEvent) {
                listener.onKeyEvent((KeyInputEvent)inputEvent);
            }
        }
    }
}
 
Example #5
Source File: AbstractCameraController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onMouseButtonEvent(MouseButtonEvent mbe) {
    //on a click release we request the focus for the top component
    //this allow netbeans to catch keyEvents and trigger actions according to keymapping
    if (mbe.isReleased()) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                SceneViewerTopComponent.findInstance().requestActive();
            }
        });
    }

}
 
Example #6
Source File: InputSystemJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void onMouseButtonEventQueued(MouseButtonEvent evt, NiftyInputConsumer nic) {
    boolean wasPressed = pressed;
    boolean forwardToNifty = true;
    
    buttonIndex = evt.getButtonIndex();
    pressed = evt.isPressed();
    
    // Mouse button raised. End dragging
    if (wasPressed && !pressed){
        if (!niftyOwnsDragging){
            forwardToNifty = false;
        }
        isDragging = false;
        niftyOwnsDragging = false;
    }

    boolean consumed = false;
    if (forwardToNifty){
        consumed = nic.processMouseEvent(x, y, 0, buttonIndex, pressed);
        if (consumed){
            evt.setConsumed();
        }
    }
    
    // Mouse button pressed. Begin dragging
    if (!wasPressed && pressed){
        isDragging = true;
        niftyOwnsDragging = consumed;
    }
}
 
Example #7
Source File: AwtMouseInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void mousePressed(MouseEvent arg0) {
    MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(arg0), true, arg0.getX(), arg0.getY());
    evt.setTime(arg0.getWhen());
    synchronized (eventQueue){
        eventQueue.add(evt);
    }
}
 
Example #8
Source File: AwtMouseInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void mouseReleased(MouseEvent arg0) {
    MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(arg0), false, arg0.getX(), arg0.getY());
    evt.setTime(arg0.getWhen());
    synchronized (eventQueue){
        eventQueue.add(evt);
    }
}
 
Example #9
Source File: AWTMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void onMouseButton(MouseEvent event, final boolean pressed) {

        final MouseButtonEvent mouseButtonEvent = new MouseButtonEvent(convertButton(event.getButton()), pressed, mouseX, mouseY);
        mouseButtonEvent.setTime(getInputTimeNanos());

        EXECUTOR.addToExecute(new Runnable() {

          @Override
          public void run() {
            mouseButtonEvents.add(mouseButtonEvent);
          }
          
        });
    }
 
Example #10
Source File: AwtMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseReleased(MouseEvent awtEvt) {
    int y = component.getHeight() - awtEvt.getY();
    MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), false, awtEvt.getX(), y);
    evt.setTime(awtEvt.getWhen());
    synchronized (eventQueue) {
        eventQueue.add(evt);
    }
}
 
Example #11
Source File: AwtMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent awtEvt) {
    // Must flip Y!
    int y = component.getHeight() - awtEvt.getY();
    MouseButtonEvent evt = new MouseButtonEvent(getJMEButtonIndex(awtEvt), true, awtEvt.getX(), y);
    evt.setTime(awtEvt.getWhen());
    synchronized (eventQueue) {
        eventQueue.add(evt);
    }
}
 
Example #12
Source File: InputManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Callback from RawInputListener. Do not use.
 */
public void onMouseButtonEvent(MouseButtonEvent evt) {
    if (!eventsPermitted) {
        throw new UnsupportedOperationException("MouseInput has raised an event at an illegal time.");
    }
    //updating cursor pos on click, so that non android touch events can properly update cursor position.
    cursorPos.set(evt.getX(), evt.getY());
    inputQueue.add(evt);
}
 
Example #13
Source File: Button.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void mouseButtonEvent( MouseButtonEvent event, Spatial target, Spatial capture ) {

    // Buttons always consume their click events
    event.setConsumed();

    // Do our own better handling of 'click' now
    //super.mouseButtonEvent(event, target, capture);
    if( !isEnabled() )
        return;                                            

    if( event.isPressed() ) {
        setPressed(event.isPressed());
    } else if( isPressed() ) {
        // Only run the up processing if we were already pressed
        // This also handles the case where we weren't enabled before
        // but are now, etc.
        
        if( target == capture ) {
            // Then we are still over the button and we should run the
            // click
            runClick();
        }
        // If we run the up without checking properly then we
        // potentially get up events with no down event.  This messes
        // up listeners that are (correctly) expecting an up for every
        // down and no ups without downs.
        // So, any time the capture is us then we will run, else not
        if( capture == Button.this ) {
            setPressed(false);
        }
    }
}
 
Example #14
Source File: TestSoftwareMouse.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onMouseButtonEvent(MouseButtonEvent evt) {
}
 
Example #15
Source File: TestBitmapFont.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void onMouseButtonEvent(MouseButtonEvent evt) { }
 
Example #16
Source File: InputManager.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void onMouseButtonEventQueued(MouseButtonEvent evt) {
    int hash = MouseButtonTrigger.mouseButtonHash(evt.getButtonIndex());
    invokeActions(hash, evt.isPressed());
    invokeTimedActions(hash, evt.getTime(), evt.isPressed());
}
 
Example #17
Source File: GlfwMouseInputVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void onMouseButton(final long window, final int button, final int action, final int mods) {
    final MouseButtonEvent mouseButtonEvent = new MouseButtonEvent(convertButton(button), action == GLFW_PRESS, mouseX, mouseY);
    mouseButtonEvent.setTime(getInputTimeNanos());
    mouseButtonEvents.add(mouseButtonEvent);
}
 
Example #18
Source File: InputSystemJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void onMouseButtonEvent(MouseButtonEvent evt) {
    if (inputManager.isCursorVisible() && evt.getButtonIndex() >= 0 || evt.getButtonIndex() <= 2){
        inputQueue.add(evt);
    }
}
 
Example #19
Source File: GlfwMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void onMouseButton(final long window, final int button, final int action, final int mods) {
    final boolean pressed = action == GLFW_PRESS;
    final MouseButtonEvent mouseButtonEvent = new MouseButtonEvent(convertButton(button), pressed, mouseX, mouseY);
    mouseButtonEvent.setTime(getInputTimeNanos());
    mouseButtonEvents.add(mouseButtonEvent);
}
 
Example #20
Source File: TestJoystick.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onMouseButtonEvent(MouseButtonEvent evt) {}
 
Example #21
Source File: AWTMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public AWTMouseInput(AWTContext context) {
    super(context);
    mouseMotionEvents = new LinkedList<MouseMotionEvent>();
    mouseButtonEvents = new LinkedList<MouseButtonEvent>();
}
 
Example #22
Source File: MouseAppState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onMouseButtonEvent( MouseButtonEvent evt ) {
    if( isEnabled() ) {
        dispatch(evt);
    }
}
 
Example #23
Source File: MouseAppState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void dispatch( MouseButtonEvent evt ) {
    if( getSession().buttonEvent(evt.getButtonIndex(), evt.getX(), evt.getY(), evt.isPressed()) ) {
        evt.setConsumed();
    }
}
 
Example #24
Source File: DefaultRawInputListener.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void onMouseButtonEvent( MouseButtonEvent evt ) {
}
 
Example #25
Source File: Button.java    From Lemur with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void click( MouseButtonEvent event, Spatial target, Spatial capture ) {
}
 
Example #26
Source File: RawInputListener.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Invoked on mouse button events.
 * 
 * @param evt 
 */
public void onMouseButtonEvent(MouseButtonEvent evt);