Java Code Examples for com.badlogic.gdx.scenes.scene2d.Stage#setScrollFocus()
The following examples show how to use
com.badlogic.gdx.scenes.scene2d.Stage#setScrollFocus() .
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: Dialog.java From uracer-kotd with Apache License 2.0 | 6 votes |
/** {@link #pack() Packs} the dialog and adds it to the stage, centered. */ public Dialog show (Stage stage) { clearActions(); removeCaptureListener(ignoreTouchDown); previousKeyboardFocus = null; Actor actor = stage.getKeyboardFocus(); if (actor != null && !actor.isDescendantOf(this)) previousKeyboardFocus = actor; previousScrollFocus = null; actor = stage.getScrollFocus(); if (actor != null && !actor.isDescendantOf(this)) previousScrollFocus = actor; // pack(); setPosition(Math.round((stage.getWidth() - getWidth()) / 2), Math.round((stage.getHeight() - getHeight()) / 2)); stage.addActor(this); stage.setKeyboardFocus(this); stage.setScrollFocus(this); if (fadeDuration > 0) { getColor().a = 0; addAction(Actions.fadeIn(fadeDuration, Interpolation.fade)); } return this; }
Example 2
Source File: Dialog.java From uracer-kotd with Apache License 2.0 | 6 votes |
/** Hides the dialog. Called automatically when a button is clicked. The default implementation fades out the dialog over * {@link #fadeDuration} seconds and then removes it from the stage. */ public void hide () { Stage stage = getStage(); if (stage != null) { if (previousKeyboardFocus != null && previousKeyboardFocus.getStage() == null) previousKeyboardFocus = null; Actor actor = stage.getKeyboardFocus(); if (actor == null || actor.isDescendantOf(this)) stage.setKeyboardFocus(previousKeyboardFocus); if (previousScrollFocus != null && previousScrollFocus.getStage() == null) previousScrollFocus = null; actor = stage.getScrollFocus(); if (actor == null || actor.isDescendantOf(this)) stage.setScrollFocus(previousScrollFocus); } if (fadeDuration > 0) { addCaptureListener(ignoreTouchDown); addAction(sequence(fadeOut(fadeDuration, Interpolation.fade), Actions.removeListener(ignoreTouchDown, true), Actions.removeActor())); } else remove(); }
Example 3
Source File: EditableSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
public void hide() { if (!list.isTouchable() || !hasParent()) return; list.setTouchable(Touchable.disabled); Stage stage = getStage(); if (stage != null) { stage.removeCaptureListener(hideListener); if (previousScrollFocus != null && previousScrollFocus.getStage() == null) previousScrollFocus = null; Actor actor = stage.getScrollFocus(); if (actor == null || isAscendantOf(actor)) stage.setScrollFocus(previousScrollFocus); } clearActions(); getColor().a = 1; addAction(sequence(fadeOut(0.15f, Interpolation.fade), Actions.removeActor())); }
Example 4
Source File: FilteredSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
public void hide() { if (!list.isTouchable() || !hasParent()) return; list.setTouchable(Touchable.disabled); Stage stage = getStage(); if (stage != null) { stage.removeCaptureListener(hideListener); if (previousScrollFocus != null && previousScrollFocus.getStage() == null) previousScrollFocus = null; Actor actor = stage.getScrollFocus(); if (actor == null || isAscendantOf(actor)) stage.setScrollFocus(previousScrollFocus); } clearActions(); selectBox.onHide(this); filterField.remove(); }
Example 5
Source File: PreviewHolder.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
@Override protected void setStage(Stage stage) { super.setStage(stage); if (stage != null) { stage.setScrollFocus(this); } }
Example 6
Source File: ScrollFocusCaptureInputListener.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
@Override public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) { Actor actor = event.getListenerActor(); Stage stage = actor.getStage(); if (stage == null) return; if (stage.getScrollFocus() != actor) { stage.setScrollFocus(actor); } }
Example 7
Source File: ScrollFocusCaptureInputListener.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
@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); } }
Example 8
Source File: CreativeInventoryActor.java From Cubes with MIT License | 5 votes |
@Override protected void setStage(Stage stage) { Stage old = getStage(); if (old != null) old.setScrollFocus(Cubes.getClient().renderer.guiRenderer.hotbar); super.setStage(stage); if (stage != null) stage.setScrollFocus(scrollPane); }
Example 9
Source File: Editor.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
@Override public void create() { if (EditorLogger.debugMode()) { EngineLogger.setDebug(); } Gdx.graphics.setWindowedMode(Math.max((int) (Gdx.graphics.getDisplayMode().width * 0.9), 1920 / 2), Math.max((int) (Gdx.graphics.getDisplayMode().height * 0.9), 1080 / 2)); skin = new BladeSkin(Gdx.files.internal(SKIN)); VisUI.load(); FileChooser.setDefaultPrefsName("com.bladecoder.engineeditor.filechooser"); /*** STAGE SETUP ***/ stage = new Stage(new ScreenViewport()); Gdx.input.setInputProcessor(stage); setCtx(); Message.init(skin); scnEditor = new ScnEditor(skin); scnEditor.setBackground("background"); skin.getFont("default-font").getData().markupEnabled = true; // RIGHT PANEL ScenePanel scenePanel = new ScenePanel(skin); ActorPanel actorPanel = new ActorPanel(skin); Table rightPanel = new Table(skin); rightPanel.top().left(); rightPanel.add(actorPanel).expand().fill().left(); rightPanel.setBackground("background"); SplitPane splitPaneRight = new SplitPane(scnEditor, rightPanel, false, skin); splitPaneRight.setSplitAmount(0.75f); // LEFT PANEL ProjectPanel projectPanel = new ProjectPanel(skin); Image img = new Image(Ctx.assetManager.getIcon("title")); img.setScaling(Scaling.none); img.setAlign(Align.left); Table leftPanel = new Table(skin); leftPanel.top().left().padLeft(10); leftPanel.add(img).expand().fill().padBottom(20).padTop(20).padLeft(0).left(); leftPanel.row(); leftPanel.add(new ProjectToolbar(skin)).expandX().fill().left(); leftPanel.row(); leftPanel.add(projectPanel).expand().fill().left(); leftPanel.row(); leftPanel.add(scenePanel).expand().fill().left(); leftPanel.setBackground("background"); SplitPane splitPaneLeft = new SplitPane(leftPanel, splitPaneRight, false, skin); splitPaneLeft.setFillParent(true); splitPaneLeft.setSplitAmount(0.25f); stage.addActor(splitPaneLeft); // LOAD LAST OPEN PROJECT String lastProject = Ctx.project.getEditorConfig().getProperty(Project.LAST_PROJECT_PROP, ""); final File lastProjectFile = new File(lastProject); if (!lastProject.isEmpty() && lastProjectFile.exists()) { EditorLogger.debug("Loading previous project: " + lastProject); try { EditorUtils.checkVersionAndLoadProject(lastProjectFile, stage, skin); } catch (Exception e) { EditorLogger.error("Error loading previous project.", e); Ctx.project.closeProject(); } } stage.setScrollFocus(scnEditor.getScnWidget()); stage.setKeyboardFocus(scnEditor.getScnWidget()); // TooltipManager.getInstance().instant(); TooltipManager.getInstance().initialTime = 0.2f; TooltipManager.getInstance().hideAll(); TooltipManager.getInstance().subsequentTime = 0.2f; }
Example 10
Source File: EditableSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
public void show(Stage stage) { if (list.isTouchable()) return; stage.removeCaptureListener(hideListener); stage.addCaptureListener(hideListener); stage.addActor(this); selectBox.localToStageCoordinates(screenPosition.set(0, 0)); // Show the list above or below the select box, limited to a number // of items and the available height in the stage. float itemHeight = list.getItemHeight(); float height = itemHeight * (maxListCount <= 0 ? list.getItems().size : Math.min(maxListCount, list.getItems().size)); Drawable scrollPaneBackground = getStyle().background; if (scrollPaneBackground != null) height += scrollPaneBackground.getTopHeight() + scrollPaneBackground.getBottomHeight(); Drawable listBackground = list.getStyle().background; if (listBackground != null) height += listBackground.getTopHeight() + listBackground.getBottomHeight(); float heightBelow = screenPosition.y; float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight(); boolean below = true; if (height > heightBelow) { if (heightAbove > heightBelow) { below = false; height = Math.min(height, heightAbove); } else height = heightBelow; } if (below) setY(screenPosition.y - height); else setY(screenPosition.y + selectBox.getHeight()); setX(screenPosition.x); setSize(Math.max(getPrefWidth(), selectBox.getWidth()), height); validate(); scrollTo(0, list.getHeight() - selectedIndex * itemHeight - itemHeight / 2, 0, 0, true, true); updateVisualScroll(); previousScrollFocus = null; Actor actor = stage.getScrollFocus(); if (actor != null && !actor.isDescendantOf(this)) previousScrollFocus = actor; stage.setScrollFocus(this); list.setTouchable(Touchable.enabled); clearActions(); // getColor().a = 0; // addAction(fadeIn(0.3f, Interpolation.fade)); }
Example 11
Source File: FilteredSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
public void show(Stage stage) { if (list.isTouchable()) return; stage.removeCaptureListener(hideListener); stage.addCaptureListener(hideListener); stage.addActor(this); stage.addActor(filterField); selectBox.localToStageCoordinates(screenPosition.set(0, 0)); // Show the list above or below the select box, limited to a number of items and // the available height in the stage. float itemHeight = list.getItemHeight(); float height = itemHeight * (maxListCount <= 0 ? selectBox.items.size : Math.min(maxListCount, selectBox.items.size)); Drawable scrollPaneBackground = getStyle().background; if (scrollPaneBackground != null) height += scrollPaneBackground.getTopHeight() + scrollPaneBackground.getBottomHeight(); Drawable listBackground = list.getStyle().background; if (listBackground != null) height += listBackground.getTopHeight() + listBackground.getBottomHeight(); float heightBelow = screenPosition.y - itemHeight; float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight(); boolean below = true; if (height > heightBelow) { if (heightAbove > heightBelow) { below = false; height = Math.min(height, heightAbove); } else height = heightBelow; } if (below) setY(screenPosition.y - height); else setY(screenPosition.y + selectBox.getHeight()); setX(screenPosition.x); setHeight(height); validate(); float width = Math.max(getPrefWidth(), selectBox.getWidth()); if (getPrefHeight() > height && !isScrollingDisabledY()) width += getScrollBarWidth(); setWidth(width); filterField.setX(getX()); filterField.setWidth(getWidth()); filterField.setHeight(filterField.getPrefHeight()); filterField.setY(getY() + getHeight() - filterField.getHeight()); stage.setKeyboardFocus(filterField); filterField.validate(); setY(getY() - filterField.getHeight()); validate(); scrollTo(0, list.getHeight() - selectBox.getSelectedIndex() * itemHeight - itemHeight / 2, 0, 0, true, true); updateVisualScroll(); previousScrollFocus = null; Actor actor = stage.getScrollFocus(); if (actor != null && !actor.isDescendantOf(this)) previousScrollFocus = actor; stage.setScrollFocus(this); list.getSelection().set(selectBox.getSelected()); list.setTouchable(Touchable.enabled); clearActions(); selectBox.onShow(this, below); filterField.setText(""); setListItems(items.toArray()); }