use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class AndroidAsyncView method flushGraphics.
@Override
public void flushGraphics(Rect rect) {
// Log.d(Display.getInstance().getProperty("AppName", "CodenameOne"), "Flush graphics invoked with pending: " + pendingRenderingOperations.size() + " and current " + renderingOperations.size());
// we might have pending entries in the rendering queue
int counter = 0;
while (!renderingOperations.isEmpty()) {
try {
synchronized (RENDERING_OPERATIONS_LOCK) {
RENDERING_OPERATIONS_LOCK.wait(5);
}
// don't let the EDT die here
counter++;
if (counter > 10) {
// Log.d(Display.getInstance().getProperty("AppName", "CodenameOne"), "Flush graphics timed out!!!");
return;
}
} catch (InterruptedException err) {
}
}
ArrayList<AsyncOp> tmp = renderingOperations;
renderingOperations = pendingRenderingOperations;
pendingRenderingOperations = tmp;
try {
for (AsyncOp o : renderingOperations) {
o.prepare();
}
} catch (java.util.ConcurrentModificationException ex) {
// This is a race condition that sometimes occurs
// Rather than add synchronized here (which may have performance implications)
// we'll just "give up" and issue a repaint.
Log.p("NOTICE: Hit concurrent modification race condition in flushGraphics. Skipping flush, and issuing another repaint.");
Log.e(ex);
Display.getInstance().callSerially(new Runnable() {
@Override
public void run() {
Form f = Display.getInstance().getCurrent();
if (f != null) {
f.repaint();
}
}
});
return;
}
int children = getChildCount();
if (children > 0) {
com.codename1.ui.Form c = Display.getInstance().getCurrent();
for (int iter = 0; iter < children; iter++) {
final View v = getChildAt(iter);
final AndroidAsyncView.LayoutParams lp = (AndroidAsyncView.LayoutParams) v.getLayoutParams();
// if (lp != null && c == lp.pc.getComponentForm()) {
// v.postInvalidate();
/*if(lp.dirty) {
lp.dirty = false;
v.post(new Runnable() {
@Override
public void run() {
if (v.getVisibility() == View.INVISIBLE) {
v.setVisibility(View.VISIBLE);
}
v.requestLayout();
}
});
} else {
if (v.getVisibility() == View.INVISIBLE) {
v.post(new Runnable() {
@Override
public void run() {
v.setVisibility(View.VISIBLE);
}
});
}
}*/
// } else {
/*if(v.getVisibility() == View.VISIBLE) {
v.post(new Runnable() {
@Override
public void run() {
v.setVisibility(View.INVISIBLE);
}
});
}*/
// }
}
}
if (rect == null) {
postInvalidate();
} else {
postInvalidate(rect.left, rect.top, rect.right, rect.bottom);
}
graphics.setClip(0, 0, cn1View.width, cn1View.height);
graphics.setAlpha(255);
graphics.setColor(0);
}
use of com.codename1.ui.Graphics 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.ui.Graphics in project CodenameOne by codenameone.
the class Component method paintRippleOverlay.
/**
* Invoked to draw the ripple effect overlay in Android where the finger of the user causes a growing
* circular overlay over time. This method is invoked after paintBackground and is invoked repeatedly until
* the users finger is removed, it will only be invoked if isRippleEffect returns true
* @param g the graphics object for the component clipped to the background
* @param x the x position of the touch
* @param y the y position of the touch
* @param position a value between 0 and 1000 with 0 indicating the beginning of the ripple effect and 1000
* indicating the completion of it
*/
public void paintRippleOverlay(Graphics g, int x, int y, int position) {
int a = g.getAlpha();
int c = g.getColor();
g.setAlpha(20);
g.setColor(0);
if (position == 1000) {
g.fillRect(getX(), getY(), getWidth(), getHeight());
} else {
float ratio = ((float) position) / 1000.0f;
int w = (int) (((float) getWidth()) * ratio);
w = Math.max(w, Display.INSTANCE.convertToPixels(4));
g.fillArc(x - getParent().getAbsoluteX() - w / 2, y - getParent().getAbsoluteY() - w / 2, w, w, 0, 360);
}
g.setAlpha(a);
g.setColor(c);
}
use of com.codename1.ui.Graphics 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.ui.Graphics in project CodenameOne by codenameone.
the class Component method paintIntersectingComponentsAbove.
private void paintIntersectingComponentsAbove(Graphics g) {
Container parent = getParent();
Component component = this;
int tx = g.getTranslateX();
int ty = g.getTranslateY();
g.translate(-tx, -ty);
while (parent != null) {
g.translate(parent.getAbsoluteX() + parent.getScrollX(), parent.getAbsoluteY() + parent.getScrollY());
parent.paintIntersecting(g, component, getAbsoluteX() + getScrollX(), getAbsoluteY() + getScrollY(), getWidth(), getHeight(), true);
g.translate(-parent.getAbsoluteX() - parent.getScrollX(), -parent.getAbsoluteY() - parent.getScrollY());
component = parent;
parent = parent.getParent();
}
g.translate(tx, ty);
}
Aggregations