Java Code Examples for com.badlogic.gdx.scenes.scene2d.InputEvent

The following examples show how to use com.badlogic.gdx.scenes.scene2d.InputEvent. These examples are extracted from open source projects. 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 Project: bladecoder-adventure-engine   Source File: EditorLogger.java    License: Apache License 2.0 6 votes vote down vote up
public static void setConsole(Console console) {
	EditorLogger.console = console;
	EditorLogger.console.setDisplayKeyID(Keys.F1);
	console.setMaxEntries(1000);

	final Stage s = (Stage) console.getInputProcessor();
	final Actor actor = s.getActors().items[0];
	actor.addListener(new InputListener() {
		@Override
		public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
			
			if (toActor == null) {
				s.setScrollFocus(null);
			}
		}
	});

	console.setCommandExecutor(new EditorCommandExecutor());
}
 
Example 2
Source Project: gdx-vfx   Source File: EffectRosterViewController.java    License: Apache License 2.0 6 votes vote down vote up
private void addEffectToChain(final EffectEntryModel effectModel) {
    if (effectsChain.containsKey(effectModel)) {
        // If the effect is already in the chain, re-add it to the end of the list.
        removeEffectFromChain(effectModel);
    }

    EffectEntryViewController viewController = new EffectEntryViewController(lmlParser, effectModel);
    Group viewRoot = viewController.getViewRoot();
    vgEffectsChain.addActor(viewRoot);
    effectsChain.put(viewController.getModel(), viewController);
    vfxManager.addEffect(viewController.getModel().getEffect());

    viewRoot.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            removeEffectFromChain(effectModel);
        }
    });
}
 
Example 3
Source Project: gdx-vfx   Source File: OnBackPressedLmlAttribute.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    final ActorConsumer<?, Actor> action = parser.parseAction(rawAttributeData, actor);
    if (action == null) {
        parser.throwError("Could not find action for: " + rawAttributeData + " with actor: " + actor);
    }
    actor.addListener(new InputListener() {
        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.BACK || keycode == Keys.ESCAPE) {
                action.consume(actor);
                return true;
            }
            return false;
        }
    });
}
 
Example 4
Source Project: Mundus   Source File: ImageChooserField.java    License: Apache License 2.0 6 votes vote down vote up
private void setupListeners() {
    fcBtn.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            FileChooser fileChooser = UI.INSTANCE.getFileChooser();
            fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
            fileChooser.setListener(new SingleFileChooserListener() {
                public void selected(FileHandle file) {
                    if (FileFormatUtils.isImage(file)) {
                        setImage(file);
                    } else {
                        Dialogs.showErrorDialog(UI.INSTANCE, "This is no image");
                    }
                }
            });
            UI.INSTANCE.addActor(fileChooser.fadeIn());
        }
    });
}
 
Example 5
Source Project: talos   Source File: MainMenu.java    License: Apache License 2.0 6 votes vote down vote up
public void updateRecentsList(Array<String> list) {
    openRecentPopup.clear();

    for(String path: list) {
        final FileHandle handle = Gdx.files.absolute(path);
        if(!handle.exists()) continue;;
        String name = handle.name();
        MenuItem item = new MenuItem(name);
        item.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                if(handle.extension().equals("tls")) {
                    TalosMain.Instance().ProjectController().setProject(ProjectController.TLS);
                    TalosMain.Instance().ProjectController().loadProject(handle);
                } else {
                    TalosMain.Instance().Addons().projectFileDrop(handle);
                }
            }
        });
        openRecentPopup.addItem(item);
    }
}
 
Example 6
Source Project: talos   Source File: ModuleBoardWidget.java    License: Apache License 2.0 6 votes vote down vote up
public ModuleBoardWidget(NodeStage mainStage) {
    super();
    this.mainStage = mainStage;

    curvePoints[0] = new Vector2();
    curvePoints[1] = new Vector2();
    curvePoints[2] = new Vector2();
    curvePoints[3] = new Vector2();

    addActor(groupContainer);
    addActor(moduleContainer);

    shapeRenderer = new ShapeRenderer();

    addListener(new ClickListener() {

        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            if(event.isHandled()) return super.keyUp(event, keycode);
            if(keycode == Input.Keys.DEL || keycode == Input.Keys.FORWARD_DEL) {
                deleteSelectedWrappers();
            }
            return super.keyUp(event, keycode);
        }
    });
}
 
