Package com.badlogic.gdx.scenes.scene2d

Examples of com.badlogic.gdx.scenes.scene2d.Stage


  }

  @Override
  public void resize(int width, int height) {
    if (stage == null)
      stage = new Stage(width, height, true);
    stage.clear();

    Gdx.input.setInputProcessor(stage);

    TextButtonStyle style = new TextButtonStyle();
View Full Code Here


    if (!layoutEnabled) return;

    Group parent = getParent();
    if (fillParent && parent != null) {
      float parentWidth, parentHeight;
      Stage stage = getStage();
      if (stage != null && parent == stage.getRoot()) {
        parentWidth = stage.getWidth();
        parentHeight = stage.getHeight();
      } else {
        parentWidth = parent.getWidth();
        parentHeight = parent.getHeight();
      }
      setSize(parentWidth, parentHeight);
View Full Code Here

  public void validate () {
    if (!layoutEnabled) return;
    Group parent = getParent();
    if (fillParent && parent != null) {
      Stage stage = getStage();

      float parentWidth, parentHeight;
      if (stage != null && parent == stage.getRoot()) {
        parentWidth = stage.getWidth();
        parentHeight = stage.getHeight();
      } else {
        parentWidth = parent.getWidth();
        parentHeight = parent.getHeight();
      }
      if (getWidth() != parentWidth || getHeight() != parentHeight) {
View Full Code Here

      public void scrollFocusChanged (FocusEvent event, Actor actor, boolean focused) {
        if (!focused) focusChanged(event);
      }

      private void focusChanged (FocusEvent event) {
        Stage stage = getStage();
        if (isModal && stage != null && stage.getRoot().getChildren().size > 0
          && stage.getRoot().getChildren().peek() == Dialog.this) { // Dialog is top most actor.
          Actor newFocusedActor = event.getRelatedActor();
          if (newFocusedActor != null && !newFocusedActor.isDescendantOf(Dialog.this)) event.cancel();
        }
      }
    });
View Full Code Here

  }

  protected void setParent (Group parent) {
    super.setParent(parent);
    if (parent == null) {
      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);
      }
    }
  }
