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

The following examples show how to use com.badlogic.gdx.scenes.scene2d.utils.Drawable. 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 File: CCTImageView.java    From cocos-ui-libgdx with 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 #2
Source File: Label.java    From riiablo with 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 #3
Source File: MainListener.java    From skin-composer with 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 #4
Source File: CellRenderer.java    From bladecoder-adventure-engine with 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 #5
Source File: TabPane.java    From dice-heroes with 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 #6
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with 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 #7
Source File: Skin.java    From gdx-skineditor with 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 #8
Source File: VisImageButton.java    From vis-ui with 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 #9
Source File: TestGenerateDisabledImage.java    From vis-ui with 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 #10
Source File: TabPane.java    From dice-heroes with 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 #11
Source File: EscapePanel.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawBackground(Batch batch, float a, float x, float y) {
  Drawable background = getBackground();
  background.draw(batch,
      x + (getWidth() / 2) - (background.getMinWidth() / 2),
      getY(),
      background.getMinWidth(),
      background.getMinHeight());
}
 
Example #12
Source File: TabPane.java    From dice-heroes with 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 #13
Source File: VisTextField.java    From vis-ui with 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 #14
Source File: VisTextArea.java    From vis-ui with 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 #15
Source File: LinkLabel.java    From vis-ui with 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 #16
Source File: DefaultSceneScreen.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
private Drawable getDrawable(String name) {
	if (name == null)
		return null;

	try {
		return getUI().getSkin().getDrawable(name);
	} catch (GdxRuntimeException e) {
		return null;
	}
}
 
Example #17
Source File: BackgroundButton.java    From talos with 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 #18
Source File: TabPane.java    From dice-heroes with 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 #19
Source File: VisSplitPane.java    From vis-ui with 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 File: Scene2dUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/** Checks if the text could fit the current textField's width. */
public static boolean isTextFitTextField(VisTextField textField, String text) {
    float availableWidth = textField.getWidth();
    Drawable fieldBg = textField.getStyle().background;
    if (fieldBg != null) {
        availableWidth = availableWidth - fieldBg.getLeftWidth() - fieldBg.getRightWidth();
    }
    BitmapFont font = textField.getStyle().font;
    return isTextFitWidth(font, availableWidth, text);
}
 
Example #21
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with 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 #22
Source File: CCPanel.java    From cocos-ui-libgdx with 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 #23
Source File: CCSpriteView.java    From cocos-ui-libgdx with 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 #24
Source File: CCImageView.java    From cocos-ui-libgdx with 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 #25
Source File: PatchGrid.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public PatchLine(Drawable drawable, Color primaryColor) {
    this.drawable = drawable;
    this.primaryColor = primaryColor;
    setTouchable(Touchable.disabled);

    updateVisualState();
}
 
Example #26
Source File: TCheckBox.java    From cocos-ui-libgdx with 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 #27
Source File: PackDialogController.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void onProcessingFinished() {
    btnClose.setDisabled(false);
    btnClose.setColor(Color.WHITE);

    FocusManager.switchFocus(stage, btnClose);

    window.closeOnEscape();

    if (!errors && cbAutoClose.isChecked()) {
        window.hide();
        showReopenLastDialogNotification();
    }

    // If there is only one pack, show log on error
    if (errors && adapter.size() == 1) {
        adapter.getView(adapter.get(0)).showLogWindow();
    }

    // Indicate total result by changing progress bar color
    {
        ProgressBar.ProgressBarStyle style = new ProgressBar.ProgressBarStyle(progressBar.getStyle());
        Drawable fill = errors ?
                VisUI.getSkin().getDrawable("progressBarErr") :
                VisUI.getSkin().getDrawable("progressBarSucc");
        style.knob = fill;
        style.knobBefore = fill;
        progressBar.setStyle(style);
    }
}
 
Example #28
Source File: HighResFileChooserIconProvider.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
protected Drawable getAudioIcon (FileChooser.FileItem item) {
	Drawable icon = getIcon(iconFileAudio, chooser.getViewMode());
	if (icon == null)
		return super.getAudioIcon(item);
	return icon;
}
 
Example #29
Source File: ProgressBar.java    From cocos-ui-libgdx with 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 File: ProgressBar.java    From cocos-ui-libgdx with 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());
    }
}