Improved code readability. Components now aware of what mouse button was clicked.
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / basic / texturedpolygon / TexturedPolygon.java
index 8d6ef26..7a6f2bf 100644 (file)
@@ -1,17 +1,11 @@
 /*
- * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
+ * Sixth 3D engine. Author: Svjatoslav Agejenko. 
+ * This project is released under Creative Commons Zero (CC0) license.
  */
-
 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon;
 
 import eu.svjatoslav.sixth.e3d.geometry.Point2D;
 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Polygon;
 import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractCoordinateShape;
 import eu.svjatoslav.sixth.e3d.renderer.raster.slicer.PolygonCoordinate;
@@ -20,6 +14,8 @@ import eu.svjatoslav.sixth.e3d.renderer.raster.texture.TextureBitmap;
 
 import java.awt.*;
 
+import static eu.svjatoslav.sixth.e3d.geometry.Polygon.pointWithinPolygon;
+
 public class TexturedPolygon extends AbstractCoordinateShape {
 
     public final Texture texture;
@@ -30,7 +26,12 @@ public class TexturedPolygon extends AbstractCoordinateShape {
      * Polygon texture coordinates.
      */
     public Point2D texturePoint1, texturePoint2, texturePoint3;
-    private boolean showBorders = false;
+
+    /**
+     * If <code>true</code> then polygon borders will be drawn.
+     * It is used for debugging purposes.
+     */
+    public boolean showBorders = false;
     private double totalTextureDistance = -1;
 
     public TexturedPolygon(final Point3D p1, final Point3D p2,
@@ -105,7 +106,7 @@ public class TexturedPolygon extends AbstractCoordinateShape {
             x2 = renderBuffer.width - 1;
 
         int renderBufferOffset = ((y * renderBuffer.width) + x1) * 4;
-        final byte[] renderBufferBytes = renderBuffer.bytes;
+        final byte[] renderBufferBytes = renderBuffer.pixels;
 
         final double twidth = tx2 - tx1;
         final double theight = ty2 - ty1;
@@ -140,11 +141,11 @@ public class TexturedPolygon extends AbstractCoordinateShape {
         projectedPoint3.roundToInteger();
 
         if (mouseInteractionController != null)
-            if (renderBuffer.mouseClick != null)
-                if (Polygon.pointWithinPolygon(
-                        renderBuffer.mouseClick.coordinate, projectedPoint1,
+            if (renderBuffer.getMouseEvent() != null)
+                if (pointWithinPolygon(
+                        renderBuffer.getMouseEvent().coordinate, projectedPoint1,
                         projectedPoint2, projectedPoint3))
-                    renderBuffer.clickedItem = mouseInteractionController;
+                    renderBuffer.setCurrentObjectUnderMouseCursor(mouseInteractionController);
 
         // Show polygon boundaries (for debugging)
         if (showBorders)