You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/05/01 01:57:11 UTC
svn commit: r770488 - in /incubator/pivot/trunk/wtk:
src/pivot/wtk/media/drawing/ src/pivot/wtk/skin/
test/pivot/wtk/media/drawing/test/
Author: gbrown
Date: Thu Apr 30 23:57:11 2009
New Revision: 770488
URL: http://svn.apache.org/viewvc?rev=770488&view=rev
Log:
Implement QuadCurve; fix paint issue in Group; fix rounding errors in Line and Path.
Added:
incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurveListener.java
Modified:
incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Group.java
incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Line.java
incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Path.java
incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurve.java
incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ImageViewSkin.java
incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Group.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Group.java?rev=770488&r1=770487&r2=770488&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Group.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Group.java Thu Apr 30 23:57:11 2009
@@ -74,10 +74,15 @@
// Draw each sub-shape
for (Shape shape : shapes) {
if (shape.isVisible()) {
+ int x = shape.getX();
+ int y = shape.getY();
+
Bounds transformedBounds = shape.getTransformedBounds();
+ transformedBounds = transformedBounds.translate(x, y);
+
if (transformedBounds.intersects(clipBounds)) {
Graphics2D shapeGraphics = (Graphics2D)graphics.create();
- shapeGraphics.translate(shape.getX(), shape.getY());
+ shapeGraphics.translate(x, y);
shapeGraphics.transform(shape.getTransforms().getAffineTransform());
shape.draw(shapeGraphics);
shapeGraphics.dispose();
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Line.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Line.java?rev=770488&r1=770487&r2=770488&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Line.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Line.java Thu Apr 30 23:57:11 2009
@@ -142,9 +142,10 @@
double bottom = Math.max(line2D.y1, line2D.y2);
double right = Math.max(line2D.x1, line2D.x2);
- setBounds((int)(left - radius), (int)(top - radius),
- (int)(right - left + radius * 2 + 1),
- (int)(bottom - top + radius * 2 + 1));
+ setBounds((int)Math.floor(left - radius),
+ (int)Math.floor(top - radius),
+ (int)Math.ceil(right - left + radius * 2 + 1),
+ (int)Math.ceil(bottom - top + radius * 2 + 1));
}
super.validate();
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Path.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Path.java?rev=770488&r1=770487&r2=770488&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Path.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/Path.java Thu Apr 30 23:57:11 2009
@@ -714,9 +714,10 @@
double radius = ((double)strokeThickness/Math.cos(Math.PI / 4)) / 2;
Rectangle2D bounds = generalPath.getBounds2D();
- setBounds((int)(bounds.getX() - radius), (int)(bounds.getY() - radius),
- (int)(bounds.getWidth() + 2 * radius + 1),
- (int)(bounds.getHeight() + 2 * radius + 1));
+ setBounds((int)Math.floor(bounds.getX() - radius),
+ (int)Math.floor(bounds.getY() - radius),
+ (int)Math.ceil(bounds.getWidth() + 2 * radius + 1),
+ (int)Math.ceil(bounds.getHeight() + 2 * radius + 1));
}
super.validate();
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurve.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurve.java?rev=770488&r1=770487&r2=770488&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurve.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurve.java Thu Apr 30 23:57:11 2009
@@ -16,7 +16,13 @@
*/
package pivot.wtk.media.drawing;
+import java.awt.BasicStroke;
import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.geom.QuadCurve2D;
+import java.awt.geom.Rectangle2D;
+
+import pivot.util.ListenerList;
/**
* Shape representing a quad curve.
@@ -24,11 +30,146 @@
* @author gbrown
*/
public class QuadCurve extends Shape {
+ private static class QuadCurveListenerList extends ListenerList<QuadCurveListener>
+ implements QuadCurveListener {
+ public void endpointsChanged(QuadCurve quadCurve, int previousX1, int previousY1,
+ int previousX2, int previousY2) {
+ for (QuadCurveListener listener : this) {
+ listener.endpointsChanged(quadCurve, previousX1, previousY1,
+ previousX2, previousY2);
+ }
+ }
+
+ public void controlPointChanged(QuadCurve quadCurve, int previousControlX,
+ int previousControlY) {
+ for (QuadCurveListener listener : this) {
+ listener.controlPointChanged(quadCurve, previousControlX,
+ previousControlY);
+ }
+ }
+ }
+
+ private QuadCurve2D.Float quadCurve2D = new QuadCurve2D.Float();
+
+ private QuadCurveListenerList quadCurveListeners = new QuadCurveListenerList();
+
+ public int getX1() {
+ return (int)quadCurve2D.x1;
+ }
+
+ public void setX1(int x1) {
+ setEndpoints(x1, getY1(), getX2(), getY2());
+ }
+
+ public int getY1() {
+ return (int)quadCurve2D.y1;
+ }
+
+ public void setY1(int y1) {
+ setEndpoints(getX1(), y1, getX2(), getY2());
+ }
+
+ public int getX2() {
+ return (int)quadCurve2D.x2;
+ }
+
+ public void setX2(int x2) {
+ setEndpoints(getX1(), getY1(), x2, getY2());
+ }
+
+ public int getY2() {
+ return (int)quadCurve2D.y2;
+ }
+
+ public void setY2(int y2) {
+ setEndpoints(getX1(), getY1(), getX2(), y2);
+ }
+
+ public void setEndpoints(int x1, int y1, int x2, int y2) {
+ int previousX1 = getX1();
+ int previousY1 = getY1();
+ int previousX2 = getX2();
+ int previousY2 = getY2();
+
+ if (previousX1 != x1
+ || previousY1 != y1
+ || previousX2 != x2
+ || previousY2 != y2) {
+ quadCurve2D.x1 = x1;
+ quadCurve2D.y1 = y1;
+ quadCurve2D.x2 = x2;
+ quadCurve2D.y2 = y2;
+ invalidate();
+ quadCurveListeners.endpointsChanged(this, previousX1, previousY1,
+ previousX2, previousY2);
+ }
+ }
+
+ public int getControlX() {
+ return (int)quadCurve2D.ctrlx;
+ }
+
+ public void setControlX(int controlX) {
+ setControlPoint(controlX, getControlY());
+ }
+
+ public int getControlY() {
+ return (int)quadCurve2D.ctrly;
+ }
+
+ public void setControlY(int controlY) {
+ setControlPoint(getControlX(), controlY);
+ }
+
+ public void setControlPoint(int controlX, int controlY) {
+ int previousControlX = getControlX();
+ int previousControlY = getControlY();
+
+ if (previousControlX != controlX
+ || previousControlY != controlY) {
+ quadCurve2D.ctrlx = controlX;
+ quadCurve2D.ctrly = controlY;
+ invalidate();
+ quadCurveListeners.controlPointChanged(this, previousControlX,
+ previousControlY);
+ }
+ }
@Override
public void draw(Graphics2D graphics) {
- // TODO Auto-generated method stub
+ Paint fill = getFill();
+ if (fill != null) {
+ graphics.setPaint(fill);
+ graphics.fill(quadCurve2D);
+ }
+
+ Paint stroke = getStroke();
+ if (stroke != null) {
+ int strokeThickness = getStrokeThickness();
+ graphics.setPaint(stroke);
+ graphics.setStroke(new BasicStroke(strokeThickness));
+ graphics.draw(quadCurve2D);
+ }
+ }
+
+ @Override
+ protected void validate() {
+ if (!isValid()) {
+ // Over-estimate the bounds to keep the logic simple
+ int strokeThickness = getStrokeThickness();
+ double radius = ((double)strokeThickness/Math.cos(Math.PI / 4)) / 2;
+ Rectangle2D boundingRectangle = quadCurve2D.getBounds2D();
+ setBounds((int)Math.floor(boundingRectangle.getX() - radius),
+ (int)Math.floor(boundingRectangle.getY() - radius),
+ (int)Math.ceil(boundingRectangle.getWidth() + radius * 2),
+ (int)Math.ceil(boundingRectangle.getHeight() + radius * 2));
+ }
+
+ super.validate();
}
+ public ListenerList<QuadCurveListener> getQuadCurveListeners() {
+ return quadCurveListeners;
+ }
}
Added: incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurveListener.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurveListener.java?rev=770488&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurveListener.java (added)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/media/drawing/QuadCurveListener.java Thu Apr 30 23:57:11 2009
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package pivot.wtk.media.drawing;
+
+/**
+ * Quadratic curve listner interface.
+ *
+ * @author gbrown
+ */
+public interface QuadCurveListener {
+ /**
+ * Called when a quad curve's endpoints have changed.
+ *
+ * @param quadCurve
+ * @param previousX1
+ * @param previousY1
+ * @param previousX2
+ * @param previousY2
+ */
+ public void endpointsChanged(QuadCurve quadCurve, int previousX1, int previousY1,
+ int previousX2, int previousY2);
+
+ /**
+ * Called when a quad curve's control point has changed.
+ *
+ * @param quadCurve
+ * @param previousControlX
+ * @param previousControlY
+ */
+ public void controlPointChanged(QuadCurve quadCurve, int previousControlX,
+ int previousControlY);
+}
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ImageViewSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ImageViewSkin.java?rev=770488&r1=770487&r2=770488&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ImageViewSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/skin/ImageViewSkin.java Thu Apr 30 23:57:11 2009
@@ -53,7 +53,9 @@
}
public void regionUpdated(Image image, int x, int y, int width, int height) {
- repaintComponent(x, y, width, height);
+ // TODO Offset this by the image location; scale by the image scale
+ // repaintComponent(x, y, width, height);
+ repaintComponent();
}
};
@@ -290,6 +292,15 @@
// Image view events
public void imageChanged(ImageView imageView, Image previousImage) {
+ if (previousImage != null) {
+ previousImage.getImageListeners().remove(imageListener);
+ }
+
+ Image image = imageView.getImage();
+ if (image != null) {
+ image.getImageListeners().add(imageListener);
+ }
+
invalidateComponent();
}
}
Modified: incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd?rev=770488&r1=770487&r2=770488&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd (original)
+++ incubator/pivot/trunk/wtk/test/pivot/wtk/media/drawing/test/sample.wtkd Thu Apr 30 23:57:11 2009
@@ -63,6 +63,11 @@
visible="false"/>
<Line x1="-10" y1="130" x2="30" y2="90" stroke="#cc00cc" strokeThickness="20"/>
</Group>
+
+ <Group x="240" y="240">
+ <QuadCurve x1="0" y1="0" x2="0" y2="50" controlX="50" controlY="25"
+ strokeThickness="4" fill="#ff00ff"/>
+ </Group>
</Canvas>
</canvas>
</Drawing>