Android Open Source - wannabe Simple Grid






From Project

Back to project page wannabe.

License

The source code is released under:

MIT License

If you think the Android project wannabe listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

// Copyright 2013 Patrick Forhan.
package wannabe.grid;
//  w w  w.java 2 s . c  om
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import wannabe.Position;
import wannabe.Voxel;

public class SimpleGrid implements Grid {
  private static final Comparator<Voxel> zIncreasing = new Comparator<Voxel>() {
    @Override public int compare(Voxel o1, Voxel o2) {
      return o1.position.z - o2.position.z;
    }
  };

  private final List<Voxel> voxels = new ArrayList<Voxel>();
  private final String name;
  private SimpleGrid subGrid;


  public SimpleGrid(String name) {
    this.name = name;
  }

  @Override public Iterator<Voxel> iterator() {
    return voxels.iterator();
  }

  @Override public Grid subGrid(int x, int y, int width, int height) {
    if (subGrid == null) subGrid = new SimpleGrid("sub of " + name);
    subGrid.voxels.clear();

    for (Voxel vox : voxels) {
      Position pos = vox.position;
      if (pos.x >= x && pos.x < x + width //
          && pos.y >= y && pos.y < y + height) {
        subGrid.voxels.add(vox);
      }
    }
    return subGrid;
  }

  /** Sorts the voxels by z order, from lowest to highest. */
  public void sortByPainters() {
    Collections.sort(voxels, zIncreasing);
  }

  @Override public boolean add(Voxel v) {
    return voxels.add(v);
  }

  @Override public boolean remove(Voxel v) {
    return voxels.remove(v);
  }

  @Override public int size() {
    return voxels.size();
  }

  @Override public Grid unmodifyableGrid() {
    // TODO implement me!
    return null;
  }

  @Override public String toString() {
    return name;
  }
}




Java Source Code List

android.util.ArrayUtils.java
android.util.SparseArray.java
android.util.SparseIntArray.java
wannabe.Camera.java
wannabe.Position.java
wannabe.Rendered.java
wannabe.UI.java
wannabe.Voxel.java
wannabe.android.MainActivity.java
wannabe.grid.FixedGrid.java
wannabe.grid.Grid.java
wannabe.grid.SimpleGrid.java
wannabe.projection.Flat.java
wannabe.projection.Isometric.java
wannabe.projection.Projection.java
wannabe.projection.Projections.java
wannabe.projection.PseudoPerspective.java
wannabe.swing.SettingsPanel.java
wannabe.swing.SwingWannabe.java
wannabe.swing.WannabePanel.java
wannabe.util.SampleGrids.java
wannabe.util.UIs.java