Exemplo n.º 1
0
  @Override
  public void render() {
    Gdx.gl.glClearColor(
        background.rgb.getRed() / 255f,
        background.rgb.getGreen() / 255f,
        background.rgb.getBlue() / 255f,
        background.rgb.getAlpha() / 255f);

    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    boolean hasUserInput = false;
    if (input.getText() != null && input.getText().length() != 0) hasUserInput = true;
    final String text =
        hasUserInput ? input.getText() : "The quick brown fox jumps over the lazy dog";

    float scale = scaleSlider.getValue();

    cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.setProjectionMatrix(cam.combined);

    batch.getProjectionMatrix().scale(scale, scale, 0.0f);

    //		batch.getTransformMatrix().scale(scale, scale, 0.0f);

    if (fonts != null) {
      batch.begin();

      int x = 5;
      int y = 0;

      for (FontElement e : fonts) {
        y += e.font.getLineHeight() + 5;
        String str = hasUserInput ? text : e.name + " " + e.size + ": " + text;
        e.font.draw(batch, str, x, y);
      }

      batch.end();
    }

    input.setY(Gdx.graphics.getHeight() - input.getHeight() - 5);
    labelInput.setY(Gdx.graphics.getHeight() - input.getHeight() - 5);

    labelScale.setY(labelInput.getY() - labelInput.getHeight() - 5);
    scaleSlider.setY(input.getY() - input.getHeight() - 5);
    scaleAmt.setY(scaleSlider.getY());

    linearFiltering.setY(scaleSlider.getY() - scaleSlider.getHeight() - 10);

    stage.act();
    stage.draw();
  }
Exemplo n.º 2
0
  @Override
  public void create() {

    //		Gdx.gl.glClearColor(
    //			background.rgb.getRed() / 255f,
    //			background.rgb.getGreen() / 255f,
    //			background.rgb.getBlue() / 255f,
    //			background.rgb.getAlpha() / 255f);
    //		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    //		Gdx.graphics.setContinuousRendering(false);
    //		Gdx.graphics.requestRendering();

    cam = new OrthographicCamera();
    batch = new SpriteBatch();

    stage = new Stage();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    input = new TextField("", skin);

    // can't use Table here since it will conflict with the Swing Table toolkit
    // this is why static is shit -.-
    labelInput = new Label("Sample Text:", skin);
    labelScale = new Label("Scale:", skin);
    scaleAmt = new Label("1.0", skin);

    labelInput.setHeight(input.getHeight());
    labelInput.setPosition(10, Gdx.graphics.getHeight() - labelInput.getHeight() - 5);
    input.setPosition(
        labelInput.getX() + labelInput.getWidth() + 10,
        Gdx.graphics.getHeight() - input.getHeight() - 5);

    scaleSlider = new Slider(0, 3, 0.05f, false, skin);
    scaleSlider.setSnapToValues(new float[] {0.0f, 0.5f, 1.0f}, 0.05f);

    scaleSlider.addListener(
        new ChangeListener() {
          @Override
          public void changed(ChangeEvent arg0, Actor arg1) {
            scaleAmt.setText(String.format("%.2f", scaleSlider.getValue()));
          }
        });
    scaleSlider.setValue(1.0f);
    scaleAmt.setText(String.format("%.2f", scaleSlider.getValue()));

    linearFiltering = new ToggleBox("Linear Filtering", skin);
    linearFiltering.addListener(
        new ClickListener() {
          public void clicked(InputEvent ev, float x, float y) {
            updateFiltering();
          }
        });

    scaleAmt.setHeight(scaleSlider.getHeight());
    labelScale.setHeight(scaleSlider.getHeight());

    labelScale.setPosition(
        input.getX() - 10 - labelScale.getWidth(), labelInput.getY() - labelInput.getHeight() - 5);
    scaleSlider.setPosition(input.getX(), input.getY() - input.getHeight() - 5);
    scaleAmt.setPosition(scaleSlider.getX() + scaleSlider.getWidth() + 5, scaleSlider.getY());

    linearFiltering.setPosition(input.getX(), scaleSlider.getY() - scaleSlider.getHeight() - 10);

    Gdx.input.setInputProcessor(stage);
    stage.addActor(labelInput);
    stage.addActor(input);
    stage.addActor(labelScale);
    stage.addActor(scaleSlider);
    stage.addActor(scaleAmt);
    stage.addActor(linearFiltering);

    myButton = new TextButton("Blah", skin);
  }