Example 7
Source Project: talos   Source File: AttachmentTypeToggle.java    License: Apache License 2.0 6 votes vote down vote up
public AttachmentTypeToggle(Skin skin) {
    setSkin(skin);
    setBackground(getSkin().getDrawable("panel_button_bg"));

    drawableMap.put(AttachmentPoint.AttachmentType.POSITION, getSkin().getDrawable("icon-target"));
    drawableMap.put(AttachmentPoint.AttachmentType.ROTATION, getSkin().getDrawable("icon-angle"));
    drawableMap.put(AttachmentPoint.AttachmentType.TRANSPARENCY, getSkin().getDrawable("icon-transparency"));
    drawableMap.put(AttachmentPoint.AttachmentType.COLOR, getSkin().getDrawable("icon-color"));

    button = new ImageButton(drawableMap.get(AttachmentPoint.AttachmentType.POSITION));

    addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            currentType = currentType.next();
            setButtonDrawable();
        }
    });

    setButtonDrawable();
}
 
Example 8
Source Project: buffer_bci   Source File: CalibrationScreen.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds exit button with listener in right bottom corner
 */
private void createBackButton() {
    // Create Button
    backButton = new TextButton("EXIT", VisUI.getSkin());

    // Set position in bottom right corner
    backButton.setX(Gdx.graphics.getWidth()-60);
    backButton.setY(0);
    backButton.setWidth(60);
    backButton.setHeight(60);
    backButton.setVisible(true);

    // Add Listener that sets the screen to the start screen of the game when button is clicked
    backButton.addListener(new ClickListener(){
        @Override
        public void clicked(InputEvent event, float x, float y) {
            StandardizedInterface.getInstance().StimuliSystem.stopStimulus();
            frameCounter = 0;
            game.setScreen(new MainMenuScreen(game));
        }
    });

    // Add Button to stage
    stage.addActor(backButton);
}
 
Example 9
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {

	super.touchUp(event, x, y, pointer, button);
	// EditorLogger.debug("Touch Up - X: " + x + " Y: " + y);

	if (draggingMode == DraggingModes.DRAGGING_ACTOR) {
		Ctx.project.getUndoStack().add(new UndoPosition(selActor, new Vector2(undoOrg)));
	} else if (draggingMode == DraggingModes.ROTATE_ACTOR) {
		Ctx.project.getUndoStack().add(new UndoRotation((SpriteActor) selActor, undoRot));
	} else if (draggingMode == DraggingModes.SCALE_ACTOR || draggingMode == DraggingModes.SCALE_LOCK_ACTOR) {
		Ctx.project.getUndoStack().add(new UndoScale((SpriteActor) selActor, new Vector2(undoOrg)));
	} else if (draggingMode == DraggingModes.DRAGGING_REFPOINT) {
		Ctx.project.getUndoStack().add(new UndoRefPosition((InteractiveActor) selActor, new Vector2(undoOrg)));
	} else if (draggingMode == DraggingModes.DRAGGING_BBOX_POINT) {
		Ctx.project.getUndoStack().add(new UndoBboxPointPos(selActor, vertIndex, new Vector2(undoOrg)));
	} else if (draggingMode == DraggingModes.DRAGGING_MARKER_0
			|| draggingMode == DraggingModes.DRAGGING_MARKER_100) {
		Ctx.project.getUndoStack().add(new UndoDepthVector(scnWidget.getScene(), new Vector2(undoOrg)));
	}

	draggingMode = DraggingModes.NONE;

	return;
}
 
Example 10
Source Project: Norii   Source File: PlayerBattleHUD.java    License: Apache License 2.0 6 votes vote down vote up
private void createActionUIs(Entity[] sortedUnits) {
	for (int i = 0; i < sortedUnits.length; i++) {
		if (sortedUnits[i].isPlayerUnit()) {
			final Entity entity = sortedUnits[i];
			actionUIs[i] = new ActionsUI(entity);
			final ActionsUI actionui = actionUIs[i];

			actionui.addListener(new InputListener() {
				@Override
				public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
					return true;
				}
			});

			stage.addActor(actionui);
		}
	}
}
 
