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

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


  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    SliderStyle 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 sliderPosHeight = height - (bg.getTopHeight() + bg.getBottomHeight());
      if (min != max) {
        sliderPos = (value - min) / (max - min) * (sliderPosHeight - knobHeight);
        sliderPos = Math.max(0, sliderPos);
        sliderPos = Math.min(sliderPosHeight - knobHeight, sliderPos) + bg.getBottomHeight();
      }

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

      float sliderPosWidth = width - (bg.getLeftWidth() + bg.getRightWidth());
      if (min != max) {
        sliderPos = (value - min) / (max - min) * (sliderPosWidth - knobWidth);
        sliderPos = Math.max(0, sliderPos);
        sliderPos = Math.min(sliderPosWidth - knobWidth, sliderPos) + bg.getLeftWidth();
      }

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


        knob.draw(batch, (int)(x + sliderPos), (int)(y + (height - knobHeight) * 0.5f), knobWidth, knobHeight);
    }
  }

  boolean calculatePositionAndValue (float x, float y) {
    final Drawable knob = (disabled && style.disabledKnob != null) ? style.disabledKnob : style.knob;
    final Drawable bg = (disabled && style.disabledBackground != null) ? style.disabledBackground : style.background;

    float value;
    float oldPosition = sliderPos;

    if (vertical) {
      float height = getHeight() - bg.getTopHeight() - bg.getBottomHeight();
      float knobHeight = knob == null ? 0 : knob.getMinHeight();
      sliderPos = y - bg.getBottomHeight() - knobHeight * 0.5f;
      value = min + (max - min) * (sliderPos / (height - knobHeight));
      sliderPos = Math.max(0, sliderPos);
      sliderPos = Math.min(height - knobHeight, sliderPos);
    } else {
      float width = getWidth() - bg.getLeftWidth() - bg.getRightWidth();
      float knobWidth = knob == null ? 0 : knob.getMinWidth();
      sliderPos = x - bg.getLeftWidth() - knobWidth * 0.5f;
      value = min + (max - min) * (sliderPos / (width - knobWidth));
      sliderPos = Math.max(0, sliderPos);
      sliderPos = Math.min(width - knobWidth, sliderPos);
    }

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

    boolean focused = stage != null && stage.getKeyboardFocus() == this;

    final BitmapFont font = style.font;
    final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor
      : ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor);
    final Drawable selection = style.selection;
    final Drawable cursorPatch = style.cursor;
    final Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground
      : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background);

    Color color = getColor();
    float x = getX();
    float y = getY();
    float width = getWidth();
    float height = getHeight();
    float textY = textBounds.height / 2 + font.getDescent();

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    float bgLeftWidth = 0;
    if (background != null) {
      background.draw(batch, x, y, width, height);
      bgLeftWidth = background.getLeftWidth();
      float bottom = background.getBottomHeight();
      textY = (int)(textY + (height - background.getTopHeight() - bottom) / 2 + bottom);
    } else
      textY = (int)(textY + height / 2);

    calculateOffsets();

View Full Code Here

    super.draw(batch, parentAlpha); // Draw actors.
  }

  /** Draws selection, icons, and expand icons. */
  private void draw (SpriteBatch batch, Array<Node> nodes, float indent) {
    Drawable plus = style.plus, minus = style.minus;
    float x = getX(), y = getY();
    for (int i = 0, n = nodes.size; i < n; i++) {
      Node node = nodes.get(i);
      Actor actor = node.actor;

      if (selectedNodes.contains(node, true) && style.selection != null) {
        style.selection.draw(batch, x, y + actor.getY() - ySpacing / 2, getWidth(), node.height + ySpacing);
      } else if (node == overNode && style.over != null) {
        style.over.draw(batch, x, y + actor.getY() - ySpacing / 2, getWidth(), node.height + ySpacing);
      }

      if (node.icon != null) {
        float iconY = actor.getY() + Math.round((node.height - node.icon.getMinHeight()) / 2);
        batch.setColor(actor.getColor());
        node.icon.draw(batch, x + node.actor.getX() - iconSpacingRight - node.icon.getMinWidth(), y + iconY,
          node.icon.getMinWidth(), node.icon.getMinHeight());
        batch.setColor(Color.WHITE);
      }

      if (node.children.size == 0) continue;

      Drawable expandIcon = node.expanded ? minus : plus;
      float iconY = actor.getY() + Math.round((node.height - expandIcon.getMinHeight()) / 2);
      expandIcon.draw(batch, x + indent - iconSpacingLeft, y + iconY, expandIcon.getMinWidth(), expandIcon.getMinHeight());
      if (node.expanded) draw(batch, node.children, indent + indentSpacing);
    }
  }
