Java Code Examples for com.badlogic.gdx.scenes.scene2d.utils.Drawable#getTopHeight()
The following examples show how to use
com.badlogic.gdx.scenes.scene2d.utils.Drawable#getTopHeight() .
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 |
@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 |
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 |
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: VisTextField.java From vis-ui with Apache License 2.0 | 5 votes |
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 5
Source File: VisTextArea.java From vis-ui with Apache License 2.0 | 5 votes |
@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 6
Source File: VisTextArea.java From vis-ui with Apache License 2.0 | 5 votes |
@Override protected float getTextY (BitmapFont font, Drawable background) { float textY = getHeight(); if (background != null) { textY = (int) (textY - background.getTopHeight()); } return textY; }
Example 7
Source File: CustomList.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
@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 8
Source File: FilteredSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
@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 9
Source File: ProgressBar.java From cocos-ui-libgdx with Apache License 2.0 | 4 votes |
@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 10
Source File: EditableSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
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 11
Source File: CustomList.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
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 12
Source File: FilteredSelectBox.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
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()); }