Example 11
Source Project: Norii   Source File: PlayerBattleHUD.java    License: Apache License 2.0 6 votes vote down vote up
private void createStatusUIs(Entity[] sortedUnits) {
	for (int i = 0; i < sortedUnits.length; i++) {
		final Entity entity = sortedUnits[i];
		statusUIs[i] = new StatusUI(entity);
		final StatusUI statusui = statusUIs[i];

		statusui.addListener(new InputListener() {
			@Override
			public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
				return true;
			}
		});

		stage.addActor(statusui);
	}
}
 
Example 12
Source Project: gdx-texture-packer-gui   Source File: PatchGrid.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
    if (button==0) {
        for (PatchLine patchLine : patchLines) {
            if (patchLine.hovered) {
                draggingLines.add(patchLine);
                patchLine.startDragging(x, y);
            }
        }
        if (draggingLines.size > 0) {
            event.handle();
            event.stop();
            return true;
        }
    }
    return false;
}
 
Example 13
Source Project: vis-ui   Source File: VisCheckBox.java    License: Apache License 2.0 6 votes vote down vote up
public VisCheckBox (String text, VisCheckBoxStyle style) {
	super(text, style);
	clearChildren();

	bgImage = new Image(style.checkBackground);
	tickImage = new Image(style.tick);
	imageStackCell = add(imageStack = new Stack(bgImage, tickImage));
	Label label = getLabel();
	add(label).padLeft(5);
	label.setAlignment(Align.left);
	setSize(getPrefWidth(), getPrefHeight());

	addListener(new InputListener() {
		@Override
		public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
			if (isDisabled() == false) FocusManager.switchFocus(getStage(), VisCheckBox.this);
			return false;
		}
	});
}
 
Example 14
Source Project: Unlucky   Source File: WorldSelectScreen.java    License: MIT License 6 votes vote down vote up
protected void handleEnterButton() {
    enterButtonGroup.setPosition(114, 4);
    stage.addActor(enterButtonGroup);
    enterLabel.setText("SELECT");
    enterButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (!game.player.settings.muteSfx) rm.buttonclick0.play(game.player.settings.sfxVolume);
            if (clickable) {
                clickable = false;
                batchFade = false;
                // fade out animation
                stage.addAction(Actions.sequence(Actions.fadeOut(0.3f),
                    Actions.run(new Runnable() {
                        @Override
                        public void run() {
                            clickable = true;
                            game.levelSelectScreen.setWorld(worldIndex);
                            game.setScreen(game.levelSelectScreen);
                        }
                    })));
            }
        }
    });
}
 
Example 15
Source Project: vis-ui   Source File: BasicColorPicker.java    License: Apache License 2.0 6 votes vote down vote up
private VisTable createColorsPreviewTable () {
	VisTable table = new VisTable(false);
	table.add(currentColorImg = new AlphaImage(commons, 5 * sizes.scaleFactor))
			.height(25 * sizes.scaleFactor).width(80 * sizes.scaleFactor).expandX().fillX();
	table.add(new Image(style.iconArrowRight)).pad(0, 2, 0, 2);
	table.add(newColorImg = new AlphaImage(commons, 5 * sizes.scaleFactor))
			.height(25 * sizes.scaleFactor).width(80 * sizes.scaleFactor).expandX().fillX();

	currentColorImg.setColor(color);
	newColorImg.setColor(color);

	currentColorImg.addListener(new ClickListener() {
		@Override
		public void clicked (InputEvent event, float x, float y) {
			restoreLastColor();
		}
	});

	return table;
}
 
Example 16
Source Project: cocos-ui-libgdx   Source File: TImage.java    License: Apache License 2.0 6 votes vote down vote up
public TImage isButton() {
    clearListeners();
    origonCenter();
    addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            addAction(Actions.sequence(Actions.scaleTo(0.9f, 0.9f, 0.1f), Actions.scaleTo(1, 1, 0.1f), Actions.run(new Runnable() {
                @Override
                public void run() {
                    if (clickListener != null) {
                        clickListener.onClicked(TImage.this);
                    }
                }
            })));
        }
    });
    return this;
}
 
Example 17
Source Project: vis-ui   Source File: Dialogs.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Dialog with given text and single OK button.
 * @param title dialog title
 */
public static VisDialog showOKDialog (Stage stage, String title, String text) {
	final VisDialog dialog = new VisDialog(title);
	dialog.closeOnEscape();
	dialog.text(text);
	dialog.button(ButtonType.OK.getText()).padBottom(3);
	dialog.pack();
	dialog.centerWindow();
	dialog.addListener(new InputListener() {
		@Override
		public boolean keyDown (InputEvent event, int keycode) {
			if (keycode == Keys.ENTER) {
				dialog.fadeOut();
				return true;
			}
			return false;
		}
	});
	stage.addActor(dialog.fadeIn());
	return dialog;
}
 
