Java Code Examples for com.badlogic.gdx.scenes.scene2d.utils.Drawable

The following examples show how to use com.badlogic.gdx.scenes.scene2d.utils.Drawable. These examples are extracted from open source projects. 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 Project: gdx-skineditor   Source File: Skin.java    License: Apache License 2.0 6 votes vote down vote up
public <T> T get(String name, Class<T> type) {
	if (name == null)
		throw new IllegalArgumentException("name cannot be null.");
	if (type == null)
		throw new IllegalArgumentException("type cannot be null.");

	if (type == Drawable.class)
		return (T) getDrawable(name);
	if (type == TextureRegion.class)
		return (T) getRegion(name);
	if (type == NinePatch.class)
		return (T) getPatch(name);
	if (type == Sprite.class)
		return (T) getSprite(name);

	ObjectMap<String, Object> typeResources = resources.get(type);
	if (typeResources == null)
		throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
	Object resource = typeResources.get(name);
	if (resource == null)
		throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
	return (T) resource;
}
 
Example 2
Source Project: skin-composer   Source File: MainListener.java    License: MIT License 6 votes vote down vote up
@Override
public void stylePropertyChanged(StyleProperty styleProperty,
        Actor styleActor) {
    if (styleProperty.type == Drawable.class) {
        dialogFactory.showDialogDrawables(styleProperty, dialogListener);
    } else if (styleProperty.type == Color.class) {
        dialogFactory.showDialogColors(styleProperty, dialogListener);
    } else if (styleProperty.type == BitmapFont.class) {
        dialogFactory.showDialogFonts(styleProperty, dialogListener);
    } else if (styleProperty.type == Float.TYPE) {
        main.getUndoableManager().addUndoable(new UndoableManager.DoubleUndoable(main, styleProperty, ((Spinner) styleActor).getValue()), false);
    } else if (styleProperty.type == ScrollPaneStyle.class) {
        main.getUndoableManager().addUndoable(new UndoableManager.SelectBoxUndoable(root, styleProperty, (SelectBox) styleActor), true);
    } else if (styleProperty.type == LabelStyle.class) {
        main.getUndoableManager().addUndoable(new UndoableManager.SelectBoxUndoable(root, styleProperty, (SelectBox) styleActor), true);
    } else if (styleProperty.type == ListStyle.class) {
        main.getUndoableManager().addUndoable(new UndoableManager.SelectBoxUndoable(root, styleProperty, (SelectBox) styleActor), true);
    }
}
 
Example 3
Source Project: vis-ui   Source File: TestGenerateDisabledImage.java    License: Apache License 2.0 6 votes vote down vote up
private void addVisWidgets () {
	Drawable icon = VisUI.getSkin().getDrawable("icon-folder");
	VisImageButton normal = new VisImageButton(icon);
	VisImageButton disabled = new VisImageButton(icon);
	disabled.setGenerateDisabledImage(true);
	disabled.setDisabled(true);
	add(new VisLabel("VisImageButton normal"));
	add(normal).row();
	add(new VisLabel("VisImageButton disabled"));
	add(disabled).row();

	VisImageTextButton normalText = new VisImageTextButton("text", icon);
	VisImageTextButton disabledText = new VisImageTextButton("text", icon);
	disabledText.setGenerateDisabledImage(true);
	disabledText.setDisabled(true);
	add(new VisLabel("VisImageTextButton normal"));
	add(normalText).row();
	add(new VisLabel("VisImageTextButton disabled"));
	add(disabledText).padBottom(3f).row();
}
 
