Java Code Examples for com.badlogic.gdx.scenes.scene2d.utils.Drawable#getLeftWidth()

The following examples show how to use com.badlogic.gdx.scenes.scene2d.utils.Drawable#getLeftWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VisTextArea.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 2
Source File: CellRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 6 votes vote down vote up
public void layout(CustomListStyle style) {
	this.style = style;

	BitmapFont font = style.font;
	Drawable selectedDrawable = style.selection;

	textOffsetX = selectedDrawable.getLeftWidth();
	textOffsetY = selectedDrawable.getTopHeight() - font.getDescent();

	itemHeight = font.getCapHeight() - font.getDescent() * 2;

	if (hasSubtitle()) {
		itemHeight += style.subtitleFont.getCapHeight() - style.subtitleFont.getDescent() * 2;
		;
	}

	itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight();
}
 
Example 3
Source File: ProgressBar.java    From cocos-ui-libgdx with Apache License 2.0 5 votes vote down vote up
boolean calculatePositionAndValue(float x, float y) {
    final Drawable bg = style.background;

    float value;
    float oldPosition = progressPos;

    if (vertical) {
        float height = getHeight() - bg.getTopHeight() - bg.getBottomHeight();
        progressPos = y - bg.getBottomHeight();
        value = min + (max - min) * (progressPos / height);
        progressPos = Math.max(0, progressPos);
        progressPos = Math.min(height, progressPos);
    } else {
        float width = getWidth() - bg.getLeftWidth() - bg.getRightWidth();
        progressPos = x - bg.getLeftWidth();
        value = min + (max - min) * (progressPos / width);
        progressPos = Math.max(0, progressPos);
        progressPos = Math.min(width, progressPos);
    }

    float oldValue = value;
    boolean valueSet = setValue(value);
    if (value == oldValue) {
        progressPos = oldPosition;
    }
    return valueSet;
}
 
Example 4
Source File: Scene2dUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/** Checks if the text could fit the current textField's width. */
public static boolean isTextFitTextField(VisTextField textField, String text) {
    float availableWidth = textField.getWidth();
    Drawable fieldBg = textField.getStyle().background;
    if (fieldBg != null) {
        availableWidth = availableWidth - fieldBg.getLeftWidth() - fieldBg.getRightWidth();
    }
    BitmapFont font = textField.getStyle().font;
    return isTextFitWidth(font, availableWidth, text);
}
 
Example 5
Source File: CustomList.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
	validate();

	Color color = getColor();
	batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);

	float x = getX(), y = getY(), width = getWidth(), height = getHeight();
	float itemY = height;

	Drawable background = style.background;
	if (background != null) {
		background.draw(batch, x, y, width, height);
		float leftWidth = background.getLeftWidth();
		x += leftWidth;
		itemY -= background.getTopHeight();
		width -= leftWidth + background.getRightWidth();
	}

	for (int i = 0; i < items.size; i++) {
		if (cullingArea == null || (itemY - cellRenderer.getItemHeight() <= cullingArea.y + cullingArea.height
				&& itemY >= cullingArea.y)) {
			T item = items.get(i);
			boolean selected = selection.contains(item);

			cellRenderer.draw(batch, parentAlpha, item, selected, x, y + itemY, width,
					cellRenderer.getItemHeight());

		} else if (itemY < cullingArea.y) {
			break;
		}
		itemY -= cellRenderer.getItemHeight();
	}
}
 
