use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class ImageViewer method paint.
/**
* {@inheritDoc}
*/
@Override
public void paint(Graphics g) {
if (panPositionX < 0) {
Style s = getStyle();
int width = getWidth() - s.getHorizontalPadding();
float ratio = ((float) width) * (panPositionX * -1);
g.drawImage(image, ((int) ratio) + getX() + imageX, getY() + imageY, imageDrawWidth, imageDrawHeight);
if (cycleLeft || swipeableImages.getSelectedIndex() > getImageLeftPos()) {
Image left = getImageLeft();
if (swipePlaceholder != null) {
left.asyncLock(swipePlaceholder);
} else {
left.lock();
}
ratio = ratio - width;
imageAspectCalc(left);
g.drawImage(left, ((int) ratio) + getX() + prefX, getY() + prefY, prefW, prefH);
}
return;
}
if (panPositionX > 1) {
Style s = getStyle();
int width = getWidth() - s.getHorizontalPadding();
float ratio = ((float) width) * (1 - panPositionX);
g.drawImage(image, ((int) ratio) + getX() + imageX, getY() + imageY, imageDrawWidth, imageDrawHeight);
if (cycleRight || swipeableImages.getSelectedIndex() < getImageRightPos()) {
Image right = getImageRight();
if (swipePlaceholder != null) {
right.asyncLock(swipePlaceholder);
} else {
right.lock();
}
ratio = ratio + width;
imageAspectCalc(right);
g.drawImage(right, ((int) ratio) + getX() + prefX, getY() + prefY, prefW, prefH);
}
return;
}
// can happen in the GUI builder
if (image != null) {
g.drawImage(image, getX() + imageX, getY() + imageY, imageDrawWidth, imageDrawHeight);
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class InfiniteProgress method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
if (this.getComponentForm() != null && Display.getInstance().getCurrent() != this.getComponentForm()) {
return;
}
super.paint(g);
if (animation == null) {
return;
}
int v = angle % 360;
Style s = getStyle();
/*if(g.isAffineSupported()) {
g.rotate(((float)v) / 57.2957795f, getAbsoluteX() + s.getPadding(LEFT) + getWidth() / 2, getAbsoluteY() + s.getPadding(TOP) + getHeight() / 2);
g.drawImage(getAnimation(), getX() + s.getPadding(LEFT), getY() + s.getPadding(TOP));
g.resetAffine();
} else {*/
Image rotated;
if (animation instanceof FontImage) {
rotated = animation.rotate(v);
} else {
Integer angle = new Integer(v);
rotated = cache.get(angle);
if (rotated == null) {
rotated = animation.rotate(v);
cache.put(v, rotated);
}
}
g.drawImage(rotated, getX() + s.getPaddingLeftNoRTL(), getY() + s.getPaddingTop());
// }
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class BarChart method drawBar.
/**
* Draws a bar.
*
* @param canvas the canvas
* @param xMin the X axis minimum
* @param yMin the Y axis minimum
* @param xMax the X axis maximum
* @param yMax the Y axis maximum
* @param halfDiffX half the size of a bar
* @param seriesNr the total number of series
* @param seriesIndex the current series index
* @param paint the paint
*/
protected void drawBar(Canvas canvas, float xMin, float yMin, float xMax, float yMax, float halfDiffX, int seriesNr, int seriesIndex, Paint paint) {
int scale = mDataset.getSeriesAt(seriesIndex).getScaleNumber();
if (mType == Type.STACKED || mType == Type.HEAPED) {
drawBar(canvas, xMin - halfDiffX, yMax, xMax + halfDiffX, yMin, scale, seriesIndex, paint);
} else {
float startX = xMin - seriesNr * halfDiffX + seriesIndex * 2 * halfDiffX;
drawBar(canvas, startX, yMax, startX + 2 * halfDiffX, yMin, scale, seriesIndex, paint);
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class CubicLineChart method drawPoints.
/**
* Draws the series points.
*
* @param canvas the canvas
* @param paint the paint object
* @param pointsList the points to be rendered
* @param seriesRenderer the series renderer
* @param yAxisValue the y axis value in pixels
* @param seriesIndex the series index
* @param startIndex the start index of the rendering points
*/
protected void drawPoints(Canvas canvas, Paint paint, List<Float> pointsList, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) {
if (isRenderPoints(seriesRenderer)) {
ScatterChart pointsChart = getPointsChart();
if (pointsChart != null) {
int length = (int) mPathMeasure.getLength();
int pointsLength = pointsList.size();
float[] coords = new float[2];
for (int i = 0; i < length; i++) {
mPathMeasure.getPosTan(i, coords, null);
double prevDiff = Double.MAX_VALUE;
boolean ok = true;
for (int j = 0; j < pointsLength && ok; j += 2) {
double diff = Math.abs(pointsList.get(j) - coords[0]);
if (diff < 1) {
pointsList.set(j + 1, coords[1]);
prevDiff = diff;
}
ok = prevDiff > diff;
}
}
pointsChart.drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
}
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class CubicLineChart method drawPath.
@Override
protected void drawPath(Canvas canvas, List<Float> points, Paint paint, boolean circular) {
GeneralPath p = new GeneralPath();
float x = points.get(0);
float y = points.get(1);
p.moveTo(x, y);
int length = points.size();
if (circular) {
length -= 4;
}
Point p1 = new Point();
Point p2 = new Point();
Point p3 = new Point();
for (int i = 0; i < length; i += 2) {
int nextIndex = i + 2 < length ? i + 2 : i;
int nextNextIndex = i + 4 < length ? i + 4 : nextIndex;
calc(points, p1, i, nextIndex, mSecondMultiplier);
p2.setX(points.get(nextIndex));
p2.setY(points.get(nextIndex + 1));
calc(points, p3, nextIndex, nextNextIndex, mFirstMultiplier);
// From last point, approaching x1/y1 and x2/y2 and ends up at x3/y3
p.curveTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY());
}
mPathMeasure = new PathMeasure(p, false);
if (circular) {
for (int i = length; i < length + 4; i += 2) {
p.lineTo(points.get(i), points.get(i + 1));
}
p.lineTo(points.get(0), points.get(1));
}
canvas.drawPath(p, paint);
}
Aggregations