Skip to content
This repository has been archived by the owner on Jul 10, 2018. It is now read-only.

Commit

Permalink
First pass for supporting fractional scaling
Browse files Browse the repository at this point in the history
Tracked by #48
  • Loading branch information
kirill-grouchnikov committed Feb 9, 2018
1 parent 2b1c41c commit c525aec
Show file tree
Hide file tree
Showing 18 changed files with 369 additions and 348 deletions.
Binary file modified drop/8.0.00-dev/substance-8.0.00-dev.jar
Binary file not shown.
Binary file modified drop/8.0.00-dev/substance-lite-8.0.00-dev.jar
Binary file not shown.
Binary file modified drop/8.0.00-dev/trident-1.5.00-dev.jar
Binary file not shown.
Binary file modified lib/trident-1.5.00-dev.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005-2010 Substance Kirill Grouchnikov. All Rights Reserved.
* Copyright (c) 2005-2018 Substance Kirill Grouchnikov and contributing authors. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@
class HiDPIScaledGraphics extends Graphics2D {
protected final Graphics2D myPeer;

public HiDPIScaledGraphics(Graphics g) {
public HiDPIScaledGraphics(/*scaled*/ Graphics g) {
myPeer = (Graphics2D)g;
double scaleFactor = UIUtil.getScaleFactor();
scale(scaleFactor, scaleFactor);
GraphicsUtil.setupAAPainting(myPeer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class JBHiDPIScaledImage extends BufferedImage implements IsHiDpiAware {
private final Image myImage;
private int myWidth; // == myImage.width / scale
private int myHeight; // == myImage.height / scale
private boolean ignoreScaling;

public JBHiDPIScaledImage(int width, int height, int type) {
this(null, (int) (UIUtil.getScaleFactor() * width),
Expand All @@ -55,6 +56,10 @@ public JBHiDPIScaledImage(ColorModel cm, WritableRaster raster, boolean isRaster
myHeight = height;
}

public void setIgnoreScaling() {
this.ignoreScaling = true;
}

@Override
public boolean isHiDpiAware() {
return true;
Expand Down Expand Up @@ -88,6 +93,10 @@ public int getHeight(ImageObserver observer) {
public Graphics2D createGraphics() {
Graphics2D g = super.createGraphics();
if (myImage == null) {
if (!this.ignoreScaling) {
double scaleFactor = UIUtil.getScaleFactor();
g.scale(scaleFactor, scaleFactor);
}
return new HiDPIScaledGraphics(g);
}
return g;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
Expand Down Expand Up @@ -499,6 +500,8 @@ protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
? SubstanceCoreUtilities.getThemedIcon(b, originalIcon) : originalIcon;

graphics.setComposite(WidgetUtilities.getAlphaComposite(b, g));
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
float activeAmount = this.substanceVisualStateTracker
.getStateTransitionTracker().getActiveStrength();
graphics.translate(iconRect.x, iconRect.y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
Expand Down Expand Up @@ -523,6 +524,8 @@ public void paint(Graphics g, JComponent c) {
int ih = icon.getIconHeight();
int origButtonWidth = SubstanceSizeUtils.getScrollBarWidth(componentFontSize);
Graphics2D forIcon = (Graphics2D) graphics.create();
forIcon.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
int iconY = 1 + insets.top + (height - insets.top - insets.bottom - ih) / 2;
if (this.comboBox.getComponentOrientation().isLeftToRight()) {
int iconX = width - origButtonWidth - insets.right / 2 + (origButtonWidth - iw) / 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
Expand Down Expand Up @@ -363,6 +364,8 @@ public void paint(Graphics g, JComponent c) {

// Paint the Icon
if (icon != null) {
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
icon.paintIcon(c, g2d, iconRect.x, iconRect.y);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,9 @@ private BufferedImage getThumbVertical(Rectangle thumbBounds) {
return baseLayer;
}

double scaleFactor = UIUtil.getScaleFactor();
BufferedImage result = SubstanceCoreUtilities.getBlankImage(
(int) (baseLayer.getWidth() / scaleFactor),
(int) (baseLayer.getHeight() / scaleFactor));
BufferedImage result = SubstanceCoreUtilities.getBlankUnscaledImage(baseLayer);
Graphics2D g2d = result.createGraphics();
g2d.drawImage(baseLayer, 0, 0, (int) (baseLayer.getWidth() / scaleFactor),
(int) (baseLayer.getHeight() / scaleFactor), null);
g2d.drawImage(baseLayer, 0, 0, baseLayer.getWidth(), baseLayer.getHeight(), null);

for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
.entrySet()) {
Expand All @@ -267,8 +263,7 @@ private BufferedImage getThumbVertical(Rectangle thumbBounds) {
.getColorScheme(this.scrollbar, ColorSchemeAssociationKind.BORDER, activeState);
BufferedImage layer = getThumbVertical(this.scrollbar, width, height, fillScheme,
borderScheme);
g2d.drawImage(layer, 0, 0, (int) (layer.getWidth() / scaleFactor),
(int) (layer.getHeight() / scaleFactor), null);
g2d.drawImage(layer, 0, 0, layer.getWidth(), layer.getHeight(), null);
}

g2d.dispose();
Expand Down Expand Up @@ -364,13 +359,9 @@ private BufferedImage getThumbHorizontal(Rectangle thumbBounds) {
return baseLayer;
}

double scaleFactor = UIUtil.getScaleFactor();
BufferedImage result = SubstanceCoreUtilities.getBlankImage(
(int) (baseLayer.getWidth() / scaleFactor),
(int) (baseLayer.getHeight() / scaleFactor));
BufferedImage result = SubstanceCoreUtilities.getBlankUnscaledImage(baseLayer);
Graphics2D g2d = result.createGraphics();
g2d.drawImage(baseLayer, 0, 0, (int) (baseLayer.getWidth() / scaleFactor),
(int) (baseLayer.getHeight() / scaleFactor), null);
g2d.drawImage(baseLayer, 0, 0, baseLayer.getWidth(), baseLayer.getHeight(), null);

for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
.entrySet()) {
Expand All @@ -394,8 +385,7 @@ private BufferedImage getThumbHorizontal(Rectangle thumbBounds) {
.getColorScheme(this.scrollbar, ColorSchemeAssociationKind.BORDER, activeState);
BufferedImage layer = getThumbHorizontal(this.scrollbar, width, height, fillScheme,
borderScheme);
g2d.drawImage(layer, 0, 0, (int) (layer.getWidth() / scaleFactor),
(int) (layer.getHeight() / scaleFactor), null);
g2d.drawImage(layer, 0, 0, layer.getWidth(), layer.getHeight(), null);
}

g2d.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ private static BufferedImage getFinalTabBackgroundImage(JTabbedPane tabPane, int
SwingConstants.TOP, colorScheme, borderScheme, false);
int fw = backgroundImage.getWidth();
int fh = backgroundImage.getHeight();
double factor = UIUtil.getScaleFactor();
BufferedImage fade = SubstanceCoreUtilities.getBlankImage(backgroundImage);
BufferedImage fade = SubstanceCoreUtilities
.getBlankUnscaledImage(backgroundImage);
Graphics2D fadeGraphics = fade.createGraphics();
fadeGraphics.setColor(tabColor);
fadeGraphics.fillRect(0, 0, fw, fh);
Expand All @@ -931,8 +931,8 @@ private static BufferedImage getFinalTabBackgroundImage(JTabbedPane tabPane, int
}
BufferedImage background = SubstanceTabbedPaneUI.getTabBackground(tabPane,
width, height, tabPlacement, colorScheme, borderScheme, true);
fadeGraphics.drawImage(background, 0, 0, (int) (background.getWidth() / factor),
(int) (background.getHeight() / factor), null);
fadeGraphics.drawImage(background, 0, 0, background.getWidth(),
background.getHeight(), null);

backgroundImage = SubstanceCoreUtilities.blendImagesVertical(backgroundImage,
fade, skin.getTabFadeStart(), skin.getTabFadeEnd());
Expand Down Expand Up @@ -1038,7 +1038,7 @@ protected void paintTabBackground(Graphics g, int tabPlacement, final int tabInd
SubstanceColorScheme baseColorScheme = SubstanceColorSchemeUtilities
.getColorScheme(this.tabPane, tabIndex, ColorSchemeAssociationKind.TAB, currState);
BufferedImage fullOpacity = null;
double scaleFactor = UIUtil.getScaleFactor();
// double scaleFactor = UIUtil.getScaleFactor();
// Slightly reduce the tab width to create "gaps" between tab visuals
w -= 1;

Expand All @@ -1060,15 +1060,13 @@ protected void paintTabBackground(Graphics g, int tabPlacement, final int tabInd
tabIndex, x, y, w, h, tabPlacement, SubstanceSlices.Side.BOTTOM, colorScheme2,
baseBorderScheme);

fullOpacity = SubstanceCoreUtilities.getBlankImage(w, h);
fullOpacity = SubstanceCoreUtilities.getBlankUnscaledImage(layer1);
Graphics2D g2d = fullOpacity.createGraphics();
if (cyclePos < 1.0f)
g2d.drawImage(layer1, 0, 0, (int) (layer1.getWidth() / scaleFactor),
(int) (layer1.getHeight() / scaleFactor), null);
g2d.drawImage(layer1, 0, 0, layer1.getWidth(), layer1.getHeight(), null);
if (cyclePos > 0.0f) {
g2d.setComposite(AlphaComposite.SrcOver.derive(cyclePos));
g2d.drawImage(layer2, 0, 0, (int) (layer2.getWidth() / scaleFactor),
(int) (layer2.getHeight() / scaleFactor), null);
g2d.drawImage(layer2, 0, 0, layer2.getWidth(), layer2.getHeight(), null);
}
g2d.dispose();
} else {
Expand All @@ -1080,11 +1078,10 @@ protected void paintTabBackground(Graphics g, int tabPlacement, final int tabInd
|| (modelStateInfo.getStateContributionMap().size() == 1)) {
fullOpacity = layerBase;
} else {
fullOpacity = SubstanceCoreUtilities.getBlankImage(w, h);
fullOpacity = SubstanceCoreUtilities.getBlankUnscaledImage(layerBase);
Graphics2D g2d = fullOpacity.createGraphics();
// draw the base layer
g2d.drawImage(layerBase, 0, 0, (int) (layerBase.getWidth() / scaleFactor),
(int) (layerBase.getHeight() / scaleFactor), null);
g2d.drawImage(layerBase, 0, 0, layerBase.getWidth(), layerBase.getHeight(), null);

// draw the other active layers
for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : modelStateInfo
Expand All @@ -1105,8 +1102,7 @@ protected void paintTabBackground(Graphics g, int tabPlacement, final int tabInd
BufferedImage layer = SubstanceTabbedPaneUI.getFinalTabBackgroundImage(
this.tabPane, tabIndex, x, y, w, h, tabPlacement,
SubstanceSlices.Side.BOTTOM, fillScheme, borderScheme);
g2d.drawImage(layer, 0, 0, (int) (layer.getWidth() / scaleFactor),
(int) (layer.getHeight() / scaleFactor), null);
g2d.drawImage(layer, 0, 0, layer.getWidth(), layer.getHeight(), null);
}
}
}
Expand Down Expand Up @@ -1147,6 +1143,7 @@ protected void paintTabBackground(Graphics g, int tabPlacement, final int tabInd

finalAlpha *= SubstanceColorSchemeUtilities.getAlpha(this.tabPane.getComponentAt(tabIndex),
currState);
double scaleFactor = UIUtil.getScaleFactor();

graphics.setComposite(WidgetUtilities.getAlphaComposite(this.tabPane, finalAlpha, g));
graphics.drawImage(fullOpacity, x, y, (int) (fullOpacity.getWidth() / scaleFactor),
Expand All @@ -1164,6 +1161,8 @@ protected void paintTabBackground(Graphics g, int tabPlacement, final int tabInd
if (alpha > 0.0) {
graphics.setComposite(
WidgetUtilities.getAlphaComposite(this.tabPane, finalAlpha * alpha, g));
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);

// paint close button
Rectangle orig = this.getCloseButtonRectangleForDraw(tabIndex, x, y, w, h);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public static BufferedImage getFullAlphaBackground(AbstractButton button, Button
// }
boolean isContentAreaFilled = button.isContentAreaFilled();
boolean isBorderPainted = button.isBorderPainted();
double factor = UIUtil.getScaleFactor();

// compute color scheme
SubstanceColorScheme baseBorderScheme = SubstanceColorSchemeUtilities.getColorScheme(button,
Expand Down Expand Up @@ -193,15 +192,13 @@ public static BufferedImage getFullAlphaBackground(AbstractButton button, Button
regularBackgrounds.put(key2, layer2);
}

BufferedImage result = SubstanceCoreUtilities.getBlankImage(width, height);
BufferedImage result = SubstanceCoreUtilities.getBlankUnscaledImage(layer1);
Graphics2D g2d = result.createGraphics();
if (cyclePos < 1.0f)
g2d.drawImage(layer1, 0, 0, (int) (layer1.getWidth() / factor),
(int) (layer1.getHeight() / factor), null);
g2d.drawImage(layer1, 0, 0, layer1.getWidth(), layer1.getHeight(), null);
if (cyclePos > 0.0f) {
g2d.setComposite(AlphaComposite.SrcOver.derive(cyclePos));
g2d.drawImage(layer2, 0, 0, (int) (layer2.getWidth() / factor),
(int) (layer2.getHeight() / factor), null);
g2d.drawImage(layer2, 0, 0, layer2.getWidth(), layer2.getHeight(), null);
}
g2d.dispose();
return result;
Expand Down Expand Up @@ -236,11 +233,10 @@ public static BufferedImage getFullAlphaBackground(AbstractButton button, Button
return layerBase;
}

BufferedImage result = SubstanceCoreUtilities.getBlankImage(width, height);
BufferedImage result = SubstanceCoreUtilities.getBlankUnscaledImage(layerBase);
Graphics2D g2d = result.createGraphics();
// draw the base layer
g2d.drawImage(layerBase, 0, 0, (int) (layerBase.getWidth() / factor),
(int) (layerBase.getHeight() / factor), null);
g2d.drawImage(layerBase, 0, 0, layerBase.getWidth(), layerBase.getHeight(), null);
// System.out.println("\nPainting base state " + currState);

// draw the other active layers
Expand Down Expand Up @@ -274,8 +270,7 @@ public static BufferedImage getFullAlphaBackground(AbstractButton button, Button
isBorderPainted);
regularBackgrounds.put(key, layer);
}
g2d.drawImage(layer, 0, 0, (int) (layer.getWidth() / factor),
(int) (layer.getHeight() / factor), null);
g2d.drawImage(layer, 0, 0, layer.getWidth(), layer.getHeight(), null);
}
}
g2d.dispose();
Expand Down
Loading

0 comments on commit c525aec

Please sign in to comment.