private void createCaches(
      String type,
      BitmapFontCache cache1,
      BitmapFontCache cache2,
      BitmapFontCache cache3,
      BitmapFontCache cache4,
      BitmapFontCache cache5) {
    cache1.setText("(" + type + ")", 10, 320 - 66);

    String text = "Sphinx of black quartz,\njudge my vow.";
    cache2.setColor(Color.RED);
    cache2.setText(text, 5, 320 - 300);

    text = "How quickly\ndaft jumping zebras vex.";
    cache3.setColor(Color.BLUE);
    cache3.setText(text, 5, 320 - 200, 470, Align.center, false);

    text = "Kerning: LYA moo";
    cache4.setText(text, 210, 320 - 66, 0, text.length() - 3, 0, Align.left, false);

    text =
        "Forsaking monastic tradition, twelve jovial friars gave\nup their vocation for a questionable existence on the flying trapeze.";
    cache5.setColor(red);
    cache5.setText(text, 0, 320 - 300, 480, Align.center, false);
  }
Example #2
0
  protected void drawBackground(SpriteBatch batch, float parentAlpha) {
    if (style.stageBackground != null) {
      Color color = getColor();
      batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
      Stage stage = getStage();
      Vector2 position = stageToLocalCoordinates(Vector2.tmp.set(0, 0));
      Vector2 size = stageToLocalCoordinates(Vector2.tmp2.set(stage.getWidth(), stage.getHeight()));
      style.stageBackground.draw(
          batch, getX() + position.x, getY() + position.y, getX() + size.x, getY() + size.y);
    }

    super.drawBackground(batch, parentAlpha);
    // Draw the title without the batch transformed or clipping applied.
    float x = getX(), y = getY() + getHeight();
    TextBounds bounds = titleCache.getBounds();
    if ((titleAlignment & Align.left) != 0) x += getPadLeft();
    else if ((titleAlignment & Align.right) != 0) x += getWidth() - bounds.width - getPadRight();
    else x += (getWidth() - bounds.width) / 2;
    if ((titleAlignment & Align.top) == 0) {
      if ((titleAlignment & Align.bottom) != 0) y -= getPadTop() - bounds.height;
      else y -= (getPadTop() - bounds.height) / 2;
    }
    titleCache.setColor(Color.tmp.set(getColor()).mul(style.titleFontColor));
    titleCache.setPosition((int) x, (int) y);
    titleCache.draw(batch, parentAlpha);
  }
Example #3
0
 public void setStyle(WindowStyle style) {
   if (style == null) throw new IllegalArgumentException("style cannot be null.");
   this.style = style;
   setBackground(style.background);
   titleCache = new BitmapFontCache(style.titleFont);
   titleCache.setColor(style.titleFontColor);
   if (title != null) setTitle(title);
   invalidateHierarchy();
 }
Example #4
0
  @Override
  public void draw() {
    if (_flickerTimer != 0) {
      _flicker = !_flicker;
      if (_flicker) return;
    }

    FlxCamera camera = FlxG._activeCamera;

    if (cameras == null) cameras = FlxG.cameras;

    if (!cameras.contains(camera, true)) return;

    if (!onScreen(camera)) return;

    _point.x = x - (camera.scroll.x * scrollFactor.x) - offset.x;
    _point.y = y - (camera.scroll.y * scrollFactor.y) - offset.y;
    _point.x += (_point.x > 0) ? 0.0000001f : -0.0000001f;
    _point.y += (_point.y > 0) ? 0.0000001f : -0.0000001f;

    // scaling
    BitmapFont font = _textField.getFont();
    if (scale.x != font.getScaleX() || scale.y != font.getScaleY()) {
      _textField.getFont().setScale(scale.x, scale.y);
      calcFrame();
    }

    // position
    _textField.setPosition(_point.x, _point.y);

    // rotation
    if (angle != 0) {
      _matrix = FlxG.batch.getTransformMatrix().cpy();

      Matrix4 rotationMatrix = FlxG.batch.getTransformMatrix();
      rotationMatrix.translate(
          _textField.getX() + (width / 2), _textField.getY() + (height / 2), 0);
      rotationMatrix.rotate(0, 0, 1, angle);
      rotationMatrix.translate(
          -(_textField.getX() + (width / 2)), -(_textField.getY() + (height / 2)), 0);

      FlxG.batch.setTransformMatrix(rotationMatrix);
    }

    // blending
    if (blend != null && currentBlend != blend) {
      int[] blendFunc = BlendMode.getOpenGLBlendMode(blend);
      FlxG.batch.setBlendFunction(blendFunc[0], blendFunc[1]);
    } else if (Gdx.graphics.isGL20Available() && (FlxG.batchShader == null || ignoreBatchShader)) {
      // OpenGL ES 2.0 shader render
      renderShader();
      // OpenGL ES 2.0 blend mode render
      renderBlend();
    }

    // Render shadow behind the text
    if (_shadow != 0) {
      // tinting
      int tintColor = FlxU.multiplyColors(_shadow, camera.getColor());
      _textField.setColor(
          ((tintColor >> 16) & 0xFF) * 0.00392f,
          ((tintColor >> 8) & 0xFF) * 0.00392f,
          (tintColor & 0xFF) * 0.00392f,
          ((_shadow >> 24) & 0xFF) * _alpha * 0.00392f);
      _textField.translate(_shadowX, _shadowY);
      _textField.draw(FlxG.batch);
      _textField.translate(-_shadowX, -_shadowY);
    }

    // tinting
    int tintColor = FlxU.multiplyColors(_color, camera.getColor());
    _textField.setColor(
        ((tintColor >> 16) & 0xFF) * 0.00392f,
        ((tintColor >> 8) & 0xFF) * 0.00392f,
        (tintColor & 0xFF) * 0.00392f,
        _alpha);

    _textField.draw(FlxG.batch);

    // rotation
    if (angle != 0) FlxG.batch.setTransformMatrix(_matrix);

    _VISIBLECOUNT++;

    if (FlxG.visualDebug && !ignoreDrawDebug) drawDebug(camera);
  }