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);
}
}
}
}
Aggregations