List of usage examples for com.badlogic.gdx.scenes.scene2d.utils Drawable getMinWidth
public float getMinWidth();
From source file:CB_UI_Base.GL_UI.utils.EmptyDrawable.java
License:Apache License
/** Creates a new empty drawable with the same sizing information as the specified drawable. */ public EmptyDrawable(Drawable drawable) { leftWidth = drawable.getLeftWidth(); rightWidth = drawable.getRightWidth(); topHeight = drawable.getTopHeight(); bottomHeight = drawable.getBottomHeight(); minWidth = drawable.getMinWidth(); minHeight = drawable.getMinHeight(); }
From source file:com.anstrat.gui.SnapScrollPane.java
License:Apache License
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(); }/*from w w w . ja v a2 s.co m*/ 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 = forceOverscrollX || (widgetWidth > areaWidth && !disableX); scrollY = forceOverscrollY || (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) widgetAreaBounds.y += scrollbarHeight; } } // 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; } amountX = MathUtils.clamp(amountX, 0, maxX); amountY = 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(); hScrollBounds.set(bgLeftWidth, bgBottomHeight, areaWidth, hScrollHeight); hKnobBounds.width = Math.max(hScrollKnob.getMinWidth(), (int) (hScrollBounds.width * areaWidth / widget.getWidth())); 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(); vScrollBounds.set(width - bgRightWidth - vScrollWidth, height - bgTopHeight - areaHeight, vScrollWidth, areaHeight); vKnobBounds.width = vScrollKnob.getMinWidth(); vKnobBounds.height = Math.max(vScrollKnob.getMinHeight(), (int) (vScrollBounds.height * areaHeight / widgetHeight)); vKnobBounds.x = width - bgRightWidth - vScrollKnob.getMinWidth(); vKnobBounds.y = vScrollBounds.y + (int) ((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY())); } else { vScrollBounds.set(0, 0, 0, 0); vKnobBounds.set(0, 0, 0, 0); } } if (widget.getWidth() != widgetWidth || widget.getHeight() != widgetHeight) { widget.setWidth(widgetWidth); widget.setHeight(widgetHeight); if (widget instanceof Layout) { Layout layout = (Layout) widget; layout.invalidate(); layout.validate(); } } else { if (widget instanceof Layout) ((Layout) widget).validate(); } }
From source file:com.apptogo.roperace.custom.MyTouchpad.java
License:Apache License
@Override public void draw(Batch batch, float parentAlpha) { validate();/*w ww . j ava 2 s . c om*/ Color c = getColor(); batch.setColor(c.r, c.g, c.b, c.a * parentAlpha); float x = getX(); float y = getY(); float w = getWidth(); float h = getHeight(); final Drawable bg = style.background; if (bg != null) bg.draw(batch, x, y, w, h); final Drawable knob = style.knob; if (knob != null) { x += knobPosition.x - knob.getMinWidth() / 2f; y += knobPosition.y - knob.getMinHeight() / 2f; knob.draw(batch, x, y, knob.getMinWidth(), knob.getMinHeight()); } }
From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java
License:Apache License
/** Draws selection rectangle **/ protected void drawSelection(Drawable selection, Batch batch, BitmapFont font, float x, float y) { //selection.draw(batch, x + selectionX + renderOffset + fontOffset, y - textHeight - font.getDescent(), selectionWidth, // textHeight); /** calanti addition - better width support */ float sx = x + selectionX + renderOffset + fontOffset; float sy = y - textHeight - font.getDescent(); float w = Math.max(selectionWidth, selection.getMinWidth()); float h = textHeight; selection.draw(batch, sx, sy, w, h); }
From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java
License:Apache License
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); /** calanti addition - proper centering of cursor */ float cx = x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset + font.getData().cursorX - cursorPatch.getMinWidth() / 2; float cy = y - textHeight - font.getDescent(); float w = cursorPatch.getMinWidth(); float h = textHeight; cursorPatch.draw(batch, cx, cy, w, h); }
From source file:com.idp.engine.ui.graphics.actors.TextArea.java
@Override protected void drawCursor(Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { y = getY() + font.getLineHeight();//from ww w. j a v a2 s . co m float textOffset = cursor >= glyphPositions.size || cursorLine * 2 >= linesBreak.size ? 0 : glyphPositions.get(cursor) - glyphPositions.get(linesBreak.items[cursorLine * 2]); cursorPatch.draw(batch, x + textOffset + fontOffset + font.getData().cursorX, y - font.getDescent() / 2 + (cursorLine - firstLineShowing - 1) * font.getLineHeight(), cursorPatch.getMinWidth(), font.getLineHeight()); }
From source file:com.kotcrab.vis.ui.widget.MultiSplitPane.java
License:Apache License
private void initialize() { addListener(new SplitPaneCursorManager(this, vertical) { @Override/* www.j av a2 s.c o m*/ protected boolean handleBoundsContains(float x, float y) { return getHandleContaining(x, y) != null; } @Override protected boolean contains(float x, float y) { for (Rectangle bound : widgetBounds) { if (bound.contains(x, y)) return true; } return getHandleContaining(x, y) != null; } }); addListener(new InputListener() { int draggingPointer = -1; @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (isTouchable() == false) return false; if (draggingPointer != -1) return false; if (pointer == 0 && button != 0) return false; Rectangle containingHandle = getHandleContaining(x, y); if (containingHandle != null) { handleOverIndex = handleBounds.indexOf(containingHandle, true); FocusManager.resetFocus(getStage()); draggingPointer = pointer; lastPoint.set(x, y); handlePosition.set(containingHandle.x, containingHandle.y); return true; } return false; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { if (pointer == draggingPointer) draggingPointer = -1; handleOver = getHandleContaining(x, y); } @Override public boolean mouseMoved(InputEvent event, float x, float y) { handleOver = getHandleContaining(x, y); return false; } @Override public void touchDragged(InputEvent event, float x, float y, int pointer) { if (pointer != draggingPointer) return; Drawable handle = style.handle; if (!vertical) { float delta = x - lastPoint.x; float availWidth = getWidth() - handle.getMinWidth(); float dragX = handlePosition.x + delta; handlePosition.x = dragX; dragX = Math.max(0, dragX); dragX = Math.min(availWidth, dragX); float targetSplit = dragX / availWidth; setSplit(handleOverIndex, targetSplit); lastPoint.set(x, y); } else { float delta = y - lastPoint.y; float availHeight = getHeight() - handle.getMinHeight(); float dragY = handlePosition.y + delta; handlePosition.y = dragY; dragY = Math.max(0, dragY); dragY = Math.min(availHeight, dragY); float targetSplit = 1 - (dragY / availHeight); setSplit(handleOverIndex, targetSplit); lastPoint.set(x, y); } invalidate(); } }); }
From source file:com.kotcrab.vis.ui.widget.VisSplitPane.java
License:Apache License
private void initialize() { addListener(new SplitPaneCursorManager(this, vertical) { @Override/* www .jav a 2 s.co m*/ protected boolean handleBoundsContains(float x, float y) { return handleBounds.contains(x, y); } @Override protected boolean contains(float x, float y) { return firstWidgetBounds.contains(x, y) || secondWidgetBounds.contains(x, y) || handleBounds.contains(x, y); } }); addListener(new InputListener() { int draggingPointer = -1; @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { //TODO potential bug with libgdx scene2d? //fixes issue when split bar could be still dragged even when touchable is set to childrenOnly, probably scene2d issue if (isTouchable() == false) return false; if (draggingPointer != -1) return false; if (pointer == 0 && button != 0) return false; if (handleBounds.contains(x, y)) { FocusManager.resetFocus(getStage()); draggingPointer = pointer; lastPoint.set(x, y); handlePosition.set(handleBounds.x, handleBounds.y); return true; } return false; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { if (pointer == draggingPointer) draggingPointer = -1; } @Override public boolean mouseMoved(InputEvent event, float x, float y) { mouseOnHandle = handleBounds.contains(x, y); return false; } @Override public void touchDragged(InputEvent event, float x, float y, int pointer) { if (pointer != draggingPointer) return; Drawable handle = style.handle; if (!vertical) { float delta = x - lastPoint.x; float availWidth = getWidth() - handle.getMinWidth(); float dragX = handlePosition.x + delta; handlePosition.x = dragX; dragX = Math.max(0, dragX); dragX = Math.min(availWidth, dragX); splitAmount = dragX / availWidth; if (splitAmount < minAmount) splitAmount = minAmount; if (splitAmount > maxAmount) splitAmount = maxAmount; lastPoint.set(x, y); } else { float delta = y - lastPoint.y; float availHeight = getHeight() - handle.getMinHeight(); float dragY = handlePosition.y + delta; handlePosition.y = dragY; dragY = Math.max(0, dragY); dragY = Math.min(availHeight, dragY); splitAmount = 1 - (dragY / availHeight); if (splitAmount < minAmount) splitAmount = minAmount; if (splitAmount > maxAmount) splitAmount = maxAmount; lastPoint.set(x, y); } invalidate(); } }); }
From source file:com.kotcrab.vis.ui.widget.VisSplitPane.java
License:Apache License
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); }
From source file:com.kotcrab.vis.ui.widget.VisTextArea.java
License:Apache License
@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()); }