Search in sources :

Example 31 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class LineView method mouseMoved.

private void mouseMoved(MouseEvent me) {
    if (getSelectedLine() == null) {
        return;
    }
    me.consume();
    double x = me.getX();
    double y = me.getY();
    LinePoint foundPoint = findGraphPoint(x, y);
    if (foundPoint != null) {
        if (selectedPoint != foundPoint) {
            selectedPoint = foundPoint;
            repaint();
        }
    } else if (selectedPoint != null) {
        selectedPoint = null;
        repaint();
    }
}
Also used : LinePoint(blue.components.lines.LinePoint)

Example 32 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class LineView method findGraphPoint.

public LinePoint findGraphPoint(double x, double y) {
    double min = getSelectedLine().getMin();
    double max = getSelectedLine().getMax();
    for (int i = 0; i < getSelectedLine().size(); i++) {
        LinePoint point = getSelectedLine().getLinePoint(i);
        double tempX = point.getX() * getWidth();
        double tempY = yToScreen(point.getY(), min, max);
        if (tempX >= x - 3 && tempX <= x + 3 && tempY >= y - 3 && tempY <= y + 3) {
            return point;
        }
    }
    return null;
}
Also used : LinePoint(blue.components.lines.LinePoint) LinePoint(blue.components.lines.LinePoint) Paint(javafx.scene.paint.Paint)

Example 33 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class ParameterLinePanel method setBoundaryXValues.

public void setBoundaryXValues() {
    Line currentLine = currentParameter.getLine();
    if (selectedPoint == currentLine.getLinePoint(0)) {
        leftBoundaryX = 0;
        rightBoundaryX = 0;
        return;
    } else if (selectedPoint == currentLine.getLinePoint(currentLine.size() - 1)) {
        LinePoint p1 = currentLine.getLinePoint(currentLine.size() - 2);
        leftBoundaryX = doubleToScreenX(p1.getX());
        rightBoundaryX = this.getWidth();
        return;
    }
    for (int i = 0; i < currentLine.size(); i++) {
        if (currentLine.getLinePoint(i) == selectedPoint) {
            LinePoint p1 = currentLine.getLinePoint(i - 1);
            LinePoint p2 = currentLine.getLinePoint(i + 1);
            leftBoundaryX = doubleToScreenX(p1.getX());
            rightBoundaryX = doubleToScreenX(p2.getX());
            return;
        }
    }
}
Also used : Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) Point(java.awt.Point) LinePoint(blue.components.lines.LinePoint)

Example 34 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class ParameterLinePanel method drawSelectionLine.

