use of com.codename1.charts.compat.GradientDrawable.Orientation 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.charts.compat.GradientDrawable.Orientation in project CodenameOne by codenameone.
the class FloatingActionButton method bindFabToContainer.
/**
* This is a utility method to bind the FAB to a given Container, it will return a new container to add or will
* use the layered pane if the container is a content pane.
*
* @param cnt the Container to add the FAB to
* @param orientation one of Component.RIGHT/LEFT/CENTER
* @param valign one of Component.TOP/BOTTOM/CENTER
*
* @return a new Container that contains the cnt and the FAB on top or null in the case of a content pane
*/
public Container bindFabToContainer(Component cnt, int orientation, int valign) {
FlowLayout flow = new FlowLayout(orientation);
flow.setValign(valign);
Form f = cnt.getComponentForm();
if (f != null && (f.getContentPane() == cnt || f == cnt)) {
// special case for content pane installs the button directly on the content pane
Container layers = f.getLayeredPane(getClass(), true);
layers.setLayout(flow);
layers.add(this);
return null;
}
Container conUpper = new Container(flow);
conUpper.add(this);
return LayeredLayout.encloseIn(cnt, conUpper);
}
use of com.codename1.charts.compat.GradientDrawable.Orientation in project CodenameOne by codenameone.
the class XYChart method drawYLabels.
/**
* The graphical representation of the labels on the Y axis.
*
* @param allYLabels the Y labels values
* @param canvas the canvas to paint to
* @param paint the paint to be used for drawing
* @param maxScaleNumber the maximum scale number
* @param left the left value of the labels area
* @param right the right value of the labels area
* @param bottom the bottom value of the labels area
* @param yPixelsPerUnit the amount of pixels per one unit in the chart labels
* @param minY the minimum value on the Y axis in the chart
*/
protected void drawYLabels(Map<Integer, List<Double>> allYLabels, Canvas canvas, Paint paint, int maxScaleNumber, int left, int right, int bottom, double[] yPixelsPerUnit, double[] minY) {
Orientation or = mRenderer.getOrientation();
boolean showGridX = mRenderer.isShowGridX();
boolean showLabels = mRenderer.isShowLabels();
boolean showTickMarks = mRenderer.isShowTickMarks();
paint.setTextSize(mRenderer.getLabelsTextSize());
for (int i = 0; i < maxScaleNumber; i++) {
paint.setTextAlign(mRenderer.getYLabelsAlign(i));
List<Double> yLabels = allYLabels.get(i);
int length = yLabels.size();
for (int j = 0; j < length; j++) {
double label = yLabels.get(j);
int axisAlign = mRenderer.getYAxisAlign(i);
boolean textLabel = mRenderer.getYTextLabel(label, i) != null;
float yLabel = (float) (bottom - yPixelsPerUnit[i] * (label - minY[i]));
if (or == Orientation.HORIZONTAL) {
if (showLabels && !textLabel) {
paint.setColor(mRenderer.getYLabelsColor(i));
if (axisAlign == Align.LEFT) {
if (showTickMarks) {
canvas.drawLine(left + getLabelLinePos(axisAlign), yLabel, left, yLabel, paint);
}
drawText(canvas, getLabel(mRenderer.getYLabelFormat(i), label), left - mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
} else {
if (showTickMarks) {
canvas.drawLine(right, yLabel, right + getLabelLinePos(axisAlign), yLabel, paint);
}
drawText(canvas, getLabel(mRenderer.getYLabelFormat(i), label), right + mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
}
}
if (showGridX) {
paint.setColor(mRenderer.getGridColor(i));
canvas.drawLine(left, yLabel, right, yLabel, paint);
}
} else if (or == Orientation.VERTICAL) {
if (showLabels && !textLabel) {
paint.setColor(mRenderer.getYLabelsColor(i));
if (showTickMarks) {
canvas.drawLine(right - getLabelLinePos(axisAlign), yLabel, right, yLabel, paint);
}
drawText(canvas, getLabel(mRenderer.getLabelFormat(), label), right + 10 + mRenderer.getYLabelsPadding(), yLabel - mRenderer.getYLabelsVerticalPadding(), paint, mRenderer.getYLabelsAngle());
}
if (showGridX) {
paint.setColor(mRenderer.getGridColor(i));
if (showTickMarks) {
canvas.drawLine(right, yLabel, left, yLabel, paint);
}
}
}
}
}
}
use of com.codename1.charts.compat.GradientDrawable.Orientation in project CodenameOne by codenameone.
the class XYChart method drawSeries.
/**
* Draws the series.
*
* @param series the series
* @param canvas the canvas
* @param paint the paint object
* @param pointsList the points to be rendered
* @param seriesRenderer the series renderer
* @param yAxisValue the y axis value in pixels
* @param seriesIndex the series index
* @param or the orientation
* @param startIndex the start index of the rendering points
*/
protected void drawSeries(XYSeries series, Canvas canvas, Paint paint, List<Float> pointsList, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, Orientation or, int startIndex) {
BasicStroke stroke = seriesRenderer.getStroke();
int cap = paint.getStrokeCap();
int join = paint.getStrokeJoin();
float miter = paint.getStrokeMiter();
// PathEffect pathEffect = paint.getPathEffect();
Style style = paint.getStyle();
if (stroke != null) {
setStroke(stroke.getCap(), stroke.getJoin(), stroke.getMiter(), Style.FILL_AND_STROKE, paint);
}
// float[] points = MathHelper.getFloats(pointsList);
drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
drawPoints(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
paint.setTextSize(seriesRenderer.getChartValuesTextSize());
if (or == Orientation.HORIZONTAL) {
paint.setTextAlign(Align.CENTER);
} else {
paint.setTextAlign(Align.LEFT);
}
if (seriesRenderer.isDisplayChartValues()) {
paint.setTextAlign(seriesRenderer.getChartValuesTextAlign());
drawChartValuesText(canvas, series, seriesRenderer, paint, pointsList, seriesIndex, startIndex);
}
if (stroke != null) {
setStroke(cap, join, miter, style, paint);
}
}
use of com.codename1.charts.compat.GradientDrawable.Orientation in project CodenameOne by codenameone.
the class FlowLayout method moveComponents.
private void moveComponents(Container target, int x, int y, int width, int height, int rowStart, int rowEnd, int baseline) {
switch(orientation) {
case Component.CENTER:
// this will remove half of last gap
if (target.isRTL()) {
x -= (width) / 2;
} else {
x += (width) / 2;
}
break;
case Component.RIGHT:
if (!target.isRTL()) {
// this will remove the last gap
x += width;
} else {
x -= width;
}
break;
}
Style parentStyle = target.getStyle();
int parentPadding = parentStyle.getHorizontalPadding();
for (int i = rowStart; i < rowEnd; i++) {
Component m = target.getComponentAt(i);
Style style = m.getStyle();
int marginX = style.getMarginLeftNoRTL() + style.getMarginRightNoRTL();
if (m.getWidth() + marginX < target.getWidth() - parentPadding) {
m.setX(m.getX() + x);
}
int marginTop = style.getMarginTop();
switch(valign) {
case Component.BOTTOM:
if (vAlignByRow) {
m.setY(y + Math.max(marginTop, height - m.getHeight()) - style.getMarginBottom());
} else {
m.setY(y + Math.max(marginTop, target.getHeight() - m.getHeight()) - style.getMarginBottom());
}
break;
case Component.CENTER:
if (vAlignByRow) {
m.setY(y + Math.max(marginTop, (height - m.getHeight()) / 2));
} else {
m.setY(y + Math.max(marginTop, (target.getHeight() - m.getHeight()) / 2));
}
break;
case Component.BASELINE:
m.setY(y + Math.max(marginTop, baseline - m.getBaseline(m.getWidth(), m.getHeight())));
break;
default:
m.setY(y + marginTop);
break;
}
}
}
Aggregations