Examples of NinePatch


Examples of com.badlogic.gdx.graphics.g2d.NinePatch

  public ScrollPaneStyle getStyle () {
    return style;
  }

  public void layout () {
    final NinePatch bg = style.background;
    final NinePatch hScrollKnob = style.hScrollKnob;
    final NinePatch vScrollKnob = style.vScrollKnob;

    // For no background, ex. background is drawn a parent who has two scroll area
    float bgLeftWidth = bg == null ? 0 : bg.getLeftWidth();
    float bgRightWidth = bg == null ? 0 : bg.getRightWidth();
    float bgTopHeight = bg == null ? 0 : bg.getTopHeight();
    float bgBottomHeight = bg == null ? 0 : bg.getTopHeight();

    // 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.width;
      widgetHeight = widget.height;
    }

    // Figure out if we need horizontal/vertical scrollbars.
    scrollX = false;
    scrollY = false;
    if (!disableX && widgetWidth > areaWidth) scrollX = true;
    if (!disableY && widgetHeight > areaHeight) scrollY = true;

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

    // Set the widget area bounds.
    widgetAreaBounds.set(bgLeftWidth, bgBottomHeight + (scrollX ? hScrollKnob.getTotalHeight() : 0), areaWidth, areaHeight);
    amountX = MathUtils.clamp(amountX, 0, widgetAreaBounds.x);
    amountY = MathUtils.clamp(amountY, 0, widgetAreaBounds.y);

    // 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);
    if (widget.width != widgetWidth || widget.height != widgetHeight) {
      widget.width = widgetWidth;
      widget.height = widgetHeight;
    }

    // Set the bounds and scroll knob sizes if scrollbars are needed.
    if (scrollX) {
      hScrollBounds.set(bgLeftWidth, bgBottomHeight, areaWidth, hScrollKnob.getTotalHeight());
      hKnobBounds.width = Math.max(hScrollKnob.getTotalWidth(), (int)(hScrollBounds.width * areaWidth / widget.width));
      hKnobBounds.height = hScrollKnob.getTotalHeight();
      hKnobBounds.x = hScrollBounds.x + (int)((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX());
      hKnobBounds.y = hScrollBounds.y;
    }
    if (scrollY) {
      vScrollBounds.set(width - bgRightWidth - vScrollKnob.getTotalWidth(), height - bgTopHeight - areaHeight,
        vScrollKnob.getTotalWidth(), areaHeight);
      vKnobBounds.width = vScrollKnob.getTotalWidth();
      vKnobBounds.height = Math.max(vScrollKnob.getTotalHeight(), (int)(vScrollBounds.height * areaHeight / widget.height));
      vKnobBounds.x = vScrollBounds.x;
      vKnobBounds.y = vScrollBounds.y + (int)((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY()));
    }

    if (widget instanceof Layout) {
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

      objects = strings;
    }

    this.items = (String[])objects;

    NinePatch bg = style.background;
    BitmapFont font = style.font;

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

    float max = 0;
    for (int i = 0; i < items.length; i++)
      max = Math.max(font.getBounds(items[i]).width, max);
    prefWidth = bg.getLeftWidth() + bg.getRightWidth() + max;

    invalidateHierarchy();
  }
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

  public void layout () {
  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    final NinePatch background = style.background;
    final BitmapFont font = style.font;
    final Color fontColor = style.fontColor;

    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[selection], 0, items[selection].length(), availableWidth);
      bounds.set(font.getBounds(items[selection]));
      float textY = (int)(height / 2) + (int)(bounds.height / 2);
      font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
      font.draw(batch, items[selection], x + background.getLeftWidth(), y + textY, 0, numGlyphs);
    }

    // calculate screen coords where list should be displayed
    ScissorStack.toWindowCoordinates(stage.getCamera(), batch.getTransformMatrix(), screenCoords.set(x, y));
  }
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

        this.y = y - height;
    }

    private void layout () {
      final BitmapFont font = style.font;
      final NinePatch listSelection = style.listSelection;

      float prefWidth = 0;
      float prefHeight = 0;

      for (int i = 0; i < items.length; i++) {
        String item = items[i];
        TextBounds bounds = font.getBounds(item);
        prefWidth = Math.max(bounds.width, prefWidth);
      }

      itemHeight = font.getCapHeight() + -font.getDescent() * 2 + style.itemSpacing;
      itemHeight += listSelection.getTopHeight() + listSelection.getBottomHeight();
      itemHeight *= SelectBox.this.parent.scaleY;
      prefWidth += listSelection.getLeftWidth() + listSelection.getRightWidth() + 2 * style.itemSpacing;
      prefHeight = items.length * itemHeight;
      textOffsetX = listSelection.getLeftWidth() + style.itemSpacing;
      textOffsetY = listSelection.getTopHeight() + -font.getDescent() + style.itemSpacing / 2;

      width = Math.max(prefWidth, SelectBox.this.width);
      width *= SelectBox.this.parent.scaleX;
      height = prefHeight;
    }
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

      height = prefHeight;
    }

    @Override
    public void draw (SpriteBatch batch, float parentAlpha) {
      final NinePatch listBackground = style.listBackground;
      final NinePatch listSelection = style.listSelection;
      final BitmapFont font = style.font;
      final Color fontColor = style.fontColor;

      batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
      listBackground.draw(batch, x, y, width, height);
      float posY = height;
      for (int i = 0; i < items.length; i++) {
        if (selected == i) {
          listSelection.draw(batch, x, y + posY - itemHeight, width, itemHeight);
        }
        font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
        font.setScale(SelectBox.this.parent.scaleX, SelectBox.this.parent.scaleY);
        font.draw(batch, items[i], x + textOffsetX, y + posY - textOffsetY);
        font.setScale(1, 1);
View Full Code Here

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

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

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

    float availWidth = width - handle.getTotalWidth();
    float leftAreaWidth = (int)(availWidth * splitAmount);
    float rightAreaWidth = availWidth - leftAreaWidth;
    float handleWidth = handle.getTotalWidth();

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

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

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

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

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

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

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

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

    NinePatch handle = style.handle;
    applyTransform(batch);
    Matrix4 transform = batch.getTransformMatrix();
    if (firstWidget != null) {
      ScissorStack.calculateScissors(stage.getCamera(), transform, firstWidgetBounds, firstScissors);
      if (ScissorStack.pushScissors(firstScissors)) {
        drawChild(firstWidget, batch, parentAlpha);
        ScissorStack.popScissors();
      }
    }
    if (secondWidget != null) {
      ScissorStack.calculateScissors(stage.getCamera(), transform, secondWidgetBounds, secondScissors);
      if (ScissorStack.pushScissors(secondScissors)) {
        drawChild(secondWidget, batch, parentAlpha);
        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

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

    if (!touchDrag) {
      super.touchDragged(x, y, pointer);
      return;
    }

    NinePatch handle = style.handle;
    if (!vertical) {
      float delta = x - lastPoint.x;
      float availWidth = width - handle.getTotalWidth();
      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 = height - handle.getTotalHeight();
      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

Examples of com.badlogic.gdx.graphics.g2d.NinePatch

      }
    });
  }

  public Button (TextureRegion region) {
    this(new ButtonStyle(new NinePatch(region), null, null, 0f, 0f, 0f, 0f));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.