|
@@ -28,7 +28,9 @@ import com.dmdirc.addons.ui_swing.components.RunnableSwingWorker;
|
28
|
28
|
import com.dmdirc.addons.ui_swing.components.SupplierLoggingSwingWorker;
|
29
|
29
|
import com.dmdirc.util.colours.Colour;
|
30
|
30
|
|
|
31
|
+import java.awt.AlphaComposite;
|
31
|
32
|
import java.awt.Color;
|
|
33
|
+import java.awt.Composite;
|
32
|
34
|
import java.awt.Font;
|
33
|
35
|
import java.awt.FontMetrics;
|
34
|
36
|
import java.awt.Graphics2D;
|
|
@@ -457,26 +459,28 @@ public final class UIUtilities {
|
457
|
459
|
* @param bounds Bounds to paint within
|
458
|
460
|
* @param backgroundImage background image
|
459
|
461
|
* @param backgroundOption How to draw the background
|
|
462
|
+ * @param opacity Opacity of the image
|
460
|
463
|
*/
|
461
|
464
|
public static void paintBackground(final Graphics2D g,
|
462
|
465
|
final Rectangle bounds,
|
463
|
466
|
final Image backgroundImage,
|
464
|
|
- final BackgroundOption backgroundOption) {
|
|
467
|
+ final BackgroundOption backgroundOption,
|
|
468
|
+ final float opacity) {
|
465
|
469
|
if (backgroundImage == null) {
|
466
|
470
|
paintNoBackground(g, bounds);
|
467
|
471
|
} else {
|
468
|
472
|
switch (backgroundOption) {
|
469
|
473
|
case TILED:
|
470
|
|
- paintTiledBackground(g, bounds, backgroundImage);
|
|
474
|
+ paintTiledBackground(g, bounds, backgroundImage, opacity);
|
471
|
475
|
break;
|
472
|
476
|
case SCALE:
|
473
|
|
- paintStretchedBackground(g, bounds, backgroundImage);
|
|
477
|
+ paintStretchedBackground(g, bounds, backgroundImage, opacity);
|
474
|
478
|
break;
|
475
|
479
|
case SCALE_ASPECT_RATIO:
|
476
|
|
- paintStretchedAspectRatioBackground(g, bounds, backgroundImage);
|
|
480
|
+ paintStretchedAspectRatioBackground(g, bounds, backgroundImage, opacity);
|
477
|
481
|
break;
|
478
|
482
|
case CENTER:
|
479
|
|
- paintCenterBackground(g, bounds, backgroundImage);
|
|
483
|
+ paintCenterBackground(g, bounds, backgroundImage, opacity);
|
480
|
484
|
break;
|
481
|
485
|
default:
|
482
|
486
|
break;
|
|
@@ -489,20 +493,26 @@ public final class UIUtilities {
|
489
|
493
|
}
|
490
|
494
|
|
491
|
495
|
private static void paintStretchedBackground(final Graphics2D g,
|
492
|
|
- final Rectangle bounds, final Image backgroundImage) {
|
|
496
|
+ final Rectangle bounds, final Image backgroundImage, final float opacity) {
|
|
497
|
+ final Composite originalComposite = g.getComposite();
|
|
498
|
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
|
493
|
499
|
g.drawImage(backgroundImage, 0, 0, bounds.width, bounds.height, null);
|
|
500
|
+ g.setComposite(originalComposite);
|
494
|
501
|
}
|
495
|
502
|
|
496
|
503
|
private static void paintCenterBackground(final Graphics2D g,
|
497
|
|
- final Rectangle bounds, final Image backgroundImage) {
|
|
504
|
+ final Rectangle bounds, final Image backgroundImage, final float opacity) {
|
498
|
505
|
final int x = bounds.width / 2 - backgroundImage.getWidth(null) / 2;
|
499
|
506
|
final int y = bounds.height / 2 - backgroundImage.getHeight(null) / 2;
|
|
507
|
+ final Composite originalComposite = g.getComposite();
|
|
508
|
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
|
500
|
509
|
g.drawImage(backgroundImage, x, y, backgroundImage.getWidth(null),
|
501
|
510
|
backgroundImage.getHeight(null), null);
|
|
511
|
+ g.setComposite(originalComposite);
|
502
|
512
|
}
|
503
|
513
|
|
504
|
514
|
private static void paintStretchedAspectRatioBackground(final Graphics2D g,
|
505
|
|
- final Rectangle bounds, final Image backgroundImage) {
|
|
515
|
+ final Rectangle bounds, final Image backgroundImage, final float opacity) {
|
506
|
516
|
final double widthratio = bounds.width
|
507
|
517
|
/ (double) backgroundImage.getWidth(null);
|
508
|
518
|
final double heightratio = bounds.height
|
|
@@ -513,11 +523,14 @@ public final class UIUtilities {
|
513
|
523
|
|
514
|
524
|
final int x = bounds.width / 2 - width / 2;
|
515
|
525
|
final int y = bounds.height / 2 - height / 2;
|
|
526
|
+ final Composite originalComposite = g.getComposite();
|
|
527
|
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
|
516
|
528
|
g.drawImage(backgroundImage, x, y, width, height, null);
|
|
529
|
+ g.setComposite(originalComposite);
|
517
|
530
|
}
|
518
|
531
|
|
519
|
532
|
private static void paintTiledBackground(final Graphics2D g,
|
520
|
|
- final Rectangle bounds, final Image backgroundImage) {
|
|
533
|
+ final Rectangle bounds, final Image backgroundImage, final float opacity) {
|
521
|
534
|
final int width = backgroundImage.getWidth(null);
|
522
|
535
|
final int height = backgroundImage.getHeight(null);
|
523
|
536
|
|
|
@@ -526,11 +539,14 @@ public final class UIUtilities {
|
526
|
539
|
return;
|
527
|
540
|
}
|
528
|
541
|
|
|
542
|
+ final Composite originalComposite = g.getComposite();
|
|
543
|
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
|
529
|
544
|
for (int x = 0; x < bounds.width; x += width) {
|
530
|
545
|
for (int y = 0; y < bounds.height; y += height) {
|
531
|
546
|
g.drawImage(backgroundImage, x, y, width, height, null);
|
532
|
547
|
}
|
533
|
548
|
}
|
|
549
|
+ g.setComposite(originalComposite);
|
534
|
550
|
}
|
535
|
551
|
|
536
|
552
|
/**
|