use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class BubbleTransition method initTransition.
@Override
public void initTransition() {
Component source = getSource();
Component destination = getDestination();
int w = source.getWidth();
int h = source.getHeight();
// improper replace() calls, this may still be valid and shouldn't fail
if (w <= 0 || h <= 0) {
return;
}
Form sourceForm = source.getComponentForm();
originSrc = findByName(sourceForm, componentName);
Form destForm = destination.getComponentForm();
originDest = findByName(destForm, componentName);
Display d = Display.getInstance();
if (getDestination() instanceof Dialog) {
Dialog dlg = (Dialog) destination;
// transparent image!
destBuffer = Image.createImage(Math.min(d.getDisplayWidth(), getDialogParent(dlg).getWidth()), Math.min(d.getDisplayHeight(), dlg.getContentPane().getParent().getHeight()), 0);
Graphics g = destBuffer.getGraphics();
Style stl = dlg.getDialogComponent().getStyle();
byte bgt = stl.getBgTransparency();
stl.setBgTransparency(0xff);
drawDialogCmp(destBuffer.getGraphics(), dlg);
stl.setBgTransparency(bgt & 0xff, true);
} else if (getSource() instanceof Dialog) {
Dialog dlg = (Dialog) source;
// transparent image!
destBuffer = Image.createImage(Math.min(d.getDisplayWidth(), getDialogParent(dlg).getWidth()), Math.min(d.getDisplayHeight(), dlg.getContentPane().getParent().getHeight()), 0);
Graphics g = destBuffer.getGraphics();
Style stl = dlg.getDialogComponent().getStyle();
byte bgt = stl.getBgTransparency();
stl.setBgTransparency(0xff);
drawDialogCmp(destBuffer.getGraphics(), dlg);
stl.setBgTransparency(bgt & 0xff, true);
} else {
if (originDest != null) {
destBuffer = createMutableImage(source.getWidth(), source.getHeight());
paint(destBuffer.getGraphics(), source, -source.getAbsoluteX(), -source.getAbsoluteY());
} else {
destBuffer = createMutableImage(destination.getWidth(), destination.getHeight());
paint(destBuffer.getGraphics(), destination, -destination.getAbsoluteX(), -destination.getAbsoluteY());
}
}
Component dest = getDestination();
if (dest instanceof Dialog) {
dest = getDialogParent(dest);
}
Component src = getSource();
if (src instanceof Dialog) {
src = getDialogParent(src);
}
if (originSrc != null) {
locMotionX = Motion.createLinearMotion(originSrc.getAbsoluteX() + originSrc.getWidth() / 2 - dest.getWidth() / 2, dest.getAbsoluteX(), duration);
locMotionX.start();
locMotionY = Motion.createLinearMotion(originSrc.getAbsoluteY() + originSrc.getHeight() / 2 - dest.getHeight() / 2, dest.getAbsoluteY(), duration);
locMotionY.start();
clipMotion = Motion.createLinearMotion(Math.min(originSrc.getWidth(), originSrc.getHeight()), Math.max(dest.getWidth(), dest.getHeight()) * 3 / 2, duration);
} else {
if (originDest != null) {
locMotionX = Motion.createLinearMotion(src.getAbsoluteX(), originDest.getAbsoluteX() + originDest.getWidth() / 2 - src.getWidth() / 2, duration);
locMotionX.start();
locMotionY = Motion.createLinearMotion(src.getAbsoluteY(), originDest.getAbsoluteY() + originDest.getHeight() / 2 - src.getHeight() / 2, duration);
locMotionY.start();
clipMotion = Motion.createLinearMotion(Math.max(src.getWidth(), src.getHeight()) * 3 / 2, Math.min(originDest.getWidth(), originDest.getHeight()), duration);
} else {
x = dest.getAbsoluteX();
y = dest.getAbsoluteY();
clipMotion = Motion.createLinearMotion(0, Math.max(dest.getWidth(), dest.getHeight()) * 3 / 2, duration);
}
}
clipMotion.start();
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class BubbleTransition method paint.
@Override
public void paint(Graphics g) {
Component source = getSource();
Component dest = getDestination();
Component srcCmp = source;
Component destCmp = dest;
if ((source instanceof Dialog && dest instanceof Form) || originDest != null) {
srcCmp = dest;
destCmp = source;
}
paint(g, srcCmp, -srcCmp.getAbsoluteX(), -srcCmp.getAbsoluteY(), true);
int[] clip = g.getClip();
if (destCmp instanceof Dialog) {
destCmp = getDialogParent(destCmp);
}
if (roundBubble && g.isShapeClipSupported()) {
GeneralPath p = getBubbleShape();
p.reset();
p.arc(x + destCmp.getWidth() / 2 - clipSize / 2, y + destCmp.getHeight() / 2 - clipSize / 2, clipSize, clipSize, 0, Math.toRadians(360));
g.setClip(p);
} else {
g.setClip(x + destCmp.getWidth() / 2 - clipSize / 2, y + destCmp.getHeight() / 2 - clipSize / 2, clipSize, clipSize);
}
g.drawImage(destBuffer, x, y);
g.setClip(clip);
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class CommonTransitions method paint.
private void paint(Graphics g, Component cmp, int x, int y, boolean background) {
boolean b = cmp.isVisible();
cmp.setVisible(true);
int cx = g.getClipX();
int cy = g.getClipY();
int cw = g.getClipWidth();
int ch = g.getClipHeight();
if (cmp instanceof Dialog) {
if (transitionType == TYPE_FADE && Display.getInstance().areMutableImagesFast()) {
cmp.paintComponent(g, background);
return;
}
if (!(getSource() instanceof Dialog && getDestination() instanceof Dialog && cmp == getDestination())) {
Painter p = cmp.getStyle().getBgPainter();
cmp.getStyle().setBgPainter(null);
g.translate(x, y);
Dialog dlg = (Dialog) cmp;
g.setClip(0, 0, cmp.getWidth(), cmp.getHeight());
getDialogParent(dlg).paintComponent(g, false);
g.translate(-x, -y);
if (drawDialogMenu && dlg.getCommandCount() > 0) {
Component menuBar = dlg.getSoftButton(0).getParent();
if (menuBar != null) {
g.setClip(0, 0, cmp.getWidth(), cmp.getHeight());
menuBar.paintComponent(g, false);
}
}
g.setClip(cx, cy, cw, ch);
cmp.getStyle().setBgPainter(p);
} else {
cmp.paintComponent(g, background);
}
return;
}
// g.clipRect(cmp.getAbsoluteX(), cmp.getAbsoluteY(), cmp.getWidth(), cmp.getHeight());
g.translate(x, y);
// g.clipRect(cmp.getAbsoluteX(), cmp.getAbsoluteY(), cmp.getWidth(), cmp.getHeight());
cmp.paintComponent(g, background);
g.translate(-x, -y);
g.setClip(cx, cy, cw, ch);
cmp.setVisible(b);
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class CommonTransitions method paintCoverAtPosition.
private void paintCoverAtPosition(Graphics g, int slideX, int slideY) {
Component source = getSource();
// if this is the first form we can't do a slide transition since we have no source form
if (source == null) {
return;
}
Component dest = getDestination();
int w = source.getWidth();
int h = source.getHeight();
if (slideType == SLIDE_HORIZONTAL) {
h = 0;
} else {
w = 0;
}
boolean dir = forward;
if (dest != null && dest.getUIManager().getLookAndFeel().isRTL()) {
dir = !dir;
}
if (dir) {
w = -w;
h = -h;
} else {
slideX = -slideX;
slideY = -slideY;
}
g.setClip(source.getAbsoluteX() + source.getScrollX(), source.getAbsoluteY() + source.getScrollY(), source.getWidth(), source.getHeight());
// dialog animation is slightly different...
if (source instanceof Dialog) {
if (buffer != null) {
g.drawImage(buffer, 0, 0);
} else {
paint(g, dest, 0, 0);
}
paint(g, source, -slideX, -slideY);
return;
}
if (dest instanceof Dialog) {
if (buffer != null) {
g.drawImage(buffer, 0, 0);
} else {
paint(g, source, 0, 0);
}
paint(g, dest, -slideX - w, -slideY - h);
return;
}
if (transitionType == TYPE_UNCOVER) {
paint(g, dest, 0, 0);
if (source.getParent() != null || buffer == null) {
source.paintBackgrounds(g);
paint(g, source, slideX + w, slideY + h);
} else {
g.drawImage(buffer, slideX + w, slideY + h);
}
} else {
if (source.getParent() != null || buffer == null) {
source.paintBackgrounds(g);
paint(g, source, 0, 0);
} else {
g.drawImage(buffer, 0, 0);
}
paint(g, dest, slideX + w, slideY + h);
}
}
use of com.codename1.charts.compat.Paint in project CodenameOne by codenameone.
the class SideMenuBar method setMenuGlassPane.
private void setMenuGlassPane(Form m, final String placement) {
boolean isRTLValue = m.isRTL();
if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
isRTLValue = !isRTLValue;
}
final boolean isRTL = isRTLValue;
final Image image = rightPanel.getStyle().getBgImage();
UIManager uim = rightPanel.getUIManager();
Image sh = (Image) uim.getThemeImageConstant("sideMenuShadowImage");
if (sh == null) {
sh = Resources.getSystemResource().getImage("sidemenu-shadow.png");
}
if (isRTL) {
sh = sh.flipHorizontally(true);
}
final Image shadow = sh;
if (m.getGlassPane() == null) {
m.setGlassPane(new Painter() {
Image img = image;
public void paint(Graphics g, Rectangle rect) {
if (img == null) {
// will happen for areMutableImagesFast returning false on iOS and Windows Phone
Component c = (Component) rightPanel.getClientProperty("$parent");
// not sure what is happening here
if (c == null) {
return;
}
boolean b = c.isVisible();
c.setVisible(true);
if (isRTL) {
int x = Math.max(draggedX, rightPanel.getWidth()) - c.getWidth();
g.translate(x, 0);
Container.sidemenuBarTranslation = x;
if (shadow != null) {
g.tileImage(shadow, x + c.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
c.paintComponent(g, true);
Container.sidemenuBarTranslation = 0;
g.translate(-x, 0);
} else {
int x = Math.min(draggedX, rightPanel.getX());
g.translate(x, 0);
Container.sidemenuBarTranslation = x;
if (shadow != null) {
g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
c.paintComponent(g, true);
Container.sidemenuBarTranslation = 0;
g.translate(-x, 0);
}
c.setVisible(b);
} else {
if (Display.getInstance().areMutableImagesFast()) {
if (img.getHeight() != Display.getInstance().getDisplayHeight()) {
img = updateRightPanelBgImage(placement, parent);
}
}
if (isRTL) {
int x = Math.max(draggedX, rightPanel.getWidth()) - img.getWidth();
if (shadow != null) {
g.tileImage(shadow, x + img.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
g.drawImage(img, x, 0);
} else {
int x = Math.min(draggedX, rightPanel.getX());
if (shadow != null) {
g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
}
g.drawImage(img, x, 0);
}
}
}
});
}
}
Aggregations