Example 4
Source Project: dice-heroes   Source File: TabPane.java    License: GNU General Public License v3.0 6 votes vote down vote up
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 5
Source Project: cocos-ui-libgdx   Source File: CocoStudioUIEditor.java    License: Apache License 2.0 6 votes vote down vote up
public Drawable findDrawable(ObjectData option, String name) {

        if (option.isScale9Enable()) {// 九宫格支持
            TextureRegion textureRegion = findTextureRegion(option, name);
            NinePatch np = new NinePatch(textureRegion,
                option.getScale9OriginX(),
                textureRegion.getRegionWidth() - option.getScale9Width() - option.getScale9OriginX(),
                option.getScale9OriginY(),
                textureRegion.getRegionHeight() - option.getScale9Height() - option.getScale9OriginY());

            np.setColor(getColor(option.getCColor(), option.getAlpha()));
            return new NinePatchDrawable(np);
        }

        TextureRegion tr = findTextureRegion(option, name);

        if (tr == null) {
            return null;
        }

        return new TextureRegionDrawable(tr);
    }
 
Example 6
Source Project: cocos-ui-libgdx   Source File: CCTImageView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {
    TImage image;
    Drawable tr = editor.findDrawable(widget, widget.getFileData());
    if (tr == null) {
        return new TImage();
    }

    image = new TImage(tr);

    String buttonType = widget.getButtonType();
    if (buttonType != null) {
        switch (buttonType) {
            case "ScaleButton":
                image.isButton();
                break;
            case "ColorButton":
                image.isColorButton();
                break;
            default:
                image.isNoButton();
                break;
        }
    }
    return image;
}
 
Example 7
Source Project: vis-ui   Source File: VisImageButton.java    License: Apache License 2.0 6 votes vote down vote up
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);

	if (generateDisabledImage && style.imageDisabled == null && isDisabled())
		image.setColor(Color.GRAY);
	else
		image.setColor(Color.WHITE);
}
 
Example 8
Source Project: bladecoder-adventure-engine   Source File: CellRenderer.java    License: Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 9
Source Project: riiablo   Source File: Label.java    License: Apache License 2.0 6 votes vote down vote up
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 10
Source Project: gdx-vfx   Source File: DtdSchemaGenerator.java    License: Apache License 2.0 5 votes vote down vote up
/** Generates skin with minimum required set of default resources. */
private static Skin createSkin() {
    BitmapFont font = new BitmapFont();
    final BaseDrawable drawable = new BaseDrawable();
    Color color = Color.WHITE;

    Skin skin = new Skin() {
        @Override
        public Drawable getDrawable(String name) {
            return drawable;
        }
    };
    skin.add("default", font);
    skin.add("default", new Label.LabelStyle(font, color));
    skin.add("default-horizontal", new SplitPane.SplitPaneStyle(drawable));
    skin.add("default-vertical", new SplitPane.SplitPaneStyle(drawable));
    skin.add("default", new CheckBox.CheckBoxStyle(drawable, drawable, font, color));
    skin.add("default-horizontal", new ProgressBar.ProgressBarStyle(drawable, drawable));
    skin.add("default-vertical", new ProgressBar.ProgressBarStyle(drawable, drawable));
    skin.add("default", new ScrollPane.ScrollPaneStyle(drawable, drawable, drawable, drawable, drawable));
    skin.add("default", new List.ListStyle(font, color, color, drawable));
    skin.add("default", new SelectBox.SelectBoxStyle(font, color, drawable, skin.get(ScrollPane.ScrollPaneStyle.class), skin.get(List.ListStyle.class)));
    skin.add("default", new Tree.TreeStyle(drawable, drawable, drawable));
    skin.add("default", new TextButton.TextButtonStyle(drawable, drawable, drawable, font));
    skin.add("default-horizontal", new Slider.SliderStyle(drawable, drawable));
    skin.add("default-vertical", new Slider.SliderStyle(drawable, drawable));
    skin.add("default", new TextTooltip.TextTooltipStyle(skin.get(Label.LabelStyle.class), drawable));
    skin.add("default", new ImageButton.ImageButtonStyle(drawable, drawable, drawable, drawable, drawable, drawable));
    skin.add("default", new TextField.TextFieldStyle(font, color, drawable, drawable, drawable));
    skin.add("default", new Window.WindowStyle(font, color, drawable));
    skin.add("default", new Button.ButtonStyle(drawable, drawable, drawable));
    skin.add("default", new Label.LabelStyle(font, color));
    skin.add("default", new Touchpad.TouchpadStyle(drawable, drawable));
    skin.add("default", new ImageTextButton.ImageTextButtonStyle(drawable, drawable, drawable, font));
    return skin;
}
 
