use of com.codename1.media.Media 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.media.Media in project CodenameOne by codenameone.
the class GameCanvasImplementation method playNativeBuiltinSound.
/**
* @inheritDoc
*/
protected void playNativeBuiltinSound(Object data) {
try {
try {
Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mpeg", null);
m.play();
} catch (Exception err) {
// some simulators take issue with the audio/mpeg string but the mp3 string
// works fine
Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mp3", null);
m.play();
}
} catch (IOException ex) {
// not likely since the stream is a byte array input stream
ex.printStackTrace();
}
}
use of com.codename1.media.Media in project CodenameOne by codenameone.
the class BlackBerryImplementation method playNativeBuiltinSound.
/**
* @inheritDoc
*/
protected void playNativeBuiltinSound(Object data) {
try {
try {
Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mpeg", null);
m.play();
} catch (Exception err) {
// some simulators take issue with the audio/mpeg string but the mp3 string
// works fine
Media m = createMedia(new ByteArrayInputStream((byte[]) data), "audio/mp3", null);
m.play();
}
} catch (IOException ex) {
// not likely since the stream is a byte array input stream
ex.printStackTrace();
}
}
Aggregations