< prev index next >

modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGRegion.java

Print this page




 697         for (int i = 0, max = fills.size(); i < max; i++) {
 698             final BackgroundFill fill = fills.get(i);
 699             // Get the paint for this BackgroundFill. It should not be possible
 700             // for it to ever be null
 701             final Paint paint = getPlatformPaint(fill.getFill());
 702             assert paint != null;
 703             g.setPaint(paint);
 704             // Adjust the box within which we will fit the shape based on the
 705             // insets. The resize shape method will resize the shape to fit
 706             final Insets insets = fill.getInsets();
 707             g.fill(resizeShape((float) insets.getTop(), (float) insets.getRight(),
 708                                (float) insets.getBottom(), (float) insets.getLeft()));
 709         }
 710 
 711         // We now need to draw each background image. Only the "cover" property
 712         // of BackgroundImage, and the "image" property itself, have any impact
 713         // on how the image is applied to a Shape.
 714         final List<BackgroundImage> images = background.getImages();
 715         for (int i = 0, max = images.size(); i < max; i++) {
 716             final BackgroundImage image = images.get(i);
 717             final Image prismImage = (Image) image.getImage().impl_getPlatformImage();
 718             if (prismImage == null) {
 719                 // The prismImage might be null if the Image has not completed loading.
 720                 // In that case, we simply must skip rendering of that layer this
 721                 // time around.
 722                 continue;
 723             }
 724             // We need to translate the shape based on 0 insets. This will for example
 725             // center and / or position the shape if necessary.
 726             final Shape translatedShape = resizeShape(0, 0, 0, 0);
 727             // Now ensure that the ImagePattern is based on the x/y position of the
 728             // shape and not on the 0,0 position of the region.
 729             final RectBounds bounds = translatedShape.getBounds();
 730             ImagePattern pattern = image.getSize().isCover() ?
 731                     new ImagePattern(prismImage, bounds.getMinX(), bounds.getMinY(),
 732                                      bounds.getWidth(), bounds.getHeight(), false, false) :
 733                     new ImagePattern(prismImage, bounds.getMinX(), bounds.getMinY(),
 734                                      prismImage.getWidth(), prismImage.getHeight(), false, false);
 735             g.setPaint(pattern);
 736             // Go ahead and finally fill!
 737             g.fill(translatedShape);


 834                     }
 835                 }
 836             }
 837         }
 838 
 839         // "cached" might not be null if either there was a cached image, or we just created one.
 840         // In either case, we need to now render from the cached texture to the graphics
 841         if (cached != null) {
 842             renderBackgroundRectangleFromCache(
 843                     g, cached, rect, textureWidth, textureHeight,
 844                     topInset, rightInset, bottomInset, leftInset,
 845                     outsetsTop, outsetsRight, outsetsBottom, outsetsLeft);
 846         } else {
 847             // no cache, rendering backgrounds directly to graphics
 848             renderBackgroundRectanglesDirectly(g, width, height);
 849         }
 850 
 851         final List<BackgroundImage> images = background.getImages();
 852         for (int i = 0, max = images.size(); i < max; i++) {
 853             final BackgroundImage image = images.get(i);
 854             Image prismImage = (Image) image.getImage().impl_getPlatformImage();
 855             if (prismImage == null) {
 856                 // The prismImage might be null if the Image has not completed loading.
 857                 // In that case, we simply must skip rendering of that layer this
 858                 // time around.
 859                 continue;
 860             }
 861 
 862             final int imgUnscaledWidth = (int)image.getImage().getWidth();
 863             final int imgUnscaledHeight = (int)image.getImage().getHeight();
 864             final int imgWidth = prismImage.getWidth();
 865             final int imgHeight = prismImage.getHeight();
 866             // TODO need to write tests where we use a writable image and draw to it a lot. (RT-26978)
 867             if (imgWidth != 0 && imgHeight != 0) {
 868                 final BackgroundSize size = image.getSize();
 869                 if (size.isCover()) {
 870                     // When "cover" is true, we can ignore most properties on the BackgroundSize and
 871                     // BackgroundRepeat and BackgroundPosition. Because the image will be stretched to
 872                     // fill the entire space, there is no need to know the repeat or position or
 873                     // size width / height.
 874                     final float scale = Math.max(width / imgWidth,height / imgHeight);


1297                 }
1298                 if (bottomStyle != BorderStrokeStyle.NONE) {
1299                     double rsum = radii.getBottomLeftHorizontalRadius() + radii.getBottomRightHorizontalRadius();
1300                     double bottomLineLength = width + rsum * (Math.PI / 4 - 1);
1301                     g.setStroke(createStroke(bottomStyle, bottomWidth, bottomLineLength, true));
1302                     g.setPaint(getPlatformPaint(bottomStroke));
1303                     g.draw(paths[2]);
1304                 }
1305                 if (leftStyle != BorderStrokeStyle.NONE) {
1306                     double rsum = radii.getTopLeftVerticalRadius() + radii.getBottomLeftVerticalRadius();
1307                     double leftLineLength = height + rsum * (Math.PI / 4 - 1);
1308                     g.setStroke(createStroke(leftStyle, leftWidth, leftLineLength, true));
1309                     g.setPaint(getPlatformPaint(leftStroke));
1310                     g.draw(paths[3]);
1311                 }
1312             }
1313         }
1314 
1315         for (int i = 0, max = images.size(); i < max; i++) {
1316             final BorderImage ib = images.get(i);
1317             final Image prismImage = (Image) ib.getImage().impl_getPlatformImage();
1318             if (prismImage == null) {
1319                 // The prismImage might be null if the Image has not completed loading.
1320                 // In that case, we simply must skip rendering of that layer this
1321                 // time around.
1322                 continue;
1323             }
1324             final int imgWidth = prismImage.getWidth();
1325             final int imgHeight = prismImage.getHeight();
1326             final float imgScale = prismImage.getPixelScale();
1327             final BorderWidths widths = ib.getWidths();
1328             final Insets insets = ib.getInsets();
1329             final BorderWidths slices = ib.getSlices();
1330 
1331             // we will get gaps if we don't round to pixel boundaries
1332             final int topInset = (int) Math.round(insets.getTop());
1333             final int rightInset = (int) Math.round(insets.getRight());
1334             final int bottomInset = (int) Math.round(insets.getBottom());
1335             final int leftInset = (int) Math.round(insets.getLeft());
1336 
1337             final int topWidth = widthSize(widths.isTopAsPercentage(), widths.getTop(), height);




 697         for (int i = 0, max = fills.size(); i < max; i++) {
 698             final BackgroundFill fill = fills.get(i);
 699             // Get the paint for this BackgroundFill. It should not be possible
 700             // for it to ever be null
 701             final Paint paint = getPlatformPaint(fill.getFill());
 702             assert paint != null;
 703             g.setPaint(paint);
 704             // Adjust the box within which we will fit the shape based on the
 705             // insets. The resize shape method will resize the shape to fit
 706             final Insets insets = fill.getInsets();
 707             g.fill(resizeShape((float) insets.getTop(), (float) insets.getRight(),
 708                                (float) insets.getBottom(), (float) insets.getLeft()));
 709         }
 710 
 711         // We now need to draw each background image. Only the "cover" property
 712         // of BackgroundImage, and the "image" property itself, have any impact
 713         // on how the image is applied to a Shape.
 714         final List<BackgroundImage> images = background.getImages();
 715         for (int i = 0, max = images.size(); i < max; i++) {
 716             final BackgroundImage image = images.get(i);
 717             final Image prismImage = (Image) Toolkit.getImageAccessor().getPlatformImage(image.getImage());
 718             if (prismImage == null) {
 719                 // The prismImage might be null if the Image has not completed loading.
 720                 // In that case, we simply must skip rendering of that layer this
 721                 // time around.
 722                 continue;
 723             }
 724             // We need to translate the shape based on 0 insets. This will for example
 725             // center and / or position the shape if necessary.
 726             final Shape translatedShape = resizeShape(0, 0, 0, 0);
 727             // Now ensure that the ImagePattern is based on the x/y position of the
 728             // shape and not on the 0,0 position of the region.
 729             final RectBounds bounds = translatedShape.getBounds();
 730             ImagePattern pattern = image.getSize().isCover() ?
 731                     new ImagePattern(prismImage, bounds.getMinX(), bounds.getMinY(),
 732                                      bounds.getWidth(), bounds.getHeight(), false, false) :
 733                     new ImagePattern(prismImage, bounds.getMinX(), bounds.getMinY(),
 734                                      prismImage.getWidth(), prismImage.getHeight(), false, false);
 735             g.setPaint(pattern);
 736             // Go ahead and finally fill!
 737             g.fill(translatedShape);


 834                     }
 835                 }
 836             }
 837         }
 838 
 839         // "cached" might not be null if either there was a cached image, or we just created one.
 840         // In either case, we need to now render from the cached texture to the graphics
 841         if (cached != null) {
 842             renderBackgroundRectangleFromCache(
 843                     g, cached, rect, textureWidth, textureHeight,
 844                     topInset, rightInset, bottomInset, leftInset,
 845                     outsetsTop, outsetsRight, outsetsBottom, outsetsLeft);
 846         } else {
 847             // no cache, rendering backgrounds directly to graphics
 848             renderBackgroundRectanglesDirectly(g, width, height);
 849         }
 850 
 851         final List<BackgroundImage> images = background.getImages();
 852         for (int i = 0, max = images.size(); i < max; i++) {
 853             final BackgroundImage image = images.get(i);
 854             Image prismImage = (Image) Toolkit.getImageAccessor().getPlatformImage(image.getImage());
 855             if (prismImage == null) {
 856                 // The prismImage might be null if the Image has not completed loading.
 857                 // In that case, we simply must skip rendering of that layer this
 858                 // time around.
 859                 continue;
 860             }
 861 
 862             final int imgUnscaledWidth = (int)image.getImage().getWidth();
 863             final int imgUnscaledHeight = (int)image.getImage().getHeight();
 864             final int imgWidth = prismImage.getWidth();
 865             final int imgHeight = prismImage.getHeight();
 866             // TODO need to write tests where we use a writable image and draw to it a lot. (RT-26978)
 867             if (imgWidth != 0 && imgHeight != 0) {
 868                 final BackgroundSize size = image.getSize();
 869                 if (size.isCover()) {
 870                     // When "cover" is true, we can ignore most properties on the BackgroundSize and
 871                     // BackgroundRepeat and BackgroundPosition. Because the image will be stretched to
 872                     // fill the entire space, there is no need to know the repeat or position or
 873                     // size width / height.
 874                     final float scale = Math.max(width / imgWidth,height / imgHeight);


1297                 }
1298                 if (bottomStyle != BorderStrokeStyle.NONE) {
1299                     double rsum = radii.getBottomLeftHorizontalRadius() + radii.getBottomRightHorizontalRadius();
1300                     double bottomLineLength = width + rsum * (Math.PI / 4 - 1);
1301                     g.setStroke(createStroke(bottomStyle, bottomWidth, bottomLineLength, true));
1302                     g.setPaint(getPlatformPaint(bottomStroke));
1303                     g.draw(paths[2]);
1304                 }
1305                 if (leftStyle != BorderStrokeStyle.NONE) {
1306                     double rsum = radii.getTopLeftVerticalRadius() + radii.getBottomLeftVerticalRadius();
1307                     double leftLineLength = height + rsum * (Math.PI / 4 - 1);
1308                     g.setStroke(createStroke(leftStyle, leftWidth, leftLineLength, true));
1309                     g.setPaint(getPlatformPaint(leftStroke));
1310                     g.draw(paths[3]);
1311                 }
1312             }
1313         }
1314 
1315         for (int i = 0, max = images.size(); i < max; i++) {
1316             final BorderImage ib = images.get(i);
1317             final Image prismImage = (Image) Toolkit.getImageAccessor().getPlatformImage(ib.getImage());
1318             if (prismImage == null) {
1319                 // The prismImage might be null if the Image has not completed loading.
1320                 // In that case, we simply must skip rendering of that layer this
1321                 // time around.
1322                 continue;
1323             }
1324             final int imgWidth = prismImage.getWidth();
1325             final int imgHeight = prismImage.getHeight();
1326             final float imgScale = prismImage.getPixelScale();
1327             final BorderWidths widths = ib.getWidths();
1328             final Insets insets = ib.getInsets();
1329             final BorderWidths slices = ib.getSlices();
1330 
1331             // we will get gaps if we don't round to pixel boundaries
1332             final int topInset = (int) Math.round(insets.getTop());
1333             final int rightInset = (int) Math.round(insets.getRight());
1334             final int bottomInset = (int) Math.round(insets.getBottom());
1335             final int leftInset = (int) Math.round(insets.getLeft());
1336 
1337             final int topWidth = widthSize(widths.isTopAsPercentage(), widths.getTop(), height);


< prev index next >