use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class TestUtils method screenshotTest.
/**
* The screenshot test takes a screenshot of the screen and compares it to
* a prior screenshot, if both are 100% identical the test passes. If not
* the test fails.<br>
* If this is the first time the test is run then the screenshot is taken
* and saved under the given name in the devices storage. The test passes
* for this case but a warning is printed to the console. The name will have
* .png appended to it so it will be identified.<br>
* This test will only work on devices that support the ImageIO API with PNG
* file format.
*
* @param screenshotName the name to use for the storage, must be unique!
* @return true if the screenshots are identical or no prior screenshot exists
* or if the test can't be run on this device. False if a screenshot exists and
* it isn't 100% identical.
*/
public static boolean screenshotTest(String screenshotName) {
if (verbose) {
log("screenshotTest(" + screenshotName + ")");
}
try {
ImageIO io = ImageIO.getImageIO();
if (io == null || !io.isFormatSupported(ImageIO.FORMAT_PNG)) {
log("screenshot test skipped due to no image IO support for PNG format");
return true;
}
Image mute = Image.createImage(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayHeight());
Display.getInstance().getCurrent().paint(mute.getGraphics());
screenshotName = screenshotName + ".png";
if (Storage.getInstance().exists(screenshotName)) {
int[] rgba = mute.getRGBCached();
Image orig = Image.createImage(Storage.getInstance().createInputStream(screenshotName));
int[] origRgba = orig.getRGBCached();
orig = null;
for (int iter = 0; iter < rgba.length; iter++) {
if (rgba[iter] != origRgba[iter]) {
log("screenshots do not match at offset " + iter + " saving additional image under " + screenshotName + ".fail");
io.save(mute, Storage.getInstance().createOutputStream(screenshotName + ".fail"), ImageIO.FORMAT_PNG, 1);
return false;
}
}
} else {
io.save(mute, Storage.getInstance().createOutputStream(screenshotName), ImageIO.FORMAT_PNG, 1);
}
return true;
} catch (IOException err) {
log(err);
return false;
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class CSSBgPainter method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g, Rectangle rect) {
Style s = parent.getStyle();
int x = rect.getX();
int y = rect.getY();
int width = rect.getSize().getWidth();
int height = rect.getSize().getHeight();
if (width <= 0 || height <= 0) {
return;
}
g.setColor(s.getBgColor());
g.fillRect(x, y, width, height, s.getBgTransparency());
Image bgImage = s.getBgImage();
if (bgImage == null) {
return;
}
if (fixedX) {
if (scrollableParent == null) {
scrollableParent = getScrollableParent(parent);
}
if (scrollableParent != null) {
x += scrollableParent.getScrollX();
y += scrollableParent.getScrollY();
width = scrollableParent.getWidth();
height = scrollableParent.getHeight();
}
}
int iW = bgImage.getWidth();
int iH = bgImage.getHeight();
int offsetX = horizPos;
int offsetY = vertPos;
if (horizIsPercentage) {
offsetX = (width - iW) * offsetX / 100;
}
if (vertIsPercentage) {
offsetY = (height - iH) * offsetY / 100;
}
switch(s.getBackgroundType()) {
case 0:
g.drawImage(s.getBgImage(), x + offsetX, y + offsetY);
return;
case Style.BACKGROUND_IMAGE_TILE_BOTH:
for (int xPos = getTiledPosition(offsetX, iW); xPos <= width; xPos += iW) {
for (int yPos = getTiledPosition(offsetY, iH); yPos <= height; yPos += iH) {
g.drawImage(s.getBgImage(), x + xPos, y + yPos);
}
}
return;
case Style.BACKGROUND_IMAGE_TILE_HORIZONTAL:
for (int xPos = getTiledPosition(offsetX, iW); xPos <= width; xPos += iW) {
g.drawImage(s.getBgImage(), x + xPos, y + offsetY);
}
return;
case Style.BACKGROUND_IMAGE_TILE_VERTICAL:
for (int yPos = getTiledPosition(offsetY, iH); yPos <= height; yPos += iH) {
g.drawImage(s.getBgImage(), x + offsetX, y + yPos);
}
return;
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class TextField method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
// the native input will show the string.
if (useNativeTextInput && Display.getInstance().isNativeEditorVisible(this)) {
return;
}
UIManager manager = getUIManager();
manager.getLookAndFeel().drawTextField(g, this);
if (drawCursor && hasFocus() && isEditable()) {
manager.getLookAndFeel().drawTextFieldCursor(g, this);
}
paintHint(g);
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class CommonTransitions method paintAlpha.
private void paintAlpha(Graphics graphics) {
Component src = getSource();
int w = src.getWidth();
int h = src.getHeight();
int position = this.position;
if (position > 255) {
position = 255;
} else {
if (position < 0) {
position = 0;
}
}
// for slow mutable images
if (buffer == null) {
Component dest = getDestination();
Component srcCmp = src;
Component destCmp = dest;
int alpha = position;
if (src instanceof Dialog && dest instanceof Form) {
srcCmp = dest;
destCmp = src;
alpha = 255 - position;
}
paint(graphics, srcCmp, 0, 0);
destCmp.setX(srcCmp.getX());
destCmp.setY(srcCmp.getY());
destCmp.setWidth(srcCmp.getWidth());
destCmp.setHeight(srcCmp.getHeight());
graphics.setAlpha(alpha);
paint(graphics, destCmp, 0, 0);
graphics.setAlpha(255);
return;
}
// this will always be invoked on the EDT so there is no race condition risk
if (rgbBuffer != null || secondaryBuffer != null) {
if (secondaryBuffer != null) {
Component dest = getDestination();
int x = dest.getAbsoluteX();
int y = dest.getAbsoluteY();
graphics.drawImage(buffer, x, y);
graphics.setAlpha(position);
graphics.drawImage(secondaryBuffer, x, y);
graphics.setAlpha(0xff);
} else {
int alpha = position << 24;
int[] bufferArray = rgbBuffer.getRGB();
int size = bufferArray.length;
for (int iter = 0; iter < size; iter++) {
bufferArray[iter] = ((bufferArray[iter] & 0xFFFFFF) | alpha);
}
Component dest = getDestination();
int x = dest.getAbsoluteX();
int y = dest.getAbsoluteY();
graphics.drawImage(buffer, x, y);
graphics.drawImage(rgbBuffer, x, y);
}
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class CommonTransitions method paint.
/**
* {@inheritDoc}
*/
public void paint(Graphics g) {
try {
switch(transitionType) {
case TYPE_FAST_SLIDE:
case TYPE_SLIDE:
// if this is an up or down slide
if (slideType == SLIDE_HORIZONTAL) {
paintSlideAtPosition(g, position, 0);
} else {
paintSlideAtPosition(g, 0, position);
}
return;
case TYPE_UNCOVER:
int p = motion.getDestinationValue() - position;
if (slideType == SLIDE_HORIZONTAL) {
paintCoverAtPosition(g, p, 0);
} else {
paintCoverAtPosition(g, 0, p);
}
return;
case TYPE_COVER:
if (slideType == SLIDE_HORIZONTAL) {
paintCoverAtPosition(g, position, 0);
} else {
paintCoverAtPosition(g, 0, position);
}
return;
case TYPE_FADE:
paintAlpha(g);
return;
case TYPE_TIMELINE:
Object mask = timeline.createMask();
paint(g, getSource(), 0, 0);
g.drawImage(buffer.applyMask(mask), 0, 0);
return;
case TYPE_SLIDE_AND_FADE:
{
Form sourceForm = (Form) getSource();
Form destForm = (Form) getDestination();
int alpha = position;
int slidePos = motion2.getValue();
int clipX = g.getClipX();
int clipY = g.getClipY();
int clipW = g.getClipWidth();
int clipH = g.getClipHeight();
if (clipW <= 0 || clipH <= 0) {
return;
}
g.translate(0, sourceForm.getTitleArea().getHeight());
Container sourcePane = ((Form) getSource()).getContentPane();
Container destPane = ((Form) getDestination()).getContentPane();
boolean dir = forward;
if (sourceForm != null && sourceForm.getUIManager().getLookAndFeel().isRTL()) {
dir = !dir;
}
if (dir) {
g.translate(slidePos, 0);
paint(g, sourcePane, -sourcePane.getAbsoluteX() - sourcePane.getScrollX(), -sourcePane.getAbsoluteY() - sourcePane.getScrollY(), true);
g.translate(-destPane.getWidth(), 0);
paint(g, destPane, -destPane.getAbsoluteX() - destPane.getScrollX(), -destPane.getAbsoluteY() - destPane.getScrollY(), true);
g.translate(destPane.getWidth() - slidePos, 0);
} else {
g.translate(-slidePos, 0);
paint(g, sourcePane, -sourcePane.getAbsoluteX() - sourcePane.getScrollX(), -sourcePane.getAbsoluteY() - sourcePane.getScrollY(), true);
g.translate(destPane.getWidth(), 0);
paint(g, destPane, -destPane.getAbsoluteX() - destPane.getScrollX(), -destPane.getAbsoluteY() - destPane.getScrollY(), true);
g.translate(slidePos - destPane.getWidth(), 0);
}
g.translate(0, -sourceForm.getTitleArea().getHeight());
g.setClip(clipX, clipY, clipW, clipH);
sourceForm.getTitleArea().paintComponentBackground(g);
paintShiftFadeHierarchy(sourceForm.getTitleArea(), 255 - alpha, g, false);
paintShiftFadeHierarchy(destForm.getTitleArea(), alpha, g, true);
return;
}
case TYPE_PULSATE_DIALOG:
paint(g, getSource(), 0, 0);
int alpha = g.getAlpha();
if (motion2 != null) {
g.setAlpha(motion2.getValue());
}
Component c = getDialogParent(getDestination());
float ratio = ((float) position) / 1000.0f;
if (g.isAffineSupported()) {
g.scale(ratio, ratio);
int w = (int) (originalWidth * ratio);
int h = (int) (originalHeight * ratio);
c.setX(originalX + ((originalWidth - w) / 2));
c.setY(originalY + ((originalHeight - h) / 2));
int currentDlgX = getDialogParent(getDestination()).getX();
int currentDlgY = getDialogParent(getDestination()).getY();
g.drawImage(buffer, currentDlgX, currentDlgY);
// paint(g, c, 0, 0);
g.resetAffine();
} else {
c.setWidth((int) (originalWidth * ratio));
c.setHeight((int) (originalHeight * ratio));
c.setX(originalX + ((originalWidth - c.getWidth()) / 2));
c.setY(originalY + ((originalHeight - c.getHeight()) / 2));
paint(g, c, 0, 0);
}
g.setAlpha(alpha);
return;
}
} catch (Throwable t) {
Log.p("An exception occurred during transition paint this might be valid in case of a resize in the middle of a transition");
Log.e(t);
}
}
Aggregations