Example #1
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);
  }
  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 #3
0
 /** Clean up memory. */
 @Override
 public void destroy() {
   _textField.clear();
   _textField = null;
   _text = null;
   super.destroy();
 }
Example #4
0
 @Override
 protected void calcFrame() {
   TextBounds bounds = _textField.setWrappedText(_text, 2, 3, width, _alignment);
   // bounds.height is shorter than it should be.
   // After some trial and error, adding seven seems to make it about right in most cases.
   height = frameHeight = (int) FlxU.ceil(bounds.height + 7);
 }
Example #5
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 #6
0
 public FixedText(String text, BitmapFont font, Color c, SpriteBatch batch1) {
   this.font = font;
   if (c == null) {
     glyphLayout = new GlyphLayout(font, text);
   } else {
     glyphLayout = new GlyphLayout(font, text, c, 0, Align.left, false);
   }
   stringValue = text;
   bitmapFontCache = new BitmapFontCache(font);
   bitmapFontCache.setText(glyphLayout, 0, 0);
   batch = batch1;
 }
  private void renderCachedScaled() {
    cacheScaled5.setColors(red);
    cacheScaled5.draw(spriteBatch);

    cacheScaled1.draw(spriteBatch);

    if (red.a > 0.6f) return;

    cacheScaled2.draw(spriteBatch);
    cacheScaled3.draw(spriteBatch);
    cacheScaled4.draw(spriteBatch);
  }
  private void renderCached() {
    cache5.setColors(red);
    cache5.draw(spriteBatch);

    cache1.draw(spriteBatch);

    if (red.a > 0.6f) return;

    cache2.draw(spriteBatch);
    cache3.draw(spriteBatch);
    cache4.draw(spriteBatch);
  }
Example #9
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);
  }
Example #10
0
 public void setStringValue(String stringValue) {
   this.stringValue = stringValue;
   bitmapFontCache.setText(glyphLayout, bitmapFontCache.getX(), bitmapFontCache.getY());
 }
Example #11
0
 public void render() {
   bitmapFontCache.draw(batch);
 }
Example #12
0
 public void setLocation(float x, float y) {
   bitmapFontCache.setPosition(x, y);
 }
Example #13
0
 public float getPrefWidth() {
   return Math.max(
       super.getPrefWidth(), titleCache.getBounds().width + getPadLeft() + getPadRight());
 }
Example #14
0
 public void setTitle(String title) {
   this.title = title;
   titleCache.setMultiLineText(title, 0, 0);
 }