use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class AbstractChart method drawLegend.
/**
* Draws the chart legend.
*
* @param canvas the canvas to paint to
* @param renderer the series renderer
* @param titles the titles to go to the legend
* @param left the left X value of the area to draw to
* @param right the right X value of the area to draw to
* @param y the y value of the area to draw to
* @param width the width of the area to draw to
* @param height the height of the area to draw to
* @param legendSize the legend size
* @param paint the paint to be used for drawing
* @param calculate if only calculating the legend size
*
* @return the legend height
*/
protected int drawLegend(Canvas canvas, DefaultRenderer renderer, String[] titles, int left, int right, int y, int width, int height, int legendSize, Paint paint, boolean calculate) {
float size = 32;
if (renderer.isShowLegend()) {
float currentX = left;
float currentY = y + height - legendSize + size;
paint.setTextAlign(Component.LEFT);
paint.setTextSize(renderer.getLegendTextSize());
int sLength = Math.min(titles.length, renderer.getSeriesRendererCount());
for (int i = 0; i < sLength; i++) {
SimpleSeriesRenderer r = renderer.getSeriesRendererAt(i);
final float lineSize = getLegendShapeWidth(i);
if (r.isShowLegendItem()) {
String text = titles[i];
if (titles.length == renderer.getSeriesRendererCount()) {
paint.setColor(r.getColor());
} else {
paint.setColor(ColorUtil.LTGRAY);
}
float[] widths = new float[text.length()];
paint.getTextWidths(text, widths);
float sum = 0;
for (float value : widths) {
sum += value;
}
float extraSize = lineSize + 10 + sum;
float currentWidth = currentX + extraSize;
if (i > 0 && getExceed(currentWidth, renderer, right, width)) {
currentX = left;
currentY += renderer.getLegendTextSize();
size += renderer.getLegendTextSize();
currentWidth = currentX + extraSize;
}
if (getExceed(currentWidth, renderer, right, width)) {
float maxWidth = right - currentX - lineSize - 10;
if (isVertical(renderer)) {
maxWidth = width - currentX - lineSize - 10;
}
int nr = paint.breakText(text, true, maxWidth, widths);
text = text.substring(0, nr) + "...";
}
if (!calculate) {
drawLegendShape(canvas, r, currentX, currentY, i, paint);
drawString(canvas, text, currentX + lineSize + 5, currentY + 5, paint);
}
currentX += extraSize;
}
}
}
return Math.round(size + renderer.getLegendTextSize());
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class ChartUtil method paintChart.
/**
* Draws the given chart onto the given graphics
*
* @param g the graphics object
* @param chart the chart object
* @param bounds the bounds in which the chart should be drawn within the graphics
* @param absX
* @param absY
*/
public void paintChart(Graphics g, AbstractChart chart, Rectangle bounds, int absX, int absY) {
c.g = g;
c.bounds = bounds;
c.absoluteX = absX;
c.absoluteY = absY;
chart.draw(c, bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), new Paint());
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class Canvas method applyPaint.
private void applyPaint(Paint paint, boolean forText) {
// Log.p("Applyingn paint : "+paint);
g.setColor(paint.getColor());
int alpha = ColorUtil.alpha(paint.getColor());
g.setAlpha(alpha);
if (forText) {
Font typeFace = paint.getTypeface();
if (typeFace != null) {
if (typeFace.getSize() != (int) paint.getTextSize()) {
typeFace = typeFace.derive(paint.getTextSize(), Font.STYLE_PLAIN);
}
g.setFont(typeFace);
} else {
g.setFont(null);
}
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class Component method paintComponent.
/**
* <p>Paints this component as a root by going to all the parent components and
* setting the absolute translation based on coordinates and scroll status.
* Restores translation when the painting is finished.<br>
* One of the uses of this method is to create a "screenshot" as is demonstrated in the code below
* that creates an image for sharing on social media</p>
* <script src="https://gist.github.com/codenameone/6bf5e68b329ae59a25e3.js"></script>
*
* @param g the graphics to paint this Component on
* @param background if true paints all parents background
*/
public final void paintComponent(Graphics g, boolean background) {
int clipX = g.getClipX();
int clipY = g.getClipY();
int clipW = g.getClipWidth();
int clipH = g.getClipHeight();
// g.pushClip();
Container parent = getParent();
int translateX = 0;
int translateY = 0;
while (parent != null) {
translateX += parent.getX();
translateY += parent.getY();
// if (parent.isScrollable()) {
if (parent.isScrollableX()) {
translateX -= parent.getScrollX();
}
if (parent.isScrollableY()) {
translateY -= parent.getScrollY();
}
// since scrollability can translate everything... we should clip based on the
// current scroll
int parentX = parent.getAbsoluteX() + parent.getScrollX();
if (isRTL()) {
parentX += parent.getSideGap();
}
g.clipRect(parentX, parent.getAbsoluteY() + parent.getScrollY(), parent.getWidth() - parent.getSideGap(), parent.getHeight() - parent.getBottomGap());
parent = parent.getParent();
}
g.clipRect(translateX + getX(), translateY + getY(), getWidth(), getHeight());
if (background) {
paintBackgrounds(g);
}
g.translate(translateX, translateY);
paintInternal(g);
g.translate(-translateX, -translateY);
paintGlassImpl(g);
g.setClip(clipX, clipY, clipW, clipH);
// g.popClip();
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class Component method paintBackgroundImpl.
private void paintBackgroundImpl(Graphics g) {
if (isBorderPainted()) {
Border b = getBorder();
if (b != null && b.isBackgroundPainter()) {
b.paintBorderBackground(g, this);
paintRippleEffect(g);
return;
}
}
if (getStyle().getBgPainter() != null) {
getStyle().getBgPainter().paint(g, bounds);
}
paintBackground(g);
paintRippleEffect(g);
}
Aggregations