Forms
Class MyPolygon

java.lang.Object
  |
  +--Forms.Forms
        |
        +--Forms.MyPolygon

public class MyPolygon
extends Forms

This class construct a new polygon.

Version:
1.0
Author:
Sebastien Baehni
See Also:
Forms

Field Summary
protected  int lastX
          The last x coordinate the polygon has been translated.
protected  int lastY
          The last y coordinate the polygon has been translated.
protected  Polygon polygon
          The polygon.
protected  boolean polygonDrawn
          Boolean to know if the polygon is drawn or not.
protected  int precision
          The precision of the polygon i.e: The user must specifies the last point of the polygon at least precision near the first point.
 
Fields inherited from class Forms.Forms
rectangle
 
Constructor Summary
MyPolygon(int precision)
          The constructor.
 
Method Summary
 void drawPolygon(int[] pixels, int width, int height, int x, int y, Color color)
          This method draw a polygon in a given array of pixels with the specified color.
 void drawPolygonWithTexture(int[] pixels, int width, int height, Texture texture)
          This method draw a polygon with the given texture.
 void drawSegment(int[] pixels, int width, int height, int[] firstPoint, int[] secondPoint, Color colorSegment)
          This method draw a segment in a given array of pixels.
 boolean isSelected(int x, int y)
          This method tells if a point is in the polygon or not.
 void optimizeDrawing(AnimatedImage animatedImage)
          This method optimize the drawing of the polygon.
 boolean polygonDrawn()
          This method tells if the polygon is finished or not.
protected  float[] returnLineParameters(int[] firstPoint, int[] secondPoint)
          This method return the line parameters m and h.
 void translate(int x, int y, int maxWidth, int maxHeight)
          This method translate the polygon to the specified point.
 
Methods inherited from class Forms.Forms
height, height, rectangle, width, width, xOrigin, xOrigin, yOrigin, yOrigin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

polygonDrawn

protected boolean polygonDrawn
Boolean to know if the polygon is drawn or not.

precision

protected int precision
The precision of the polygon i.e: The user must specifies the last point of the polygon at least precision near the first point.

lastX

protected int lastX
The last x coordinate the polygon has been translated.

lastY

protected int lastY
The last y coordinate the polygon has been translated.

polygon

protected Polygon polygon
The polygon. This polygon class is given by java. This will be very useful when we must know if a point is in or out of a polygon.
Constructor Detail

MyPolygon

public MyPolygon(int precision)
The constructor.
Parameters:
precision - The precision of the polygon (see the variable upper).
Method Detail

drawPolygon

public void drawPolygon(int[] pixels,
                        int width,
                        int height,
                        int x,
                        int y,
                        Color color)
This method draw a polygon in a given array of pixels with the specified color.
Parameters:
pixels - The array of pixels on which we want to draw the polygon.
width - The width of the array of pixels.
height - The height of the arra of pixels.
x - The x coordinate of the current point to be drawn.
y - The y coordinate of the current point to be drawn.
color - The color we want to draw the polygon.

drawSegment

public void drawSegment(int[] pixels,
                        int width,
                        int height,
                        int[] firstPoint,
                        int[] secondPoint,
                        Color colorSegment)
This method draw a segment in a given array of pixels.
Parameters:
pixels - The array of pixels on which we want to draw the segment.
width - The width of the array of pixels.
height - The height of the array of pixels.
firstPoint - The first point of the segment.
secondPoint - The second point of the segment.
colorSegment - The color we want to draw the segment.

drawPolygonWithTexture

public void drawPolygonWithTexture(int[] pixels,
                                   int width,
                                   int height,
                                   Texture texture)
                            throws TextureError
This method draw a polygon with the given texture.
Parameters:
pixels - The array of pixels on which we want to draw the polygon.
width - The width of the array of pixels.
height - The height of the array of pixels.
texture - The texture of the polygon.
Throws:
TextureError -  

optimizeDrawing

public void optimizeDrawing(AnimatedImage animatedImage)
This method optimize the drawing of the polygon. It refreshes only the bounding box of the polygon.

returnLineParameters

protected float[] returnLineParameters(int[] firstPoint,
                                       int[] secondPoint)
This method return the line parameters m and h.
Parameters:
firstPoint - The first point of the line.
secondPoint - The second point of the line.
Returns:
An array of two elements containing the line parameters. The first element is m and the second one is h.

isSelected

public boolean isSelected(int x,
                          int y)
This method tells if a point is in the polygon or not.
Parameters:
x - The x coordinate of the point we test if it's containing in the polygon.
y - The y coordinate of the point we test if it's containing in the polygon.
Returns:
True if the point is in the polygon, false otherwise.
Overrides:
isSelected in class Forms

translate

public void translate(int x,
                      int y,
                      int maxWidth,
                      int maxHeight)
This method translate the polygon to the specified point.
Parameters:
x - The x coordinate the center of the polygon must be translated.
y - The y coordinate the center of the polygon must be translated.
maxWidth - The maximum width the polygon must be translated. This prevent the polygon from going out of the the animatedImage.
maxHeight - The maximum height the polygon must be translated. This prevent the polygon from going out of the the animatedImage.
Overrides:
translate in class Forms

polygonDrawn

public boolean polygonDrawn()
This method tells if the polygon is finished or not.
Returns:
True if the polygon is finished, false otherwise.