Example 18
Source Project: gdx-texture-packer-gui   Source File: Scene2dUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void simulateClickGlobal(Actor actor, int button, int pointer, float stageX, float stageY) {
    InputEvent event = Pools.obtain(InputEvent.class);
    event.setStage(actor.getStage());
    event.setRelatedActor(actor);
    event.setTarget(actor);
    event.setStageX(stageX);
    event.setStageY(stageY);
    event.setButton(button);
    event.setPointer(pointer);

    event.setType(InputEvent.Type.touchDown);
    actor.notify(event, false);
    event.setType(InputEvent.Type.touchUp);
    actor.notify(event, false);

    Pools.free(event);
}
 
Example 19
@Override public final void start(final Callback callback) {
    final Actor target = getTargetActor();
    stage = target.getStage();
    if (stage == null)
        throw new IllegalStateException("actor not on stage!");
    listener = new InputListener() {
        @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (!event.getTarget().isDescendantOf(target)) {
                event.cancel();
                return false;
            }
            return true;
        }
    };
    stage.addCaptureListener(listener);
    resources.put("allowTouchDownTo", listener);
    callback.taskEnded();
}
 
Example 20
Source Project: gdx-soundboard   Source File: FileChooser.java    License: MIT License 5 votes vote down vote up
@Override
public Dialog show(Stage stage, Action action) {
    final Table content = getContentTable();
    content.add(fileListLabel).top().left().expandX().fillX().row();
    content.add(new ScrollPane(fileList, skin)).size(300, 150).fill().expand().row();

    if (fileNameEnabled) {
        content.add(fileNameLabel).fillX().expandX().row();
        content.add(fileNameInput).fillX().expandX().row();
        stage.setKeyboardFocus(fileNameInput);
    }

    if (newFolderEnabled) {
        content.add(newFolderButton).fillX().expandX().row();
    }
    
    if(directoryBrowsingEnabled){
        fileList.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                final FileListItem selected = fileList.getSelected();
                if (selected.file.isDirectory()) {
                    changeDirectory(selected.file);
                }
            }
        });
    }

    this.stage = stage;
    changeDirectory(baseDir);
    return super.show(stage, action);
}
 
Example 21
@Override
public void enter(InputEvent event, float x, float y, int pointer,
		com.badlogic.gdx.scenes.scene2d.Actor fromActor) {
	super.enter(event, x, y, pointer, fromActor);
	// EditorLogger.debug("ENTER - X: " + x + " Y: " + y);
	scnWidget.getStage().setScrollFocus(scnWidget);
	scnWidget.getStage().setKeyboardFocus(scnWidget);
}
 
Example 22
Source Project: libgdx-utils   Source File: TooltipListener.java    License: MIT License 5 votes vote down vote up
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
	inside = true;
	tooltip.setVisible(true);
	tmp.set(x, y);
	event.getListenerActor().localToStageCoordinates(tmp);
	tooltip.setPosition(tmp.x + position.x + offset.x, tmp.y + position.y + offset.y);
	tooltip.toFront();
}
 
Example 23
Source Project: vis-ui   Source File: Spinner.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
	if (buttonRepeatTask.isScheduled() == false) {
		buttonRepeatTask.advance = advance;
		buttonRepeatTask.cancel();
		Timer.schedule(buttonRepeatTask, buttonRepeatInitialTime, buttonRepeatTime);
	}
	return true;
}
 
Example 24
Source Project: talos   Source File: GlobalValueListContainer.java    License: Apache License 2.0 5 votes vote down vote up
private void build() {

        Table main = new Table();
        list = new CustomList<>(getSkin());
        list.setBackground(getSkin().getDrawable("dynamic_list_bg"));

        Stack stack = new Stack();
        Table listContainer = new Table();
        Table bottomPanelContainer = new Table();
        Table bottomPanel = new Table();
        stack.add(listContainer);
        stack.add(bottomPanelContainer);

        bottomPanelContainer.add().expandY().row();
        bottomPanelContainer.add(bottomPanel).padBottom(2f).left().expandX();

        ImageButton newRowButton = new ImageButton(getSkin().getDrawable("ic-input-file-add"));
        bottomPanel.add(newRowButton).left().padLeft(2);
        bottomPanel.add().expandX();

        listContainer.add(list).grow().minHeight(90);
        main.add(stack).grow();
        add(main).growX();

        newRowButton.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                addNewRow();
            }
        });
    }
 
