List of usage examples for com.badlogic.gdx.scenes.scene2d Stage getKeyboardFocus
public Actor getKeyboardFocus()
From source file:com.aia.hichef.ui.n.MyDialog.java
License:Apache License
/** {@link #pack() Packs} the dialog and adds it to the stage, centered. */ public MyDialog show(Stage stage) { clearActions();//from w ww.j a va 2s . c o m 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; }
From source file:com.aia.hichef.ui.n.MyDialog.java
License:Apache License
/** * 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. */// w w w . jav a 2s. c o m 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(); }
From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java
License:Apache License
@Override public void draw(Batch batch, float parentAlpha) { Stage stage = getStage(); focused = stage != null && stage.getKeyboardFocus() == this; if (!focused) keyRepeatTask.cancel();//from ww w. jav a2 s . co m final BitmapFont font = style.font; final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor); final Drawable selection = style.selection; final Drawable cursorPatch = style.cursor; final Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background); Color color = getColor(); float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); float bgLeftWidth = 0, bgRightWidth = 0; if (background != null) { background.draw(batch, x, y, width, height); bgLeftWidth = background.getLeftWidth(); bgRightWidth = background.getRightWidth(); } float textY = getTextY(font, background); calculateOffsets(); if (focused && hasSelection && selection != null) { drawSelection(selection, batch, font, x + bgLeftWidth, y + textY); } float yOffset = font.isFlipped() ? -textHeight : 0; if (displayText.length() == 0) { if (!focused && messageText != null) { if (style.messageFontColor != null) { font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b, style.messageFontColor.a * color.a * parentAlpha); } else font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha); BitmapFont messageFont = style.messageFont != null ? style.messageFont : font; messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, 0, messageText.length(), width - bgLeftWidth - bgRightWidth, textHAlign, false, "..."); } } else { font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha); drawText(batch, font, x + bgLeftWidth, y + textY + yOffset); } if (focused && !disabled) { blink(); if (cursorOn && cursorPatch != null) { drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY); } } }
From source file:com.kotcrab.vis.ui.FocusManager.java
License:Apache License
/** * Takes focus from current focused widget (if any), and sets current focused widget to null * @param stage if passed stage is not null then stage keyboard focus will be set to null only if current * focus owner is passed actor/*from w ww .j a v a 2 s. c o m*/ */ public static void resetFocus(Stage stage, Actor caller) { if (focusedWidget != null) focusedWidget.focusLost(); if (stage != null && stage.getKeyboardFocus() == caller) stage.setKeyboardFocus(null); focusedWidget = null; }
From source file:com.minikara.ttfinput.TextField.java
License:Apache License
@Override public void draw(Batch batch, float parentAlpha) { Stage stage = getStage(); boolean focused = stage != null && stage.getKeyboardFocus() == this; if (!focused) keyRepeatTask.cancel();//from w w w . ja v a2s. c o m final BitmapFont font = style.font; final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor); final Drawable selection = style.selection; final Drawable cursorPatch = style.cursor; final Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background); Color color = getColor(); float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); float bgLeftWidth = 0, bgRightWidth = 0; if (background != null) { background.draw(batch, x, y, width, height); bgLeftWidth = background.getLeftWidth(); bgRightWidth = background.getRightWidth(); } float textY = getTextY(font, background); calculateOffsets(); if (focused && hasSelection && selection != null) { drawSelection(selection, batch, font, x + bgLeftWidth, y + textY); } float yOffset = font.isFlipped() ? -textHeight : 0; if (displayText.length() == 0) { if (!focused && messageText != null) { if (style.messageFontColor != null) { font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b, style.messageFontColor.a * color.a * parentAlpha); } else font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha); BitmapFont messageFont = style.messageFont != null ? style.messageFont : font; messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, width - bgLeftWidth - bgRightWidth, textHAlign, false); } } else { font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha); drawText(batch, font, x + bgLeftWidth, y + textY + yOffset); } if (focused && !disabled) { blink(); if (cursorOn && cursorPatch != null) { drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY); } } }
From source file:de.longri.cachebox3.gui.Window.java
License:Open Source License
private void drawStageBackground(Batch batch, float parentAlpha) { Stage stage = getStage(); if (stage.getKeyboardFocus() == null) stage.setKeyboardFocus(this); stageToLocalCoordinates(tmpPosition.set(0, 0)); stageToLocalCoordinates(tmpSize.set(stage.getWidth(), stage.getHeight())); Color color = getColor();/*from w w w. j a v a 2 s.c om*/ batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); stageBackground.draw(batch, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x, getY() + tmpSize.y); }
From source file:es.eucm.ead.editor.view.builders.SearchView.java
License:Open Source License
@Override public boolean onBackPressed() { Stage stage = repoGallery.getStage(); if (stage.getKeyboardFocus() == textField) { hideTextField();//from w w w .j ava 2 s .c o m } else { controller.action(ChangeView.class, ResourcesView.class); } return true; }
From source file:es.eucm.ead.editor.view.widgets.Dialog.java
License:Open Source License
/** * Shows the dialog in the stage/*from w w w.j a va2 s .c o m*/ */ public void show(Stage stage) { 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; stage.addActor(this); stage.setKeyboardFocus(this); stage.setScrollFocus(this); }
From source file:es.eucm.ead.editor.view.widgets.Dialog.java
License:Open Source License
/** * Hides the dialog// w w w .ja v a 2 s . co m */ 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); } remove(); }