Search in sources :

Example 1 with MPElement

use of com.xenoage.zong.core.position.MPElement in project Zong by Xenoage.

the class Content method onClick.

/**
 * This method is called when the mouse was clicked on the content.
 * A message with the clicked element is shown to the user.
 */
public void onClick(Point2f positionPx) {
    if (layout.getScoreFrames().size() == 0)
        return;
    // get the layout of first score frame
    ScoreFrame frame = layout.getScoreFrames().get(0);
    ScoreFrameLayout frameLayout = frame.getScoreFrameLayout();
    // convert position from screen space to page space, then from page space
    // to frame space, and them from frame space to score frame space
    Point2f positionMm = positionPx.scale(Units.pxToMm(1, mainWindow.getZoom()));
    Point2f framePositionMm = positionMm.sub(frame.getAbsolutePosition());
    Point2f scorePositionMm = frame.getScoreLayoutPosition(framePositionMm);
    // find elements under this position
    for (Stamping stamping : frameLayout.getAllStampings()) {
        if (stamping.getBoundingShape() != null && stamping.getBoundingShape().contains(scorePositionMm)) {
            MusicElement element = stamping.getMusicElement();
            if (element != null) {
                // music element found
                String message = "An element was clicked: " + element;
                if (element instanceof MPElement) {
                    // music element with a known musical position found
                    MPElement mpElement = (MPElement) element;
                    if (mpElement.getParent() != null)
                        message += " at " + mpElement.getMP();
                }
                mainWindow.showMessageDialog(message);
            }
        }
    }
}
Also used : Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) ScoreFrame(com.xenoage.zong.layout.frames.ScoreFrame) Point2f(com.xenoage.utils.math.geom.Point2f) MusicElement(com.xenoage.zong.core.music.MusicElement) MPElement(com.xenoage.zong.core.position.MPElement) ScoreFrameLayout(com.xenoage.zong.musiclayout.ScoreFrameLayout)

Aggregations

Point2f (com.xenoage.utils.math.geom.Point2f)1 MusicElement (com.xenoage.zong.core.music.MusicElement)1 MPElement (com.xenoage.zong.core.position.MPElement)1 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)1 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)1 Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)1