public void draw (SpriteBatch batch, float parentAlpha) {
Stage stage = getStage();
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();
if (focused && hasSelection && selection != null) {
selection.draw(batch, x + selectionX + bgLeftWidth + renderOffset, y + textY - textBounds.height - font.getDescent(),
selectionWidth, textBounds.height + font.getDescent() / 2);
}
float yOffset = font.isFlipped() ? -textBounds.height : 0;
if (displayText.length() == 0) {
if (!focused && messageText != null) {
if (style.messageFontColor != null) {
font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b,
style.messageFontColor.a * parentAlpha);
} else
font.setColor(0.7f, 0.7f, 0.7f, parentAlpha);
BitmapFont messageFont = style.messageFont != null ? style.messageFont : font;
messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset);
}
} else {
font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
font.draw(batch, displayText, x + bgLeftWidth + textOffset, y + textY + yOffset, visibleTextStart, visibleTextEnd);
}