Example 25
Source Project: talos   Source File: ModuleWrapper.java    License: Apache License 2.0 5 votes vote down vote up
protected VisTextField addInputSlotWithTextField(String title, int key, float size, boolean grow) {
    Table slotRow = new Table();
    Image icon = new Image(getSkin().getDrawable("node-connector-off"));
    VisLabel label = new VisLabel(title, "small");
    slotRow.add(icon).left();
    slotRow.add(label).left().padBottom(4).padLeft(5).padRight(10);

    final VisTextField textField = new VisTextField();
    slotRow.add().fillX().expandX().growX();
    slotRow.add(textField).right().width(size);

    Cell cell = leftWrapper.add(slotRow).pad(3).expandX().left();
    if(grow) {
        cell.growX();
    }

    leftWrapper.row();

    textField.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);

            if(textField.getSelection().length() == 0) {
                textField.selectAll();
            }
        }
    });

    configureNodeActions(icon, key, true);

    return textField;
}
 
Example 26
Source Project: Radix   Source File: ToggleOption.java    License: MIT License 5 votes vote down vote up
@Override
public Actor getManipulationActor() {
    TextButton button = new TextButton(String.format("%s: %s", title, getValueStr()), RadixClient.getInstance().getSceneTheme().getButtonStyle());
    button.addListener(new ClickListener() {
        @Override
        public void clicked (InputEvent event, float x, float y) {
            ToggleOption.this.value = !ToggleOption.this.value;
            button.setText(String.format("%s: %s", title, getValueStr()));
        }
    });
    return button;
}
 
Example 27
Source Project: Norii   Source File: MoveActionUIButton.java    License: Apache License 2.0 5 votes vote down vote up
public MoveActionUIButton(final String imageFileName, final Entity linkedUnit) {
	super(imageFileName);
	active = true;

	button.addListener(new ClickListener() {
		@Override
		public void clicked(final InputEvent event, final float x, final float y) {
			if (linkedUnit.canMove()) {
				linkedUnit.setInMovementPhase(true);
			}
		}
	});
}
 
Example 28
Source Project: Norii   Source File: PlayerBattleHUD.java    License: Apache License 2.0 5 votes vote down vote up
private void createPortraits(Entity[] sortedUnits) {
	portraits = new PortraitsUI(sortedUnits);

	portraits.addListener(new InputListener() {
		@Override
		public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
			return true;

		}
	});

	stage.addActor(portraits);
}
 
Example 29
Source Project: riiablo   Source File: QuestsPanel.java    License: Apache License 2.0 5 votes vote down vote up
QuestButton(Tab tab, Quests.Entry quest, int q) {
  this.parent = tab;
  this.quest = quest;
  setName(quest.qstr);

  DCWrapper background = new DCWrapper();
  background.setDrawable(questdone.getTexture(quest.questdone));
  background.setPosition(5, 4);
  background.setSize(72, 86);
  addActor(background);

  anim = Animation.newAnimation(questicons[q]);
  anim.setClamp(FRAME_UP, FRAME_DOWN);
  anim.setFrameDuration(Float.MAX_VALUE);
  AnimationWrapper animWrapper = new AnimationWrapper(anim);
  animWrapper.setPosition(5, 4);
  addActor(animWrapper);

  overlay = new DCWrapper();
  overlay.setDrawable(questsockets.getTexture(0));
  overlay.setSize(80, 95);
  addActor(overlay);

  addListener(clickListener = new ClickListener() {
    @Override
    public void clicked(InputEvent event, float x, float y) {
      parent.setSelected(QuestsPanel.QuestButton.this);
    }
  });
}
 
Example 30
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
    Actor actor = event.getListenerActor();
    Stage stage = actor.getStage();
    if (stage == null) return;

    // Stage fires "exit" event upon touchUp() even if pointer is still over the actor.
    // This is simple workaround.
    if (x > 0 && y > 0 && x < actor.getWidth() && y < actor.getHeight()) return;

    if (stage.getScrollFocus() == actor) {
        stage.setScrollFocus(null);
    }
}