Package com.badlogic.gdx.scenes.scene2d.utils

Examples of com.badlogic.gdx.scenes.scene2d.utils.Drawable


  @Override
  public void draw (Batch batch, float parentAlpha) {
    ProgressBarStyle style = this.style;
    boolean disabled = this.disabled;
    final Drawable knob = (disabled && style.disabledKnob != null) ? style.disabledKnob : style.knob;
    final Drawable bg = (disabled && style.disabledBackground != null) ? style.disabledBackground : style.background;
    final Drawable knobBefore = (disabled && style.disabledKnobBefore != null) ? style.disabledKnobBefore : style.knobBefore;
    final Drawable knobAfter = (disabled && style.disabledKnobAfter != null) ? style.disabledKnobAfter : style.knobAfter;

    Color color = getColor();
    float x = getX();
    float y = getY();
    float width = getWidth();
    float height = getHeight();
    float knobHeight = knob == null ? 0 : knob.getMinHeight();
    float knobWidth = knob == null ? 0 : knob.getMinWidth();
    float value = getVisualValue();

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);

    if (vertical) {
      bg.draw(batch, x + (int)((width - bg.getMinWidth()) * 0.5f), y, bg.getMinWidth(), height);

      float positionHeight = height - (bg.getTopHeight() + bg.getBottomHeight());
      float knobHeightHalf = 0;
      if (min != max) {
        if (knob == null) {
          knobHeightHalf = knobBefore == null ? 0 : knobBefore.getMinHeight() * 0.5f;
          position = (value - min) / (max - min) * (positionHeight - knobHeightHalf);
          position = Math.min(positionHeight - knobHeightHalf, position);
        } else {
          knobHeightHalf = knobHeight * 0.5f;
          position = (value - min) / (max - min) * (positionHeight - knobHeight);
          position = Math.min(positionHeight - knobHeight, position) + bg.getBottomHeight();
        }
        position = Math.max(0, position);
      }

      if (knobBefore != null) {
        float offset = 0;
        if (bg != null) offset = bg.getTopHeight();
        knobBefore.draw(batch, x + (int)((width - knobBefore.getMinWidth()) * 0.5f), y + offset, knobBefore.getMinWidth(),
          (int)(position + knobHeightHalf));
      }
      if (knobAfter != null) {
        knobAfter.draw(batch, x + (int)((width - knobAfter.getMinWidth()) * 0.5f), y + (int)(position + knobHeightHalf),
          knobAfter.getMinWidth(), height - (int)(position + knobHeightHalf));
      }
      if (knob != null) knob.draw(batch, x + (int)((width - knobWidth) * 0.5f), (int)(y + position), knobWidth, knobHeight);
    } else {
      bg.draw(batch, x, y + (int)((height - bg.getMinHeight()) * 0.5f), width, bg.getMinHeight());

      float positionWidth = width - (bg.getLeftWidth() + bg.getRightWidth());
      float knobWidthHalf = 0;
      if (min != max) {
        if (knob == null) {
          knobWidthHalf = knobBefore == null ? 0 : knobBefore.getMinWidth() * 0.5f;
          position = (value - min) / (max - min) * (positionWidth - knobWidthHalf);
          position = Math.min(positionWidth - knobWidthHalf, position);
        } else {
          knobWidthHalf = knobWidth * 0.5f;
          position = (value - min) / (max - min) * (positionWidth - knobWidth);
          position = Math.min(positionWidth - knobWidth, position) + bg.getLeftWidth();
        }
        position = Math.max(0, position);
      }

      if (knobBefore != null) {
        float offset = 0;
        if (bg != null) offset = bg.getLeftWidth();
        knobBefore.draw(batch, x + offset, y + (int)((height - knobBefore.getMinHeight()) * 0.5f),
          (int)(position + knobWidthHalf), knobBefore.getMinHeight());
      }
      if (knobAfter != null) {
        knobAfter.draw(batch, x + (int)(position + knobWidthHalf), y + (int)((height - knobAfter.getMinHeight()) * 0.5f),
          width - (int)(position + knobWidthHalf), knobAfter.getMinHeight());
      }
      if (knob != null) knob.draw(batch, (int)(x + position), (int)(y + (height - knobHeight) * 0.5f), knobWidth, knobHeight);
    }
  }
View Full Code Here


    this.stepSize = stepSize;
  }

  public float getPrefWidth () {
    if (vertical) {
      final Drawable knob = (disabled && style.disabledKnob != null) ? style.disabledKnob : style.knob;
      final Drawable bg = (disabled && style.disabledBackground != null) ? style.disabledBackground : style.background;
      return Math.max(knob == null ? 0 : knob.getMinWidth(), bg.getMinWidth());
    } else
      return 140;
  }
View Full Code Here

  public float getPrefHeight () {
    if (vertical)
      return 140;
    else {
      final Drawable knob = (disabled && style.disabledKnob != null) ? style.disabledKnob : style.knob;
      final Drawable bg = (disabled && style.disabledBackground != null) ? style.disabledBackground : style.background;
      return Math.max(knob == null ? 0 : knob.getMinHeight(), bg.getMinHeight());
    }
  }
