use of javafx.geometry.Rectangle2D in project Board-Instrumentation-Framework by intel.
the class ConfigurationReader method CalculateScaling.
private void CalculateScaling() {
if (null == _Configuration) {
return;
}
if (_Configuration.isAutoScale() && _Configuration.getCreationHeight() > 0 && _Configuration.getCreationWidth() > 0) {
Rectangle2D visualBounds = _Configuration.getPrimaryScreen().getVisualBounds();
double appWidth = visualBounds.getWidth();
double appHeight = visualBounds.getHeight();
// if app size specified
if (getConfiguration().getWidth() > 0) {
appWidth = getConfiguration().getWidth();
}
if (getConfiguration().getHeight() > 0) {
appHeight = getConfiguration().getHeight();
}
double createWidth = (double) _Configuration.getCreationWidth();
double createHeight = (double) _Configuration.getCreationHeight();
double widthScale, heightScale, appScale;
Font defFont = Font.getDefault();
LOGGER.info("System Font info: " + defFont.toString());
if (appWidth == createWidth && appHeight == createHeight) {
LOGGER.info("Attempting to automatically scale, however current resolution is the same as specified <CreationSize>");
return;
}
widthScale = appWidth / createWidth;
heightScale = appHeight / createHeight;
appScale = widthScale;
if (// pick the smaller of the 2
heightScale < widthScale) {
appScale = heightScale;
}
_Configuration.setScaleFactor(appScale);
String strCurr = " screen resolution: [" + Double.toString(appWidth) + "x" + Double.toString(appHeight) + "]";
String strCreated = " created screen resolution: [" + Double.toString(createWidth) + "x" + Double.toString(createHeight) + "]";
LOGGER.info("AutoScale set to " + Double.toString(appScale) + strCurr + strCreated);
} else {
_Configuration.setAutoScale(false);
}
}
use of javafx.geometry.Rectangle2D in project tokentool by RPTools.
the class ImageUtil method autoCropImage.
/*
* Crop image to smallest width/height based on transparency
*/
private static Image autoCropImage(Image imageSource) {
ImageView croppedImageView = new ImageView(imageSource);
PixelReader pixelReader = imageSource.getPixelReader();
int imageWidth = (int) imageSource.getWidth();
int imageHeight = (int) imageSource.getHeight();
int minX = imageWidth, minY = imageHeight, maxX = 0, maxY = 0;
// Find the first and last pixels that are not transparent to create a bounding viewport
for (int readY = 0; readY < imageHeight; readY++) {
for (int readX = 0; readX < imageWidth; readX++) {
Color pixelColor = pixelReader.getColor(readX, readY);
if (!pixelColor.equals(Color.TRANSPARENT)) {
if (readX < minX)
minX = readX;
if (readX > maxX)
maxX = readX;
if (readY < minY)
minY = readY;
if (readY > maxY)
maxY = readY;
}
}
}
if (maxX - minX <= 0 || maxY - minY <= 0)
return new WritableImage(1, 1);
// Create a viewport to clip the image using snapshot
Rectangle2D viewPort = new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
SnapshotParameters parameter = new SnapshotParameters();
parameter.setViewport(viewPort);
parameter.setFill(Color.TRANSPARENT);
return croppedImageView.snapshot(parameter, null);
}
use of javafx.geometry.Rectangle2D in project tokentool by RPTools.
the class ImageUtil method composePreview.
public static Image composePreview(StackPane compositeTokenPane, Color bgColor, ImageView portraitImageView, ImageView maskImageView, ImageView overlayImageView, boolean useAsBase, boolean clipImage) {
// Process layout as maskImage may have changed size if the overlay was changed
compositeTokenPane.layout();
SnapshotParameters parameter = new SnapshotParameters();
Image finalImage = null;
Group blend;
if (clipImage) {
// We need to clip the portrait image first then blend the overlay image over it
// We will first get a snapshot of the portrait equal to the mask overlay image width/height
double x, y, width, height;
x = maskImageView.getParent().getLayoutX();
y = maskImageView.getParent().getLayoutY();
width = maskImageView.getFitWidth();
height = maskImageView.getFitHeight();
Rectangle2D viewPort = new Rectangle2D(x, y, width, height);
Rectangle2D maskViewPort = new Rectangle2D(1, 1, width, height);
WritableImage newImage = new WritableImage((int) width, (int) height);
WritableImage newMaskImage = new WritableImage((int) width, (int) height);
ImageView overlayCopyImageView = new ImageView();
ImageView clippedImageView = new ImageView();
parameter.setViewport(viewPort);
parameter.setFill(bgColor);
portraitImageView.snapshot(parameter, newImage);
parameter.setViewport(maskViewPort);
parameter.setFill(Color.TRANSPARENT);
maskImageView.setVisible(true);
maskImageView.snapshot(parameter, newMaskImage);
maskImageView.setVisible(false);
clippedImageView.setFitWidth(width);
clippedImageView.setFitHeight(height);
clippedImageView.setImage(clipImageWithMask(newImage, newMaskImage));
// Our masked portrait image is now stored in clippedImageView, lets now blend the overlay image over it
// We'll create a temporary group to hold our temporary ImageViews's and blend them and take a snapshot
overlayCopyImageView.setImage(overlayImageView.getImage());
overlayCopyImageView.setFitWidth(overlayImageView.getFitWidth());
overlayCopyImageView.setFitHeight(overlayImageView.getFitHeight());
overlayCopyImageView.setOpacity(overlayImageView.getOpacity());
if (useAsBase) {
blend = new Group(overlayCopyImageView, clippedImageView);
} else {
blend = new Group(clippedImageView, overlayCopyImageView);
}
// Last, we'll clean up any excess transparent edges by cropping it
finalImage = autoCropImage(blend.snapshot(parameter, null));
} else {
parameter.setFill(Color.TRANSPARENT);
finalImage = autoCropImage(compositeTokenPane.snapshot(parameter, null));
}
return finalImage;
}
use of javafx.geometry.Rectangle2D in project org.csstudio.display.builder by kasemir.
the class Rubberband method handleStop.
private void handleStop(final MouseEvent event) {
if (!active)
return;
final Point2D in_parent = parent.sceneToLocal(event.getSceneX(), event.getSceneY());
x1 = in_parent.getX();
y1 = in_parent.getY();
parent.getChildren().remove(rect);
active = false;
handler.handleSelectedRegion(new Rectangle2D(Math.min(x0, x1), Math.min(y0, y1), Math.abs(x1 - x0), Math.abs(y1 - y0)), event.isControlDown());
event.consume();
}
use of javafx.geometry.Rectangle2D in project org.csstudio.display.builder by kasemir.
the class SelectedWidgetUITracker method updateWidgetsFromTracker.
/**
* Updates widgets to current tracker location and size
*/
private void updateWidgetsFromTracker(final Rectangle2D original, final Rectangle2D current) {
if (updating)
return;
updating = true;
try {
group_handler.hide();
final List<Rectangle2D> orig_position = widgets.stream().map(GeometryTools::getBounds).collect(Collectors.toList());
// If there was only one widget, the tracker bounds represent
// the desired widget location and size.
// But tracker bounds can apply to one or more widgets, so need to
// determine the change in tracker bounds, apply those to each widget.
final double dx = current.getMinX() - original.getMinX();
final double dy = current.getMinY() - original.getMinY();
final double dw = current.getWidth() - original.getWidth();
final double dh = current.getHeight() - original.getHeight();
final int N = orig_position.size();
// Use compound action if there's more than one widget
final CompoundUndoableAction compound = N > 1 ? new CompoundUndoableAction(Messages.UpdateWidgetLocation) : null;
for (int i = 0; i < N; ++i) {
final Widget widget = widgets.get(i);
final Rectangle2D orig = orig_position.get(i);
final ChildrenProperty orig_parent_children = ChildrenProperty.getParentsChildren(widget);
ChildrenProperty parent_children = group_handler.getActiveParentChildren();
if (parent_children == null)
parent_children = widget.getDisplayModel().runtimeChildren();
if (orig_parent_children == parent_children) {
// Slightly faster since parent stays the same
if (!widget.propX().isUsingWidgetClass())
widget.propX().setValue((int) (orig.getMinX() + dx));
if (!widget.propY().isUsingWidgetClass())
widget.propY().setValue((int) (orig.getMinY() + dy));
} else {
// Update to new parent
if (widget.getDisplayModel().isClassModel()) {
logger.log(Level.WARNING, "Widget hierarchy is not permitted for class model");
return;
}
final Point2D old_offset = GeometryTools.getDisplayOffset(widget);
orig_parent_children.removeChild(widget);
parent_children.addChild(widget);
final Point2D new_offset = GeometryTools.getDisplayOffset(widget);
logger.log(Level.FINE, "{0} moves from {1} ({2}) to {3} ({4})", new Object[] { widget, orig_parent_children.getWidget(), old_offset, parent_children.getWidget(), new_offset });
// Account for old and new display offset
if (!widget.propX().isUsingWidgetClass())
widget.propX().setValue((int) (orig.getMinX() + dx + old_offset.getX() - new_offset.getX()));
if (!widget.propY().isUsingWidgetClass())
widget.propY().setValue((int) (orig.getMinY() + dy + old_offset.getY() - new_offset.getY()));
}
if (!widget.propWidth().isUsingWidgetClass())
widget.propWidth().setValue((int) Math.max(1, orig.getWidth() + dw));
if (!widget.propHeight().isUsingWidgetClass())
widget.propHeight().setValue((int) Math.max(1, orig.getHeight() + dh));
final UndoableAction step = new UpdateWidgetLocationAction(widget, orig_parent_children, parent_children, (int) orig.getMinX(), (int) orig.getMinY(), (int) orig.getWidth(), (int) orig.getHeight());
if (compound == null)
undo.add(step);
else
compound.add(step);
}
if (compound != null)
undo.add(compound);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Failed to move/resize widgets", ex);
} finally {
updating = false;
updateTrackerFromWidgets();
}
}
Aggregations