import com.badlogic.gdx.scenes.scene2d.utils.Drawable; //导入方法依赖的package包/类
@Override
public void draw(Batch batch, float parentAlpha) {
ProgressBarStyle style = this.style;
final Drawable bg = style.background;
final Drawable knobBefore = style.progress;
Color color = getColor();
float x = getX();
float y = getY();
float width = getWidth();
float height = getHeight();
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 progressPosHeight = height - (bg.getTopHeight() + bg.getBottomHeight());
if (min != max) {
progressPos = (value - min) / (max - min) * progressPosHeight;
progressPos = Math.max(0, progressPos);
progressPos = Math.min(progressPosHeight, progressPos) + bg.getBottomHeight();
}
if (knobBefore != null) {
knobBefore.draw(batch, x + (int) ((width - knobBefore.getMinWidth()) * 0.5f), y, knobBefore.getMinWidth(),
(int) progressPos);
}
} else {
bg.draw(batch, x, y + (int) ((height - bg.getMinHeight()) * 0.5f), width, bg.getMinHeight());
float progressPosWidth = width - (bg.getLeftWidth() + bg.getRightWidth());
if (min != max) {
progressPos = (value - min) / (max - min) * progressPosWidth;
progressPos = Math.max(0, progressPos);
progressPos = Math.min(progressPosWidth, progressPos) + bg.getLeftWidth();
}
if (knobBefore != null) {
knobBefore.draw(batch, x, y + (int) ((height - knobBefore.getMinHeight()) * 0.5f), (int) progressPos,
knobBefore.getMinHeight());
}
}
super.draw(batch, parentAlpha);
}