X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=sixth-3d-demos.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fexamples%2Flife%2FCell.java;fp=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fexamples%2Flife%2FCell.java;h=0000000000000000000000000000000000000000;hp=fb78e4b2993c09286205a85ea6d228f5ec3eb487;hb=08719db537fae3645ca86f9ee6f8deba4dadf4f4;hpb=f0ebc20d0438fc46be1d98fb3643bd4196cb64c9 diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Cell.java b/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Cell.java deleted file mode 100755 index fb78e4b..0000000 --- a/src/main/java/eu/svjatoslav/sixth/e3d/examples/life/Cell.java +++ /dev/null @@ -1,131 +0,0 @@ -package eu.svjatoslav.sixth.e3d.examples.life; - -import eu.svjatoslav.sixth.e3d.geometry.Point3D; -import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController; -import eu.svjatoslav.sixth.e3d.renderer.raster.Color; -import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.SolidPolygon; -import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape; - -/** - * This class corresponds to a single cell within matrix. - */ -class Cell extends AbstractCompositeShape implements - MouseInteractionController { - - /** - * cell visual size - */ - static final int SIZE = 20; - /** - * Color of the active cell (R, G, B, A) - */ - private static final Color ACTIVE_COLOR = new Color("A8FF"); - /** - * Color of the active cell (R, G, B, A) while mouse is over it. - */ - private static final Color ACTIVE_COLOR_MOUSE_OVER = new Color("F9FF"); - /** - * Color of the inactive cell (R, G, B, A) - */ - private static final Color INACTIVE_COLOR = new Color("55F8"); - /** - * Color of the inactive cell (R, G, B, A) while mouse is over it. - */ - private static final Color INACTIVE_COLOR_MOUSE_OVER = new Color("77F8"); - /** - * A placeholder variable to help in next generation computation. Indicates - * whether cell is going to survive within next generation. - */ - public boolean survives; - /** - * Indicates whether cell is currently active - */ - private boolean active; - /** - * Indicates whether mouse pointer is currently over this cell. - */ - private boolean isMouseOver = false; - - public Cell(final Point3D center) { - super(center); - - createCellShape(); - - // enable receiving of mouse events - setMouseInteractionController(this); - } - - private void createCellShape() { - final double halfSize = SIZE / 2f; - - // define 4 points corresponding to cell borders - final Point3D p1 = new Point3D(-halfSize, 0, -halfSize); - - final Point3D p2 = new Point3D(+halfSize, 0, -halfSize); - - final Point3D p3 = new Point3D(+halfSize, 0, +halfSize); - - final Point3D p4 = new Point3D(-halfSize, 0, +halfSize); - - // connect 4 points with 2 polygons - addShape(new SolidPolygon(p1, p2, p3, computeCellColor())); - addShape(new SolidPolygon(p1, p4, p3, computeCellColor())); - } - - /** - * Compute cell color depending if cell is active and if mouse is over the - * cell. - */ - private Color computeCellColor() { - if (active) - if (isMouseOver) - return ACTIVE_COLOR_MOUSE_OVER; - else - return ACTIVE_COLOR; - else if (isMouseOver) - return INACTIVE_COLOR_MOUSE_OVER; - else - return INACTIVE_COLOR; - } - - public boolean isActive() { - return active; - } - - public void setActive(final boolean active) { - this.active = active; - updateColor(); - } - - @Override - public boolean mouseClicked() { - setActive(!isActive()); - return true; - } - - @Override - public boolean mouseEntered() { - setMouseOver(true); - return true; - } - - @Override - public boolean mouseExited() { - setMouseOver(false); - return true; - } - - private void setMouseOver(final boolean isMouseOver) { - this.isMouseOver = isMouseOver; - updateColor(); - } - - /** - * This method is called when cell status is changed to update its color - * too. - */ - private void updateColor() { - setColor(computeCellColor()); - } - -}