Search in sources :

Example 46 with KeyCode

use of javafx.scene.input.KeyCode in project FXyzLib by Birdasaur.

the class BillBoardBehaviorTest method initFirstPersonControls.

private void initFirstPersonControls(SubScene scene) {
    //make sure Subscene handles KeyEvents
    scene.setOnMouseEntered(e -> {
        scene.requestFocus();
    });
    //First person shooter keyboard movement
    scene.setOnKeyPressed(event -> {
        double change = 10.0;
        if (event.isShiftDown()) {
            change = 50.0;
        }
        KeyCode keycode = event.getCode();
        if (keycode == KeyCode.W) {
            camera.setTranslateZ(camera.getTranslateZ() + change);
        }
        if (keycode == KeyCode.S) {
            camera.setTranslateZ(camera.getTranslateZ() - change);
        }
        if (keycode == KeyCode.A) {
            camera.setTranslateX(camera.getTranslateX() - change);
        }
        if (keycode == KeyCode.D) {
            camera.setTranslateX(camera.getTranslateX() + change);
        }
    });
    scene.setOnMousePressed((MouseEvent me) -> {
        if (!scene.isFocused()) {
            scene.requestFocus();
        }
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseOldX = me.getSceneX();
        mouseOldY = me.getSceneY();
    });
    scene.setOnMouseDragged((MouseEvent me) -> {
        mouseOldX = mousePosX;
        mouseOldY = mousePosY;
        mousePosX = me.getSceneX();
        mousePosY = me.getSceneY();
        mouseDeltaX = (mousePosX - mouseOldX);
        mouseDeltaY = (mousePosY - mouseOldY);
        double modifier = 10.0;
        double modifierFactor = 0.1;
        if (me.isControlDown()) {
            modifier = 0.1;
        }
        if (me.isShiftDown()) {
            modifier = 50.0;
        }
        if (me.isPrimaryButtonDown()) {
            // +
            cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
            cameraTransform.rx.setAngle(MathUtils.clamp(-60, (((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180), // - 
            60));
        } else if (me.isSecondaryButtonDown()) {
            double z = camera.getTranslateZ();
            double newZ = z + mouseDeltaX * modifierFactor * modifier;
            camera.setTranslateZ(newZ);
        } else if (me.isMiddleButtonDown()) {
            // -
            cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
            // -
            cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
        }
    });
}
Also used : MouseEvent(javafx.scene.input.MouseEvent) KeyCode(javafx.scene.input.KeyCode)

Example 47 with KeyCode

use of javafx.scene.input.KeyCode in project Gargoyle by callakrsos.

the class VoEditorController method initialize.

/**
	 * 이벤트 초기화
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2015. 10. 15.
	 */
@FXML
public void initialize() {
    colType.setCellFactory(new ClassTypeCheckBoxCellFactory());
    colName.setCellFactory(TextFieldTableCell.forTableColumn());
    colSize.setCellFactory(TextFieldTableCell.forTableColumn());
    colDesc.setCellFactory(TextFieldTableCell.forTableColumn());
    CommonsContextMenu.addMenus(tbVoEditor, (Menus.useCudButtons() | Menus.UP | Menus.DOWN));
    // tbVoEditor.setContextMenu();
    tbVoEditor.addEventHandler(ActionEvent.ACTION, event -> {
        if (event instanceof CommonContextMenuEvent) {
            CommonContextMenuEvent _event = (CommonContextMenuEvent) event;
            int mode = _event.getMode();
            ObservableList<TableModelDVO> items = tbVoEditor.getItems();
            int selectedIndex = tbVoEditor.getSelectionModel().getSelectedIndex();
            int rowSize = items.size();
            boolean isMove = false;
            if (Menus.isAdd(mode)) {
                items.add(defaultTableModelDVO());
                isMove = true;
            } else if (Menus.isDelete(mode)) {
                items.remove(selectedIndex);
                isMove = true;
            } else if (Menus.isUp(mode)) {
                btnUpOnMouseClick();
            } else if (Menus.isDown(mode)) {
                btnDownOnMouseClick();
            }
            if (isMove) {
                tbVoEditor.getSelectionModel().select(rowSize - 1);
            }
        }
    });
    // 컨트롤 키를 누르면 그리드 데이터 이동처리.
    tbVoEditor.setOnKeyPressed(event -> {
        if (event.isControlDown()) {
            KeyCode code = event.getCode();
            switch(code) {
                case UP:
                    btnUpOnMouseClick();
                    break;
                case DOWN:
                    btnDownOnMouseClick();
                    break;
                default:
                    break;
            }
            event.consume();
        }
    });
    btnGenerate.addEventHandler(MouseEvent.MOUSE_CLICKED, this::btnGenerateOnMouseClick);
    btnSelect.setOnMouseClicked(this::btnSelectOnMouseClick);
    btnDatabase.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            DatabaseTableView databaseTableView = new DatabaseTableView();
            TableDVO show = databaseTableView.show();
            if (show != null) {
                TableMasterDVO tableMasterDVO = show.getTableMasterDVO();
                List<TableModelDVO> tableModelDVOList = show.getTableModelDVOList();
                ObservableList<TableModelDVO> items = tbVoEditor.getItems();
                if (tableMasterDVO != null) {
                    txtClassName.setText(tableMasterDVO.getClassName());
                    txtAreaDesc.setText(tableMasterDVO.getDescription());
                }
                if (tableModelDVOList != null) {
                    items.clear();
                    items.addAll(tableModelDVOList);
                }
            }
        }
    });
}
Also used : TableMasterDVO(kyj.Fx.dao.wizard.core.model.vo.TableMasterDVO) CommonContextMenuEvent(com.kyj.fx.voeditor.visual.events.CommonContextMenuEvent) MouseEvent(javafx.scene.input.MouseEvent) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) DatabaseTableView(com.kyj.fx.voeditor.visual.component.popup.DatabaseTableView) ClassTypeCheckBoxCellFactory(com.kyj.fx.voeditor.visual.component.ClassTypeCheckBoxCellFactory) TableDVO(kyj.Fx.dao.wizard.core.model.vo.TableDVO) ObservableList(javafx.collections.ObservableList) KeyCode(javafx.scene.input.KeyCode) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) FXML(javafx.fxml.FXML)

