/*
 * Copyright ©1998-2020 by Richard A. Wilkes. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, version 2.0. If a copy of the MPL was not distributed with
 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, version 2.0.
 */

package com.trollworks.gcs.ui;

import com.trollworks.gcs.ui.image.Img;
import com.trollworks.gcs.ui.scale.Scale;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.Icon;

public class RetinaIcon implements Icon {
    private Img mNormal;
    private Img mRetina;

    public RetinaIcon(Img normal, Img retina) {
        mNormal = normal;
        mRetina = retina;
    }

    public Img getNormal() {
        return mNormal;
    }

    public Img getRetina() {
        return mRetina;
    }

    @Override
    public void paintIcon(Component component, Graphics g, int x, int y) {
        Graphics2D     gc    = (Graphics2D) g;
        RenderingHints saved = GraphicsUtilities.setMaximumQualityForGraphics(gc);
        Scale          scale = Scale.get(component);
        Img            img   = mRetina != null && (scale.getScale() > 1 || GraphicsUtilities.isRetinaDisplay(g)) ? mRetina : mNormal;
        gc.drawImage(img, x, y, scale.scale(getIconWidth()), scale.scale(getIconHeight()), component);
        gc.setRenderingHints(saved);
    }

    @Override
    public int getIconWidth() {
        return mNormal.getWidth();
    }

    @Override
    public int getIconHeight() {
        return mNormal.getHeight();
    }

    public RetinaIcon createDisabled() {
        return new RetinaIcon(mNormal.translucent(0.3f), mRetina != null ? mRetina.translucent(0.3f) : null);
    }
}

@@ -520,16 +520,62 @@
 e.Scale;
+%0Aimport com.trollworks.gcs.utility.PrintProxy;
 %0A%0Aimport
@@ -1145,16 +1145,21 @@
   gc    
+     
 = (Graph
@@ -1197,16 +1197,21 @@
 s saved 
+     
 = Graphi
@@ -1256,16 +1256,112 @@
 cs(gc);%0A
+        PrintProxy     printProxy = UIUtilities.getAncestorOfType(component, PrintProxy.class);%0A
         
@@ -1381,16 +1381,21 @@
   scale 
+     
 = Scale.
@@ -1439,16 +1439,21 @@
   img   
+     
 = mRetin
@@ -1466,16 +1466,67 @@
 ull && (
+(printProxy != null && printProxy.isPrinting()) %7C%7C 
 scale.ge

Fix image scaling when printing