/* Draws line when in selection mode (MULTILINE, SCORE when SCALING) */
private final void drawSelectionLine(Graphics g, Parameter p) {
    Line tempLine = p.getLine();
    if (selectionList.size() > 0) {
        tempLine = getSelectionSortedLine(tempLine);
    } else if (newSelectionStartTime >= 0) {
        tempLine = getSelectionScalingSortedLine(tempLine);
    } else if (ModeManager.getInstance().getMode() == ScoreMode.SCORE) {
        drawLine(g, p, false);
        return;
    }
    Color currentColor = g.getColor();
    Rectangle clipBounds = g.getClipBounds();
    if (tempLine.size() == 0) {
        return;
    }
    double pixelSecond = (double) timeState.getPixelSecond();
    double selectionStart;
    double selectionEnd;
    if (newSelectionStartTime >= 0) {
        selectionStart = newSelectionStartTime;
        selectionEnd = newSelectionEndTime;
    } else {
        selectionStart = marquee.startTime;
        selectionEnd = marquee.endTime;
    }
    if (tempLine.size() == 1) {
        LinePoint lp = tempLine.getLinePoint(0);
        double min = tempLine.getMin();
        double max = tempLine.getMax();
        int x = doubleToScreenX(lp.getX());
        int y = doubleToScreenY(lp.getY(), min, max);
        g.setColor(currentColor);
        g.drawLine(0, y, getWidth(), y);
        paintSelectionPoint(g, x, y, lp.getX(), selectionStart, selectionEnd);
        return;
    }
    if (p.getResolution().doubleValue() <= 0) {
        int[] xValues = new int[tempLine.size()];
        int[] yValues = new int[tempLine.size()];
        double[] pointX = new double[tempLine.size()];
        double min = tempLine.getMin();
        double max = tempLine.getMax();
        for (int i = 0; i < tempLine.size(); i++) {
            LinePoint point = tempLine.getLinePoint(i);
            pointX[i] = point.getX();
            xValues[i] = doubleToScreenX(pointX[i]);
            yValues[i] = doubleToScreenY(point.getY(), min, max);
        }
        g.drawPolyline(xValues, yValues, xValues.length);
        final int lastX = xValues[xValues.length - 1];
        if (lastX < this.getWidth()) {
            int lastY = yValues[yValues.length - 1];
            g.drawLine(lastX, lastY, getWidth(), lastY);
        }
        for (int i = 0; i < xValues.length; i++) {
            paintSelectionPoint(g, xValues[i], yValues[i], pointX[i], selectionStart, selectionEnd);
        }
    } else {
        LinePoint previous = null;
        int x, y;
        double min = p.getMin();
        double max = p.getMax();
        BigDecimal resolution = p.getResolution();
        for (int i = 0; i < tempLine.size(); i++) {
            LinePoint point = tempLine.getLinePoint(i);
            x = doubleToScreenX(point.getX());
            y = doubleToScreenY(point.getY(), min, max);
            if (previous != null) {
                double startVal = previous.getY();
                int startX = doubleToScreenX(previous.getX());
                int startY = doubleToScreenY(startVal, min, max);
                int endX = doubleToScreenX(point.getX());
                int endY = doubleToScreenY(point.getY(), min, max);
                if (startVal == point.getY()) {
                    g.setColor(currentColor);
                    g.drawLine(startX, startY, endX, startY);
                    previous = point;
                    continue;
                }
                if (previous.getX() == point.getX()) {
                    if (startY != endY) {
                        g.setColor(currentColor);
                        g.drawLine(startX, startY, startX, endY);
                    }
                    previous = point;
                    continue;
                }
                int lastY = startY;
                int lastX = startX;
                for (int j = startX; j <= endX; j++) {
                    double timeVal = screenToDoubleX(j);
                    double val = tempLine.getValue(timeVal);
                    int newY = doubleToScreenY(val, min, max);
                    if (endY > startY) {
                        if (newY < startY) {
                            newY = startY;
                        }
                    } else if (newY > startY) {
                        newY = startY;
                    }
                    if (newY != lastY) {
                        g.setColor(currentColor);
                        g.drawLine(lastX, lastY, j, lastY);
                        g.drawLine(j, lastY, j, newY);
                        lastX = j;
                        lastY = newY;
                    }
                }
                if (lastX != endX) {
                    g.setColor(currentColor);
                    g.drawLine(lastX, lastY, endX, lastY);
                    g.drawLine(endX, lastY, endX, endY);
                }
            }
            paintSelectionPoint(g, x, y, point.getX(), selectionStart, selectionEnd);
            previous = point;
        }
        if (previous.getX() < this.getWidth()) {
            int lastX = doubleToScreenX(previous.getX());
            int lastY = doubleToScreenY(previous.getY(), min, max);
            g.setColor(currentColor);
            g.drawLine(lastX, lastY, getWidth(), lastY);
        }
    }
}
Also used : Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Point(java.awt.Point) LinePoint(blue.components.lines.LinePoint) BigDecimal(java.math.BigDecimal)

Example 35 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class LineCanvas method findGraphPoint.

public LinePoint findGraphPoint(int x) {
    for (int i = 0; i < currentLine.size(); i++) {
        LinePoint point = currentLine.getLinePoint(i);
        int tempX = doubleToScreenX(point.getX());
        if (tempX >= x - 2 && tempX <= x + 2) {
            return point;
        }
    }
    return null;
}
Also used : LinePoint(blue.components.lines.LinePoint) Point(java.awt.Point) LinePoint(blue.components.lines.LinePoint)

Aggregations

LinePoint (blue.components.lines.LinePoint)43 Line (blue.components.lines.Line)18 Point (java.awt.Point)13 Paint (javafx.scene.paint.Paint)6 SoundObjectParameterLine (blue.components.lines.SoundObjectParameterLine)3 Rectangle (java.awt.Rectangle)3 MenuItem (javafx.scene.control.MenuItem)3 Parameter (blue.automation.Parameter)2 DragDirection (blue.components.DragDirection)2 LineList (blue.components.lines.LineList)2 BlueFX (blue.jfx.BlueFX)2 Sound (blue.soundObject.Sound)2 NumberUtilities (blue.utility.NumberUtilities)2 BigDecimal (java.math.BigDecimal)2 Optional (java.util.Optional)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 ObjectProperty (javafx.beans.property.ObjectProperty)2 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 ListChangeListener (javafx.collections.ListChangeListener)2