View Full Code Here

        if (pointer == 0 && button != 0) return false;
        if (disabled) return true;
        clearSelection();
        setCursorPosition(x);
        selectionStart = cursor;
        Stage stage = getStage();
        if (stage != null) stage.setKeyboardFocus(TextField.this);
        keyboard.show(true);
        return true;
      }

      public void touchDragged (InputEvent event, float x, float y, int pointer) {
        super.touchDragged(event, x, y, pointer);
        lastBlink = 0;
        cursorOn = false;
        setCursorPosition(x);
        hasSelection = true;
      }

      private void setCursorPosition (float x) {
        lastBlink = 0;
        cursorOn = false;
        x -= renderOffset + textOffset;
        for (int i = 0; i < glyphPositions.size; i++) {
          if (glyphPositions.items[i] > x) {
            cursor = Math.max(0, i - 1);
            return;
          }
        }
        cursor = Math.max(0, glyphPositions.size - 1);
      }

      public boolean keyDown (InputEvent event, int keycode) {
        if (disabled) return false;

        lastBlink = 0;
        cursorOn = false;

        Stage stage = getStage();
        if (stage != null && stage.getKeyboardFocus() == TextField.this) {
          boolean repeat = false;
          boolean ctrl;
          if (isMac)
            ctrl = Gdx.input.isKeyPressed(Keys.SYM);
          else
            ctrl = Gdx.input.isKeyPressed(Keys.CONTROL_LEFT) || Gdx.input.isKeyPressed(Keys.CONTROL_RIGHT);
          if (ctrl) {
            // paste
            if (keycode == Keys.V) {
              paste();
              return true;
            }
            // copy
            if (keycode == Keys.C || keycode == Keys.INSERT) {
              copy();
              return true;
            }
            // cut
            if (keycode == Keys.X || keycode == Keys.DEL) {
              cut();
              return true;
            }
            // select all
            if (keycode == Keys.A) {
              selectAll();
              return true;
            }
          }
          if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT) || Gdx.input.isKeyPressed(Keys.SHIFT_RIGHT)) {
            // paste
            if (keycode == Keys.INSERT) paste();
            // cut
            if (keycode == Keys.FORWARD_DEL) {
              if (hasSelection) {
                copy();
                delete();
              }
            }
            // selection
            if (keycode == Keys.LEFT) {
              if (!hasSelection) {
                selectionStart = cursor;
                hasSelection = true;
              }
              while (--cursor > 0 && ctrl) {
                char c = text.charAt(cursor);
                if (c >= 'A' && c <= 'Z') continue;
                if (c >= 'a' && c <= 'z') continue;
                if (c >= '0' && c <= '9') continue;
                break;
              }
              repeat = true;
            }
            if (keycode == Keys.RIGHT) {
              if (!hasSelection) {
                selectionStart = cursor;
                hasSelection = true;
              }
              int length = text.length();
              while (++cursor < length && ctrl) {
                char c = text.charAt(cursor - 1);
                if (c >= 'A' && c <= 'Z') continue;
                if (c >= 'a' && c <= 'z') continue;
                if (c >= '0' && c <= '9') continue;
                break;
              }
              repeat = true;
            }
            if (keycode == Keys.HOME) {
              if (!hasSelection) {
                selectionStart = cursor;
                hasSelection = true;
              }
              cursor = 0;
            }
            if (keycode == Keys.END) {
              if (!hasSelection) {
                selectionStart = cursor;
                hasSelection = true;
              }
              cursor = text.length();
            }

            cursor = Math.max(0, cursor);
            cursor = Math.min(text.length(), cursor);
          } else {
            // cursor movement or other keys (kill selection)
            if (keycode == Keys.LEFT) {
              while (cursor-- > 1 && ctrl) {
                char c = text.charAt(cursor - 1);
                if (c >= 'A' && c <= 'Z') continue;
                if (c >= 'a' && c <= 'z') continue;
                if (c >= '0' && c <= '9') continue;
                break;
              }
              clearSelection();
              repeat = true;
            }
            if (keycode == Keys.RIGHT) {
              int length = text.length();
              while (++cursor < length && ctrl) {
                char c = text.charAt(cursor - 1);
                if (c >= 'A' && c <= 'Z') continue;
                if (c >= 'a' && c <= 'z') continue;
                if (c >= '0' && c <= '9') continue;
                break;
              }
              clearSelection();
              repeat = true;
            }
            if (keycode == Keys.HOME) {
              cursor = 0;
              clearSelection();
            }
            if (keycode == Keys.END) {
              cursor = text.length();
              clearSelection();
            }

            cursor = Math.max(0, cursor);
            cursor = Math.min(text.length(), cursor);
          }
          if (repeat && (!keyRepeatTask.isScheduled() || keyRepeatTask.keycode != keycode)) {
            keyRepeatTask.keycode = keycode;
            keyRepeatTask.cancel();
            Timer.schedule(keyRepeatTask, keyRepeatInitialTime, keyRepeatTime);
          }
          return true;
        }
        return false;
      }

      public boolean keyUp (InputEvent event, int keycode) {
        if (disabled) return false;
        keyRepeatTask.cancel();
        return true;
      }

      public boolean keyTyped (InputEvent event, char character) {
        if (disabled) return false;

        final BitmapFont font = style.font;

        Stage stage = getStage();
        if (stage != null && stage.getKeyboardFocus() == TextField.this) {
          if (character == BACKSPACE) {
            if (cursor > 0 || hasSelection) {
              if (!hasSelection) {
                text = text.substring(0, cursor - 1) + text.substring(cursor);
                updateDisplayText();
View Full Code Here

  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {

    Stage stage = getStage();
    boolean focused = stage != null && stage.getKeyboardFocus() == this;

    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;
View Full Code Here

  }

  /** Focuses the next TextField. If none is found, the keyboard is hidden. Does nothing if the text field is not in a stage.
   * @param up If true, the TextField with the same or next smallest y coordinate is found, else the next highest. */
  public void next (boolean up) {
    Stage stage = getStage();
    if (stage == null) return;
    getParent().localToStageCoordinates(tmp1.set(getX(), getY()));
    TextField textField = findNextTextField(stage.getActors(), null, tmp2, tmp1, up);
    if (textField == null) { // Try to wrap around.
      if (up)
        tmp1.set(Float.MIN_VALUE, Float.MIN_VALUE);
      else
        tmp1.set(Float.MAX_VALUE, Float.MAX_VALUE);
      textField = findNextTextField(getStage().getActors(), null, tmp2, tmp1, up);
    }
    if (textField != null)
      stage.setKeyboardFocus(textField);
    else
      Gdx.input.setOnscreenKeyboardVisible(false);
  }
View Full Code Here

    addListener(clickListener = new ClickListener() {
      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
        if (pointer == 0 && button != 0) return false;
        if (disabled) return false;
        Stage stage = getStage();
        if (list == null) list = new SelectList();
        list.show(stage);
        return true;
      }
    });
View Full Code Here

  public WindowStyle getStyle () {
    return style;
  }

  public void draw (SpriteBatch batch, float parentAlpha) {
    Stage stage = getStage();
    if (keepWithinStage && getParent() == stage.getRoot()) {
      float parentWidth = stage.getWidth();
      float parentHeight = stage.getHeight();
      if (getX() < 0) setX(0);
      if (getRight() > parentWidth) setX(parentWidth - getWidth());
      if (getY() < 0) setY(0);
      if (getTop() > parentHeight) setY(parentHeight - getHeight());
    }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.scenes.scene2d.Stage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.