use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class CodenameOneImplementation method paintDirty.
/**
* Invoked by the EDT to paint the dirty regions
*/
public void paintDirty() {
int size = 0;
synchronized (displayLock) {
size = paintQueueFill;
Animation[] array = paintQueue;
paintQueue = paintQueueTemp;
paintQueueTemp = array;
paintQueueFill = 0;
}
if (size > 0) {
Graphics wrapper = getCodenameOneGraphics();
int dwidth = getDisplayWidth();
int dheight = getDisplayHeight();
int topX = dwidth;
int topY = dheight;
int bottomX = 0;
int bottomY = 0;
for (int iter = 0; iter < size; iter++) {
Animation ani = paintQueueTemp[iter];
// might happen due to paint queue removal
if (ani == null) {
continue;
}
paintQueueTemp[iter] = null;
wrapper.translate(-wrapper.getTranslateX(), -wrapper.getTranslateY());
wrapper.setClip(0, 0, dwidth, dheight);
if (ani instanceof Component) {
Component cmp = (Component) ani;
Rectangle dirty = cmp.getDirtyRegion();
if (dirty != null) {
Dimension d = dirty.getSize();
wrapper.setClip(dirty.getX(), dirty.getY(), d.getWidth(), d.getHeight());
cmp.setDirtyRegion(null);
}
cmp.paintComponent(wrapper);
getPaintableBounds(cmp, paintDirtyTmpRect);
int cmpAbsX = paintDirtyTmpRect.getX();
topX = Math.min(cmpAbsX, topX);
bottomX = Math.max(cmpAbsX + paintDirtyTmpRect.getWidth(), bottomX);
int cmpAbsY = paintDirtyTmpRect.getY();
topY = Math.min(cmpAbsY, topY);
bottomY = Math.max(cmpAbsY + paintDirtyTmpRect.getHeight(), bottomY);
} else {
bottomX = dwidth;
bottomY = dheight;
topX = 0;
topY = 0;
ani.paint(wrapper);
}
}
paintOverlay(wrapper);
// Log.p("Flushing graphics : "+topX+","+topY+","+bottomX+","+bottomY);
flushGraphics(topX, topY, bottomX - topX, bottomY - topY);
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class CodenameOneImplementation method repaint.
/**
* Invoked to add an element to the paintQueue
*
* @param cmp component or animation to push into the paint queue
*/
public void repaint(Animation cmp) {
synchronized (displayLock) {
for (int iter = 0; iter < paintQueueFill; iter++) {
Animation ani = paintQueue[iter];
if (ani == cmp) {
return;
}
// no need to paint a Component if one of its parent is already in the queue
if (ani instanceof Container && cmp instanceof Component) {
Component parent = ((Component) cmp).getParent();
while (parent != null) {
if (parent == ani) {
return;
}
parent = parent.getParent();
}
}
}
// overcrowding the queue don't try to grow the array!
if (paintQueueFill >= paintQueue.length) {
System.out.println("Warning paint queue size exceeded, please watch the amount of repaint calls");
return;
}
paintQueue[paintQueueFill] = cmp;
paintQueueFill++;
displayLock.notify();
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class OnOffSwitch method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
if (iosMode) {
int switchButtonPadInt = UIManager.getInstance().getThemeConstant("switchButtonPadInt", 16);
if (Display.getInstance().getDisplayWidth() > 480) {
// is retina
switchButtonPadInt *= 2;
}
Style s = getStyle();
int x = getX() + s.getPaddingLeftNoRTL();
int y = getY() + s.getPaddingTop();
if (!value) {
if (deltaX > 0) {
dragged = false;
} else {
if (deltaX < -switchOnImage.getWidth()) {
deltaX = -switchOnImage.getWidth();
}
}
} else {
if (deltaX < 0) {
dragged = false;
} else {
if (deltaX > switchOnImage.getWidth()) {
deltaX = switchOnImage.getWidth();
}
}
}
if (dragged) {
int onX;
int offX;
if (value) {
onX = x - deltaX;
offX = x - deltaX + switchOnImage.getWidth() - 2 * switchButtonPadInt;
} else {
onX = x - deltaX - switchOnImage.getWidth() + 2 * switchButtonPadInt;
offX = x - deltaX;
}
switchButtonPadInt /= 2;
int oldClipX = g.getClipX();
int oldClipY = g.getClipY();
int oldClipW = g.getClipWidth();
int oldClipH = g.getClipHeight();
g.clipRect(getX(), getY(), switchMaskImage.getWidth(), switchMaskImage.getHeight());
g.drawImage(switchOnImage, onX, y);
g.drawImage(switchOffImage, offX, y);
int strWidth = s.getFont().stringWidth(on);
int sX = onX + switchMaskImage.getWidth() / 2 - strWidth / 2 - switchButtonPadInt;
int sY = y + switchMaskImage.getHeight() / 2 - s.getFont().getHeight() / 2;
g.setFont(s.getFont());
g.setColor(0xffffff);
if (!noTextMode) {
g.drawString(on, sX, sY, Style.TEXT_DECORATION_3D);
}
strWidth = s.getFont().stringWidth(off);
g.setColor(0x333333);
sX = offX + switchMaskImage.getWidth() / 2 - strWidth / 2 + switchButtonPadInt;
if (!noTextMode) {
g.drawString(off, sX, sY);
}
g.setClip(oldClipX, oldClipY, oldClipW, oldClipH);
} else {
String str;
switchButtonPadInt /= 2;
if (value) {
g.drawImage(switchOnImage, x, y);
str = on;
g.setColor(0xffffff);
switchButtonPadInt *= -1;
} else {
g.drawImage(switchOffImage, x, y);
str = off;
g.setColor(0x333333);
}
int strWidth = s.getFont().stringWidth(str);
int sX = x + switchMaskImage.getWidth() / 2 - strWidth / 2 + switchButtonPadInt;
int sY = y + switchMaskImage.getHeight() / 2 - s.getFont().getHeight() / 2;
g.setFont(s.getFont());
if (!noTextMode) {
g.drawString(str, sX, sY);
}
}
g.drawImage(switchMaskImage, x, y);
} else {
super.paint(g);
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class RangeBarChart method drawSeries.
/**
* The graphical representation of a series.
*
* @param canvas the canvas to paint to
* @param paint the paint to be used for drawing
* @param points the array of points to be used for drawing the series
* @param seriesRenderer the series renderer
* @param yAxisValue the minimum value of the y axis
* @param seriesIndex the index of the series currently being drawn
* @param startIndex the start index of the rendering points
*/
@Override
public void drawSeries(Canvas canvas, Paint paint, List<Float> points, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, int startIndex) {
int seriesNr = mDataset.getSeriesCount();
int length = points.size();
paint.setColor(seriesRenderer.getColor());
paint.setStyle(Style.FILL);
float halfDiffX = getHalfDiffX(points, length, seriesNr);
int start = 0;
if (startIndex > 0) {
start = 2;
}
for (int i = start; i < length; i += 4) {
if (points.size() > i + 3) {
float xMin = points.get(i);
float yMin = points.get(i + 1);
// xMin = xMax
float xMax = points.get(i + 2);
float yMax = points.get(i + 3);
drawBar(canvas, xMin, yMin, xMax, yMax, halfDiffX, seriesNr, seriesIndex, paint);
}
}
paint.setColor(seriesRenderer.getColor());
}
use of com.codename1.charts.compat.Paint 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