Example 11
Source Project: gdx-vfx   Source File: ImageDrawableLmlAttribute.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void process(LmlParser parser, LmlTag tag, Image image, String rawAttributeData) {
    ActorConsumer<Drawable, Image> action = (ActorConsumer<Drawable, Image>) parser.parseAction(rawAttributeData, image);
    if (action == null) {
        parser.throwError("Cannot find action: " + rawAttributeData);
        return;
    }

    Drawable drawable = action.consume(image);
    image.setDrawable(drawable);
}
 
Example 12
Source Project: vis-ui   Source File: LinkLabel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	super.draw(batch, parentAlpha);
	Drawable underline = style.underline;
	if (underline != null && clickListener.isOver()) {
		Color color = tempColor.set(getColor());
		color.a *= parentAlpha;
		if (style.fontColor != null) color.mul(style.fontColor);
		batch.setColor(color);
		underline.draw(batch, getX(), getY(), getWidth(), 1);
	}
}
 
Example 13
Source Project: talos   Source File: BackgroundButton.java    License: Apache License 2.0 5 votes vote down vote up
public BackgroundButton(Skin skin, Drawable on, Drawable off) {
    setSkin(skin);
    setBackground(getSkin().getDrawable("panel_button_bg"));

    button = new ImageButton(on, on, off);

    add(button);
}
 
Example 14
Source Project: talos   Source File: BackgroundButton.java    License: Apache License 2.0 5 votes vote down vote up
public BackgroundButton(Skin skin, Drawable drawable) {
    setSkin(skin);
    setBackground(getSkin().getDrawable("panel_button_bg"));

    button = new ImageButton(drawable);

    add(button);
}
 
Example 15
Source Project: bladecoder-adventure-engine   Source File: CustomList.java    License: Apache License 2.0 5 votes vote down vote up
@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 16
Source Project: vis-ui   Source File: VisTextArea.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected float getTextY (BitmapFont font, Drawable background) {
	float textY = getHeight();
	if (background != null) {
		textY = (int) (textY - background.getTopHeight());
	}
	return textY;
}
 
Example 17
@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 18
public FilteredSelectBoxStyle(BitmapFont font, Color fontColor, Drawable background,
		ScrollPaneStyle scrollStyle, ListStyle listStyle, TextFieldStyle textFieldStyle) {
	this.font = font;
	this.fontColor.set(fontColor);
	this.background = background;
	this.scrollStyle = scrollStyle;
	this.listStyle = listStyle;
	this.textFieldStyle = textFieldStyle;
}
 
Example 19
Source Project: vis-ui   Source File: VisSplitPane.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 20
Source Project: vis-ui   Source File: VisTextField.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 21
Source Project: dice-heroes   Source File: TabPane.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 22
Source Project: dice-heroes   Source File: TabPane.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 23
Source Project: dice-heroes   Source File: TabPane.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 24
Source Project: cocos-ui-libgdx   Source File: CocoStudioUIEditor.java    License: Apache License 2.0 5 votes vote down vote up
public Drawable findDrawable(ObjectData option, FileData fileData) {
    //显示Default
    if (fileData == null) {// 默认值不显示
        return null;
    }

    return findDrawable(option, fileData.getPath());
}
 