View Full Code Here

  public Array<T> getItems () {
    return items;
  }

  public void layout () {
    Drawable bg = style.background;
    BitmapFont font = style.font;

    prefHeight = Math.max(bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2,
      bg.getMinHeight());

    float maxItemWidth = 0;
    for (int i = 0; i < items.size; i++)
      maxItemWidth = Math.max(font.getBounds(items.get(i).toString()).width, maxItemWidth);

    prefWidth = bg.getLeftWidth() + bg.getRightWidth() + maxItemWidth;

    ListStyle listStyle = style.listStyle;
    ScrollPaneStyle scrollStyle = style.scrollStyle;
    prefWidth = Math.max(
      prefWidth,
View Full Code Here

  @Override
  public void draw (Batch batch, float parentAlpha) {
    validate();

    Drawable background;
    if (disabled && style.backgroundDisabled != null)
      background = style.backgroundDisabled;
    else if (scroll.hasParent() && style.backgroundOpen != null)
      background = style.backgroundOpen;
    else if (clickListener.isOver() && style.backgroundOver != null)
      background = style.backgroundOver;
    else
      background = style.background;
    final BitmapFont font = style.font;
    final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : style.fontColor;

    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);
    background.draw(batch, x, y, width, height);
    T selected = this.selected != null ? this.selected : selection.first();
    if (selected != null) {
      float availableWidth = width - background.getLeftWidth() - background.getRightWidth();
      String string = selected.toString();
      int numGlyphs = font.computeVisibleGlyphs(string, 0, string.length(), availableWidth);
      bounds.set(font.getBounds(string));
      height -= background.getBottomHeight() + background.getTopHeight();
      float textY = (int)(height / 2 + background.getBottomHeight() + bounds.height / 2);
      font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
      font.draw(batch, string, x + background.getLeftWidth(), y + textY, 0, numGlyphs);
    }
  }
View Full Code Here

      screenCoords.set(tmpCoords);

      // Show the list above or below the select box, limited to a number of items and the available height in the stage.
      float itemHeight = list.getItemHeight();
      float height = itemHeight * (maxListCount <= 0 ? items.size : Math.min(maxListCount, items.size));
      Drawable scrollPaneBackground = getStyle().background;
      if (scrollPaneBackground != null) height += scrollPaneBackground.getTopHeight() + scrollPaneBackground.getBottomHeight();
      Drawable listBackground = list.getStyle().background;
      if (listBackground != null) height += listBackground.getTopHeight() + listBackground.getBottomHeight();

      float heightBelow = tmpCoords.y;
      float heightAbove = stage.getCamera().viewportHeight - tmpCoords.y - SelectBox.this.getHeight();
      boolean below = true;
      if (height > heightBelow) {
View Full Code Here

  public void setStyle (ButtonStyle style) {
    if (style == null) throw new IllegalArgumentException("style cannot be null.");
    this.style = style;

    Drawable background = style.up;
    if (background == null) {
      background = style.down;
      if (background == null) background = style.checked;
    }
    if (background != null) {
      padBottom(background.getBottomHeight());
      padTop(background.getTopHeight());
      padLeft(background.getLeftWidth());
      padRight(background.getRightWidth());
    }
    invalidateHierarchy();
  }
View Full Code Here

  }

  public void draw (SpriteBatch batch, float parentAlpha) {
    validate();

    Drawable background = null;
    float offsetX = 0, offsetY = 0;
    if (isPressed() && !isDisabled) {
      background = style.down == null ? style.up : style.down;
      offsetX = style.pressedOffsetX;
      offsetY = style.pressedOffsetY;
    } else {
      if (isDisabled && style.disabled != null)
        background = style.disabled;
      else if (isChecked && style.checked != null)
        background = (isOver() && style.checkedOver != null) ? style.checkedOver : style.checked;
      else if (isOver() && style.over != null)
        background = style.over;
      else
        background = style.up;
      offsetX = style.unpressedOffsetX;
      offsetY = style.unpressedOffsetY;
    }

    if (background != null) {
      Color color = getColor();
      batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
      background.draw(batch, getX(), getY(), getWidth(), getHeight());
    }

    Array<Actor> children = getChildren();
    for (int i = 0; i < children.size; i++)
      children.get(i).translate(offsetX, offsetY);
View Full Code Here

        text.append("...");
      }
    } else
      text = this.text;

    Drawable background = style.background;
    float x = 0, y = 0;
    if (background != null) {
      x = background.getLeftWidth();
      y = background.getBottomHeight();
      width -= background.getLeftWidth() + background.getRightWidth();
      height -= background.getBottomHeight() + background.getTopHeight();
    }
    if ((labelAlign & Align.top) != 0) {
      y += cache.getFont().isFlipped() ? 0 : height - bounds.height;
      y += style.font.getDescent();
    } else if ((labelAlign & Align.bottom) != 0) {
View Full Code Here

  public float getPrefWidth () {
    if (wrap) return 0;
    if (sizeInvalid) computeSize();
    float width = bounds.width;
    Drawable background = style.background;
    if (background != null) width += background.getLeftWidth() + background.getRightWidth();
    return width;
  }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.scenes.scene2d.utils.Drawable

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.