Search in sources :

Example 26 with Array

use of com.badlogic.gdx.utils.Array in project commons-gdx by gemserk.

the class Gdx2dMeshBuilder method buildVertexAttributes.

private VertexAttribute[] buildVertexAttributes(boolean hasNormals, boolean hasColor, int numTexCoords) {
    Array<VertexAttribute> attribs = new Array<VertexAttribute>();
    attribs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
    if (hasNormals)
        attribs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
    if (hasColor)
        attribs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
    for (int i = 0; i < numTexCoords; i++) {
        attribs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i));
    }
    VertexAttribute[] array = new VertexAttribute[attribs.size];
    for (int i = 0; i < attribs.size; i++) array[i] = attribs.get(i);
    return array;
}
Also used : Array(com.badlogic.gdx.utils.Array) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute)

Example 27 with Array

use of com.badlogic.gdx.utils.Array in project nhglib by VoidZombie.

the class NhgModelLoader method getDependencies.

@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, P parameters) {
    final Array<AssetDescriptor> deps = new Array();
    ModelData data = loadModelData(file, parameters);
    if (data == null)
        return deps;
    ObjectMap.Entry<String, ModelData> item = new ObjectMap.Entry<String, ModelData>();
    item.key = fileName;
    item.value = data;
    synchronized (items) {
        items.add(item);
    }
    TextureLoader.TextureParameter textureParameter = (parameters != null) ? parameters.textureParameter : defaultParameters.textureParameter;
    for (final ModelMaterial modelMaterial : data.materials) {
        if (modelMaterial.textures != null) {
            for (final ModelTexture modelTexture : modelMaterial.textures) {
                String fName = modelTexture.fileName;
                if (fName.contains("/")) {
                    fName = fName.substring(fName.lastIndexOf("/") + 1);
                }
                deps.add(new AssetDescriptor(currentAsset.dependenciesPath + fName, Texture.class, textureParameter));
            }
        }
    }
    return deps;
}
Also used : ModelData(com.badlogic.gdx.graphics.g3d.model.data.ModelData) TextureLoader(com.badlogic.gdx.assets.loaders.TextureLoader) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) Texture(com.badlogic.gdx.graphics.Texture) ModelTexture(com.badlogic.gdx.graphics.g3d.model.data.ModelTexture) Array(com.badlogic.gdx.utils.Array) ObjectMap(com.badlogic.gdx.utils.ObjectMap) ModelMaterial(com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 28 with Array

use of com.badlogic.gdx.utils.Array in project libgdx by libgdx.

the class Preloader method list.

public FileHandle[] list(String url, String suffix) {
    Array<FileHandle> files = new Array<FileHandle>();
    for (String path : texts.keys()) {
        if (isChild(path, url) && path.endsWith(suffix)) {
            files.add(new GwtFileHandle(this, path, FileType.Internal));
        }
    }
    FileHandle[] list = new FileHandle[files.size];
    System.arraycopy(files.items, 0, list, 0, list.length);
    return list;
}
Also used : Array(com.badlogic.gdx.utils.Array) GwtFileHandle(com.badlogic.gdx.backends.gwt.GwtFileHandle) FileHandle(com.badlogic.gdx.files.FileHandle) GwtFileHandle(com.badlogic.gdx.backends.gwt.GwtFileHandle)

Example 29 with Array

use of com.badlogic.gdx.utils.Array in project Alkahest-Coffee by AlkahestDev.

the class GifDecoder method getAnimation.

public Animation getAnimation(Animation.PlayMode playType) {
    int nrFrames = getFrameCount();
    Pixmap frame = getFrame(0);
    int width = frame.getWidth();
    int height = frame.getHeight();
    int vzones = (int) Math.sqrt((double) nrFrames);
    int hzones = vzones;
    while (vzones * hzones < nrFrames) vzones++;
    int v, h;
    Pixmap target = new Pixmap(width * hzones, height * vzones, Pixmap.Format.RGBA8888);
    for (h = 0; h < hzones; h++) {
        for (v = 0; v < vzones; v++) {
            int frameID = v + h * vzones;
            if (frameID < nrFrames) {
                frame = getFrame(frameID);
                target.drawPixmap(frame, h * width, v * height);
            }
        }
    }
    Texture texture = new Texture(target);
    Array<TextureRegion> texReg = new Array<TextureRegion>();
    for (h = 0; h < hzones; h++) {
        for (v = 0; v < vzones; v++) {
            int frameID = v + h * vzones;
            if (frameID < nrFrames) {
                TextureRegion tr = new TextureRegion(texture, h * width, v * height, width, height);
                texReg.add(tr);
            }
        }
    }
    float frameDuration = (float) getDelay(0);
    // convert milliseconds into seconds
    frameDuration /= 1000;
    return new Animation<TextureRegion>(frameDuration, texReg, playType);
}
Also used : Array(com.badlogic.gdx.utils.Array) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Animation(com.badlogic.gdx.graphics.g2d.Animation) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 30 with Array

use of com.badlogic.gdx.utils.Array in project gdx-skineditor by cobolfoo.

the class PreviewPane method refresh.

/**
	 * 
	 */
public void refresh() {
    Gdx.app.log("PreviewPane", "Refresh pane!");
    clear();
    ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
    String widget = button.getUserObject().toString();
    String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
    try {
        Class<?> style = Class.forName(widgetStyle);
        ObjectMap<String, ?> styles = game.skinProject.getAll(style);
        if (styles == null) {
            Label label = new Label("No styles defined for this widget type", game.skin, "error");
            add(label).row().pad(10);
        } else {
            Keys<String> keys = styles.keys();
            Array<String> sortedKeys = new Array<String>();
            for (String key : keys) {
                sortedKeys.add(key);
            }
            sortedKeys.sort();
            for (String key : sortedKeys) {
                // We render one per key
                add(new Label(key, game.skin, "title")).left().pad(10).expandX().row();
                try {
                    if (widget.equals("Label")) {
                        Label w = new Label("This is a Label widget", game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("Button")) {
                        // Button
                        Button w = new Button(game.skinProject, key);
                        add(w).width(120).height(32).pad(10).padBottom(20).row();
                    } else if (widget.equals("TextButton")) {
                        // TextButton
                        TextButton w = new TextButton("This is a TextButton widget", game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("ImageButton")) {
                        // ImageButton
                        ImageButton w = new ImageButton(game.skinProject, key);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("CheckBox")) {
                        // CheckBox
                        CheckBox w = new CheckBox("This is a CheckBox widget", game.skinProject, key);
                        w.setChecked(true);
                        add(w).pad(10).padBottom(20).row();
                    } else if (widget.equals("TextField")) {
                        // TextField
                        TextField w = new TextField("This is a TextField widget", game.skinProject, key);
                        if (w.getStyle().fontColor == null) {
                            throw new Exception("Textfield style requires a font color!");
                        }
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(220).padBottom(20).row();
                    } else if (widget.equals("List")) {
                        // List
                        List w = new List(game.skinProject, key);
                        Array<String> items = new Array<String>();
                        items.add("This is");
                        items.add("a");
                        items.add("List widget!");
                        w.setItems(items);
                        add(w).pad(10).width(220).height(120).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("SelectBox")) {
                        // SelectBox
                        SelectBox<String> w = new SelectBox<String>(game.skinProject, key);
                        Array<String> items = new Array<String>();
                        items.add("This is");
                        items.add("a");
                        items.add("SelectBox widget!");
                        w.setItems(items);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("ProgressBar")) {
                        // ProgressBar
                        ProgressBarStyle progressStyle = game.skinProject.get(key, ProgressBarStyle.class);
                        // Check for edge-case: fields knob and knobBefore are optional but at least one should be specified
                        if (progressStyle.knob == null && progressStyle.knobBefore == null) {
                            throw new IllegalArgumentException("Fields 'knob' and 'knobBefore' in ProgressBarStyle are both optional but at least one should be specified");
                        }
                        ProgressBar w = new ProgressBar(0, 100, 5, false, progressStyle);
                        w.setValue(50);
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Slider")) {
                        // Slider
                        Slider w = new Slider(0, 100, 5, false, game.skinProject, key);
                        add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
                        w.addListener(stopTouchDown);
                        Slider w2 = new Slider(0, 100, 5, true, game.skinProject, key);
                        add(w2).pad(10).padBottom(20).expandX().fillX().row();
                        w2.addListener(stopTouchDown);
                    } else if (widget.equals("ScrollPane")) {
                        // ScrollPane
                        Table t = new Table(game.skin);
                        for (int i = 0; i < 20; i++) {
                            t.add("This is a ScrollPane Widget").padRight(10);
                            t.add("This is a ScrollPane Widget").padRight(10);
                            t.add("This is a ScrollPane Widget").row();
                        }
                        ScrollPane w = new ScrollPane(t, game.skinProject, key);
                        w.addListener(stopTouchDown);
                        w.setFlickScroll(true);
                        w.setScrollbarsOnTop(true);
                        w.setScrollBarPositions(true, true);
                        w.setFadeScrollBars(false);
                        add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("SplitPane")) {
                        for (int j = 0; j < 2; j++) {
                            Table t = new Table(game.skin);
                            t.setBackground(game.skin.getDrawable("default-rect"));
                            Table t2 = new Table(game.skin);
                            t2.setBackground(game.skin.getDrawable("default-rect"));
                            for (int i = 0; i < 20; i++) {
                                t.add("This is a SplitPane Widget").pad(10).row();
                                t2.add("This is a SplitPane Widget").pad(10).row();
                            }
                            SplitPane w = new SplitPane(t, t2, (j % 2 == 0), game.skinProject, key);
                            w.addListener(stopTouchDown);
                            add(w).pad(10).width(220).height(160).padBottom(20).expandX().fillX();
                        }
                        row();
                    } else if (widget.equals("Window")) {
                        // Window
                        Table t = new Table(game.skin);
                        for (int i = 0; i < 5; i++) {
                            t.add("This is a Window Widget").row();
                        }
                        Window w = new Window("This is a Window Widget", game.skinProject, key);
                        w.addListener(stopTouchDown);
                        w.add(t);
                        add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Touchpad")) {
                        // Touchpad
                        Touchpad w = new Touchpad(0, game.skinProject, key);
                        w.addListener(stopTouchDown);
                        add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
                    } else if (widget.equals("Tree")) {
                        // Tree
                        Tree w = new Tree(game.skinProject, key);
                        Tree.Node node = new Tree.Node(new Label("This", game.skin));
                        Tree.Node node1 = new Tree.Node(new Label("is", game.skin));
                        Tree.Node node2 = new Tree.Node(new Label("a", game.skin));
                        Tree.Node node3 = new Tree.Node(new Label("Tree", game.skin));
                        Tree.Node node4 = new Tree.Node(new Label("Widget", game.skin));
                        node3.add(node4);
                        node2.add(node3);
                        node1.add(node2);
                        node.add(node1);
                        w.add(node);
                        w.expandAll();
                        add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
                    } else {
                        add(new Label("Unknown widget type!", game.skin, "error")).pad(10).padBottom(20).row();
                    }
                } catch (Exception e) {
                    add(new Label("Please fill all required fields", game.skin, "error")).pad(10).padBottom(20).row();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Node(com.badlogic.gdx.graphics.g3d.model.Node) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) ProgressBarStyle(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar.ProgressBarStyle) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Tree(com.badlogic.gdx.scenes.scene2d.ui.Tree) List(com.badlogic.gdx.scenes.scene2d.ui.List) ProgressBar(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) Array(com.badlogic.gdx.utils.Array) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)

Aggregations

Array (com.badlogic.gdx.utils.Array)67 FileHandle (com.badlogic.gdx.files.FileHandle)18 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)16 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)9 Texture (com.badlogic.gdx.graphics.Texture)8 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 IntArray (com.badlogic.gdx.utils.IntArray)7 Element (com.badlogic.gdx.utils.XmlReader.Element)7 IOException (java.io.IOException)7 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)5 JsonValue (com.badlogic.gdx.utils.JsonValue)5 ObjectMap (com.badlogic.gdx.utils.ObjectMap)5 Color (com.badlogic.gdx.graphics.Color)4 ModelMaterial (com.badlogic.gdx.graphics.g3d.model.data.ModelMaterial)4 Page (com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)4 Rect (com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect)4 Json (com.badlogic.gdx.utils.Json)4 TextureParameter (com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter)3 GwtFileHandle (com.badlogic.gdx.backends.gwt.GwtFileHandle)3