use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class CommonTransitions method paintShiftFadeHierarchy.
private void paintShiftFadeHierarchy(Container c, int alpha, Graphics g, boolean incoming) {
int componentCount = c.getComponentCount();
for (int iter = 0; iter < componentCount; iter++) {
Component current = c.getComponentAt(iter);
if (current instanceof Container) {
paintShiftFadeHierarchy((Container) current, alpha, g, incoming);
continue;
}
g.setAlpha(alpha);
Motion m = getComponentShiftMotion(current, incoming);
if (m != null) {
int tval = m.getValue();
g.translate(tval, 0);
current.paintComponent(g, false);
g.translate(-tval, 0);
}
g.setAlpha(255);
}
}
use of com.codename1.ui.Container 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);
}
}
use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class CommonTransitions method cleanup.
/**
* {@inheritDoc}
*/
public void cleanup() {
if (transitionType == TYPE_SLIDE_AND_FADE) {
Component c = getSource();
if (c instanceof Container) {
removeConstant((Container) c);
}
c = getDestination();
if (c instanceof Container) {
removeConstant((Container) c);
}
}
super.cleanup();
buffer = null;
rgbBuffer = null;
secondaryBuffer = null;
timeline = null;
}
use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class CommonTransitions method initTransition.
/**
* {@inheritDoc}
*/
public void initTransition() {
firstFinished = false;
if (transitionType == TYPE_EMPTY) {
return;
}
startTime = System.currentTimeMillis();
Component source = getSource();
Component destination = getDestination();
position = 0;
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;
}
// nothing to prepare in advance for a shift fade transition
if (transitionType == TYPE_SLIDE_AND_FADE) {
if (getSource() instanceof Form && getDestination() instanceof Form) {
motion = createMotion(100, 200, speed);
motion2 = createMotion(0, getDestination().getWidth(), speed);
motion.start();
motion2.start();
return;
}
transitionType = TYPE_SLIDE;
}
if (transitionType == TYPE_PULSATE_DIALOG) {
if (getDestination() instanceof Dialog) {
motion = createMotion(600, 1100, 150);
motion.start();
motion2 = createMotion(100, 255, 225);
motion2.start();
pulseState = 0;
Component c = getDialogParent(getDestination());
originalX = c.getX();
originalY = c.getY();
originalWidth = c.getWidth();
originalHeight = c.getHeight();
Display d = Display.getInstance();
Dialog dlg = (Dialog) destination;
// transparent image!
buffer = Image.createImage(Math.min(d.getDisplayWidth(), getDialogParent(dlg).getWidth()), Math.min(d.getDisplayHeight(), dlg.getContentPane().getParent().getHeight() + getDialogTitleHeight(dlg)), 0);
Graphics g = buffer.getGraphics();
Style stl = dlg.getDialogComponent().getStyle();
byte bgt = stl.getBgTransparency();
stl.setBgTransparency(0xff);
drawDialogCmp(buffer.getGraphics(), dlg);
stl.setBgTransparency(bgt & 0xff, true);
return;
}
transitionType = TYPE_EMPTY;
motion = createMotion(0, 0, 0);
pulseState = (byte) 3;
return;
}
if (Display.getInstance().areMutableImagesFast() || transitionType == TYPE_TIMELINE) {
if (buffer == null) {
buffer = createMutableImage(w, h);
} else {
// this might happen when screen orientation changes
if (buffer.getWidth() != w || buffer.getHeight() != h) {
buffer = createMutableImage(w, h);
rgbBuffer = null;
// slide motion might need resetting since screen size is different
motion = null;
}
}
}
if (transitionType == TYPE_FADE) {
motion = createMotion(0, 256, speed);
motion.start();
if (Display.getInstance().areMutableImagesFast()) {
Graphics g = buffer.getGraphics();
g.translate(-source.getAbsoluteX(), -source.getAbsoluteY());
if (getSource().getParent() != null) {
getSource().getComponentForm().paintComponent(g);
}
getSource().paintBackgrounds(g);
g.setClip(0, 0, buffer.getWidth() + source.getAbsoluteX(), buffer.getHeight() + source.getAbsoluteY());
paint(g, getDestination(), 0, 0);
rgbBuffer = new RGBImage(buffer.getRGBCached(), buffer.getWidth(), buffer.getHeight());
paint(g, getSource(), 0, 0, true);
g.translate(source.getAbsoluteX(), source.getAbsoluteY());
}
return;
}
if (transitionType == TYPE_TIMELINE) {
Graphics g = buffer.getGraphics();
g.translate(-source.getAbsoluteX(), -source.getAbsoluteY());
g.setClip(0, 0, buffer.getWidth() + source.getAbsoluteX(), buffer.getHeight() + source.getAbsoluteY());
if (timeline.getWidth() != buffer.getWidth() || timeline.getHeight() != buffer.getHeight()) {
timeline = timeline.scaled(buffer.getWidth(), buffer.getHeight());
}
if (timeline instanceof Timeline) {
((Timeline) timeline).setTime(0);
((Timeline) timeline).setLoop(false);
((Timeline) timeline).setAnimationDelay(0);
}
paint(g, getDestination(), 0, 0);
g.translate(source.getAbsoluteX(), source.getAbsoluteY());
return;
}
if (transitionType == TYPE_SLIDE || transitionType == TYPE_FAST_SLIDE || transitionType == TYPE_COVER || transitionType == TYPE_UNCOVER) {
int dest;
int startOffset = 0;
boolean direction = forward;
// flip the direction only for horizontal slides
if ((source.getUIManager().getLookAndFeel().isRTL()) && slideType == SLIDE_HORIZONTAL) {
direction = !direction;
}
if (slideType == SLIDE_HORIZONTAL) {
dest = w;
if (destination instanceof Dialog) {
startOffset = w - getDialogParent(destination).getWidth();
if (direction) {
startOffset -= getDialogParent(destination).getStyle().getMarginLeft(destination.isRTL());
} else {
startOffset -= getDialogParent(destination).getStyle().getMarginRight(destination.isRTL());
}
} else {
if (source instanceof Dialog) {
dest = getDialogParent(source).getWidth();
if (direction) {
dest += getDialogParent(source).getStyle().getMarginLeft(source.isRTL());
} else {
dest += getDialogParent(source).getStyle().getMarginRight(source.isRTL());
}
}
}
} else {
dest = h;
if (destination instanceof Dialog) {
startOffset = h - getDialogParent(destination).getHeight() - getDialogTitleHeight((Dialog) destination);
if (direction) {
startOffset -= getDialogParent(destination).getStyle().getMarginBottom();
} else {
startOffset -= getDialogParent(destination).getStyle().getMarginTop();
startOffset -= ((Dialog) destination).getTitleStyle().getMarginTop();
if (!drawDialogMenu && ((Dialog) destination).getCommandCount() > 0) {
Container p = ((Dialog) destination).getSoftButton(0).getParent();
if (p != null) {
startOffset -= p.getHeight();
}
}
}
} else {
if (source instanceof Dialog) {
dest = getDialogParent(source).getHeight() + getDialogTitleHeight((Dialog) source);
if (direction) {
dest += getDialogParent(source).getStyle().getMarginBottom();
} else {
dest += getDialogParent(source).getStyle().getMarginTop();
dest += ((Dialog) source).getTitleStyle().getMarginTop();
if (((Dialog) source).getCommandCount() > 0) {
Container p = ((Dialog) source).getSoftButton(0).getParent();
if (p != null) {
dest += p.getHeight();
}
}
}
}
}
}
motion = createMotion(startOffset, dest, speed);
if (!Display.getInstance().areMutableImagesFast()) {
motion.start();
buffer = null;
return;
}
// make sure the destination is painted fully at least once
// we must use a full buffer otherwise the clipping will take effect
Graphics g = buffer.getGraphics();
// tinting is expensive
if (getSource() instanceof Dialog) {
paint(g, getDestination(), 0, 0);
if (transitionType == TYPE_FAST_SLIDE && !(destination instanceof Dialog)) {
Dialog d = (Dialog) source;
secondaryBuffer = createMutableImage(getDialogParent(d).getWidth(), getDialogParent(d).getHeight() + getDialogTitleHeight(d));
drawDialogCmp(secondaryBuffer.getGraphics(), d);
}
} else {
if (getDestination() instanceof Dialog) {
paint(g, getSource(), 0, 0);
if (transitionType == TYPE_FAST_SLIDE && !(source instanceof Dialog)) {
Dialog d = (Dialog) destination;
secondaryBuffer = createMutableImage(getDialogParent(d).getWidth(), d.getContentPane().getParent().getHeight() + getDialogTitleHeight(d));
drawDialogCmp(secondaryBuffer.getGraphics(), d);
}
} else {
paint(g, source, -source.getAbsoluteX(), -source.getAbsoluteY(), true);
if (transitionType == TYPE_FAST_SLIDE) {
secondaryBuffer = createMutableImage(destination.getWidth(), destination.getHeight());
paint(secondaryBuffer.getGraphics(), destination, -destination.getAbsoluteX(), -destination.getAbsoluteY());
}
}
}
motion.start();
}
}
use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class CommonTransitions method removeConstant.
private void removeConstant(Container c) {
int componentCount = c.getComponentCount();
c.putClientProperty("$shm", null);
for (int iter = 0; iter < componentCount; iter++) {
Component cmp = c.getComponentAt(iter);
cmp.putClientProperty("$shm", null);
if (cmp instanceof Container) {
removeConstant((Container) cmp);
}
}
}
Aggregations