Example 48 with KeyCode

use of javafx.scene.input.KeyCode in project fx2048 by brunoborges.

the class GamePane method addKeyHandler.

private void addKeyHandler(Node node) {
    node.setOnKeyPressed(ke -> {
        KeyCode keyCode = ke.getCode();
        if (keyCode.equals(KeyCode.S)) {
            gameManager.saveSession();
            return;
        }
        if (keyCode.equals(KeyCode.R)) {
            gameManager.restoreSession();
            return;
        }
        if (keyCode.equals(KeyCode.P)) {
            gameManager.pauseGame();
            return;
        }
        if (keyCode.equals(KeyCode.Q) || keyCode.equals(KeyCode.ESCAPE)) {
            gameManager.quitGame();
            return;
        }
        if (keyCode.isArrowKey()) {
            Direction direction = Direction.valueFor(keyCode);
            move(direction);
        }
    });
}
Also used : KeyCode(javafx.scene.input.KeyCode)

Aggregations

KeyCode (javafx.scene.input.KeyCode)48 Scene (javafx.scene.Scene)36 PerspectiveCamera (javafx.scene.PerspectiveCamera)31 MouseEvent (javafx.scene.input.MouseEvent)30 Group (javafx.scene.Group)29 PointLight (javafx.scene.PointLight)24 Rotate (javafx.scene.transform.Rotate)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 AnimationTimer (javafx.animation.AnimationTimer)14 Point3D (org.fxyz.geometry.Point3D)11 Translate (javafx.scene.transform.Translate)10 ArrayList (java.util.ArrayList)9 AmbientLight (javafx.scene.AmbientLight)8 Sphere (javafx.scene.shape.Sphere)8 Color (javafx.scene.paint.Color)7 OBJWriter (org.fxyz.utils.OBJWriter)7 KeyFrame (javafx.animation.KeyFrame)6 KeyValue (javafx.animation.KeyValue)6 Timeline (javafx.animation.Timeline)6 PhongMaterial (javafx.scene.paint.PhongMaterial)6