Example 6
Source File: FilteredSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
	validate();

	Drawable background;
	if (disabled && style.backgroundDisabled != null)
		background = style.backgroundDisabled;
	else if (selectBoxList.hasParent() && style.backgroundOpen != null)
		background = style.backgroundOpen;
	else if (clickListener.isOver() && style.backgroundOver != null)
		background = style.backgroundOver;
	else if (style.background != null)
		background = style.background;
	else
		background = null;
	BitmapFont font = style.font;
	Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : style.fontColor;

	Color color = getColor();
	float x = getX(), y = getY();
	float width = getWidth(), height = getHeight();

	batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
	if (background != null)
		background.draw(batch, x, y, width, height);

	T selected = selection.first();
	if (selected != null) {
		if (background != null) {
			width -= background.getLeftWidth() + background.getRightWidth();
			height -= background.getBottomHeight() + background.getTopHeight();
			x += background.getLeftWidth();
			y += (int) (height / 2 + background.getBottomHeight() + font.getData().capHeight / 2);
		} else {
			y += (int) (height / 2 + font.getData().capHeight / 2);
		}
		font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
		drawItem(batch, font, selected, x, y, width);
	}
}
 
Example 7
Source File: ProgressBar.java    From cocos-ui-libgdx with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 8
Source File: VisTextField.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	Stage stage = getStage();
	boolean focused = stage != null && stage.getKeyboardFocus() == this;
	if (!focused) keyRepeatTask.cancel();

	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;
	Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground
			: ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background);

	// vis
	if (!disabled && style.backgroundOver != null && (clickListener.isOver() || focused)) {
		background = style.backgroundOver;
	}

	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);
	float bgLeftWidth = 0, bgRightWidth = 0;
	if (background != null) {
		background.draw(batch, x, y, width, height);
		bgLeftWidth = background.getLeftWidth();
		bgRightWidth = background.getRightWidth();
	}

	float textY = getTextY(font, background);
	calculateOffsets();

	if (focused && hasSelection && selection != null) {
		drawSelection(selection, batch, font, x + bgLeftWidth, y + textY);
	}

	float yOffset = font.isFlipped() ? -textHeight : 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 * color.a * parentAlpha);
			} else
				font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha);
			BitmapFont messageFont = style.messageFont != null ? style.messageFont : font;
			messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, 0, messageText.length(),
					width - bgLeftWidth - bgRightWidth, textHAlign, false, "...");
		}
	} else {
		font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha);
		drawText(batch, font, x + bgLeftWidth, y + textY + yOffset);
	}
	if (drawBorder && focused && !disabled) {
		blink();
		if (cursorOn && cursorPatch != null) {
			drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY);
		}
	}

	// vis
	if (isDisabled() == false && inputValid == false && style.errorBorder != null)
		style.errorBorder.draw(batch, getX(), getY(), getWidth(), getHeight());
	else if (focusBorderEnabled && drawBorder && style.focusBorder != null)
		style.focusBorder.draw(batch, getX(), getY(), getWidth(), getHeight());

}
 
Example 9
Source File: CustomList.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void layout() {
	final BitmapFont font = style.font;
	final BitmapFont subfont = style.subtitleFont;
	final Drawable selectedDrawable = style.selection;

	cellRenderer.layout(style);

	GlyphLayout textLayout = new GlyphLayout();

	prefWidth = 0;
	for (int i = 0; i < items.size; i++) {

		textLayout.setText(font, cellRenderer.getCellTitle(items.get(i)));

		prefWidth = Math.max(textLayout.width, prefWidth);
		
		if (cellRenderer.hasImage()) {
			TextureRegion r = cellRenderer.getCellImage(items.get(i));

			float ih = r.getRegionHeight();
			float iw = r.getRegionWidth();

			if (ih > getItemHeight() - 10) {
				ih = getItemHeight() - 10;
				iw *= ih / r.getRegionHeight();
			}

			prefWidth = Math.max(iw + textLayout.width, prefWidth);
		}

		if (cellRenderer.hasSubtitle()) {
			String subtitle = cellRenderer.getCellSubTitle(items.get(i));

			if (subtitle != null) {
				textLayout.setText(subfont, subtitle);
				prefWidth = Math.max(textLayout.width, prefWidth);
			}
		}
	}
	
	prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();

	prefHeight = items.size * cellRenderer.getItemHeight();

	Drawable background = style.background;
	if (background != null) {
		prefWidth += background.getLeftWidth() + background.getRightWidth();
		prefHeight += background.getTopHeight() + background.getBottomHeight();
	}
}