Java Code Examples for com.badlogic.gdx.scenes.scene2d.utils.Drawable#draw()
The following examples show how to use
com.badlogic.gdx.scenes.scene2d.utils.Drawable#draw() .
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: TabPane.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
private void drawGap(int i, Batch batch) { Drawable headerGap; if (i == selectedIndex) { //current active headerGap = style.activeBorderRight; } else if (i == selectedIndex - 1) { //next active headerGap = style.activeBorderLeft; } else { headerGap = style.inactiveBorder; } if (headerGap != null) { headerGap.draw( batch, getX() + headerWidth * (i + 1) + headersLeftOffset + i * headersBetweenOffset, getY() + contentHeight, headersBetweenOffset, getHeight() - contentHeight ); } }
Example 2
Source File: Label.java From riiablo with Apache License 2.0 | 6 votes |
public void draw(PaletteIndexedBatch batch, float a) { validate(); LabelStyle style = getStyle(); if (style != null) { Drawable background = style.background; if (background != null) { background.draw(batch, getX() - background.getLeftWidth(), getY() - background.getBottomHeight(), getWidth() + background.getMinWidth(), getHeight() + background.getMinHeight()); } } batch.setBlendMode(((FontTBL.BitmapFont) getStyle().font).getBlendMode()); BitmapFontCache cache = getBitmapFontCache(); cache.setPosition(getX(), getY()); cache.tint(getColor()); cache.draw(batch); batch.resetBlendMode(); }
Example 3
Source File: GradientWidget.java From talos with Apache License 2.0 | 5 votes |
public void drawPoints(Batch batch, float parentAlpha) { Array<ColorPoint> points = module.getPoints(); for(int i = 0; i < points.size; i++) { Drawable backgroundFrame = getSkin().getDrawable(TRIANGLE); batch.setColor(points.get(i).color); backgroundFrame.draw(batch, getX() + areaPos.x + areaSize.x * points.get(i).pos - 9, getY() + areaPos.y - 16f, 18f, 16f); } }
Example 4
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 5
Source File: VisTextArea.java From vis-ui with Apache License 2.0 | 5 votes |
@Override protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { float textOffset = cursor >= glyphPositions.size || cursorLine * 2 >= linesBreak.size ? 0 : glyphPositions.get(cursor) - glyphPositions.get(linesBreak.items[cursorLine * 2]); cursorX = textOffset + fontOffset + font.getData().cursorX; cursorPatch.draw(batch, x + cursorX, y - font.getDescent() / 2 - (cursorLine - firstLineShowing + 1) * font.getLineHeight(), cursorPatch.getMinWidth(), font.getLineHeight()); }
Example 6
Source File: VisTextArea.java From vis-ui with Apache License 2.0 | 5 votes |
@Override protected void drawSelection (Drawable selection, Batch batch, BitmapFont font, float x, float y) { int i = firstLineShowing * 2; float offsetY = 0; int minIndex = Math.min(cursor, selectionStart); int maxIndex = Math.max(cursor, selectionStart); while (i + 1 < linesBreak.size && i < (firstLineShowing + linesShowing) * 2) { int lineStart = linesBreak.get(i); int lineEnd = linesBreak.get(i + 1); if (!((minIndex < lineStart && minIndex < lineEnd && maxIndex < lineStart && maxIndex < lineEnd) || (minIndex > lineStart && minIndex > lineEnd && maxIndex > lineStart && maxIndex > lineEnd))) { int start = Math.max(linesBreak.get(i), minIndex); int end = Math.min(linesBreak.get(i + 1), maxIndex); float selectionX = glyphPositions.get(start) - glyphPositions.get(linesBreak.get(i)); float selectionWidth = glyphPositions.get(end) - glyphPositions.get(start); selection.draw(batch, x + selectionX + fontOffset, y - textHeight - font.getDescent() - offsetY, selectionWidth, font.getLineHeight()); } offsetY += font.getLineHeight(); i += 2; } }
Example 7
Source File: VisSplitPane.java From vis-ui with Apache License 2.0 | 5 votes |
@Override public void draw (Batch batch, float parentAlpha) { validate(); Color color = getColor(); applyTransform(batch, computeTransform()); // Matrix4 transform = batch.getTransformMatrix(); if (firstWidget != null) { getStage().calculateScissors(firstWidgetBounds, firstScissors); if (ScissorStack.pushScissors(firstScissors)) { if (firstWidget.isVisible()) firstWidget.draw(batch, parentAlpha * color.a); batch.flush(); ScissorStack.popScissors(); } } if (secondWidget != null) { getStage().calculateScissors(secondWidgetBounds, secondScissors); if (ScissorStack.pushScissors(secondScissors)) { if (secondWidget.isVisible()) secondWidget.draw(batch, parentAlpha * color.a); batch.flush(); ScissorStack.popScissors(); } } Drawable handle = style.handle; if (mouseOnHandle && isTouchable() && style.handleOver != null) handle = style.handleOver; batch.setColor(color.r, color.g, color.b, parentAlpha * color.a); handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height); resetTransform(batch); }
Example 8
Source File: VisTextField.java From vis-ui with Apache License 2.0 | 5 votes |
protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { float cursorHeight = textHeight * cursorPercentHeight; float cursorYPadding = (textHeight - cursorHeight) / 2; cursorPatch.draw(batch, x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset + font.getData().cursorX, y - textHeight - font.getDescent() + cursorYPadding, cursorPatch.getMinWidth(), cursorHeight); }
Example 9
Source File: MultiSplitPane.java From vis-ui with Apache License 2.0 | 5 votes |
@Override public void draw (Batch batch, float parentAlpha) { validate(); Color color = getColor(); applyTransform(batch, computeTransform()); SnapshotArray<Actor> actors = getChildren(); for (int i = 0; i < actors.size; i++) { Actor actor = actors.get(i); Rectangle bounds = widgetBounds.get(i); Rectangle scissor = scissors.get(i); getStage().calculateScissors(bounds, scissor); if (ScissorStack.pushScissors(scissor)) { if (actor.isVisible()) actor.draw(batch, parentAlpha * color.a); batch.flush(); ScissorStack.popScissors(); } } batch.setColor(color.r, color.g, color.b, parentAlpha * color.a); Drawable handle = style.handle; Drawable handleOver = style.handle; if (isTouchable() && style.handleOver != null) handleOver = style.handleOver; for (Rectangle rect : handleBounds) { if (this.handleOver == rect) { handleOver.draw(batch, rect.x, rect.y, rect.width, rect.height); } else { handle.draw(batch, rect.x, rect.y, rect.width, rect.height); } } resetTransform(batch); }
Example 10
Source File: MundusMultiSplitPane.java From Mundus with Apache License 2.0 | 5 votes |
@Override public void draw(Batch batch, float parentAlpha) { validate(); Color color = getColor(); applyTransform(batch, computeTransform()); SnapshotArray<Actor> actors = getChildren(); for (int i = 0; i < actors.size; i++) { Actor actor = actors.get(i); Rectangle bounds = widgetBounds.get(i); Rectangle scissor = scissors.get(i); getStage().calculateScissors(bounds, scissor); if (ScissorStack.pushScissors(scissor)) { if (actor.isVisible()) actor.draw(batch, parentAlpha * color.a); batch.flush(); ScissorStack.popScissors(); } } batch.setColor(color.r, color.g, color.b, parentAlpha * color.a); Drawable handle = style.handle; Drawable handleOver = style.handle; if (isTouchable() && style.handleOver != null) handleOver = style.handleOver; for (Rectangle rect : handleBounds) { if (this.handleOver == rect) { handleOver.draw(batch, rect.x, rect.y, rect.width, rect.height); } else { handle.draw(batch, rect.x, rect.y, rect.width, rect.height); } } resetTransform(batch); }
Example 11
Source File: MundusSplitPane.java From Mundus with Apache License 2.0 | 5 votes |
@Override public void draw(Batch batch, float parentAlpha) { validate(); Color color = getColor(); applyTransform(batch, computeTransform()); // Matrix4 transform = batch.getTransformMatrix(); if (firstWidget != null) { getStage().calculateScissors(firstWidgetBounds, firstScissors); if (ScissorStack.pushScissors(firstScissors)) { if (firstWidget.isVisible()) firstWidget.draw(batch, parentAlpha * color.a); batch.flush(); ScissorStack.popScissors(); } } if (secondWidget != null) { getStage().calculateScissors(secondWidgetBounds, secondScissors); if (ScissorStack.pushScissors(secondScissors)) { if (secondWidget.isVisible()) secondWidget.draw(batch, parentAlpha * color.a); batch.flush(); ScissorStack.popScissors(); } } Drawable handle = style.handle; if (mouseOnHandle && isTouchable() && style.handleOver != null) handle = style.handleOver; batch.setColor(color.r, color.g, color.b, parentAlpha * color.a); handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height); resetTransform(batch); }
Example 12
Source File: EscapePanel.java From riiablo with Apache License 2.0 | 5 votes |
@Override protected void drawBackground(Batch batch, float a, float x, float y) { Drawable background = getBackground(); background.draw(batch, x + (getWidth() / 2) - (background.getMinWidth() / 2), getY(), background.getMinWidth(), background.getMinHeight()); }
Example 13
Source File: TabPane.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
private void drawLeftBorder(Batch batch) { Drawable leftBorder; if (selectedIndex == 0) { leftBorder = style.activeBorderLeftEdge; } else { leftBorder = style.inactiveBorderLeftEdge; } if (leftBorder != null) { leftBorder.draw(batch, getX(), getY() + contentHeight, headersLeftOffset, getHeight() - contentHeight); } }
Example 14
Source File: TabPane.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
private void drawRightBorder(Batch batch) { Drawable rightBorder; if (selectedIndex == headers.size - 1) { rightBorder = style.activeBorderRightEdge; } else { rightBorder = style.inactiveBorderRightEdge; } if (rightBorder != null) { float x = getX() + getWidth() - headersRightOffset; float y = getY() + contentHeight; rightBorder.draw(batch, x, y, headersRightOffset, getHeight() - contentHeight); } }
Example 15
Source File: TabPane.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@Override public void draw(Batch batch, float parentAlpha) { if (selectedIndex == -1) return; validate(); Color color = getColor(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); drawContentBackground(batch); drawLeftBorder(batch); drawRightBorder(batch); for (int i = 0; i < headers.size; i++) { if (i != headers.size - 1) drawGap(i, batch); Drawable headerBackground; if (selectedIndex == i) { headerBackground = style.active; } else { headerBackground = style.inactive; } if (headerBackground != null) { headerBackground.draw( batch, getX() + headerWidth * i + headersLeftOffset + i * headersBetweenOffset - 0.5f, getY() + contentHeight, headerWidth + 1f, getHeight() - contentHeight ); } } super.draw(batch, parentAlpha); }
Example 16
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 17
Source File: VisTextField.java From vis-ui with Apache License 2.0 | 4 votes |
@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 18
Source File: VisTextField.java From vis-ui with Apache License 2.0 | 4 votes |
/** Draws selection rectangle **/ protected void drawSelection (Drawable selection, Batch batch, BitmapFont font, float x, float y) { selection.draw(batch, x + selectionX + textOffset + fontOffset, y - textHeight - font.getDescent(), selectionWidth, textHeight); }
Example 19
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 20
Source File: RetroSceneScreen.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
private void drawHotspots(SpriteBatch batch) { final World world = ui.getWorld(); for (BaseActor a : world.getCurrentScene().getActors().values()) { if (!(a instanceof InteractiveActor) || !a.isVisible() || a == world.getCurrentScene().getPlayer()) continue; InteractiveActor ia = (InteractiveActor) a; if (!ia.canInteract()) continue; Polygon p = a.getBBox(); if (p == null) { EngineLogger.error("ERROR DRAWING HOTSPOT FOR: " + a.getId()); } Rectangle r = a.getBBox().getBoundingRectangle(); unprojectTmp.set(r.getX() + r.getWidth() / 2, r.getY() + r.getHeight() / 2, 0); world.getSceneCamera().scene2screen(worldViewport, unprojectTmp); if (world.getInventory().isVisible()) { // unprojectTmp.y += verbUI.getHeight(); } if (ia.getDesc() == null) { float size = DPIUtils.ICON_SIZE * DPIUtils.getSizeMultiplier(); Drawable drawable = ((TextureRegionDrawable) getUI().getSkin().getDrawable("circle")).tint(Color.RED); drawable.draw(batch, unprojectTmp.x - size / 2, unprojectTmp.y - size / 2, size, size); } else { BitmapFont font = getUI().getSkin().getFont("desc"); String desc = ia.getDesc(); if (desc.charAt(0) == I18N.PREFIX) desc = getWorld().getI18N().getString(desc.substring(1)); textLayout.setText(font, desc); float textX = unprojectTmp.x - textLayout.width / 2; float textY = unprojectTmp.y + textLayout.height; RectangleRenderer.draw(batch, textX - 8, textY - textLayout.height - 8, textLayout.width + 16, textLayout.height + 16, Color.BLACK); font.draw(batch, textLayout, textX, textY); } } }