本文整理汇总了Java中org.piccolo2d.util.PBounds类的典型用法代码示例。如果您正苦于以下问题:Java PBounds类的具体用法?Java PBounds怎么用?Java PBounds使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PBounds类属于org.piccolo2d.util包,在下文中一共展示了PBounds类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: relocateHandle
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
/**
* Force this handle to relocate itself using its locator.
*/
public void relocateHandle() {
if (locator != null) {
final PBounds b = getBoundsReference();
final Point2D aPoint = locator.locatePoint(null);
if (locator instanceof PNodeLocator) {
final PNode located = ((PNodeLocator) locator).getNode();
final PNode parent = getParent();
located.localToGlobal(aPoint);
globalToLocal(aPoint);
if (parent != located && parent instanceof PCamera) {
((PCamera) parent).viewToLocal(aPoint);
}
}
final double newCenterX = aPoint.getX();
final double newCenterY = aPoint.getY();
if (newCenterX != b.getCenterX() || newCenterY != b.getCenterY()) {
centerBoundsOnPoint(newCenterX, newCenterY);
}
}
}
示例2: updateMarquee
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
/** {@inheritDoc} */
protected void updateMarquee(final PInputEvent pie) {
super.updateMarquee(pie);
final PBounds b = new PBounds();
if (marqueeParent instanceof PCamera) {
b.add(canvasPressPt);
b.add(pie.getCanvasPosition());
}
else {
b.add(pressPt);
b.add(pie.getPosition());
}
marquee.setPathToRectangle((float) b.x, (float) b.y, (float) b.width, (float) b.height);
b.reset();
b.add(pressPt);
b.add(pie.getPosition());
}
示例3: testTransformRect
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
public void testTransformRect() {
final PBounds b1 = new PBounds(0, 0, 100, 80);
final PBounds b2 = new PBounds(100, 100, 100, 80);
at.scale(0.5, 0.5);
at.translate(100, 50);
at.transform(b1, b1);
at.transform(b2, b2);
PiccoloAsserts.assertEquals(new PBounds(50, 25, 50, 40), b1, 0.0001);
PiccoloAsserts.assertEquals(new PBounds(100, 75, 50, 40), b2, 0.0001);
at.inverseTransform(b1, b1);
at.inverseTransform(b2, b2);
PiccoloAsserts.assertEquals(new PBounds(0, 0, 100, 80), b1, 0.0001);
PiccoloAsserts.assertEquals(new PBounds(100, 100, 100, 80), b2, 0.0001);
}
示例4: paint
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
/** {@inheritDoc} */
protected void paint(final PPaintContext paintContext) {
if (getImage() != null) {
final Rectangle r = image.getBounds();
final PBounds b = getBoundsReference();
final SWTGraphics2D g2 = (SWTGraphics2D) paintContext.getGraphics();
if (b.x == 0 && b.y == 0 && b.width == r.width && b.height == r.height) {
g2.drawImage(image, 0, 0);
}
else {
g2.translate(b.x, b.y);
g2.scale(b.width / r.width, b.height / r.height);
g2.drawImage(image, 0, 0);
g2.scale(r.width / b.width, r.height / b.height);
g2.translate(-b.x, -b.y);
}
}
}
示例5: testCenterRotate
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
public void testCenterRotate() {
PSWTPath path = PSWTPath.createRectangle(10.0f, 20.0f, 100.0f, 200.0f);
path.rotate(Math.PI / 8.0d);
PBounds bounds = path.getBoundsReference();
// hard to believe the tolerance in SWT is this poor
assertEquals(10.0d, bounds.getX(), 1.0d);
assertEquals(20.0d, bounds.getY(), 1.0d);
assertEquals(200.0d, bounds.getHeight(), 2.0d);
assertEquals(100.0d, bounds.getWidth(), 2.0d);
// center is calculated in terms of local bounds, not full bounds
Point2D center = path.getCenter();
assertEquals(60.0d, center.getX(), 0.1d);
assertEquals(120.0d, center.getY(), 0.1d);
}
示例6: fullPaint
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
/**
* Overrides the camera's full paint method to do the fast rendering when
* possible.
*
* @param paintContext Paint Contex in which the painting is done
*/
public void fullPaint(final PPaintContext paintContext) {
if (imageAnimate) {
final PBounds fRef = getFullBoundsReference();
final PBounds viewBounds = getViewBounds();
final double scale = getFullBoundsReference().getWidth() / imageAnimateBounds.getWidth();
final double xOffset = (viewBounds.getX() - imageAnimateBounds.getX()) * scale;
final double yOffset = (viewBounds.getY() - imageAnimateBounds.getY()) * scale;
final double scaleW = viewBounds.getWidth() * scale;
final double scaleH = viewBounds.getHeight() * scale;
paintContext.getGraphics().drawImage(paintBuffer, 0, 0, (int) Math.ceil(fRef.getWidth()),
(int) Math.ceil(fRef.getHeight()), (int) Math.floor(xOffset), (int) Math.floor(yOffset),
(int) Math.ceil(xOffset + scaleW), (int) Math.ceil(yOffset + scaleH), null);
}
else {
super.fullPaint(paintContext);
}
}
示例7: fullIntersectsNodes
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
public void fullIntersectsNodes() {
final PNode parent = new PNode();
final PNode[] nodes = new PNode[NUMBER_NODES];
final PBounds b = new PBounds(0, 50, 100, 20);
for (int i = 0; i < NUMBER_NODES; i++) {
nodes[i] = new PNode();
parent.addChild(nodes[i]);
}
// parent.validateFullBounds(); // now protected
parent.getFullBoundsReference(); // calls validateFullBounds as a side
// effect.
log.startTest();
for (int i = 0; i < NUMBER_NODES; i++) {
nodes[i].fullIntersects(b);
}
log.endTest("Do fullIntersects test for " + NUMBER_NODES + " nodes");
}
示例8: getViewPosition
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
/**
* Get the View position given the specified camera bounds.
*
* @param viewBounds The bounds for which the view position will be computed
* @return The view position
*/
public Point getViewPosition(final Rectangle2D viewBounds) {
final Point pos = new Point();
if (camera != null) {
// First we compute the union of all the layers
final PBounds layerBounds = new PBounds();
final List layers = camera.getLayersReference();
for (final Iterator i = layers.iterator(); i.hasNext();) {
final PLayer layer = (PLayer) i.next();
layerBounds.add(layer.getFullBoundsReference());
}
// Then we put the bounds into camera coordinates and
// union the camera bounds
camera.viewToLocal(layerBounds);
layerBounds.add(viewBounds);
pos.setLocation((int) (viewBounds.getX() - layerBounds.getX() + 0.5), (int) (viewBounds.getY()
- layerBounds.getY() + 0.5));
}
return pos;
}
示例9: paint
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
/**
* Renders the wrapped Image, stretching it appropriately if the bounds of
* this PImage doesn't match the bounds of the image.
*
* @param paintContext context into which the rendering will occur
*/
protected void paint(final PPaintContext paintContext) {
if (getImage() == null) {
return;
}
final double iw = image.getWidth(null);
final double ih = image.getHeight(null);
final PBounds b = getBoundsReference();
final Graphics2D g2 = paintContext.getGraphics();
if (b.x != 0 || b.y != 0 || b.width != iw || b.height != ih) {
g2.translate(b.x, b.y);
g2.scale(b.width / iw, b.height / ih);
g2.drawImage(image, 0, 0, null);
g2.scale(iw / b.width, ih / b.height);
g2.translate(-b.x, -b.y);
}
else {
g2.drawImage(image, 0, 0, null);
}
}
示例10: testFindIntersectingNodes
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
public void testFindIntersectingNodes() {
final PNode n = new PNode();
final PNode c = new PNode();
n.addChild(c);
n.setBounds(0, 0, 100, 100);
c.setBounds(0, 0, 100, 100);
c.scale(200);
ArrayList found = new ArrayList();
final Rectangle2D rect2d = new Rectangle2D.Double(50, 50, 10, 10);
n.findIntersectingNodes(rect2d, found);
assertEquals(found.size(), 2);
assertEquals(rect2d.getHeight(), 10, 0);
found = new ArrayList();
final PBounds bounds = new PBounds(50, 50, 10, 10);
n.findIntersectingNodes(bounds, found);
assertEquals(found.size(), 2);
assertEquals(bounds.getHeight(), 10, 0);
}
示例11: getBoundsReference
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
/**
* Since our bounds are volatile, we can override this method to indicate
* that we are expanding our bounds beyond our children
*/
public PBounds getBoundsReference() {
final PBounds bds = super.getBoundsReference();
getUnionOfChildrenBounds(bds);
cachedChildBounds.setRect(bds);
final double scaledIndent = INDENT / renderCamera.getViewScale();
bds.setRect(bds.getX() - scaledIndent, bds.getY() - scaledIndent, bds.getWidth() + 2 * scaledIndent, bds
.getHeight()
+ 2 * scaledIndent);
return bds;
}
示例12: getViewPosition
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
/**
* Get the View position given the specified camera bounds - modified
* such that:
*
* Rather than finding the distance from the upper left corner of the
* window to the upper left corner of the document - we instead find the
* distance from the lower right corner of the window to the upper left
* corner of the document THEN we subtract that value from total
* document width so that the position is inverted
*
* @param viewBounds The bounds for which the view position will be
* computed
* @return The view position
*/
public Point getViewPosition(final Rectangle2D viewBounds) {
final Point pos = new Point();
if (camera != null) {
// First we compute the union of all the layers
final PBounds layerBounds = new PBounds();
final java.util.List layers = camera.getLayersReference();
for (final Iterator i = layers.iterator(); i.hasNext();) {
final PLayer layer = (PLayer) i.next();
layerBounds.add(layer.getFullBoundsReference());
}
// Then we put the bounds into camera coordinates and
// union the camera bounds
camera.viewToLocal(layerBounds);
layerBounds.add(viewBounds);
// Rather than finding the distance from the upper left corner
// of the window to the upper left corner of the document -
// we instead find the distance from the lower right corner
// of the window to the upper left corner of the document
// THEN we measure the offset from the lower right corner
// of the document
pos.setLocation((int) (layerBounds.getWidth()
- (viewBounds.getX() + viewBounds.getWidth() - layerBounds.getX()) + 0.5), (int) (layerBounds
.getHeight()
- (viewBounds.getY() + viewBounds.getHeight() - layerBounds.getY()) + 0.5));
}
return pos;
}
示例13: testTransformRectLeavesEmptyBoundsEmpty
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
public void testTransformRectLeavesEmptyBoundsEmpty() {
final PBounds b1 = new PBounds();
at.scale(0.5, 0.5);
at.translate(100, 50);
at.transform(b1, b1);
assertTrue(b1.isEmpty());
}
示例14: composeOtherNodes
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
public void composeOtherNodes() {
final PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
// create parts for the face.
final PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
eye1.setPaint(Color.YELLOW);
final PNode eye2 = (PNode) eye1.clone();
final PNode mouth = PPath.createRectangle(0, 0, 40, 20);
mouth.setPaint(Color.BLACK);
// add the face parts
myCompositeFace.addChild(eye1);
myCompositeFace.addChild(eye2);
myCompositeFace.addChild(mouth);
// don't want anyone grabbing out our eye's.
myCompositeFace.setChildrenPickable(false);
// position the face parts.
eye2.translate(25, 0);
mouth.translate(0, 30);
// set the face bounds so that it neatly contains the face parts.
final PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
myCompositeFace.setBounds(b.inset(-5, -5));
// opps it to small, so scale it up.
myCompositeFace.scale(1.5);
getCanvas().getLayer().addChild(myCompositeFace);
}
示例15: getBoundsReference
import org.piccolo2d.util.PBounds; //导入依赖的package包/类
/** {@inheritDoc} */
public PBounds getBoundsReference() {
final PBounds targetBounds = target.getFullBounds();
camera.viewToLocal(targetBounds);
camera.globalToLocal(targetBounds);
final PBounds bounds = super.getBoundsReference();
bounds.setRect(targetBounds);
return super.getBoundsReference();
}