Skip to content

Commit

Permalink
Workaround splash image inverted on Mac Sonoma
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillipus committed Oct 15, 2023
1 parent ee3e1fe commit 8d1fcd7
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.splash.AbstractSplashHandler;

import com.archimatetool.editor.utils.PlatformUtils;

/**
* Splash Handler
*/
Expand All @@ -26,6 +32,10 @@ public SplashHandler() {
@Override
public void init(Shell shell) {
super.init(shell);

// Check for Mac bug
checkMacBackgroundImageInverted(shell);

shell.setBackgroundMode(SWT.INHERIT_FORCE);

String version = Messages.SplashHandler_0 + " " + ArchiPlugin.INSTANCE.getVersion(); //$NON-NLS-1$
Expand All @@ -43,4 +53,48 @@ public void paintControl(PaintEvent e) {
}
});
}

/**
* macOS Sonoma 14 flips background images on Control#setBackgroundImage
* See https://github.com/eclipse-platform/eclipse.platform.swt/issues/772
*/
private void checkMacBackgroundImageInverted(Shell shell) {
if(PlatformUtils.isMac() && PlatformUtils.compareOSVersion("14.0") >= 0) { //$NON-NLS-1$
// Flip the image
shell.setBackgroundImage(flipImage(shell.getDisplay(), shell.getBackgroundImage()));

// We are now responsible for disposing the new image
shell.addDisposeListener(e -> {
shell.getBackgroundImage().dispose();
});
}
}

/**
* From https://github.com/knime/knime-product/commit/095c88e22ba6d84e22a480f50734141836098169
*/
private Image flipImage(Display display, Image srcImage) {
Rectangle bounds = srcImage.getBounds();
Image newImage = new Image(display, bounds.width, bounds.height);

GC gc = new GC(newImage);
gc.setAdvanced(true);
gc.setAntialias(SWT.ON);
gc.setInterpolation(SWT.HIGH);

Transform transform = new Transform(display);
// flip down
transform.setElements(1, 0, 0, -1, 0, 0);
// move up
transform.translate(0, -bounds.height);
gc.setTransform(transform);

gc.drawImage(srcImage, 0, 0, bounds.width, bounds.height,
0, 0, bounds.width, bounds.height);

gc.dispose();
transform.dispose();

return newImage;
}
}

0 comments on commit 8d1fcd7

Please sign in to comment.