com.badlogic.gdx.scenes.scene2d.utils.Drawable类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中com.badlogic.gdx.scenes.scene2d.utils.Drawable类的一些代码示例,展示了Drawable类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Drawable类的具体详情如下:
包路径:com.badlogic.gdx.scenes.scene2d.utils.Drawable
类名称:Drawable

Drawable介绍

[英]A drawable knows how to draw itself at a given rectangular size. It provides border sizes and a minimum size so that other code can determine how to size and position content.
[中]可绘制对象知道如何以给定的矩形大小绘制自身。它提供了边框大小和最小大小,以便其他代码可以确定内容的大小和位置。

代码示例

代码示例来源:origin: libgdx/libgdx

/** Draws selection rectangle **/
protected void drawSelection (Drawable selection, Batch batch, BitmapFont font, float x, float y) {
  selection.draw(batch, x + textOffset + selectionX + fontOffset, y - textHeight - font.getDescent(), selectionWidth,
    textHeight);
}

代码示例来源:origin: libgdx/libgdx

/** Creates a new empty drawable with the same sizing information as the specified drawable. */
public BaseDrawable (Drawable drawable) {
  if (drawable instanceof BaseDrawable) name = ((BaseDrawable)drawable).getName();
  leftWidth = drawable.getLeftWidth();
  rightWidth = drawable.getRightWidth();
  topHeight = drawable.getTopHeight();
  bottomHeight = drawable.getBottomHeight();
  minWidth = drawable.getMinWidth();
  minHeight = drawable.getMinHeight();
}

代码示例来源:origin: libgdx/libgdx

/** @return -1 if not over an item. */
public int getItemIndexAt (float y) {
  float height = getHeight();
  Drawable background = List.this.style.background;
  if (background != null) {
    height -= background.getTopHeight() + background.getBottomHeight();
    y -= background.getBottomHeight();
  }
  int index = (int)((height - y) / itemHeight);
  if (index < 0 || index >= items.size) return -1;
  return index;
}

代码示例来源:origin: libgdx/libgdx

public float getPrefWidth () {
  if (widget instanceof Layout) {
    float width = ((Layout)widget).getPrefWidth();
    if (style.background != null) width += style.background.getLeftWidth() + style.background.getRightWidth();
    if (forceScrollY) {
      float scrollbarWidth = 0;
      if (style.vScrollKnob != null) scrollbarWidth = style.vScrollKnob.getMinWidth();
      if (style.vScroll != null) scrollbarWidth = Math.max(scrollbarWidth, style.vScroll.getMinWidth());
      width += scrollbarWidth;
    }
    return width;
  }
  return 150;
}

代码示例来源:origin: libgdx/libgdx

/** Sets the background drawable and, if adjustPadding is true, sets the container's padding to
 * {@link Drawable#getBottomHeight()} , {@link Drawable#getTopHeight()}, {@link Drawable#getLeftWidth()}, and
 * {@link Drawable#getRightWidth()}.
 * @param background If null, the background will be cleared and padding removed. */
public void setBackground (Drawable background, boolean adjustPadding) {
  if (this.background == background) return;
  this.background = background;
  if (adjustPadding) {
    if (background == null)
      pad(Value.zero);
    else
      pad(background.getTopHeight(), background.getLeftWidth(), background.getBottomHeight(), background.getRightWidth());
    invalidate();
  }
}

代码示例来源:origin: libgdx/libgdx

public float getPrefHeight () {
  if (widget instanceof Layout) {
    float height = ((Layout)widget).getPrefHeight();
    if (style.background != null) height += style.background.getTopHeight() + style.background.getBottomHeight();
    if (forceScrollX) {
      float scrollbarHeight = 0;
      if (style.hScrollKnob != null) scrollbarHeight = style.hScrollKnob.getMinHeight();
      if (style.hScroll != null) scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
      height += scrollbarHeight;
    }
    return height;
  }
  return 150;
}

代码示例来源:origin: libgdx/libgdx

@Override
public void draw (Batch batch, float parentAlpha) {
  validate();
  Color c = getColor();
  batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);
  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());
  }
}

代码示例来源:origin: libgdx/libgdx

public float getScrollBarHeight () {
  if (!scrollX) return 0;
  float height = 0;
  if (style.hScrollKnob != null) height = style.hScrollKnob.getMinHeight();
  if (style.hScroll != null) height = Math.max(height, style.hScroll.getMinHeight());
  return height;
}

