public void _init(Drawable[] textures, int depth, Vector2[] bias) { if (bias != null && bias.length != textures.length) throw new IllegalArgumentException(); group = new Group(); images = new Image[textures.length]; for (int i=0; i<textures.length; i++) { Drawable texture = textures[i]; Image image = new Image(texture); images[i] = image; image.setBounds(0, 0, texture.getMinWidth(), texture.getMinHeight()); if (bias != null) image.setPosition(bias[i].x, bias[i].y, Align.center); else image.setPosition(0, 0, Align.center); group.addActor(image); } mDepth = depth; biases = bias; }
@Override protected void drawStageBackground(Batch batch, float parentAlpha, float x, float y, float width, float height) { Drawable background = getStyle().stageBackground; float drawableWidth = background.getMinWidth(); float drawableHeight = background.getMinHeight(); if (drawableWidth < width || drawableHeight < height) { Vector2 tempVector = MathUtil.getVector2(); Stage stage = getStage(); x = stage.getWidth()/2 - drawableWidth/2; y = stage.getHeight()/2 - drawableHeight/2; //stageToLocalCoordinates(tempVector.set(x, y)); //x = tempVector.x; //y = tempVector.y; MathUtil.freeVector2(tempVector); width = background.getMinWidth(); height = background.getMinHeight(); } super.drawStageBackground(batch, parentAlpha, x, y, width, height); }
@Override public void fillRoundedRect(float x, float y, float w, float h, int cornerRadius) { Drawable drawable = getRoundedRectDrawable(cornerRadius); Color originalColor = null; ensureSpriteBatchOpen(); if (brushType == BrushType.COLOR) { originalColor = spriteBatch.getColor(); Color color = getAlphaMultiplied(colorBrush); spriteBatch.setColor(color); freeColor(color); } drawable.draw(spriteBatch, x, viewportSize.y - y - h, w, h); if (originalColor != null) { spriteBatch.setColor(originalColor); } }
private Drawable getRoundedRectDrawable(int radius) { switch (radius) { case 1: case 2: return getDefaultToolkit().getSkin().getDrawable("rounded_rect_2"); case 3: return getDefaultToolkit().getSkin().getDrawable("rounded_rect_3"); case 4: return getDefaultToolkit().getSkin().getDrawable("rounded_rect_4"); case 5: return getDefaultToolkit().getSkin().getDrawable("rounded_rect_5"); case 6: return getDefaultToolkit().getSkin().getDrawable("rounded_rect_6"); default: return getDefaultToolkit().getSkin().getDrawable("rounded_rect_2"); } }
@Override public void stylePropertyChanged(StyleProperty styleProperty, Actor styleActor) { if (styleProperty.type == Drawable.class) { dialogFactory.showDialogDrawables(styleProperty); } else if (styleProperty.type == Color.class) { dialogFactory.showDialogColors(styleProperty); } else if (styleProperty.type == BitmapFont.class) { dialogFactory.showDialogFonts(styleProperty); } 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); } }
public void setValue(int value) { if (value < 0 || value > 10) { throw new RuntimeException("value must between 0-10! it was:" + Integer.toString(value)); } Skin skin = VisUI.getSkin(); Drawable star1 = value >= 2 ? skin.getDrawable("star") : value >= 1 ? skin.getDrawable("star_half") : skin.getDrawable("star0"); Drawable star2 = value >= 4 ? skin.getDrawable("star") : value >= 3 ? skin.getDrawable("star_half") : skin.getDrawable("star0"); Drawable star3 = value >= 6 ? skin.getDrawable("star") : value >= 5 ? skin.getDrawable("star_half") : skin.getDrawable("star0"); Drawable star4 = value >= 8 ? skin.getDrawable("star") : value >= 7 ? skin.getDrawable("star_half") : skin.getDrawable("star0"); Drawable star5 = value == 10 ? skin.getDrawable("star") : value >= 9 ? skin.getDrawable("star_half") : skin.getDrawable("star0"); setImage(image1, star1); setImage(image2, star2); setImage(image3, star3); setImage(image4, star4); setImage(image5, star5); this.invalidateHierarchy(); }
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); }
private Drawable getFontIcon(FileChooser.FileItem item) { FileHandle fileHandle = item.getFile(); BitmapFont bitmapFont; try { FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fileHandle); FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter(); parameter.size = CB.getScaledInt(50); parameter.characters = SkinFont.DEFAULT_CHARACTER; parameter.genMipMaps = true; parameter.minFilter = Texture.TextureFilter.MipMapNearestNearest; bitmapFont = generator.generateFont(parameter); } catch (Exception e) { return getImageIcon(item); } Drawable drawable = new BitmapFontDrawable(bitmapFont, item.getFile().nameWithoutExtension()); return drawable; }
public ReloadCacheActivity() { super("CheckStateActivity"); bCancel = new CharSequenceButton(Translation.get("cancel")); gsLogo = new Image(CB.getSkin().getIcon.GC_Live); lblTitle = new VisLabel(Translation.get("ReloadCacheAPI")); Label.LabelStyle style = new Label.LabelStyle(lblTitle.getStyle()); style.fontColor.set(Color.WHITE); lblTitle.setStyle(style); Drawable animationDrawable = VisUI.getSkin().getDrawable("download-animation"); workAnimation = new Image(animationDrawable); progressBar = new VisProgressBar(0, 100, 1, false, "default"); createOkCancelBtn(); setWorkAnimationVisible(false); this.setStageBackground(new ColorDrawable(VisUI.getSkin().getColor("dialog_background"))); // this.setDebug(true, true); }
@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; }
private static void parseButton(Button button, XmlReader.Element element){ String upPath = element.get("up"); String downPath = element.get("down"); String checkPath = element.get("check"); Drawable up = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal(upPath)))); Drawable down = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal(downPath)))); Drawable checked = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal(checkPath)))); Button.ButtonStyle buttonStyle = new Button.ButtonStyle(up,down,checked); button.setStyle(buttonStyle); }
public static void parseButton(VisImageButton button, XmlReader.Element element){ String upPath = element.get("up"); String downPath = element.get("down"); String checkPath = element.get("check"); Drawable up = new TextureRegionDrawable(new TextureRegion(new Texture(Config.getImageFilePath(upPath)))); Drawable down = new TextureRegionDrawable(new TextureRegion(new Texture(Config.getImageFilePath(downPath)))); Drawable checked = new TextureRegionDrawable(new TextureRegion(new Texture(Config.getImageFilePath(checkPath)))); VisImageButton.VisImageButtonStyle buttonStyle = new VisImageButton.VisImageButtonStyle( up,down,checked,up,down,checked ); button.setStyle(buttonStyle); attr2Button(button, new String[]{upPath, downPath, checkPath}); }
@Override public void Initialize(Entity entity) { super.Initialize(entity); animationDrawable.setAnimation(animationStay); existTime = 0; entity.AddComponent(mRenderer = new ImageGroupRenderer(new Drawable[] { animationDrawable, playerAnimation }, 0, null)); mReimuWing1 = new ReimuWing(new Vector2(transform.position.x, transform.position.y + 20), 4f, mType); mReimuWing2 = new ReimuWing(new Vector2(transform.position.x, transform.position.y), -4f, mType); }
public LogMenu() { label = new Label("", new LabelStyle(Fonts.smallHUD, Color.BLACK)); label.setWrap(true); Drawable background = new TextureRegionDrawable(Assets.getTextureRegion("core:hud/LogBackground.png")); scrollPane = new ScrollPane(label, new ScrollPaneStyle(background, null, null, null, null)); scrollPane.setScrollingDisabled(true, false); back = MenuTools.getBackButton(this); stage.addActor(scrollPane); stage.addActor(back); refresh(); }
/** @param drawable May be null. */ public BouncingImage (Drawable drawable, Scaling scaling, int align) { setDrawable(drawable); this.scaling = scaling; this.align = align; setSize(getPrefWidth(), getPrefHeight()); addBounce(); }
/** @param drawable May be null. */ public void setDrawable (Drawable drawable) { if (this.drawable == drawable) return; if (drawable != null) { if (getPrefWidth() != drawable.getMinWidth() || getPrefHeight() != drawable.getMinHeight()) invalidateHierarchy(); } else invalidateHierarchy(); this.drawable = drawable; }
private Drawable createDrawable(int width, int height, Color color) { Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888); pixmap.setColor(color); pixmap.fillRectangle(0, 0, width, height); Texture texture = new Texture(pixmap); return new TextureRegionDrawable(new TextureRegion(texture)); }
private Skin createSkin() { Skin returnValue = new Skin(); returnValue.add("bg", createDrawable(20, 20, Color.DARK_GRAY), Drawable.class); returnValue.add("progress-bar-back", createDrawable(20, 20, Color.BLACK), Drawable.class); returnValue.add("progress-bar", createDrawable(1, 20, Color.BLUE), Drawable.class); ProgressBarStyle progressBarStyle = new ProgressBarStyle(); progressBarStyle.background = returnValue.getDrawable("progress-bar-back"); progressBarStyle.knobBefore = returnValue.getDrawable("progress-bar"); returnValue.add("default-horizontal", progressBarStyle); return returnValue; }
private Drawable getNationDrawable(Nation nation) { switch(nation) { case AIR: return airTexture; case EARTH: return earthTexture; case FIRE: return fireTexture; case WATER: return waterTexture; } return null; }
@Override public void reset(){ this.setVisible(false); this.setRotation(0); this.setScale(1f, 1f); this.getColor().set(1f, 1f, 1f, 1f); this.setTransform(false); this.msgEnCola = false; this.clearActions(); tbText.setSkin(null); TextureRegion r = null; tbText.setBackground((Drawable)r); }
@Override public Drawable getIcon() { boolean hasSpoiler = CB.selectedCachehasSpoiler(); if (hasSpoiler) { return CB.getSkin().getMenuIcon.imagesIcon; } return CB.getSkin().getMenuIcon.imagesIconOff; }
@Override protected void drawSelf(KrRenderer renderer) { Drawable background = getBackgroundForState(state); renderer.setBrush(background); renderer.setOpacity(getOpacity()); renderer.fillRect(0, 0, getWidth(), getHeight()); Vector2 contentSize = getContentSize(tmpVec); Vector2 textPosition = KrAlignmentTool.alignRectangles(0, 0, contentSize.x, contentSize.y, 0, 0, getWidth(), getHeight(), getTextAlignment()); Vector2 textOffset = state == State.ARMED ? Vector2.Y : Vector2.Zero; textPosition.add(textOffset); // render icon if (hasIcon()) { getStyle().icon.draw(renderer, (int) textPosition.x, (int) textPosition.y); textPosition.x += ICON_TEXT_PADDING + getStyle().icon.getSize().x; } // render text if (hasText()) { textPosition.y += (contentSize.y - text.getBounds().height) / 2; renderer.setPen(1, getStyle().foregroundColor); renderer.setFont(getStyle().font); renderer.drawTextWithShadow(text.getString(), textPosition, getStyle().textShadowOffset, getStyle().textShadowColor); } Pools.free(textPosition); }
private Drawable getBackgroundForState(State state) { KrButtonStyle buttonStyle = ((KrButtonStyle) getStyle()); switch (state) { case NORMAL: return buttonStyle.backgroundNormal; case HOVERED: return buttonStyle.backgroundNormal; case ARMED: return buttonStyle.backgroundArmed; } throw new IllegalArgumentException("State not supported: " + state); }
/** 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); }
public static KrScrollBarStyle createScrollBarStyle() { KrScrollBarStyle style = new KrScrollBarStyle(createWidgetStyle()); style.size = 5; style.thumb = mock(Drawable.class); style.track = mock(Drawable.class); return style; }
private void updateStyleValuesForRename(String oldName, String newName) { Values<Array<StyleData>> values = main.getJsonData().getClassStyleMap().values(); for (Array<StyleData> styles : values) { for (StyleData style : styles) { for (StyleProperty styleProperty : style.properties.values()) { if (Drawable.class.isAssignableFrom(styleProperty.type)) { if (styleProperty.value != null && styleProperty.value.equals(oldName)) { styleProperty.value = newName; } } } } } }
public BooleanPropertyListView(int listIndex, final BooleanProperty property, Drawable icon, final CharSequence name) { super(listIndex); this.property = property; //Left icon final Image iconImage = new Image(icon, Scaling.none); this.add(iconImage).center().padRight(CB.scaledSizes.MARGIN_HALF); //Center name text final Label label = new VisLabel(name); label.setWrap(true); this.add(label).expandX().fillX().padTop(CB.scaledSizes.MARGIN).padBottom(CB.scaledSizes.MARGIN); //Right checkBox checkImage = new Image(style.CheckNo); this.add(checkImage).width(checkImage.getWidth()).pad(CB.scaledSizes.MARGIN / 2); this.setCheckImage(); this.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { property.set(!property.get()); } }); property.setChangeListener(new Property.PropertyChangedListener() { @Override public void propertyChanged() { log.debug("Property {} changed to {}", name, property.get()); //property changed, so set name to "?" filterSettings.filterProperties.setName("?"); setCheckImage(); } }); }
/** * Removes any duplicate drawables that share the same file name. This * ignores the file extension and also deletes TintedDrawables from the * same file. * @param handle */ private void removeDuplicateDrawables(FileHandle handle) { boolean refreshDrawables = false; String name = DrawableData.proper(handle.name()); for (int i = 0; i < main.getAtlasData().getDrawables().size; i++) { DrawableData data = main.getAtlasData().getDrawables().get(i); if (name.equals(DrawableData.proper(data.file.name()))) { main.getAtlasData().getDrawables().removeValue(data, true); for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) { for (StyleData tempData : datas) { for (StyleProperty prop : tempData.properties.values()) { if (prop != null && prop.type.equals(Drawable.class) && prop.value != null && prop.value.equals(data.toString())) { prop.value = null; } } } } refreshDrawables = true; i--; } } main.getRootTable().refreshStyleProperties(true); main.getRootTable().refreshPreview(); if (refreshDrawables) { gatherDrawables(); } }
@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; }
/** * * @param drawables the frames to be drawn * @param frameDuration the delay between frames in seconds. */ public AnimatedDrawable(Array<Drawable> drawables, float frameDuration) { if (drawables != null) { this.drawables = new Array<>(drawables); recalcSize(); } else { this.drawables = new Array<>(); } t = 0.0f; this.frameDuration = frameDuration; index = 0; }
private static void addButtonStyles(String styleName, String iconPath) { Drawable drawable = getDrawable(iconPath); skin.add(styleName, getImageTextButtonStyle(drawable)); skin.add(styleName, getImageButtonStyle(drawable)); }
private static Drawable getDrawable(String path) { Texture texture = new Texture(path); texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); return new SpriteDrawable(new Sprite(texture)); }
public QuickButtonItem(int listIndex, Drawable background, final AbstractAction action, CharSequence Desc, QuickActions type) { super(listIndex); this.background = background; quickActionsEnum = type; mAction = action; mActionDesc = Desc; try { spriteDrawable = action.getIcon(); } catch (Exception e) { throw new IllegalStateException(action.getName() + " Action has no Icon"); } mButtonIcon = new Image(spriteDrawable, Scaling.none, Align.center); this.addActor(mButtonIcon); if (action instanceof Action_Show_Hint) { EventHandler.add(new SelectedCacheChangedListener() { @Override public void selectedCacheChanged(SelectedCacheChangedEvent event) { spriteDrawable = action.getIcon(); mButtonIcon.setDrawable(spriteDrawable); needsLayout = true; QuickButtonItem.this.invalidate(); } }); } }
public BeepingImageButton( Drawable imageUp, Drawable imageDown, Drawable imageChecked) { super(imageUp, imageDown, imageChecked); init(); }
public float getPrefHeight() { ProgressBarStyle style = this.getStyle(); boolean disabled = this.isDisabled(); boolean vertical = this.isVertical(); 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 : getKnobMinHeight(knob), bg == null ? 0 : getKnobMinHeight(bg)); } }
@Override public Drawable provideIcon(FileChooser.FileItem item) { if (item.isDirectory()) return getDirIcon(item); String ext = item.getFile().extension().toLowerCase(); if (ext.equals("svg")) return getSvgImageIcon(item); return super.provideIcon(item); }
public float getPrefWidth() { ProgressBarStyle style = this.getStyle(); boolean disabled = this.isDisabled(); boolean vertical = this.isVertical(); if (vertical) { final Drawable knob = getKnobDrawable(); final Drawable bg = (disabled && style.disabledBackground != null) ? style.disabledBackground : style.background; return Math.max(knob == null ? 0 : getDrawableMinWidth(knob), getDrawableMinWidth(bg)); } else return 140; }
public CacheWidget(CacheTypes cacheType, CacheTypeStyle style, Drawable leftInfoIcon, Drawable rightInfoIcon) { this.typeIcon = cacheType.getDrawable(style); this.leftInfoIcon = leftInfoIcon; this.rightInfoIcon = rightInfoIcon; hasInfoIcon = leftInfoIcon != null || rightInfoIcon != null; }
public GestureHelp(CB_RectF ellipseRectangle, Drawable buttonDrawable, Drawable gestureRightIcon, Drawable gestureUpIcon, Drawable gestureLeftIcon, Drawable gestureDownIcon) { super(ellipseRectangle); this.gestureRightIcon = gestureRightIcon; this.gestureUpIcon = gestureUpIcon; this.gestureLeftIcon = gestureLeftIcon; this.gestureDownIcon = gestureDownIcon; this.buttonDrawable = buttonDrawable; this.style = VisUI.getSkin().get("default", GestureHelpStyle.class); super.setStyle(this.style); }