use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class ImageIO method save.
/**
* Saves an image object to the given format
*
* @param img the image object
* @param response resulting image output will be written to this stream
* @param format the format for the image either FORMAT_PNG or FORMAT_JPEG
* @param quality the quality for the resulting image output (applicable mostly for JPEG), a value between 0 and 1 notice that
* this isn't implemented in all platforms.
*/
public void save(Image img, OutputStream response, String format, float quality) throws IOException {
if (img instanceof EncodedImage) {
EncodedImage i = (EncodedImage) img;
save(new ByteArrayInputStream(i.getImageData()), response, format, i.getWidth(), i.getHeight(), quality);
} else {
if (img.getImage() == null) {
Image img2 = Image.createImage(img.getWidth(), img.getHeight(), 0);
Graphics g = img2.getGraphics();
g.drawImage(img, 0, 0);
saveImage(img2, response, format, quality);
} else {
saveImage(img, response, format, quality);
}
}
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class SwipeBackSupport method startBackTransition.
void startBackTransition(final Form currentForm, Form destination) {
final Transition t = destination.getTransitionOutAnimator().copy(true);
if (t instanceof CommonTransitions) {
Transition originalTransition = currentForm.getTransitionOutAnimator();
currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
Form blank = new Form() {
protected boolean shouldSendPointerReleaseToOtherForm() {
return true;
}
};
blank.addPointerDraggedListener(pointerDragged);
blank.addPointerReleasedListener(pointerReleased);
blank.addPointerPressedListener(pointerPressed);
blank.setTransitionInAnimator(CommonTransitions.createEmpty());
blank.setTransitionOutAnimator(CommonTransitions.createEmpty());
blank.show();
currentForm.setTransitionOutAnimator(originalTransition);
((CommonTransitions) t).setMotion(new LazyValue<Motion>() {
public Motion get(Object... args) {
return new ManualMotion(((Integer) args[0]).intValue(), ((Integer) args[1]).intValue(), ((Integer) args[2]).intValue());
}
});
t.init(currentForm, destination);
t.initTransition();
blank.setGlassPane(new Painter() {
public void paint(Graphics g, Rectangle rect) {
t.animate();
t.paint(g);
}
});
}
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class ArrowLinesLayer method paintSegment.
/**
* Paints arrows on each segment. arrowSegmentLength decides how many
* arrows will be on each segment.
* @param g
* @param segment
* @param tile
*/
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
super.paintSegment(g, segment, tile);
int pointsNo = segment.length;
for (int i = 1; i < pointsNo; i++) {
Coord start = segment[i - 1];
Coord end = segment[i];
Point s = tile.pointPosition(start);
Point e = tile.pointPosition(end);
int noOfSegments = calculateLength(s, e) / arrowSegmentLength;
if (noOfSegments == 0 && calculateLength(s, e) > minArrowSementLength) {
noOfSegments = 1;
}
for (int j = 1; j <= noOfSegments; j++) {
if (j == 1) {
double div = 1.0 / noOfSegments;
drawArrow(g, new Point(s.getX(), s.getY()), new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))));
} else if (j == noOfSegments) {
double div = (noOfSegments - 1) / (noOfSegments * 1.0);
drawArrow(g, new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))), new Point(e.getX(), e.getY()));
} else {
double div = ((j - 1) * 1.0) / noOfSegments;
double div2 = (j * 1.0) / noOfSegments;
drawArrow(g, new Point((int) (div * e.getX() + s.getX() * (1 - div)), (int) (div * e.getY() + s.getY() * (1 - div))), new Point((int) (div2 * e.getX() + s.getX() * (1 - div2)), (int) (div2 * e.getY() + s.getY() * (1 - div2))));
}
}
}
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class LinesLayer method paintSegment.
/**
* Paint a segment.
*
* @param g a Graphics Object to paint on
* @param segment array of Coord to draw a Line.
* @param tile
*/
protected void paintSegment(Graphics g, Coord[] segment, Tile tile) {
int pointsNo = segment.length;
for (int i = 1; i < pointsNo; i++) {
Coord start = (Coord) segment[i - 1];
Coord end = (Coord) segment[i];
Point s = tile.pointPosition(start);
Point e = tile.pointPosition(end);
g.drawLine(s.getX(), s.getY(), e.getX(), e.getY());
// lame & simple way to make line thicker
g.drawLine(s.getX() - 1, s.getY(), e.getX() - 1, e.getY());
g.drawLine(s.getX() + 1, s.getY(), e.getX() + 1, e.getY());
g.drawLine(s.getX(), s.getY() - 1, e.getX(), e.getY() - 1);
g.drawLine(s.getX(), s.getY() + 1, e.getX(), e.getY() + 1);
}
}
use of com.codename1.ui.Graphics in project CodenameOne by codenameone.
the class LayerWithZoomLevels method drawAttribution.
private void drawAttribution(Graphics g, String attribution) {
if (attribution == null) {
return;
}
g.setColor(0);
g.setFont(attributionFont);
Font f = g.getFont();
g.drawString(attribution, getWidth() - f.stringWidth(attribution) - 2, getHeight() - f.getHeight() - 2);
}
Aggregations