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

The following examples show how to use com.badlogic.gdx.scenes.scene2d.utils.Drawable#getBottomHeight() . 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: 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 2
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 3
Source File: VisTextField.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
protected float getTextY (BitmapFont font, Drawable background) {
	float height = getHeight();
	float textY = textHeight / 2 + font.getDescent();
	if (background != null) {
		float bottom = background.getBottomHeight();
		textY = textY + (height - background.getTopHeight() - bottom) / 2 + bottom;
	} else {
		textY = textY + height / 2;
	}
	if (font.usesIntegerPositions()) textY = (int) textY;
	return textY;
}
 
Example 4
Source File: VisTextArea.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
protected void sizeChanged () {
	lastText = null; // Cause calculateOffsets to recalculate the line breaks.

	// The number of lines showed must be updated whenever the height is updated
	BitmapFont font = style.font;
	Drawable background = style.background;
	float availableHeight = getHeight() - (background == null ? 0 : background.getBottomHeight() + background.getTopHeight());
	linesShowing = (int) Math.floor(availableHeight / font.getLineHeight());
}
 
Example 5
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 6
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 7
Source File: EditableSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void show(Stage stage) {
	if (list.isTouchable())
		return;

	stage.removeCaptureListener(hideListener);
	stage.addCaptureListener(hideListener);
	stage.addActor(this);

	selectBox.localToStageCoordinates(screenPosition.set(0, 0));

	// Show the list above or below the select box, limited to a number
	// of items and the available height in the stage.
	float itemHeight = list.getItemHeight();
	float height = itemHeight
			* (maxListCount <= 0 ? list.getItems().size : Math.min(maxListCount, list.getItems().size));
	Drawable scrollPaneBackground = getStyle().background;
	if (scrollPaneBackground != null)
		height += scrollPaneBackground.getTopHeight() + scrollPaneBackground.getBottomHeight();
	Drawable listBackground = list.getStyle().background;
	if (listBackground != null)
		height += listBackground.getTopHeight() + listBackground.getBottomHeight();

	float heightBelow = screenPosition.y;
	float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight();
	boolean below = true;
	if (height > heightBelow) {
		if (heightAbove > heightBelow) {
			below = false;
			height = Math.min(height, heightAbove);
		} else
			height = heightBelow;
	}

	if (below)
		setY(screenPosition.y - height);
	else
		setY(screenPosition.y + selectBox.getHeight());
	setX(screenPosition.x);
	setSize(Math.max(getPrefWidth(), selectBox.getWidth()), height);

	validate();
	scrollTo(0, list.getHeight() - selectedIndex * itemHeight - itemHeight / 2, 0, 0, true, true);
	updateVisualScroll();

	previousScrollFocus = null;
	Actor actor = stage.getScrollFocus();
	if (actor != null && !actor.isDescendantOf(this))
		previousScrollFocus = actor;
	stage.setScrollFocus(this);

	list.setTouchable(Touchable.enabled);
	clearActions();
	// getColor().a = 0;
	// addAction(fadeIn(0.3f, Interpolation.fade));
}
 
Example 8
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();
	}
}
 
Example 9
Source File: FilteredSelectBox.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void show(Stage stage) {
	if (list.isTouchable())
		return;

	stage.removeCaptureListener(hideListener);
	stage.addCaptureListener(hideListener);
	stage.addActor(this);
	stage.addActor(filterField);

	selectBox.localToStageCoordinates(screenPosition.set(0, 0));

	// Show the list above or below the select box, limited to a number of items and
	// the available height in the stage.
	float itemHeight = list.getItemHeight();
	float height = itemHeight
			* (maxListCount <= 0 ? selectBox.items.size : Math.min(maxListCount, selectBox.items.size));
	Drawable scrollPaneBackground = getStyle().background;
	if (scrollPaneBackground != null)
		height += scrollPaneBackground.getTopHeight() + scrollPaneBackground.getBottomHeight();
	Drawable listBackground = list.getStyle().background;
	if (listBackground != null)
		height += listBackground.getTopHeight() + listBackground.getBottomHeight();

	float heightBelow = screenPosition.y - itemHeight;
	float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight();
	boolean below = true;
	if (height > heightBelow) {
		if (heightAbove > heightBelow) {
			below = false;
			height = Math.min(height, heightAbove);
		} else
			height = heightBelow;
	}

	if (below)
		setY(screenPosition.y - height);
	else
		setY(screenPosition.y + selectBox.getHeight());
	setX(screenPosition.x);
	setHeight(height);
	validate();
	float width = Math.max(getPrefWidth(), selectBox.getWidth());
	if (getPrefHeight() > height && !isScrollingDisabledY())
		width += getScrollBarWidth();
	setWidth(width);

	filterField.setX(getX());
	filterField.setWidth(getWidth());
	filterField.setHeight(filterField.getPrefHeight());
	filterField.setY(getY() + getHeight() - filterField.getHeight());
	stage.setKeyboardFocus(filterField);
	filterField.validate();
	setY(getY() - filterField.getHeight());

	validate();
	scrollTo(0, list.getHeight() - selectBox.getSelectedIndex() * itemHeight - itemHeight / 2, 0, 0, true,
			true);
	updateVisualScroll();

	previousScrollFocus = null;
	Actor actor = stage.getScrollFocus();
	if (actor != null && !actor.isDescendantOf(this))
		previousScrollFocus = actor;
	stage.setScrollFocus(this);

	list.getSelection().set(selectBox.getSelected());
	list.setTouchable(Touchable.enabled);
	clearActions();
	selectBox.onShow(this, below);

	filterField.setText("");
	setListItems(items.toArray());
}