public Dimension getPreferredSize() { int maxx = MIN_SIZE; int maxy = MIN_SIZE; if (background != null) { maxx = Math.max(maxx, background.getWidth()); maxy = Math.max(maxx, background.getHeight()); } for (Shape s : shapes) { maxx = (int) Math.max(maxx, s.getX() + s.getWidth()); maxy = (int) Math.max(maxy, s.getY() + s.getHeight()); } return new Dimension(maxx + MARGIN, maxy + MARGIN); }
/** * Draw the the given shape filled in with a texture. Only the vertices are set. The colour has to * be set independently of this method. This method is required to fit the texture scaleX times * across the shape and scaleY times down the shape. * * @param shape The shape to texture. * @param image The image to tile across the shape * @param scaleX The scale to apply on the x axis for texturing * @param scaleY The scale to apply on the y axis for texturing */ public static final void textureFit( Shape shape, final Image image, final float scaleX, final float scaleY) { if (!validFill(shape)) { return; } float points[] = shape.getPoints(); Texture t = TextureImpl.getLastBind(); image.getTexture().bind(); final float minX = shape.getX(); final float minY = shape.getY(); final float maxX = shape.getMaxX() - minX; final float maxY = shape.getMaxY() - minY; fill( shape, new PointCallback() { public float[] preRenderPoint(Shape shape, float x, float y) { x -= shape.getMinX(); y -= shape.getMinY(); x /= (shape.getMaxX() - shape.getMinX()); y /= (shape.getMaxY() - shape.getMinY()); float tx = x * scaleX; float ty = y * scaleY; tx = image.getTextureOffsetX() + (image.getTextureWidth() * tx); ty = image.getTextureOffsetY() + (image.getTextureHeight() * ty); GL.glTexCoord2f(tx, ty); return null; } }); if (t == null) { TextureImpl.bindNone(); } else { t.bind(); } }