[cairo-commit] cairo-java/src/java/org/freedesktop/cairo
Context.java, 1.14, 1.15 Rectangle.java, 1.3, 1.4
Dan Williams
commit at pdx.freedesktop.org
Thu Mar 23 10:55:09 PST 2006
Committed by: dcbw
Update of /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo
In directory kemper:/tmp/cvs-serv25576/src/java/org/freedesktop/cairo
Modified Files:
Context.java Rectangle.java
Log Message:
2006-03-23 Dan Williams <dcbw at redhat.com>
* src/java/org/freedesktop/cairo/Rectangle.java
- Convert Rectangle to x/y/w/h rather than x1/y1/x2/y2 to match
cairo usage semantics
- Mark old x1/y1/x2/y2 functions as deprecated, but accept them and
convert their input to the x/y/w/h
- Add new accessors for get/set origin and get/set width
- Add new Rectangle() constructor for empty rectangles
- Add new Rectangle(Rectangle) constructor
* src/java/org/freedesktop/cairo/Context.java
- Correct Rectangle usage in cairo_rectangle(). Should use x/y/w/h
not x1/y1/x2/y2
- Add inStroke(Point p) and inFill(Point p)
- Add some javadoc for inFill, inStroke, and rectangle
Index: Context.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/Context.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- Context.java 23 Mar 2006 16:32:09 -0000 1.14
+++ Context.java 23 Mar 2006 18:55:07 -0000 1.15
@@ -481,13 +481,29 @@
cairo_rel_curve_to(getHandle(), x1, y1, x2, y2, x3, y3);
}
- public void rectangle(Point p1, Point p2) {
- cairo_rectangle(getHandle(), p1.getX(), p1.getY(), p2.getX(), p2.getY());
+ /**
+ * Draws a rectangle defined by the upper-left point p1 and the
+ * lower-right point p2.
+ *
+ * @param upperLeft
+ * x and y coordinates of the upper-left point
+ * @param lowerRight
+ * x and y coordinates of the lower-right point
+ */
+ public void rectangle(Point upperLeft, Point lowerRight) {
+ Rectangle r = new Rectangle(upperLeft, lowerRight);
+ rectangle(r);
}
+ /**
+ * Draws a rectangle defined by the Rectangle object rect.
+ *
+ * @param rect
+ * Rectangle defining the coordinate of the shape to draw
+ */
public void rectangle(Rectangle rect) {
- cairo_rectangle(getHandle(), rect.getX1(), rect.getY1(), rect.getX2(),
- rect.getY2());
+ cairo_rectangle(getHandle(), rect.getX(), rect.getY(), rect.getWidth(),
+ rect.getHeight());
}
/**
@@ -586,14 +602,42 @@
cairo_show_page(getHandle());
}
+ /**
+ * Determines whether the point specified by (x, y) lies inside
+ * the area bounded by the current path, including the path's
+ * stroke area.
+ *
+ * @param x
+ * x coordinate of the point to test
+ * @param y
+ * y coordinate of the point to test
+ */
public boolean inStroke(double x, double y) {
return cairo_in_stroke(getHandle(), x, y);
}
+ public boolean inStroke(Point p) {
+ return cairo_in_stroke(getHandle(), p.getX(), p.getY());
+ }
+
+ /**
+ * Determines whether the point specified by (x, y) lies inside
+ * the area bounded by the current path, excluding the path's
+ * stroke area.
+ *
+ * @param x
+ * x coordinate of the point to test
+ * @param y
+ * y coordinate of the point to test
+ */
public boolean inFill(double x, double y) {
return cairo_in_fill(getHandle(), x, y);
}
+ public boolean inFill(Point p) {
+ return cairo_in_fill(getHandle(), p.getX(), p.getY());
+ }
+
public Rectangle strokeExtents() {
double[] x1 = new double[1];
double[] y1 = new double[1];
Index: Rectangle.java
===================================================================
RCS file: /cvs/cairo/cairo-java/src/java/org/freedesktop/cairo/Rectangle.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Rectangle.java 12 Feb 2006 09:05:44 -0000 1.3
+++ Rectangle.java 23 Mar 2006 18:55:07 -0000 1.4
@@ -10,57 +10,204 @@
public class Rectangle {
- double x1;
+ protected double x;
- double y1;
+ protected double y;
- double x2;
+ protected double width;
- double y2;
+ protected double height;
+ /**
+ * Constructs a new Rectangle object defined by four bounding
+ * coordinates, (x1, y1) and (x2, y2)
+ *
+ * @param x1
+ * x coordinate of the upper-left point of the rectangle
+ * @param y1
+ * y coordinate of the upper-left point of the rectangle
+ * @param x2
+ * x coordinate of the lower-right point of the rectangle
+ * @param y2
+ * y coordinate of the lower-right point of the rectangle
+ */
public Rectangle(double x1, double y1, double x2, double y2) {
- this.x1 = x1;
- this.y1 = y1;
- this.x2 = x2;
- this.y2 = y2;
+ if (x1 <= x2) {
+ this.x = x1;
+ this.width = x2 - x1;
+ } else {
+ this.x = x2;
+ this.width = x1 - x2;
+ }
+
+ if (y1 <= y2) {
+ this.y = y1;
+ this.height = y2 - y1;
+ } else {
+ this.y = y2;
+ this.height = y1 - y2;
+ }
}
+ /**
+ * Constructs a new Rectangle object defined by two Point objects,
+ * which specify the upper-left and lower-right coordinates of the
+ * rectangle
+ *
+ * @param upperLeft
+ * x coordinate of the upper-left point of the rectangle
+ * @param lowerRight
+ * y coordinate of the lower-right point of the rectangle
+ */
public Rectangle(Point upperLeft, Point lowerRight) {
- this.x1 = upperLeft.getX();
- this.y1 = upperLeft.getY();
- this.x2 = lowerRight.getX();
- this.y2 = lowerRight.getY();
+ this(upperLeft.getX(), upperLeft.getY(),
+ lowerRight.getX(), lowerRight.getY());
+ }
+
+ /**
+ * Constructs a new Rectangle object with position and size
+ * set to 0.
+ */
+ public Rectangle() {
+ this.x = this.y = this.width = this.height = 0;
+ }
+
+ public Rectangle(Rectangle r) {
+ this.x = r.x;
+ this.y = r.y;
+ this.width = r.width;
+ this.height = r.height;
}
+ public double getWidth() {
+ return this.width;
+ }
+
+ public void setWidth(double width) {
+ this.width = width;
+ }
+
+ public double getHeight() {
+ return this.height;
+ }
+
+ public void setHeight(double height) {
+ this.height = height;
+ }
+
+ public void setSize(Point size) {
+ this.width = size.getX();
+ this.height = size.getY();
+ }
+
+ public double getX() {
+ return this.x;
+ }
+
+ public void setX(double x) {
+ this.x = x;
+ }
+
+ public double getY() {
+ return this.y;
+ }
+
+ public void setY(double y) {
+ this.y = y;
+ }
+
+ public void setOrigin(Point origin) {
+ this.x = origin.getX();
+ this.y = origin.getY();
+ }
+
+ /**
+ * @deprecated This method is deprecated in favor of
+ * {@link #getX}.
+ *
+ * @see #getX
+ */
public double getX1() {
- return x1;
+ return x;
}
+ /**
+ * @deprecated This method is deprecated in favor of
+ * {@link #setX}.
+ *
+ * @see #setX
+ */
public void setX1(double x1) {
- this.x1 = x1;
+ this.x = x1;
}
+ /**
+ * @deprecated This method is deprecated in favor of
+ * {@link #getWidth}.
+ *
+ * @see #getWidth
+ */
public double getX2() {
- return x2;
+ return x + width;
}
+ /**
+ * @deprecated This method is deprecated in favor of
+ * {@link #setWidth}.
+ *
+ * @see #setWidth
+ */
public void setX2(double x2) {
- this.x2 = x2;
+ if (x2 >= this.x) {
+ this.width = x2 - this.x;
+ } else {
+ this.width = this.x - x2;
+ this.x = x2;
+ }
}
+ /**
+ * @deprecated This method is deprecated in favor of
+ * {@link #getY}.
+ *
+ * @see #getY
+ */
public double getY1() {
- return y1;
+ return y;
}
+ /**
+ * @deprecated This method is deprecated in favor of
+ * {@link #setY}.
+ *
+ * @see #setY
+ */
public void setY1(double y1) {
- this.y1 = y1;
+ this.y = y1;
}
+ /**
+ * @deprecated This method is deprecated in favor of
+ * {@link #getHeight}.
+ *
+ * @see #getHeight
+ */
public double getY2() {
- return y2;
+ return y + height;
}
+ /**
+ * @deprecated This method is deprecated in favor of
+ * {@link #setHeight}.
+ *
+ * @see #setHeight
+ */
public void setY2(double y2) {
- this.y2 = y2;
+ if (y2 >= this.y) {
+ this.height = y2 - this.y;
+ } else {
+ this.height = this.y - y2;
+ this.y = y2;
+ }
}
}
More information about the cairo-commit
mailing list