@Override public void draw(Batch batch, float parentAlpha) { validate(); Color color = getColor(); Drawable handle = style.handle; 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(); } } batch.setColor(color.r, color.g, color.b, parentAlpha * color.a); handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height); resetTransform(batch); }
public void draw(SpriteBatch batch, float parentAlpha) { super.draw(batch, parentAlpha); (selected ? checked : active) .draw(batch, getX(), getY(), checked.getMinWidth(), checked.getMinHeight()); font.draw(batch, text, getX() + checked.getMinWidth() + pad, getY() + font.getCapHeight()); }
/** * Sets the background drawable and sets the table's padding to {@link Drawable#getBottomHeight()} * , {@link Drawable#getTopHeight()}, {@link Drawable#getLeftWidth()}, and {@link * Drawable#getRightWidth()}. * * @param background If null, the background will be cleared and all padding is removed. */ public void setBackground(Drawable background) { if (this.background == background) return; this.background = background; if (background == null) pad(null); else { padBottom(background.getBottomHeight()); padTop(background.getTopHeight()); padLeft(background.getLeftWidth()); padRight(background.getRightWidth()); invalidate(); } }
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; }
protected void drawCursor(Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { cursorPatch.draw( batch, x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset + font.getData().cursorX, y - textHeight - font.getDescent(), cursorPatch.getMinWidth(), textHeight); }
private void calculateHorizBoundsAndPositions() { Drawable handle = style.handle; float height = getHeight(); float availWidth = getWidth() - handle.getMinWidth(); float leftAreaWidth = (int) (availWidth * splitAmount); float rightAreaWidth = availWidth - leftAreaWidth; float handleWidth = handle.getMinWidth(); firstWidgetBounds.set(0, 0, leftAreaWidth, height); secondWidgetBounds.set(leftAreaWidth + handleWidth, 0, rightAreaWidth, height); handleBounds.set(leftAreaWidth, 0, handleWidth, height); }
@Override public void draw(SpriteBatch batch, float parentAlpha) { Drawable background; if (list != null && list.getParent() != null && style.backgroundOpen != null) background = style.backgroundOpen; else if (clickListener.isOver() && style.backgroundOver != null) background = style.backgroundOver; else background = style.background; final BitmapFont font = style.font; final Color fontColor = style.fontColor; 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); background.draw(batch, x, y, width, height); if (items.length > 0) { float availableWidth = width - background.getLeftWidth() - background.getRightWidth(); int numGlyphs = font.computeVisibleGlyphs( items[selectedIndex], 0, items[selectedIndex].length(), availableWidth); bounds.set(font.getBounds(items[selectedIndex])); height -= background.getBottomHeight() + background.getTopHeight(); float textY = (int) (height / 2 + background.getBottomHeight() + bounds.height / 2); font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha); font.draw( batch, items[selectedIndex], x + background.getLeftWidth(), y + textY, 0, numGlyphs); } // calculate screen coords where list should be displayed getStage().toScreenCoordinates(screenCoords.set(x, y), batch.getTransformMatrix()); }
@Override public void draw(SpriteBatch batch, float parentAlpha) { final Drawable listBackground = style.listBackground; final Drawable listSelection = style.listSelection; final BitmapFont font = style.font; final Color fontColor = style.fontColor; float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); Color color = getColor(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); listBackground.draw(batch, x, y, width, height); width -= listBackground.getLeftWidth() + listBackground.getRightWidth(); x += listBackground.getLeftWidth(); float posY = height - listBackground.getTopHeight(); for (int i = 0; i < items.length; i++) { if (listSelectedIndex == i) { listSelection.draw(batch, x, y + posY - itemHeight, width, itemHeight); } font.setColor(fontColor.r, fontColor.g, fontColor.b, color.a * fontColor.a * parentAlpha); font.draw(batch, items[i], x + textOffsetX, y + posY - textOffsetY); posY -= itemHeight; } }
private void calculateVertBoundsAndPositions() { Drawable handle = style.handle; float width = getWidth(); float height = getHeight(); float availHeight = height - handle.getMinHeight(); float topAreaHeight = (int) (availHeight * splitAmount); float bottomAreaHeight = availHeight - topAreaHeight; float handleHeight = handle.getMinHeight(); firstWidgetBounds.set(0, height - topAreaHeight, width, topAreaHeight); secondWidgetBounds.set(0, 0, width, bottomAreaHeight); handleBounds.set(0, bottomAreaHeight, width, handleHeight); }
/** * Called to draw the background, before clipping is applied (if enabled). Default implementation * draws the background drawable. */ protected void drawBackground(Batch batch, float parentAlpha) { if (background != null) { Color color = getColor(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); background.draw(batch, getX(), getY(), getWidth(), getHeight()); } }
/** Draws selection rectangle * */ protected void drawSelection(Drawable selection, Batch batch, BitmapFont font, float x, float y) { selection.draw( batch, x + textOffset + selectionX + fontOffset, y - textHeight - font.getDescent(), selectionWidth, textHeight); }
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(); }
@Override public void draw(SpriteBatch batch, float parentAlpha) { // TODO Auto-generated method stub super.draw(batch, parentAlpha); if (imageUp != null) { imageUp.draw(batch, getX(), getY(), getWidth(), getHeight()); } Lab.draw(batch, parentAlpha); }
public ToggleBox(String text, Skin skin) { this.text = text; this.skin = skin; font = skin.getFont("default-font"); checked = skin.getDrawable("check-on"); active = skin.getDrawable("check-off"); setTouchable(Touchable.enabled); addListener( new ClickListener() { public void clicked(InputEvent ev, float x, float y) { setSelected(!isSelected()); } }); TextBounds fb = font.getBounds(text); setSize( checked.getMinWidth() + pad + fb.width, Math.max(checked.getMinHeight(), font.getCapHeight())); }
/** Draws selection, icons, and expand icons. */ private void draw(SpriteBatch batch, Array<Node> nodes, float indent) { Drawable plus = style.plus, minus = style.minus; float x = getX(), y = getY(); for (int i = 0, n = nodes.size; i < n; i++) { Node node = nodes.get(i); Actor actor = node.actor; if (selectedNodes.contains(node, true) && style.selection != null) { style.selection.draw( batch, x, y + actor.getY() - ySpacing / 2, getWidth(), node.height + ySpacing); } else if (node == overNode && style.over != null) { style.over.draw( batch, x, y + actor.getY() - ySpacing / 2, getWidth(), node.height + ySpacing); } if (node.icon != null) { float iconY = actor.getY() + Math.round((node.height - node.icon.getMinHeight()) / 2); batch.setColor(actor.getColor()); node.icon.draw( batch, x + node.actor.getX() - iconSpacing - node.icon.getMinWidth(), y + iconY, node.icon.getMinWidth(), node.icon.getMinHeight()); batch.setColor(Color.WHITE); } if (node.children.size == 0) continue; Drawable expandIcon = node.expanded ? minus : plus; float iconY = actor.getY() + Math.round((node.height - expandIcon.getMinHeight()) / 2); expandIcon.draw( batch, x + indent - iconSpacing, y + iconY, expandIcon.getMinWidth(), expandIcon.getMinHeight()); if (node.expanded) draw(batch, node.children, indent + indentSpacing); } }
public void setItems(Object[] objects) { if (objects == null) throw new IllegalArgumentException("items cannot be null."); if (!(objects instanceof String[])) { String[] strings = new String[objects.length]; for (int i = 0, n = objects.length; i < n; i++) strings[i] = String.valueOf(objects[i]); objects = strings; } this.items = (String[]) objects; selectedIndex = 0; Drawable bg = style.background; BitmapFont font = style.font; prefHeight = Math.max( bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2, bg.getMinHeight()); float max = 0; for (int i = 0; i < items.length; i++) max = Math.max(font.getBounds(items[i]).width, max); prefWidth = bg.getLeftWidth() + bg.getRightWidth() + max; prefWidth = Math.max( prefWidth, max + style.listBackground.getLeftWidth() + style.listBackground.getRightWidth() + 2 * style.itemSpacing); invalidateHierarchy(); }
private void layout() { final BitmapFont font = style.font; final Drawable listSelection = style.listSelection; final Drawable listBackground = style.listBackground; itemHeight = font.getCapHeight() + -font.getDescent() * 2 + style.itemSpacing; itemHeight += listSelection.getTopHeight() + listSelection.getBottomHeight(); textOffsetX = listSelection.getLeftWidth() + style.itemSpacing; textOffsetY = listSelection.getTopHeight() + -font.getDescent() + style.itemSpacing / 2; setWidth(SelectBox.this.getWidth()); setHeight( items.length * itemHeight + listBackground.getTopHeight() + listBackground.getBottomHeight()); }
public void draw(Drawable drawable, Batch batch, float parentAlpha) { Color color = getColor(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); if (drawable instanceof TransformDrawable) { if (getScaleX() != 1 || getScaleY() != 1 || getRotation() != 0) { ((TransformDrawable) drawable) .draw( batch, getX(), getY(), (getWidth() / 2), (getHeight() / 2), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation()); return; } } if (drawable != null) drawable.draw(batch, getX(), getY(), getWidth() * getScaleX(), getHeight() * getScaleY()); }
@Override public void draw(SpriteBatch batch, float parentAlpha) { final BitmapFont font = style.font; final Color fontColor = disabled ? style.disabledFontColor : style.fontColor; final Drawable selection = style.selection; final Drawable cursorPatch = style.cursor; final Drawable background = 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(); Stage stage = getStage(); boolean focused = stage != null && stage.getKeyboardFocus() == this; 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); } if (focused && !disabled) { blink(); if (cursorOn && cursorPatch != null) { cursorPatch.draw( batch, x + bgLeftWidth + textOffset + glyphPositions.get(cursor) - glyphPositions.items[visibleTextStart] - 1, y + textY - textBounds.height - font.getDescent(), cursorPatch.getMinWidth(), textBounds.height + font.getDescent() / 2); } } }
public float getPrefHeight() { if (background != null) return Math.max(layout.getPrefHeight(), background.getMinHeight()); return layout.getPrefHeight(); }
@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; 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(); 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 (focused && !disabled) { blink(); if (cursorOn && cursorPatch != null) { drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY); } } }
/** @param drawable May be null. */ public void setDrawable(Drawable drawable) { if (this.drawable == drawable) return; this.drawable = drawable; setSize(drawable.getMinWidth(), drawable.getMinHeight()); setPosition(0, 0); }
public void layout() { final Drawable bg = style.background; final Drawable hScrollKnob = style.hScrollKnob; final Drawable vScrollKnob = style.vScrollKnob; float bgLeftWidth = 0, bgRightWidth = 0, bgTopHeight = 0, bgBottomHeight = 0; if (bg != null) { bgLeftWidth = bg.getLeftWidth(); bgRightWidth = bg.getRightWidth(); bgTopHeight = bg.getTopHeight(); bgBottomHeight = bg.getBottomHeight(); } float width = getWidth(); float height = getHeight(); float scrollbarHeight = 0; if (hScrollKnob != null) scrollbarHeight = hScrollKnob.getMinHeight(); if (style.hScroll != null) scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight()); float scrollbarWidth = 0; if (vScrollKnob != null) scrollbarWidth = vScrollKnob.getMinWidth(); if (style.vScroll != null) scrollbarWidth = Math.max(scrollbarWidth, style.vScroll.getMinWidth()); // Get available space size by subtracting background's padded area. areaWidth = width - bgLeftWidth - bgRightWidth; areaHeight = height - bgTopHeight - bgBottomHeight; if (widget == null) return; // Get widget's desired width. float widgetWidth, widgetHeight; if (widget instanceof Layout) { Layout layout = (Layout) widget; widgetWidth = layout.getPrefWidth(); widgetHeight = layout.getPrefHeight(); } else { widgetWidth = widget.getWidth(); widgetHeight = widget.getHeight(); } // Determine if horizontal/vertical scrollbars are needed. scrollX = forceScrollX || (widgetWidth > areaWidth && !disableX); scrollY = forceScrollY || (widgetHeight > areaHeight && !disableY); boolean fade = fadeScrollBars; if (!fade) { // Check again, now taking into account the area that's taken up by any enabled scrollbars. if (scrollY) { areaWidth -= scrollbarWidth; if (!scrollX && widgetWidth > areaWidth && !disableX) { scrollX = true; } } if (scrollX) { areaHeight -= scrollbarHeight; if (!scrollY && widgetHeight > areaHeight && !disableY) { scrollY = true; areaWidth -= scrollbarWidth; } } } // Set the widget area bounds. widgetAreaBounds.set(bgLeftWidth, bgBottomHeight, areaWidth, areaHeight); if (fade) { // Make sure widget is drawn under fading scrollbars. if (scrollX) areaHeight -= scrollbarHeight; if (scrollY) areaWidth -= scrollbarWidth; } else { if (scrollbarsOnTop) { // Make sure widget is drawn under non-fading scrollbars. if (scrollX) widgetAreaBounds.height += scrollbarHeight; if (scrollY) widgetAreaBounds.width += scrollbarWidth; } else { // Offset widget area y for horizontal scrollbar. if (scrollX) { if (hScrollOnBottom) { widgetAreaBounds.y += scrollbarHeight; } else { widgetAreaBounds.y = 0; } } // Offset widget area x for vertical scrollbar. if (scrollY) { if (vScrollOnRight) { widgetAreaBounds.x = 0; } else { widgetAreaBounds.x += scrollbarWidth; } } } } // If the widget is smaller than the available space, make it take up the available space. widgetWidth = disableX ? width : Math.max(areaWidth, widgetWidth); widgetHeight = disableY ? height : Math.max(areaHeight, widgetHeight); maxX = widgetWidth - areaWidth; maxY = widgetHeight - areaHeight; if (fade) { // Make sure widget is drawn under fading scrollbars. if (scrollX) maxY -= scrollbarHeight; if (scrollY) maxX -= scrollbarWidth; } scrollX(MathUtils.clamp(amountX, 0, maxX)); scrollY(MathUtils.clamp(amountY, 0, maxY)); // Set the bounds and scroll knob sizes if scrollbars are needed. if (scrollX) { if (hScrollKnob != null) { float hScrollHeight = style.hScroll != null ? style.hScroll.getMinHeight() : hScrollKnob.getMinHeight(); // the small gap where the two scroll bars intersect might have to flip from right to left float boundsX, boundsY; if (vScrollOnRight) { boundsX = bgLeftWidth; } else { boundsX = bgLeftWidth + scrollbarWidth; } // bar on the top or bottom if (hScrollOnBottom) { boundsY = bgBottomHeight; } else { boundsY = height - bgTopHeight - hScrollHeight; } hScrollBounds.set(boundsX, boundsY, areaWidth, hScrollHeight); hKnobBounds.width = Math.max( hScrollKnob.getMinWidth(), (int) (hScrollBounds.width * areaWidth / widgetWidth)); hKnobBounds.height = hScrollKnob.getMinHeight(); hKnobBounds.x = hScrollBounds.x + (int) ((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX()); hKnobBounds.y = hScrollBounds.y; } else { hScrollBounds.set(0, 0, 0, 0); hKnobBounds.set(0, 0, 0, 0); } } if (scrollY) { if (vScrollKnob != null) { float vScrollWidth = style.vScroll != null ? style.vScroll.getMinWidth() : vScrollKnob.getMinWidth(); // the small gap where the two scroll bars intersect might have to flip from bottom to top float boundsX, boundsY; if (hScrollOnBottom) { boundsY = height - bgTopHeight - areaHeight; } else { boundsY = bgBottomHeight; } // bar on the left or right if (vScrollOnRight) { boundsX = width - bgRightWidth - vScrollWidth; } else { boundsX = bgLeftWidth; } vScrollBounds.set(boundsX, boundsY, vScrollWidth, areaHeight); vKnobBounds.width = vScrollKnob.getMinWidth(); vKnobBounds.height = Math.max( vScrollKnob.getMinHeight(), (int) (vScrollBounds.height * areaHeight / widgetHeight)); if (vScrollOnRight) { vKnobBounds.x = width - bgRightWidth - vScrollKnob.getMinWidth(); } else { vKnobBounds.x = bgLeftWidth; } vKnobBounds.y = vScrollBounds.y + (int) ((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY())); } else { vScrollBounds.set(0, 0, 0, 0); vKnobBounds.set(0, 0, 0, 0); } } widget.setSize(widgetWidth, widgetHeight); if (widget instanceof Layout) ((Layout) widget).validate(); }
public void draw( Batch batch, float parentAlpha, T item, boolean selected, float x, float y, float width, float height) { BitmapFont font = style.font; Drawable selectedDrawable = style.selection; Color fontColorSelected = style.fontColorSelected; Color fontColorUnselected = style.fontColorUnselected; if (selected) { selectedDrawable.draw(batch, x, y - height, width, height); font.setColor( fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha); } else { font.setColor( fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha); } if (hasImage()) { TextureRegion r = getCellImage(item); float ih = r.getRegionHeight(); float iw = r.getRegionWidth(); if (ih > getItemHeight() - MARGIN) { ih = getItemHeight() - MARGIN; iw *= ih / r.getRegionHeight(); } batch.draw(r, x, y - ih - MARGIN / 2, iw, ih); x += iw; } font.draw(batch, getCellTitle(item), x + textOffsetX, y - textOffsetY); if (hasSubtitle()) { if (selected) { style.subtitleFont.setColor( fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha * 0.5f); } else { style.subtitleFont.setColor( fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha * 0.5f); } style.subtitleFont.draw( batch, getCellSubTitle(item), x + textOffsetX, y - textOffsetY - (font.getCapHeight() - font.getDescent() * 2)); } }