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

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


  }

  public float getPrefHeight () {
    if (sizeInvalid) computeSize();
    float height = bounds.height - style.font.getDescent() * 2;
    Drawable background = style.background;
    if (background != null) height += background.getTopHeight() + background.getBottomHeight();
    return height;
  }
View Full Code Here


   * created from the region and stored in the skin. */
  public TiledDrawable getTiledDrawable (String name) {
    TiledDrawable tiled = optional(name, TiledDrawable.class);
    if (tiled != null) return tiled;

    Drawable drawable = optional(name, Drawable.class);
    if (drawable != null) {
      if (!(drawable instanceof TiledDrawable)) {
        throw new GdxRuntimeException("Drawable found but is not a TiledDrawable: " + name + ", "
          + drawable.getClass().getName());
      }
      return (TiledDrawable)drawable;
    }

    tiled = new TiledDrawable(getRegion(name));
View Full Code Here

  }

  /** Returns a registered drawable. If no drawable is found but a region, ninepatch, or sprite exists with the name, then the
   * appropriate drawable is created and stored in the skin. */
  public Drawable getDrawable (String name) {
    Drawable drawable = optional(name, Drawable.class);
    if (drawable != null) return drawable;

    drawable = optional(name, TiledDrawable.class);
    if (drawable != null) return drawable;

View Full Code Here

  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    BitmapFont font = style.font;
    Drawable selectedDrawable = style.selection;
    Color fontColorSelected = style.fontColorSelected;
    Color fontColorUnselected = style.fontColorUnselected;

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

    float x = getX();
    float y = getY();

    font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha);
    float itemY = getHeight();
    for (int i = 0; i < items.length; i++) {
      if (cullingArea == null || (itemY - itemHeight <= cullingArea.y + cullingArea.height && itemY >= cullingArea.y)) {
        if (selectedIndex == i) {
          selectedDrawable.draw(batch, x, y + itemY - itemHeight, getWidth(), itemHeight);
          font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha);
        }
        font.draw(batch, items[i], x + textOffsetX, y + itemY - textOffsetY);
        if (selectedIndex == i) {
          font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a
View Full Code Here

      items = (String[])objects;

    selectedIndex = 0;

    final BitmapFont font = style.font;
    final Drawable selectedDrawable = style.selection;

    itemHeight = font.getCapHeight() - font.getDescent() * 2;
    itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight();
    textOffsetX = selectedDrawable.getLeftWidth();
    textOffsetY = selectedDrawable.getTopHeight() - font.getDescent();

    prefWidth = 0;
    for (int i = 0; i < items.length; i++) {
      TextBounds bounds = font.getBounds(items[i]);
      prefWidth = Math.max(bounds.width, prefWidth);
    }
    prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();
    prefHeight = items.length * itemHeight;

    invalidateHierarchy();
  }
 
View Full Code Here

    float x = getX();
    float y = getY();
    float w = getWidth();
    float h = getHeight();

    final Drawable bg = style.background;
    if (bg != null) bg.draw(batch, x, y, w, h);

    final Drawable knob = style.knob;
    if (knob != null) {
      x += knobPosition.x - knob.getMinWidth() / 2f;
      y += knobPosition.y - knob.getMinHeight() / 2f;
      knob.draw(batch, x, y, knob.getMinWidth(), knob.getMinHeight());
    }
  }
View Full Code Here

      }

      public void touchDragged (InputEvent event, float x, float y, int pointer) {
        if (pointer != draggingPointer) return;

        Drawable handle = style.handle;
        if (!vertical) {
          float delta = x - lastPoint.x;
          float availWidth = getWidth() - handle.getMinWidth();
          float dragX = handlePosition.x + delta;
          handlePosition.x = dragX;
          dragX = Math.max(0, dragX);
          dragX = Math.min(availWidth, dragX);
          splitAmount = dragX / availWidth;
          if (splitAmount < minAmount) splitAmount = minAmount;
          if (splitAmount > maxAmount) splitAmount = maxAmount;
          lastPoint.set(x, y);
        } else {
          float delta = y - lastPoint.y;
          float availHeight = getHeight() - handle.getMinHeight();
          float dragY = handlePosition.y + delta;
          handlePosition.y = dragY;
          dragY = Math.max(0, dragY);
          dragY = Math.min(availHeight, dragY);
          splitAmount = 1 - (dragY / availHeight);
View Full Code Here

  public void setVertical (boolean vertical) {
    this.vertical = vertical;
  }

  private void calculateHorizBoundsAndPositions () {
    Drawable handle = style.handle;

    float height = getHeight();

    float availWidth = getWidth() - handle.getMinWidth();
    float leftAreaWidth = (int)(availWidth * splitAmount);
    float rightAreaWidth = availWidth - leftAreaWidth;
    float handleWidth = handle.getMinWidth();

    firstWidgetBounds.set(0, 0, leftAreaWidth, height);
    secondWidgetBounds.set(leftAreaWidth + handleWidth, 0, rightAreaWidth, height);
    handleBounds.set(leftAreaWidth, 0, handleWidth, height);
  }
View Full Code Here

    secondWidgetBounds.set(leftAreaWidth + handleWidth, 0, rightAreaWidth, height);
    handleBounds.set(leftAreaWidth, 0, handleWidth, height);
  }

  private void calculateVertBoundsAndPositions () {
    Drawable handle = style.handle;

    float width = getWidth();
    float height = getHeight();

    float availHeight = height - handle.getMinHeight();
    float topAreaHeight = (int)(availHeight * splitAmount);
    float bottomAreaHeight = availHeight - topAreaHeight;
    float handleHeight = handle.getMinHeight();

    firstWidgetBounds.set(0, height - topAreaHeight, width, topAreaHeight);
    secondWidgetBounds.set(0, 0, width, bottomAreaHeight);
    handleBounds.set(0, bottomAreaHeight, width, handleHeight);
  }
View Full Code Here

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

    Color color = getColor();

    Drawable handle = style.handle;
    applyTransform(batch, computeTransform());
    Matrix4 transform = batch.getTransformMatrix();
    if (firstWidget != null) {
      getStage().calculateScissors(firstWidgetBounds, firstScissors);
      if (ScissorStack.pushScissors(firstScissors)) {
        if (firstWidget.isVisible()) firstWidget.draw(batch, parentAlpha * color.a);
        batch.flush();
        ScissorStack.popScissors();
      }
    }
    if (secondWidget != null) {
      getStage().calculateScissors(secondWidgetBounds, secondScissors);
      if (ScissorStack.pushScissors(secondScissors)) {
        if (secondWidget.isVisible()) secondWidget.draw(batch, parentAlpha * color.a);
        batch.flush();
        ScissorStack.popScissors();
      }
    }
    batch.setColor(color.r, color.g, color.b, color.a);
    handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
    resetTransform(batch);
  }
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.