in ConstraintLayoutExamples/CycleEditor/src/com/google/androidstudio/motionlayoutcycles/CycleView.java [483:606]
public void paint(Graphics2D g, int w, int h) {
g.setColor(drawing);
if (xPoints.length == 0) {
return;
}
if (xp.length < xPoints[0].length * 2) {
xp = new int[xPoints[0].length * 2];
yp = new int[xPoints[0].length * 2];
}
int draw_width = w - ins_left - ins_right;
int draw_height = h - ins_top - ins_left;
for (int k = 0; k < xPoints.length; k++) {
if (xPoints[k] == null || yPoints[k] == null) {
continue;
}
for (int i = 0; i < xPoints[k].length; i++) {
float x = draw_width * (xPoints[k][i] - minx)
/ (maxx - minx) + ins_left;
float y = draw_height
* (1 - (yPoints[k][i] - miny) / (maxy - miny))
+ ins_top;
xp[i] = (int) x;
yp[i] = (int) y;
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(pointColor[k]);
g.setStroke(stroke);
switch (pointMode[k]) {
case -1:
break;
case RANGE_MODE:
for (int i = 0; i < xPoints[k].length; i++) {
float x = draw_width * (xPoints[k][i] - minx)
/ (maxx - minx) + ins_left;
float y1 = draw_height
* (1 - (yPoints[k][i] - miny) / (maxy - miny))
+ ins_top;
float y2 = draw_height
* (1 - (yPoints[k - 1][i] - miny) / (maxy - miny))
+ ins_top;
xp[i] = (int) x;
yp[i] = (int) y1;
int i2 = xPoints[k].length * 2 - i - 1;
xp[i2] = (int) x;
yp[i2] = (int) y2;
}
g.fillPolygon(xp, yp, xPoints[k].length * 2);
if (selected_node >= 0) {
float x_center = draw_width * (xPoints[selected_graph][selected_node] - minx)
/ (maxx - minx) + ins_left;
float x_min = x_center - 0.01f;
if (selected_node > 0) {
x_min = draw_width * (xPoints[selected_graph][selected_node - 1] - minx)
/ (maxx - minx) + ins_left;
}
float x_max = x_center;
if (selected_node < xPoints[selected_graph].length - 1) {
x_max = draw_width * (xPoints[selected_graph][selected_node + 1] - minx)
/ (maxx - minx) + ins_left;
}
if (x_center >= x_max) {
float[] spacing = new float[]{0, 0.999f, 1};
LinearGradientPaint gradientPaint = new LinearGradientPaint(x_min - 1, 1, x_center,
1,
spacing, new Color[]{COLOR_CLEAR, COLOR_BLUE, COLOR_CLEAR});
g.setPaint(gradientPaint);
} else if (x_center <= x_min) {
float[] spacing = new float[]{0, 0.001f, 1};
LinearGradientPaint gradientPaint = new LinearGradientPaint(x_center, 1, x_max + 1,
1,
spacing, new Color[]{COLOR_CLEAR, COLOR_BLUE, COLOR_CLEAR});
g.setPaint(gradientPaint);
} else {
float[] spacing = new float[]{0, (float) (x_center - x_min) / (x_max - x_min), 1};
LinearGradientPaint gradientPaint = new LinearGradientPaint(x_min, 1, x_max, 1,
spacing, new Color[]{COLOR_CLEAR, COLOR_BLUE, COLOR_CLEAR});
g.setPaint(gradientPaint);
}
g.fillPolygon(xp, yp, xPoints[k].length * 2);
g.drawPolygon(xp, yp, xPoints[k].length * 2);
g.setColor(pointColor[k]);
g.drawPolygon(xp, yp, xPoints[k].length * 2);
}
break;
case 2: { // ticks
final int TICK_SIZE = 2;
for (int i = 0; i < xPoints[k].length; i++) {
int pointX = xp[i];
int pointY = yp[i];
g.fillRoundRect(pointX - TICK_SIZE, pointY - TICK_SIZE * 4, TICK_SIZE * 2,
TICK_SIZE * 8, TICK_SIZE * 2, TICK_SIZE * 8);
}
break;
}
case 1: {
final int CIRCLE_SIZE = 10;
for (int i = 0; i < xPoints[k].length; i++) { // CIRCLE
int pointX = xp[i];
int pointY = yp[i];
if (selected_graph == k && selected_node == i) {
g.setColor(SELECTED_COLOR);
} else {
g.setColor(pointColor[k]);
}
g.fillRoundRect(pointX - CIRCLE_SIZE, pointY - CIRCLE_SIZE, CIRCLE_SIZE * 2,
CIRCLE_SIZE * 2, CIRCLE_SIZE * 2, CIRCLE_SIZE * 2);
}
}
break;
default:
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.drawPolyline(xp, yp, xPoints[k].length);
}
}
}