Example usage for com.badlogic.gdx.scenes.scene2d.utils Drawable draw

List of usage examples for com.badlogic.gdx.scenes.scene2d.utils Drawable draw

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.utils Drawable draw.

Prototype

public void draw(Batch batch, float x, float y, float width, float height);

Source Link

Document

Draws this drawable at the specified bounds.

Usage

From source file:CB_UI_Base.GL_UI.Activitys.ImageActivity.java

License:Open Source License

private void renderImage(Batch batch) {
    //   batch.disableBlending();

    float faktor = camera.zoom;
    float dx = this.thisWorldRec.getCenterPosX() - MainViewBase.mainView.getCenterPosX();
    float dy = this.thisWorldRec.getCenterPosY() - MainViewBase.mainView.getCenterPosY();
    camera.position.set(0, 0, 0);//from   w  ww  . j  a v a 2 s  .c  om
    float dxr = dx;
    float dyr = dy;

    camera.up.x = 0;
    camera.up.y = 1;
    camera.up.z = 0;
    camera.rotate(-imageHeading, 0, 0, 1);
    double angle = imageHeading * MathUtils.DEG_RAD;
    dxr = (float) (Math.cos(angle) * dx + Math.sin(angle) * dy);
    dyr = (float) (-Math.sin(angle) * dx + Math.cos(angle) * dy);

    camera.translate(-dxr * faktor, -dyr * faktor, 0);
    camera.update();
    Matrix4 mat = camera.combined;
    batch.setProjectionMatrix(mat);

    Drawable drw = img.getDrawable();

    if (drw != null) {

        float drawwidth = getWidth();
        float drawHeight = getHeight();

        ImageLoader imageLoader = img.getImageLoader();

        if (imageLoader.getSpriteWidth() > 0 && imageLoader.getSpriteHeight() > 0) {
            float proportionWidth = getWidth() / imageLoader.getSpriteWidth();
            float proportionHeight = getHeight() / imageLoader.getSpriteHeight();

            float proportion = Math.min(proportionWidth, proportionHeight);

            drawwidth = imageLoader.getSpriteWidth() * proportion;
            drawHeight = imageLoader.getSpriteHeight() * proportion;
        }

        long posFactor = getPosFactor(0);

        float xPos = -(screenCenterW.x * posFactor) - (screenCenterT.x * camera.zoom);
        float yPos = (screenCenterW.y * posFactor) - (screenCenterT.y * camera.zoom);
        float xSize = drawwidth * posFactor;
        float ySize = drawHeight * posFactor;

        drw.draw(batch, xPos, yPos, xSize, ySize);
    }
}

From source file:CB_UI_Base.GL_UI.Controls.Button.java

License:Open Source License

/**
 * render//w w  w . j a  v  a 2 s.co  m
 */
@Override
protected void render(Batch batch) {
    if (dragableButton) {
        if (isPressed && !GL.getIsTouchDown()) {
            isPressed = false;
            GL.that.renderOnce();
        }
    }

    if (!isPressed && !isDisabled && !isFocused) {
        if (drawableNormal != null) {
            drawableNormal.draw(batch, 0, 0, getWidth(), getHeight());
        } else {
            Initial();
            GL.that.renderOnce();
        }
    } else if (isPressed) {
        if (drawablePressed != null) {
            drawablePressed.draw(batch, 0, 0, getWidth(), getHeight());
        } else {
            Initial();
            GL.that.renderOnce();
        }
    } else if (isFocused) {
        if (drawableFocused != null) {
            drawableFocused.draw(batch, 0, 0, getWidth(), getHeight());
        } else {
            Initial();
            GL.that.renderOnce();
        }
    } else {
        if (drawableDisabled != null) {
            drawableDisabled.draw(batch, 0, 0, getWidth(), getHeight());
        } else {
            Initial();
            GL.that.renderOnce();
        }
    }

    for (int i = 0, n = DrawableOverlayList.size(); i < n; i++) {
        Drawable drw = DrawableOverlayList.get(i);
        drw.draw(batch, 0, 0, getWidth(), getHeight());
    }

}

From source file:com.agateau.ui.menu.SwitchMenuItem.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    mStyle.frame.draw(batch, getX(), getY(), getWidth(), getHeight());

    mFocusIndicator.draw(batch, getX(), getY(), getWidth(), getHeight());

    // Draw handle
    Drawable handle = mStyle.handle;
    float padding = mStyle.framePadding;
    float handleWidth = (getWidth() - 2 * padding) / 2;
    float x = handleWidth * mXOffset;
    handle.draw(batch, getX() + x + padding, getY() + padding, handleWidth, getHeight() - 2 * padding);

    // Draw text//from  w ww .j a va  2 s.c  o  m
    float y = getY() + (mFont.getCapHeight() + getHeight()) / 2;
    mFont.draw(batch, formatValue(false), getX() + padding, y, handleWidth, Align.center, /* wrap= */false);
    mFont.draw(batch, formatValue(true), getX() + padding + handleWidth, y, handleWidth, Align.center,
            /* wrap= */false);
}

From source file:com.agateau.ui.menu.TabMenuItem.java

License:Apache License

private void drawFrameBorder(Batch batch, Drawable drawable, float x, float width) {
    drawable.draw(batch, x, getY(), width, drawable.getMinHeight());
}

From source file:com.apptogo.roperace.custom.MyTouchpad.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();/*from   w  w w. jav a  2  s  . c o  m*/

    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.bladecoder.engine.ui.retro.RetroSceneScreen.java

License:Apache License

private void drawHotspots(SpriteBatch batch) {
    final World world = World.getInstance();
    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();//  w ww .j  av  a  2 s .  c o m

        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 = I18N.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);
        }
    }
}

From source file:com.bladecoder.engineeditor.ui.components.CellRenderer.java

License:Apache License

public void draw(Batch batch, float parentAlpha, T item, boolean selected, float x, float y, float width,
        float height) {
    BitmapFont font = style.font;//w w  w  . j  a va 2  s.  c o m
    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()) {
        String sub = getCellSubTitle(item);

        if (sub != null) {
            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, sub, x + textOffsetX,
                    y - textOffsetY - (font.getCapHeight() - font.getDescent() * 2));
        }
    }
}

From source file:com.bladecoder.engineeditor.ui.components.CustomList.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();/*from  w  w  w  . j  a v a 2  s. co m*/

    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();
    }
}

From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    Stage stage = getStage();//from  ww  w  .  j  a v a2 s .co m
    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);
        }
    }
}

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);
}