代码示例来源:origin: libgdx/libgdx

protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) {
  cursorPatch.draw(batch,
    x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset + font.getData().cursorX,
    y - textHeight - font.getDescent(), cursorPatch.getMinWidth(), textHeight);
}

代码示例来源:origin: libgdx/libgdx

public float getScrollBarWidth () {
  if (!scrollY) return 0;
  float width = 0;
  if (style.vScrollKnob != null) width = style.vScrollKnob.getMinWidth();
  if (style.vScroll != null) width = Math.max(width, style.vScroll.getMinWidth());
  return width;
}

代码示例来源:origin: libgdx/libgdx

public float getPrefWidth () {
  if (wrap) return 0;
  if (prefSizeInvalid) scaleAndComputePrefSize();
  float width = prefSize.x;
  Drawable background = style.background;
  if (background != null) width += background.getLeftWidth() + background.getRightWidth();
  return width;
}

代码示例来源:origin: libgdx/libgdx

/** Sets a new drawable for the image. The image's pref size is the drawable's min size. If using the image actor's size rather
 * than the pref size, {@link #pack()} can be used to size the image to its pref size.
 * @param drawable May be null. */
public void setDrawable (Drawable drawable) {
  if (this.drawable == drawable) return;
  if (drawable != null) {
    if (getPrefWidth() != drawable.getMinWidth() || getPrefHeight() != drawable.getMinHeight()) invalidateHierarchy();
  } else
    invalidateHierarchy();
  this.drawable = drawable;
}

代码示例来源:origin: libgdx/libgdx

@Override
protected void setCursorPosition (float x, float y) {
  moveOffset = -1;
  Drawable background = style.background;
  BitmapFont font = style.font;
  float height = getHeight();
  if (background != null) {
    height -= background.getTopHeight();
    x -= background.getLeftWidth();
  }
  x = Math.max(0, x);
  if (background != null) {
    y -= background.getTopHeight();
  }
  cursorLine = (int)Math.floor((height - y) / font.getLineHeight()) + firstLineShowing;
  cursorLine = Math.max(0, Math.min(cursorLine, getLines() - 1));
  super.setCursorPosition(x, y);
  updateCurrentLine();
}

代码示例来源:origin: libgdx/libgdx

public float get (Actor context) {
    Drawable background = ((Table)context).background;
    return background == null ? 0 : background.getTopHeight();
  }
};

代码示例来源:origin: libgdx/libgdx

public float get (Actor context) {
    Drawable background = ((Table)context).background;
    return background == null ? 0 : background.getLeftWidth();
  }
};

代码示例来源:origin: libgdx/libgdx

public float get (Actor context) {
    Drawable background = ((Table)context).background;
    return background == null ? 0 : background.getBottomHeight();
  }
};

代码示例来源:origin: libgdx/libgdx

public float get (Actor context) {
    Drawable background = ((Table)context).background;
    return background == null ? 0 : background.getRightWidth();
  }
};

代码示例来源:origin: libgdx/libgdx

/** Sets the background drawable and, if adjustPadding is true, sets the container's padding to
 * {@link Drawable#getBottomHeight()} , {@link Drawable#getTopHeight()}, {@link Drawable#getLeftWidth()}, and
 * {@link Drawable#getRightWidth()}.
 * @param background If null, the background will be cleared and padding removed. */
public void setBackground (Drawable background, boolean adjustPadding) {
  if (this.background == background) return;
  this.background = background;
  if (adjustPadding) {
    if (background == null)
      pad(Value.zero);
    else
      pad(background.getTopHeight(), background.getLeftWidth(), background.getBottomHeight(), background.getRightWidth());
    invalidate();
  }
}

代码示例来源:origin: libgdx/libgdx

public float getPrefHeight () {
  if (widget instanceof Layout) {
    float height = ((Layout)widget).getPrefHeight();
    if (style.background != null) height += style.background.getTopHeight() + style.background.getBottomHeight();
    if (forceScrollX) {
      float scrollbarHeight = 0;
      if (style.hScrollKnob != null) scrollbarHeight = style.hScrollKnob.getMinHeight();
      if (style.hScroll != null) scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
      height += scrollbarHeight;
    }
    return height;
  }
  return 150;
}

代码示例来源:origin: libgdx/libgdx

@Override
public void draw (Batch batch, float parentAlpha) {
  validate();
  Color c = getColor();
  batch.setColor(c.r, c.g, c.b, c.a * parentAlpha);
  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());
  }
}

相关文章