use of org.eclipse.draw2d.geometry.PrecisionPoint in project yamcs-studio by yamcs.
the class PointListCreationTool method handleMove.
/**
* {@inheritDoc}
*/
@Override
protected boolean handleMove() {
if (getState() != STATE_TERMINAL && getState() != STATE_INVALID) {
if (_points.size() > 0) {
// snap
PrecisionPoint location = getSnapedLocation();
// update the last point in the list to update the graphical
// feedback
_points.setPoint(location, _points.size() - 1);
}
updateTargetRequest();
updateTargetUnderMouse();
setCurrentCommand(getCommand());
showTargetFeedback();
return true;
}
return false;
}
use of org.eclipse.draw2d.geometry.PrecisionPoint in project yamcs-studio by yamcs.
the class PointListCreationTool method getSnapedLocation.
/**
* Gets the "snapped" location based on the current location of the mouse.
*
* @return the point of the snapped location
*/
private PrecisionPoint getSnapedLocation() {
CreateRequest req = getCreateRequest();
PrecisionPoint location = new PrecisionPoint(getLocation().x, getLocation().y);
if (_snap2Helper != null) {
_snap2Helper.snapPoint(req, PositionConstants.NORTH_WEST, new PrecisionPoint(getLocation().x, getLocation().y), location);
}
return location;
}
use of org.eclipse.draw2d.geometry.PrecisionPoint in project yamcs-studio by yamcs.
the class PolyPointDragTracker method updateSourceRequest.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
protected void updateSourceRequest() {
super.updateSourceRequest();
ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();
PrecisionPoint location = new PrecisionPoint(getLocation().x, getLocation().y);
if (_snapToHelper != null) {
_snapToHelper.snapPoint(request, PositionConstants.NORTH_WEST, new PrecisionPoint(getLocation().x, getLocation().y), location);
}
_owner.getFigure().translateToRelative(location);
PointList oldPoints = ((PointList) request.getExtendedData().get(EXT_DATA_POINTS)).getCopy();
PointList newPoints = oldPoints.getCopy();
newPoints.setPoint(location.getCopy(), _pointIndex);
// calculate difference
Rectangle oldBounds = _oldPoints.getBounds();
Rectangle newBounds = newPoints.getBounds();
request.setLocation(getLocation());
Dimension locationDiff = newBounds.getLocation().getDifference(oldBounds.getLocation());
_owner.getFigure().translateToAbsolute(locationDiff);
Dimension sizeDiff = newBounds.getSize().getDifference(oldBounds.getSize());
_owner.getFigure().translateToAbsolute(sizeDiff);
request.setMoveDelta(new Point(locationDiff.width, locationDiff.height));
request.setSizeDelta(sizeDiff);
request.getExtendedData().put(EXT_DATA_POINTS, newPoints);
request.getExtendedData().put(EXT_DATA_POINT_INDEX, _pointIndex);
}
use of org.eclipse.draw2d.geometry.PrecisionPoint in project statecharts by Yakindu.
the class SimpleSnapFeedbackPolicy method highlightGuide.
// Even offset indicates a vertical feedback line; odd, horizontal.
void highlightGuide(Integer pos, Color color, int offset) {
if (pos == null) {
if (guide[offset] != null) {
removeFeedback(guide[offset]);
guide[offset] = null;
}
location[offset] = pos;
return;
}
// pos is an integer relative to target's client area.
// translate pos to absolute, and then make it relative to fig.
int position = pos.intValue();
PrecisionPoint loc = new PrecisionPoint(position, position);
IFigure contentPane = ((GraphicalEditPart) getHost()).getContentPane();
contentPane.translateToParent(loc);
contentPane.translateToAbsolute(loc);
if (location[offset] == null || !location[offset].equals(pos)) {
location[offset] = pos;
if (guide[offset] != null) {
removeFeedback(guide[offset]);
guide[offset] = null;
}
IFigure fig = new FadeIn(color);
guide[offset] = fig;
addFeedback(fig);
fig.translateToRelative(loc);
position = offset % 2 == 0 ? (int) Math.round(loc.preciseX()) : (int) Math.round(loc.preciseY());
Rectangle figBounds = getFeedbackLayer().getBounds().getCopy();
if ((offset % 2) == 1) {
figBounds.height = 1;
figBounds.y = position;
} else {
figBounds.x = position;
figBounds.width = 1;
}
fig.setBounds(figBounds);
} else {
// The feedback layer could have grown (if auto-scrolling), so
// resize the fade-in
// line.
IFigure fig = guide[offset];
Rectangle figBounds = fig.getBounds().getCopy();
Rectangle feedbackBounds = getFeedbackLayer().getBounds();
if ((offset % 2) == 1) {
figBounds.x = feedbackBounds.x;
figBounds.width = feedbackBounds.width;
} else {
figBounds.y = feedbackBounds.y;
figBounds.height = feedbackBounds.height;
}
fig.setBounds(figBounds);
}
}
use of org.eclipse.draw2d.geometry.PrecisionPoint in project statecharts by Yakindu.
the class AdjustIdentityAnchorCommand method computeNewAnchor.
private PrecisionPoint computeNewAnchor(PrecisionPoint currentAnchorPoint, EditPart editPart) {
double scale = getScale(editPart);
IFigure figure = ((IGraphicalEditPart) editPart).getFigure();
Rectangle bounds = figure.getBounds();
if (figure instanceof HandleBounds) {
bounds = ((HandleBounds) figure).getHandleBounds();
}
Point currentRelativePoint = getAnchorRelativePoint(currentAnchorPoint, bounds);
if (futureSize != null && delta != null) {
// and delta are used instead of the request data.
return new PrecisionPoint(((double) (currentRelativePoint.x - delta.x)) / futureSize.width, ((double) (currentRelativePoint.y - delta.y)) / futureSize.height);
} else {
double logicalWidthDelta = request.getSizeDelta().width / scale;
double logicalHeightDelta = request.getSizeDelta().height / scale;
int direction = request.getResizeDirection();
double newRelativeX = computeNewXRelativeLocation(direction, currentRelativePoint, logicalWidthDelta);
double newRelativeY = computeNewYRelativeLocation(direction, currentRelativePoint, logicalHeightDelta);
return new PrecisionPoint(newRelativeX / (bounds.width() + logicalWidthDelta), newRelativeY / (bounds.height() + logicalHeightDelta));
}
}
Aggregations