use of com.codename1.ui.geom.Shape in project CodenameOne by codenameone.
the class IOSImplementation method createAlphaMask.
// -------------------------------------------------------------------------
// METHODS FOR DRAWING SHAPES AND TRANSFORMATIONS
// -------------------------------------------------------------------------
/**
* Creates a platform-specific alpha mask for a shape. This is used to cache
* masks in the {@link com.codename1.ui.GeneralPath} class. On iOS the alpha
* mask is an OpenGL texture ID (not a raster of alpha pixels), but other platforms
* may use different representations if they like.
*
* <p>The {@link com.codename1.ui.Graphics#drawAlphaMask} method
* is used to draw a mask on the graphics context and this will ultimately call {@link #drawAlphaMask}
* which can be platform specific also.
* </p>
* @param shape The shape that will have an alpha mask created.
* @param stroke The stroke settings for stroking the outline of the mask. Leave null to produce a fill
* mask.
* @return The platform specific alpha mask object or null if it is not supported or failed.
* @see #deleteAlphaMask
* @see #drawAlphaMask
* @see #isAlphaMaskSupported
* @see com.codename1.ui.Graphics#drawAlphaMask
* @see com.codename1.ui.GeneralPath#getAlphaMask
*/
public TextureAlphaMask createAlphaMask(Shape shape, Stroke stroke) {
int[] bounds = new int[] { 0, 0, 0, 0 };
long tex = nativeCreateAlphaMaskForShape(shape, stroke, bounds);
Rectangle shapeBounds = shape.getBounds();
int[] padding = new int[] { // top
shapeBounds.getY() - bounds[1], // right
bounds[2] - (shapeBounds.getX() + shapeBounds.getWidth()), // bottom
bounds[3] - (shapeBounds.getY() + shapeBounds.getHeight()), // left
shapeBounds.getX() - bounds[0] };
if (tex == 0) {
return null;
}
return new TextureAlphaMask(tex, new Rectangle(bounds[0], bounds[1], bounds[2] - bounds[0], bounds[3] - bounds[1]), padding);
}
use of com.codename1.ui.geom.Shape in project CodenameOne by codenameone.
the class IOSImplementation method renderShape.
private NativePathRenderer renderShape(Shape shape, Stroke stroke) {
if (stroke != null) {
float lineWidth = stroke.getLineWidth();
int capStyle = stroke.getCapStyle();
int miterStyle = stroke.getJoinStyle();
float miterLimit = stroke.getMiterLimit();
PathIterator path = shape.getPathIterator();
Rectangle rb = shape.getBounds();
// Notice that these will be cleaned up in the dealloc method of the DrawPath objective-c class
int padding = (int) Math.ceil(lineWidth);
int padding2 = padding * 2;
NativePathRenderer renderer = new NativePathRenderer(rb.getX() - padding, rb.getY() - padding, rb.getWidth() + padding2, rb.getHeight() + padding2, path.getWindingRule());
NativePathStroker stroker = new NativePathStroker(renderer, lineWidth, capStyle, miterStyle, miterLimit);
NativePathConsumer c = stroker.consumer;
fillPathConsumer(path, c);
// We don't need the stroker anymore because it has passed the strokes to the renderer.
stroker.destroy();
return renderer;
} else {
Rectangle rb = shape.getBounds();
PathIterator path = shape.getPathIterator();
// Notice that this will be cleaned up in the dealloc method of the DrawPath objective-c class.
NativePathRenderer renderer = new NativePathRenderer(rb.getX(), rb.getY(), rb.getWidth(), rb.getHeight(), path.getWindingRule());
NativePathConsumer c = renderer.consumer;
fillPathConsumer(path, c);
return renderer;
}
}
use of com.codename1.ui.geom.Shape in project CodenameOne by codenameone.
the class PieSegment method getShape.
public Shape getShape(float cX, float cY, float radius) {
GeneralPath out = new GeneralPath();
out.moveTo(cX, cY);
out.lineTo(cX + radius * Math.cos(Math.toRadians(mStartAngle)), cY + radius * Math.sin(Math.toRadians(mStartAngle)));
out.arcTo(cX, cY, cX + radius * Math.cos(Math.toRadians(mEndAngle)), cY + radius * Math.sin(Math.toRadians(mEndAngle)));
out.closePath();
return out;
}
use of com.codename1.ui.geom.Shape in project CodenameOne by codenameone.
the class ChartComponent method zoomTransition.
private void zoomTransition(double minX, double maxX, double minY, double maxY, int duration) {
if (chart instanceof XYChart) {
BBox currentViewPort = getBBox();
BBox targetViewPort = getBBox(minX, maxX, minY, maxY, (int) currentViewPort.topLeft.getX(), (int) currentViewPort.topLeft.getY(), (int) currentViewPort.bottomRight.getX(), (int) currentViewPort.bottomRight.getY());
ZoomTransitionXY zt = new ZoomTransitionXY(currentViewPort, targetViewPort, duration);
animations.add(zt);
if (animations.size() == 1) {
zt.start();
}
} else {
Shape currentViewPort = screenToChartShape(new Rectangle(getAbsoluteX(), getAbsoluteY(), getWidth(), getHeight()));
float[] currentRect = currentViewPort.getBounds2D();
float[] newRect = new float[] { (float) minX, (float) (maxX - minX), (float) minY, (float) (maxY - minY) };
float currentAspect = currentRect[2] / currentRect[3];
float newAspect = newRect[3] / newRect[3];
Rectangle newViewPort = new Rectangle((int) newRect[0], (int) newRect[1], (int) newRect[2], (int) newRect[3]);
if (newAspect != currentAspect) {
newViewPort.setHeight((int) (((double) newViewPort.getWidth()) / currentAspect));
newRect = newViewPort.getBounds2D();
newAspect = newRect[2] / newRect[3];
}
ZoomTransition zt = new ZoomTransition(currentViewPort.getBounds(), newViewPort, duration);
animations.add(zt);
if (animations.size() == 1) {
zt.start();
}
}
}
use of com.codename1.ui.geom.Shape in project CodenameOne by codenameone.
the class RoundChart method drawLegendShape.
/**
* The graphical representation of the legend shape.
*
* @param canvas the canvas to paint to
* @param renderer the series renderer
* @param x the x value of the point the shape should be drawn at
* @param y the y value of the point the shape should be drawn at
* @param seriesIndex the series index
* @param paint the paint to be used for drawing
*/
public void drawLegendShape(Canvas canvas, SimpleSeriesRenderer renderer, float x, float y, int seriesIndex, Paint paint) {
if (renderer.isGradientEnabled() && canvas.isShapeClipSupported()) {
GradientDrawable gr = new GradientDrawable(Orientation.TOP_BOTTOM, new int[] { renderer.getGradientStartColor(), renderer.getGradientStopColor() });
gr.setBounds((int) x, (int) (y - SHAPE_WIDTH / 2), (int) (x + SHAPE_WIDTH), (int) (y + SHAPE_WIDTH / 2));
gr.draw(canvas);
} else {
canvas.drawRect(x, y - SHAPE_WIDTH / 2, x + SHAPE_WIDTH, y + SHAPE_WIDTH / 2, paint);
}
}
Aggregations