View Full Code Here

    }

    this.items = (String[])objects;
    selectedIndex = 0;

    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.length; i++)
      maxItemWidth = Math.max(font.getBounds(items[i]).width, maxItemWidth);

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

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

    return items;
  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    Drawable background;
    if (disabled)
      background = style.backgroundDisabled;
    else if (list != null && list.getParent() != null && 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);
    if (items.length > 0) {
      float availableWidth = width - background.getLeftWidth() - background.getRightWidth();
      int numGlyphs = font.computeVisibleGlyphs(items[selectedIndex], 0, items[selectedIndex].length(), availableWidth);
      bounds.set(font.getBounds(items[selectedIndex]));
      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, items[selectedIndex], x + background.getLeftWidth(), y + textY, 0, numGlyphs);
    }
  }
View Full Code Here

      list.setSelectedIndex(selectedIndex);

      // 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.length : Math.min(maxListCount, items.length));
      Drawable background = getStyle().background;
      if (background != null) height += background.getTopHeight() + background.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 layout () {
    final Drawable bg = style.background;
    final Drawable hScrollKnob = style.hScrollKnob;
    final Drawable vScrollKnob = style.vScrollKnob;

    float bgLeftWidth = 0, bgRightWidth = 0, bgTopHeight = 0, bgBottomHeight = 0;
    if (bg != null) {
      bgLeftWidth = bg.getLeftWidth();
      bgRightWidth = bg.getRightWidth();
      bgTopHeight = bg.getTopHeight();
      bgBottomHeight = bg.getBottomHeight();
    }

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

    float scrollbarHeight = 0;
    if (hScrollKnob != null) scrollbarHeight = hScrollKnob.getMinHeight();
    if (style.hScroll != null) scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
    float scrollbarWidth = 0;
    if (vScrollKnob != null) scrollbarWidth = vScrollKnob.getMinWidth();
    if (style.vScroll != null) scrollbarWidth = Math.max(scrollbarWidth, style.vScroll.getMinWidth());

    // Get available space size by subtracting background's padded area.
    areaWidth = width - bgLeftWidth - bgRightWidth;
    areaHeight = height - bgTopHeight - bgBottomHeight;

    if (widget == null) return;

    // Get widget's desired width.
    float widgetWidth, widgetHeight;
    if (widget instanceof Layout) {
      Layout layout = (Layout)widget;
      widgetWidth = layout.getPrefWidth();
      widgetHeight = layout.getPrefHeight();
    } else {
      widgetWidth = widget.getWidth();
      widgetHeight = widget.getHeight();
    }

    // Determine if horizontal/vertical scrollbars are needed.
    scrollX = forceScrollX || (widgetWidth > areaWidth && !disableX);
    scrollY = forceScrollY || (widgetHeight > areaHeight && !disableY);

    boolean fade = fadeScrollBars;
    if (!fade) {
      // Check again, now taking into account the area that's taken up by any enabled scrollbars.
      if (scrollY) {
        areaWidth -= scrollbarWidth;
        if (!scrollX && widgetWidth > areaWidth && !disableX) {
          scrollX = true;
        }
      }
      if (scrollX) {
        areaHeight -= scrollbarHeight;
        if (!scrollY && widgetHeight > areaHeight && !disableY) {
          scrollY = true;
          areaWidth -= scrollbarWidth;
        }
      }
    }

    // Set the widget area bounds.
    widgetAreaBounds.set(bgLeftWidth, bgBottomHeight, areaWidth, areaHeight);

    if (fade) {
      // Make sure widget is drawn under fading scrollbars.
      if (scrollX) areaHeight -= scrollbarHeight;
      if (scrollY) areaWidth -= scrollbarWidth;
    } else {
      if (scrollbarsOnTop) {
        // Make sure widget is drawn under non-fading scrollbars.
        if (scrollX) widgetAreaBounds.height += scrollbarHeight;
        if (scrollY) widgetAreaBounds.width += scrollbarWidth;
      } else {
        // Offset widget area y for horizontal scrollbar.
        if (scrollX) {
          if (hScrollOnBottom) {
            widgetAreaBounds.y += scrollbarHeight;
          } else {
            widgetAreaBounds.y = 0;
          }
        }
        // Offset widget area x for vertical scrollbar.
        if (scrollY) {
          if (vScrollOnRight) {
            widgetAreaBounds.x = 0;
          } else {
            widgetAreaBounds.x += scrollbarWidth;
          }
        }
      }
    }

    // If the widget is smaller than the available space, make it take up the available space.
    widgetWidth = disableX ? width : Math.max(areaWidth, widgetWidth);
    widgetHeight = disableY ? height : Math.max(areaHeight, widgetHeight);

    maxX = widgetWidth - areaWidth;
    maxY = widgetHeight - areaHeight;
    if (fade) {
      // Make sure widget is drawn under fading scrollbars.
      if (scrollX) maxY -= scrollbarHeight;
      if (scrollY) maxX -= scrollbarWidth;
    }
    scrollX(MathUtils.clamp(amountX, 0, maxX));
    scrollY(MathUtils.clamp(amountY, 0, maxY));

    // Set the bounds and scroll knob sizes if scrollbars are needed.
    if (scrollX) {
      if (hScrollKnob != null) {
        float hScrollHeight = style.hScroll != null ? style.hScroll.getMinHeight() : hScrollKnob.getMinHeight();
        // the small gap where the two scroll bars intersect might have to flip from right to left
        float boundsX, boundsY;
        if (vScrollOnRight) {
          boundsX = bgLeftWidth;
        } else {
          boundsX = bgLeftWidth + scrollbarWidth;
        }
        // bar on the top or bottom
        if (hScrollOnBottom) {
          boundsY = bgBottomHeight;
        } else {
          boundsY = height - bgTopHeight - hScrollHeight;
        }
        hScrollBounds.set(boundsX, boundsY, areaWidth, hScrollHeight);
        hKnobBounds.width = Math.max(hScrollKnob.getMinWidth(), (int)(hScrollBounds.width * areaWidth / widgetWidth));
        hKnobBounds.height = hScrollKnob.getMinHeight();
        hKnobBounds.x = hScrollBounds.x + (int)((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX());
        hKnobBounds.y = hScrollBounds.y;
      } else {
        hScrollBounds.set(0, 0, 0, 0);
        hKnobBounds.set(0, 0, 0, 0);
      }
    }
    if (scrollY) {
      if (vScrollKnob != null) {
        float vScrollWidth = style.vScroll != null ? style.vScroll.getMinWidth() : vScrollKnob.getMinWidth();
        // the small gap where the two scroll bars intersect might have to flip from bottom to top
        float boundsX, boundsY;
        if (hScrollOnBottom) {
          boundsY = height - bgTopHeight - areaHeight;
        } else {
          boundsY = bgBottomHeight;
        }
        // bar on the left or right
        if (vScrollOnRight) {
          boundsX = width - bgRightWidth - vScrollWidth;
        } else {
          boundsX = bgLeftWidth;
        }
        vScrollBounds.set(boundsX, boundsY, vScrollWidth, areaHeight);
        vKnobBounds.width = vScrollKnob.getMinWidth();
        vKnobBounds.height = Math.max(vScrollKnob.getMinHeight(), (int)(vScrollBounds.height * areaHeight / widgetHeight));
        if (vScrollOnRight) {
          vKnobBounds.x = width - bgRightWidth - vScrollKnob.getMinWidth();
        } else {
          vKnobBounds.x = bgLeftWidth;
        }
        vKnobBounds.y = vScrollBounds.y + (int)((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY()));
      } else {
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.