private void updatePlaceholder(Node newView) { if (view.getWidth() > 0 && view.getHeight() > 0) { SnapshotParameters parameters = new SnapshotParameters(); parameters.setFill(Color.TRANSPARENT); Image placeholderImage = view.snapshot(parameters, new WritableImage((int) view.getWidth(), (int) view.getHeight())); placeholder.setImage(placeholderImage); placeholder.setFitWidth(placeholderImage.getWidth()); placeholder.setFitHeight(placeholderImage.getHeight()); } else { placeholder.setImage(null); } placeholder.setVisible(true); placeholder.setOpacity(1.0); view.getChildren().setAll(placeholder, newView); placeholder.toFront(); } }
public double getWidth() { if (this.image != null) return image.getWidth(); else return 640; }
public static double getMatchingHeight(double width, Image i) { return ((i.getHeight() * width) / i.getWidth()); }
public static double getMatchingWidth(double height, Image i) { return ((i.getWidth() * height) / i.getHeight()); }
private synchronized void addToCache(ImageIdentifier identifier, Image image) { cleanCache((int) image.getHeight() * (int) image.getWidth()); cache.put(identifier, new WeakReference<Image>(image)); updateUsage(identifier); pixelCount = pixelCount + (int) image.getHeight() * (int) image.getWidth(); }
public static int[] getRGB(Image image) { return getRGB(image, 0, 0, (int) image.getWidth(), (int) image.getHeight()); }
/** * {@inheritDoc} */ @Override protected Collection<Decoration> createRequiredDecorations(Control target) { return Arrays.asList(new GraphicDecoration(new ImageView(REQUIRED_IMAGE),Pos.TOP_LEFT, REQUIRED_IMAGE.getWidth()/2, REQUIRED_IMAGE.getHeight()/2)); }
public static Image fitInDimensionAndCutEdges(Image image, double width, double heigth) { Dimension2D newImageDimension = UiUtilities.shouldFitIn(image.getWidth(), image.getHeight(), width, heigth); Image resizedImage = fastResize(image, newImageDimension); return clipImage(resizedImage, new Rectangle2D((resizedImage.getWidth() - width) / 2, (resizedImage.getHeight() - heigth) / 2, width, heigth)); } }
private boolean scrolledAllToTheRight() { return clip.getX() >= imgView.getImage().getWidth() - clip.getWidth(); }
/** * Override this to create your own splash pane parent node. * * @return A standard image */ public Parent getParent() { final ImageView imageView = new ImageView(getClass().getResource(getImagePath()).toExternalForm()); final ProgressBar splashProgressBar = new ProgressBar(); splashProgressBar.setPrefWidth(imageView.getImage().getWidth()); final VBox vbox = new VBox(); vbox.getChildren().addAll(imageView, splashProgressBar); return vbox; }
private void focusOnPoint(Point2D focus) { double totalwidth = imgView.getImage().getWidth(); double focusX = focus.getX(); double clipX = clip.getX(); double clipWidth = clip.getWidth(); double centerX = clipX + clipWidth/2; if (clipX == 0.0 && focusX < centerX) { // we are all to the left } else if (clipX + clipWidth >= totalwidth) { // we are all to the right } else { double x = Math.min(focusX - clipWidth/2, totalwidth - clipWidth); resetClipXPosition(x); } }
public static Image filter(Image image, ImageFilter filter) { int width = (int) image.getWidth(); int height = (int) image.getHeight(); WritableImage filteredImage = new WritableImage(width, height); int[] inPixels = getRGB(image); int[] outPixels = filter.filter(width, height, inPixels); setRGB(filteredImage, 0, 0, width, height, outPixels); return filteredImage; }
private void drawShipsInCities(Image mapImage, double scale, double x) { for (ICity city : map.getCities()) { if (city.getCoordinates().getX() >= x && city.getCoordinates().getX() <= x + mapImage.getWidth()) { List<INavigableVessel> ships = viewState.getPlayer().findShips(city); if (!ships.isEmpty()) { drawShipPresenceInCity(city); } } } }
public void setCenter(Point2D center) { this.center = center; this.sprite.translateXProperty().set(this.center.getX() - this.sprite.getImage().getWidth() / 2d); this.sprite.translateYProperty().set(this.center.getY() - this.sprite.getImage().getHeight() / 2d); } // END setCenter
private void setUpImageView() { String imageName = getImageNameFromScene(); Image tmpImg = xmlLoader.getImage(imageName); ImageData imgData = xmlLoader.getImageData(imageName); Dimension2D targetDim = new Dimension2D(controlWidth, controlHeight); ImageScaleState state = new ImageScaleState(new Dimension2D(tmpImg.getWidth(), tmpImg.getHeight()), targetDim, imgData.getCrop(), imgData.getMaxCrop()); logger.debug("State of the port scene before: " + state); // // todo: andi 13/12/13: it would be simpler to bound the values instead of reinitializing them imgView = new MainGameImageView(controlWidth, controlHeight, imageUtils.cropAndScale(imageName, state), state); List<Polygon> polygons = polygonInitFactory.getScenePolygonInitializer().initialzePolygons(state); imgView.resetPolygons(polygons); viewState.setState(EViewState.CITY); logger.debug("State of the port scene after : " + state); } private void setUpSeamapImageView() {
@Override public void bindViewSizeToParent() { container.setPrefWidth(imageProp.getValue().getWidth()); container.setPrefHeight(imageProp.getValue().getHeight()); photoImageView.fitHeightProperty().bind(container.heightProperty()); photoImageView.fitWidthProperty().bind(container.widthProperty()); }
public void updateShipPosition() { INavigableVessel vessel = control.getVessel(); final Point2D location = vessel.getLocation(); double x = location.getX() * control.scaleProperty().get(); double y = location.getY() * control.scaleProperty().get(); control.setLayoutX(x - shipIcon.getWidth() / 2); control.setLayoutY(y - shipIcon.getHeight() / 2); logger.trace("Update ship {} position to {},{} in view {},{}", vessel.getName(), vessel.getLocation().getX(), vessel.getLocation().getY(), control.getLayoutX(), control.getLayoutY()); }
private void drawCityInfo(Image mapImage, double scale, double x) { for (ICity city : map.getCities()) { if (city.getCoordinates().getX() >= x && city.getCoordinates().getX() <= x + mapImage.getWidth()) { CityIcons cityIcons = new CityIcons(city.getCityState(), imageLoader); // draw below city double xPos = (city.getCoordinates().getX() - ImageUtil.CITY_RADIUS) * scale; double yPos = (city.getCoordinates().getY() + ImageUtil.CITY_RADIUS + 5) * scale; cityIcons.setScaleX(scale); cityIcons.setScaleY(scale); cityIcons.setLayoutX(xPos); cityIcons.setLayoutY(yPos); shipCanvas.getChildren().add(0, cityIcons); } } }
private void updatePlaceholder(Node newView) { if (root.getWidth() > 0 && root.getHeight() > 0) { Image placeholderImage = root.snapshot(null, new WritableImage((int) root.getWidth(), (int) root.getHeight())); placeholder.setImage(placeholderImage); placeholder.setFitWidth(placeholderImage.getWidth()); placeholder.setFitHeight(placeholderImage.getHeight()); } else { placeholder.setImage(null); } placeholder.setVisible(true); placeholder.setOpacity(1.0); root.getChildren().setAll(placeholder); root.getChildren().add(newView); placeholder.toFront(); } }