Example 25
Source Project: cocos-ui-libgdx   Source File: CCPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {
    Table table = new Table();

    Size size = widget.getSize();
    if (widget.getComboBoxIndex() == 0) { // 无颜色

    } else if (widget.getComboBoxIndex() == 1 && widget.getBackColorAlpha() != 0) {// 单色
        Pixmap pixmap = new Pixmap((int) size.getX(), (int) size.getY(),
            Format.RGBA8888);

        pixmap.setColor(editor.getColor(widget.getSingleColor(),
            widget.getBackColorAlpha()));

        pixmap.fill();

        Drawable d = new TextureRegionDrawable(new TextureRegion(
            new Texture(pixmap)));
        table.setBackground(d);
        pixmap.dispose();
    }

    if (widget.getFileData() != null) {// Panel的图片并不是拉伸平铺的!!.但是这里修改为填充
        Drawable tr = editor.findDrawable(widget, widget.getFileData());
        if (tr != null) {
            Image bg = new Image(tr);
            bg.setPosition((size.getX() - bg.getWidth()) / 2,
                (size.getY() - bg.getHeight()) / 2);
            // bg.setFillParent(true);
            bg.setTouchable(Touchable.disabled);

            table.addActor(bg);
        }
    }

    table.setClip(widget.isClipAble());

    return table;
}
 
Example 26
Source Project: cocos-ui-libgdx   Source File: CCSpriteView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {

    Drawable tr = editor.findDrawable(widget, widget.getFileData());
    if (tr == null) {
        return new Image();
    }
    Image image = new Image(tr);

    return image;
}
 
Example 27
Source Project: cocos-ui-libgdx   Source File: CCImageView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {

    Drawable tr = editor.findDrawable(widget, widget.getFileData());
    if (tr == null) {
        return new Image();
    }
    return new Image(tr);
}
 
Example 28
Source Project: cocos-ui-libgdx   Source File: TCheckBox.java    License: Apache License 2.0 5 votes vote down vote up
public void draw(Batch batch, float parentAlpha) {
    if (bg != null){
        bg.draw(batch, parentAlpha);
    }

    Drawable checkbox = null;
    if (isDisabled()) {
        if (bg != null){
            bg.setDrawable(style.disableBack);
        }

        if (isChecked()) {
            checkbox = style.nodeDissable;
        } else {
            checkbox = null;
        }
    } else {
        if (isChecked() && style.checkboxOn != null) {
            checkbox = style.checkboxOn;
        } else if (isOver() && style.checkboxOver != null && !isDisabled()) {
            checkbox = style.checkboxOver;
        } else {
            checkbox = style.checkboxOff;
        }
    }

    /*if (checkbox == null) {
        if (isChecked() && style.checkboxOn != null)
            checkbox = style.checkboxOn;
        else if (isOver() && style.checkboxOver != null && !isDisabled())
            checkbox = style.checkboxOver;
        else
            checkbox = style.checkboxOff;
    }*/

    image.setDrawable(checkbox);
    super.draw(batch, parentAlpha);
}
 
Example 29
Source Project: cocos-ui-libgdx   Source File: ProgressBar.java    License: Apache License 2.0 5 votes vote down vote up
boolean calculatePositionAndValue(float x, float y) {
    final Drawable bg = style.background;

    float value;
    float oldPosition = progressPos;

    if (vertical) {
        float height = getHeight() - bg.getTopHeight() - bg.getBottomHeight();
        progressPos = y - bg.getBottomHeight();
        value = min + (max - min) * (progressPos / height);
        progressPos = Math.max(0, progressPos);
        progressPos = Math.min(height, progressPos);
    } else {
        float width = getWidth() - bg.getLeftWidth() - bg.getRightWidth();
        progressPos = x - bg.getLeftWidth();
        value = min + (max - min) * (progressPos / width);
        progressPos = Math.max(0, progressPos);
        progressPos = Math.min(width, progressPos);
    }

    float oldValue = value;
    boolean valueSet = setValue(value);
    if (value == oldValue) {
        progressPos = oldPosition;
    }
    return valueSet;
}
 
Example 30
Source Project: cocos-ui-libgdx   Source File: ProgressBar.java    License: Apache License 2.0 5 votes vote down vote up
public float getPrefHeight() {
    if (vertical) {
        return 140;
    } else {
        final Drawable bg = style.background;
        return Math.max(0, bg.getMinHeight());
    }
}