Search in sources :

Example 16 with Drawable

use of com.badlogic.gdx.scenes.scene2d.utils.Drawable in project libgdx by libgdx.

the class List method draw.

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();
    BitmapFont font = style.font;
    Drawable selectedDrawable = style.selection;
    Color fontColorSelected = style.fontColorSelected;
    Color fontColorUnselected = style.fontColorUnselected;
    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();
    }
    font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha);
    for (int i = 0; i < items.size; i++) {
        if (cullingArea == null || (itemY - itemHeight <= cullingArea.y + cullingArea.height && itemY >= cullingArea.y)) {
            T item = items.get(i);
            boolean selected = selection.contains(item);
            if (selected) {
                selectedDrawable.draw(batch, x, y + itemY - itemHeight, width, itemHeight);
                font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha);
            }
            drawItem(batch, font, i, item, x + textOffsetX, y + itemY - textOffsetY);
            if (selected) {
                font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha);
            }
        } else if (itemY < cullingArea.y) {
            break;
        }
        itemY -= itemHeight;
    }
}
Also used : Color(com.badlogic.gdx.graphics.Color) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 17 with Drawable

use of com.badlogic.gdx.scenes.scene2d.utils.Drawable in project libgdx by libgdx.

the class ProgressBar method getPrefHeight.

public float getPrefHeight() {
    if (vertical)
        return 140;
    else {
        final Drawable knob = getKnobDrawable();
        final Drawable bg = (disabled && style.disabledBackground != null) ? style.disabledBackground : style.background;
        return Math.max(knob == null ? 0 : knob.getMinHeight(), bg == null ? 0 : bg.getMinHeight());
    }
}
Also used : Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable)

Example 18 with Drawable

use of com.badlogic.gdx.scenes.scene2d.utils.Drawable in project libgdx by libgdx.

the class Button method setStyle.

public void setStyle(ButtonStyle style) {
    if (style == null)
        throw new IllegalArgumentException("style cannot be null.");
    this.style = style;
    Drawable background = null;
    if (isPressed() && !isDisabled()) {
        background = style.down == null ? style.up : style.down;
    } else {
        if (isDisabled() && style.disabled != null)
            background = style.disabled;
        else if (isChecked && style.checked != null)
            background = (isOver() && style.checkedOver != null) ? style.checkedOver : style.checked;
        else if (isOver() && style.over != null)
            background = style.over;
        else
            background = style.up;
    }
    setBackground(background);
}
Also used : Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable)

Example 19 with Drawable

use of com.badlogic.gdx.scenes.scene2d.utils.Drawable in project libgdx by libgdx.

the class ImageButton method updateImage.

private void updateImage() {
    Drawable drawable = null;
    if (isDisabled() && style.imageDisabled != null)
        drawable = style.imageDisabled;
    else if (isPressed() && style.imageDown != null)
        drawable = style.imageDown;
    else if (isChecked && style.imageChecked != null)
        drawable = (style.imageCheckedOver != null && isOver()) ? style.imageCheckedOver : style.imageChecked;
    else if (isOver() && style.imageOver != null)
        drawable = style.imageOver;
    else if (//
    style.imageUp != null)
        drawable = style.imageUp;
    image.setDrawable(drawable);
}
Also used : Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable)

Example 20 with Drawable

use of com.badlogic.gdx.scenes.scene2d.utils.Drawable in project libgdx by libgdx.

the class ImageTextButton method updateImage.

private void updateImage() {
    Drawable drawable = null;
    if (isDisabled() && style.imageDisabled != null)
        drawable = style.imageDisabled;
    else if (isPressed() && style.imageDown != null)
        drawable = style.imageDown;
    else if (isChecked && style.imageChecked != null)
        drawable = (style.imageCheckedOver != null && isOver()) ? style.imageCheckedOver : style.imageChecked;
    else if (isOver() && style.imageOver != null)
        drawable = style.imageOver;
    else if (//
    style.imageUp != null)
        drawable = style.imageUp;
    image.setDrawable(drawable);
}
Also used : Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable)

Aggregations

Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)34 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)10 Color (com.badlogic.gdx.graphics.Color)9 SpriteDrawable (com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable)7 NinePatchDrawable (com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)5 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)5 TiledDrawable (com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable)5 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)5 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)4 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)3 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)3 ListStyle (com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle)3 ScrollPaneStyle (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle)3 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)3 Array (com.badlogic.gdx.utils.Array)3 FileHandle (com.badlogic.gdx.files.FileHandle)2 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)2 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)2