use of net.drewke.tdme.gui.events.GUIMouseEvent in project tdme by andreasdr.
the class CameraRotationInputHandler method handleInputEvents.
/*
* (non-Javadoc)
* @see net.drewke.tdme.gui.events.GUIInputEventHandler#handleInputEvents()
*/
public void handleInputEvents() {
// handle mouse events
for (int i = 0; i < engine.getGUI().getMouseEvents().size(); i++) {
GUIMouseEvent event = engine.getGUI().getMouseEvents().get(i);
// skip on processed events
if (event.isProcessed() == true)
continue;
// dragging
if (mouseDragging == true) {
if (event.getButton() == 1) {
float xMoved = (event.getX() - mouseLastX) / 5f;
float yMoved = (event.getY() - mouseLastY) / 5f;
mouseLastX = event.getX();
mouseLastY = event.getY();
Rotation xRotation = lookFromRotations.getRotations().get(0);
Rotation yRotation = lookFromRotations.getRotations().get(1);
float xRotationAngle = xRotation.getAngle() + xMoved;
float yRotationAngle = yRotation.getAngle() + yMoved;
xRotation.setAngle(xRotationAngle);
yRotation.setAngle(yRotationAngle);
lookFromRotations.update();
} else {
mouseDragging = false;
}
} else {
if (event.getButton() == 1) {
mouseDragging = true;
mouseLastX = event.getX();
mouseLastY = event.getY();
}
}
// process mouse wheel events
float mouseWheel = event.getWheelY();
if (mouseWheel != 0) {
scale += mouseWheel * 0.05f;
if (scale < 0.05f)
scale = 0.05f;
}
}
// handle keyboard events
for (int i = 0; i < engine.getGUI().getKeyboardEvents().size(); i++) {
GUIKeyboardEvent event = engine.getGUI().getKeyboardEvents().get(i);
// skip on processed events
if (event.isProcessed() == true)
continue;
//
boolean isKeyDown = event.getType() == Type.KEY_PRESSED;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_LEFT)
keyLeft = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_RIGHT)
keyRight = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_UP)
keyUp = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_DOWN)
keyDown = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == '.')
keyPeriod = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == ',')
keyComma = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == '+')
keyPlus = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == '-')
keyMinus = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'r')
keyR = isKeyDown;
}
//
// handle keyboard input
// get rotations
Rotation rotationX = lookFromRotations.getRotations().get(0);
Rotation rotationY = lookFromRotations.getRotations().get(1);
Rotation rotationZ = lookFromRotations.getRotations().get(2);
// transfer keyboard inputs to rotations
if (keyLeft)
rotationX.setAngle(rotationX.getAngle() - 1f);
if (keyRight)
rotationX.setAngle(rotationX.getAngle() + 1f);
if (keyUp)
rotationY.setAngle(rotationY.getAngle() + 1f);
if (keyDown)
rotationY.setAngle(rotationY.getAngle() - 1f);
if (keyComma)
rotationZ.setAngle(rotationZ.getAngle() - 1f);
if (keyPeriod)
rotationZ.setAngle(rotationZ.getAngle() + 1f);
if (keyMinus)
scale += 0.05f;
if (keyPlus && scale > 0.05f)
scale -= 0.05f;
if (keyR == true || resetRequested == true) {
rotationY.setAngle(-45f);
rotationZ.setAngle(0f);
scale = 1.0f;
}
// update transformations if key was pressed
if (keyLeft || keyRight || keyUp || keyDown || keyComma || keyPeriod || keyR || resetRequested) {
lookFromRotations.update();
resetRequested = false;
}
// set up cam
Camera cam = engine.getCamera();
// we have a fixed look at
Vector3 lookAt = cam.getLookAt();
// look at -> look to vector
Vector3 lookAtToFromVector = new Vector3(0f, 0f, +(maxAxisDimension * 1.2f));
// apply look from rotations
// apply look from rotations
Vector3 lookAtToFromVectorTransformed = new Vector3();
Vector3 lookAtToFromVectorScaled = new Vector3();
Vector3 upVector = new Vector3();
lookFromRotations.getTransformationsMatrix().multiply(lookAtToFromVector, lookAtToFromVectorTransformed);
lookAtToFromVectorScaled.set(lookAtToFromVectorTransformed).scale(scale);
lookFromRotations.getRotations().get(2).getQuaternion().multiply(new Vector3(0f, 1f, 0f), upVector);
/*
Vector3 forwardVector = lookAtToFromVectorTransformed.clone().scale(-1f);
Vector3 sideVector = Vector3.computeCrossProduct(forwardVector, upVector);
if (keyA) camLookAt.sub(sideVector.clone().scale(0.05f));
if (keyD) camLookAt.add(sideVector.clone().scale(0.05f));
if (keyW) camLookAt.add(upVector.clone().scale(0.05f * forwardVector.computeLength()));
if (keyS) camLookAt.sub(upVector.clone().scale(0.05f * forwardVector.computeLength()));
*/
// look from with rotations
Vector3 lookFrom = lookAt.clone().add(lookAtToFromVectorScaled);
cam.getLookFrom().set(lookFrom);
// up vector
cam.getUpVector().set(upVector);
}
use of net.drewke.tdme.gui.events.GUIMouseEvent in project tdme by andreasdr.
the class GUI method handleEvents.
/**
* Handle events for given node
* @param node
*/
private void handleEvents(GUINode node) {
// handle mouse events
for (int i = 0; i < mouseEvents.size(); i++) {
GUIMouseEvent event = mouseEvents.get(i);
if (event.isProcessed() == true)
continue;
// take GUI position effect into account
event.setX(event.getX() + node.getScreenNode().getGUIEffectOffsetX());
event.setY(event.getY() + node.getScreenNode().getGUIEffectOffsetY());
node.handleMouseEvent(event);
}
// handle keyboard events
for (int i = 0; i < keyboardEvents.size(); i++) {
GUIKeyboardEvent event = keyboardEvents.get(i);
if (event.isProcessed() == true)
continue;
// handle focussing
switch(event.getKeyCode()) {
case (GUIKeyboardEvent.KEYCODE_TAB):
{
if (event.getType() == GUIKeyboardEvent.Type.KEY_PRESSED) {
if (event.isShiftDown() == true) {
focusPreviousNode();
} else {
focusNextNode();
}
}
event.setProcessed(true);
break;
}
default:
{
break;
}
}
// delegate keyboard event to node if not yet processed
if (event.isProcessed() == true) {
continue;
}
// delegate event to focussed node
if (focussedNode != null) {
focussedNode.handleKeyboardEvent(event);
}
}
}
use of net.drewke.tdme.gui.events.GUIMouseEvent in project tdme by andreasdr.
the class GUI method mouseMoved.
/*
* (non-Javadoc)
* @see com.jogamp.newt.event.MouseListener#mouseMoved(com.jogamp.newt.event.MouseEvent)
*/
public void mouseMoved(MouseEvent event) {
lockEvents();
GUIMouseEvent guiMouseEvent = mouseEventsPool.allocate();
guiMouseEvent.setTime(System.currentTimeMillis());
guiMouseEvent.setType(Type.MOUSE_MOVED);
guiMouseEvent.setX(event.getX());
guiMouseEvent.setY(event.getY());
guiMouseEvent.setButton(event.getButton());
guiMouseEvent.setWheelX(event.getRotation()[0] * event.getRotationScale());
guiMouseEvent.setWheelY(event.getRotation()[1] * event.getRotationScale());
guiMouseEvent.setWheelZ(event.getRotation()[2] * event.getRotationScale());
guiMouseEvent.setProcessed(false);
mouseEvents.add(guiMouseEvent);
unlockEvents();
}
use of net.drewke.tdme.gui.events.GUIMouseEvent in project tdme by andreasdr.
the class LevelEditorView method handleInputEvents.
/*
* (non-Javadoc)
* @see net.drewke.tdme.gui.events.GUIInputEventHandler#handleInputEvents()
*/
public void handleInputEvents() {
boolean keyDeleteBefore = keyDelete;
boolean keyControlBefore = keyControl;
boolean keyCBefore = keyC;
boolean keyVBefore = keyV;
boolean keyXBefore = keyX;
// handle keyboard events
for (int i = 0; i < engine.getGUI().getKeyboardEvents().size(); i++) {
GUIKeyboardEvent event = engine.getGUI().getKeyboardEvents().get(i);
// skip on processed events
if (event.isProcessed() == true)
continue;
//
boolean isKeyDown = event.getType() == Type.KEY_PRESSED;
//
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_CONTROL)
keyControl = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_ESCAPE)
keyEscape = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_LEFT)
keyLeft = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_RIGHT)
keyRight = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_UP)
keyUp = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_DOWN)
keyDown = isKeyDown;
if (event.getKeyCode() == GUIKeyboardEvent.KEYCODE_BACKSPACE)
keyDelete = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'x')
keyX = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'c')
keyC = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'v')
keyV = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'a')
keyA = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'd')
keyD = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'w')
keyW = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 's')
keyS = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == '+')
keyPlus = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == '-')
keyMinus = isKeyDown;
if (Character.toLowerCase(event.getKeyChar()) == 'r')
keyR = isKeyDown;
}
// unselect objects by key escape
if (keyEscape == true && selectedObjects.size() > 0) {
ArrayList<Entity> objectsToRemove = new ArrayList<Entity>();
for (Entity selectedObject : selectedObjects) {
objectsToRemove.add(selectedObject);
}
for (Entity objectToRemove : objectsToRemove) {
setStandardObjectColorEffect(objectToRemove);
selectedObjects.remove(objectToRemove);
selectedObjectsById.remove(objectToRemove.getId());
}
levelEditorScreenController.unselectObjectsInObjectListBox();
}
// handle mouse events
for (int i = 0; i < engine.getGUI().getMouseEvents().size(); i++) {
GUIMouseEvent event = engine.getGUI().getMouseEvents().get(i);
// skip on processed events
if (event.isProcessed() == true)
continue;
// check if dragging
if (event.getButton() != MOUSE_BUTTON_NONE) {
// check if dragging
if (mouseDragging == false) {
if (mouseDownLastX != event.getX() || mouseDownLastY != event.getY()) {
mouseDragging = true;
}
}
} else {
// unset dragging
if (mouseDragging == true) {
mouseDownLastX = MOUSE_DOWN_LAST_POSITION_NONE;
mouseDownLastY = MOUSE_DOWN_LAST_POSITION_NONE;
mouseDragging = false;
mouseDraggingLastObject = null;
}
}
// selection
if (event.getButton() == MOUSE_BUTTON_LEFT) {
// check if dragging
if (mouseDragging == false) {
if (mouseDownLastX != event.getX() || mouseDownLastY != event.getY()) {
mouseDragging = true;
}
}
// unselect current selected objects
if (keyControl == false) {
ArrayList<Entity> objectsToRemove = new ArrayList<Entity>();
for (Entity selectedObject : selectedObjects) {
if (mouseDragging == true && mouseDraggingLastObject == selectedObject) {
/// no op
} else {
objectsToRemove.add(selectedObject);
}
}
for (Entity objectToRemove : objectsToRemove) {
setStandardObjectColorEffect(objectToRemove);
selectedObjects.remove(objectToRemove);
selectedObjectsById.remove(objectToRemove.getId());
levelEditorScreenController.unselectObjectInObjectListBox(objectToRemove.getId());
}
}
// check if object was clicked first
Entity selectedObject = engine.getObjectByMousePosition(event.getX(), event.getY(), entityPickingFilterNoGrid);
// if not, check if ground plate was clicked
if (selectedObject == null) {
selectedObject = engine.getObjectByMousePosition(event.getX(), event.getY());
}
// select cell if any was selected
if (selectedObject != null) {
// add to selected objects if not yet done
if (mouseDragging == true && mouseDraggingLastObject == selectedObject) {
// no op
} else {
if (selectedObjects.contains(selectedObject) == false) {
setStandardObjectColorEffect(selectedObject);
setHighlightObjectColorEffect(selectedObject);
selectedObjects.add(selectedObject);
selectedObjectsById.put(selectedObject.getId(), selectedObject);
// select in objects listbox
levelEditorScreenController.selectObjectInObjectListbox(selectedObject.getId());
// select in entity library
LevelEditorObject levelEditorObject = level.getObjectById(selectedObject.getId());
if (levelEditorObject != null) {
TDMELevelEditor.getInstance().getLevelEditorEntityLibraryScreenController().selectEntity(levelEditorObject.getEntity().getId());
}
} else {
// undo add
setStandardObjectColorEffect(selectedObject);
selectedObjects.remove(selectedObject);
selectedObjectsById.remove(selectedObject.getId());
// unselect in objects listbox
levelEditorScreenController.unselectObjectInObjectListBox(selectedObject.getId());
}
}
}
// set mouse dragging last
mouseDraggingLastObject = selectedObject;
// update gui elements
updateGUIElements();
} else // panning
if (event.getButton() == MOUSE_BUTTON_RIGHT) {
if (mouseDownLastX != MOUSE_DOWN_LAST_POSITION_NONE && mouseDownLastY != MOUSE_DOWN_LAST_POSITION_NONE) {
mousePanningSide = event.getX() - mouseDownLastX;
mousePanningForward = event.getY() - mouseDownLastY;
}
} else if (event.getButton() == MOUSE_BUTTON_MIDDLE) {
centerObject();
if (mouseDownLastX != MOUSE_DOWN_LAST_POSITION_NONE && mouseDownLastY != MOUSE_DOWN_LAST_POSITION_NONE) {
mouseRotationX = event.getX() - mouseDownLastX;
mouseRotationY = event.getY() - mouseDownLastY;
}
}
// last mouse down position
if (event.getButton() != MOUSE_BUTTON_NONE) {
//
mouseDownLastX = event.getX();
mouseDownLastY = event.getY();
}
// process mouse wheel events
float mouseWheel = event.getWheelY();
if (mouseWheel != 0) {
camScale += -mouseWheel * 0.05f;
if (camScale < camScaleMin)
camScale = camScaleMin;
if (camScale > camScaleMax)
camScale = camScaleMax;
}
}
// delete objects
if (keyDeleteBefore == true && keyDelete == false) {
removeObject();
}
// cut objects
if ((keyControlBefore == true || keyControl == true) && keyXBefore == true && keyX == false) {
copyObjects();
removeObject();
}
// copy objects
if ((keyControlBefore == true || keyControl == true) && keyCBefore == true && keyC == false) {
copyObjects();
}
// paste objects
if ((keyControlBefore == true || keyControl == true) && keyVBefore == true && keyV == false) {
pasteObjects();
}
}
use of net.drewke.tdme.gui.events.GUIMouseEvent in project tdme by andreasdr.
the class GUI method mouseDragged.
/*
* (non-Javadoc)
* @see com.jogamp.newt.event.MouseListener#mouseDragged(com.jogamp.newt.event.MouseEvent)
*/
public void mouseDragged(MouseEvent event) {
lockEvents();
GUIMouseEvent guiMouseEvent = mouseEventsPool.allocate();
guiMouseEvent.setTime(System.currentTimeMillis());
guiMouseEvent.setType(Type.MOUSE_DRAGGED);
guiMouseEvent.setX(event.getX());
guiMouseEvent.setY(event.getY());
guiMouseEvent.setButton(event.getButton());
guiMouseEvent.setWheelX(event.getRotation()[0] * event.getRotationScale());
guiMouseEvent.setWheelY(event.getRotation()[1] * event.getRotationScale());
guiMouseEvent.setWheelZ(event.getRotation()[2] * event.getRotationScale());
guiMouseEvent.setProcessed(false);
mouseEvents.add(guiMouseEvent);
unlockEvents();
}
Aggregations