Skip to content

Commit

Permalink
Tweaking APIs for surface tokens
Browse files Browse the repository at this point in the history
Add surface render color tokens, use them for background tokens at the skin levels, use surface for the background fill. For #400
  • Loading branch information
kirill-grouchnikov committed Dec 2, 2024
1 parent 1a0834b commit 67bbc2a
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.pushingpixels.radiance.theming.api.RadianceThemingCortex;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;
import org.pushingpixels.radiance.theming.api.palette.SurfaceRenderColorTokens;

import javax.swing.*;
import java.awt.*;
Expand All @@ -53,10 +53,11 @@ public static RadianceIcon getLogoIcon(RadianceColorScheme scheme) {
return base;
}

public static RadianceIcon getLogoIcon(ContainerRenderColorTokens renderColorTokens) {
public static RadianceIcon getLogoIcon(SurfaceRenderColorTokens renderColorTokens) {
// Step 1 - create a colorized version of the transcoded Radiance logo
RadianceIcon base = radiance_menu.factory().createNewIcon();
base.setColorFilter(color -> renderColorTokens.getOnContainerColorTokens().getOnContainer());
base.setColorFilter(color -> renderColorTokens.getSurfaceContainerRenderColorTokens()
.getOnContainerColorTokens().getOnContainer());
// Step 2 - configure the colorized version to be 16x16
base.setDimension(new Dimension(16, 16));
// Step 3 - good to go
Expand All @@ -67,7 +68,7 @@ public static BufferedImage getLogoImage(Component comp, RadianceColorScheme sch
return getLogoIcon(scheme).toImage(RadianceCommonCortex.getScaleFactor(comp));
}

public static BufferedImage getLogoImage(Component comp, ContainerRenderColorTokens renderColorTokens) {
public static BufferedImage getLogoImage(Component comp, SurfaceRenderColorTokens renderColorTokens) {
return getLogoIcon(renderColorTokens).toImage(RadianceCommonCortex.getScaleFactor(comp));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ public SampleSkin(RadianceColorScheme accentScheme) {
RadianceThemingSlices.DecorationAreaType.HEADER);

// First tonal configuration
Hct seedHct = Hct.fromInt(0xFF20F290);
Hct seedHct = Hct.fromInt(0xFF9020F4);
double seedHue = seedHct.getHue();
double seedChroma = seedHct.getChroma();

TonalPalette primary = TonalPalette.fromHueAndChroma(seedHue, seedChroma);
TonalPalette neutral = TonalPalette.fromHueAndChroma(seedHue, 10.0);
TonalPalette neutralVariant = TonalPalette.fromHueAndChroma(seedHue, 16.0);
TonalPalette neutral = TonalPalette.fromHueAndChroma(seedHue, 6.0);
TonalPalette neutralVariant = TonalPalette.fromHueAndChroma(seedHue, 8.0);

Palettes samplePalettes = Palettes.builder()
.setNeutralPalette(neutral)
Expand All @@ -114,10 +114,11 @@ public SampleSkin(RadianceColorScheme accentScheme) {
this.registerDecorationAreaColorScheme(lightColorScheme,
RadianceThemingSlices.DecorationAreaType.NONE);

this.registerAsDecorationArea(lightColorScheme.getTonalContainerTokens(),
RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE,
RadianceThemingSlices.DecorationAreaType.SECONDARY_TITLE_PANE,
RadianceThemingSlices.DecorationAreaType.HEADER);
this.registerAsDecorationArea(
lightColorScheme.getTonalSurfaceRenderColorTokens(),
RadianceThemingSlices.DecorationAreaType.PRIMARY_TITLE_PANE,
RadianceThemingSlices.DecorationAreaType.SECONDARY_TITLE_PANE,
RadianceThemingSlices.DecorationAreaType.HEADER);

this.buttonShaper = new ClassicButtonShaper();
this.fillPainter = new ClassicTonalFillPainter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.pushingpixels.radiance.theming.api.painter.overlay.RadianceOverlayPainter;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;
import org.pushingpixels.radiance.theming.api.palette.RadianceColorScheme2;
import org.pushingpixels.radiance.theming.api.palette.SurfaceRenderColorTokens;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.api.shaper.RadianceButtonShaper;
import org.pushingpixels.radiance.theming.api.trait.RadianceTrait;
Expand Down Expand Up @@ -202,7 +203,7 @@ public RadianceColorScheme getWindowChromeAccent() {
*/
private Map<RadianceThemingSlices.DecorationAreaType, RadianceColorScheme> backgroundColorSchemeMap;

private Map<RadianceThemingSlices.DecorationAreaType, ContainerRenderColorTokens> tonalBackgroundRenderColorTokensMap;
private Map<RadianceThemingSlices.DecorationAreaType, SurfaceRenderColorTokens> tonalBackgroundRenderColorTokensMap;

/**
* Maps decoration area type to the registered overlay painters. Each
Expand Down Expand Up @@ -568,16 +569,15 @@ public void registerDecorationAreaSchemeBundle(
}

public void registerDecorationAreaColorScheme(
RadianceColorScheme2 colorScheme,
ContainerRenderColorTokens backgroundRenderColorTokens,
RadianceThemingSlices.DecorationAreaType... areaTypes) {
RadianceColorScheme2 colorScheme,
SurfaceRenderColorTokens backgroundRenderColorTokens,
RadianceThemingSlices.DecorationAreaType... areaTypes) {
if (colorScheme == null) {
return;
}

if (backgroundRenderColorTokens == null) {
throw new IllegalArgumentException(
"Cannot pass null background color render tokens");
throw new IllegalArgumentException("Cannot pass null background color render tokens");
}

for (RadianceThemingSlices.DecorationAreaType areaType : areaTypes) {
Expand All @@ -603,7 +603,7 @@ public void registerDecorationAreaSchemeBundle(

public void registerDecorationAreaColorScheme(
RadianceColorScheme2 colorScheme, RadianceThemingSlices.DecorationAreaType... areaTypes) {
this.registerDecorationAreaColorScheme(colorScheme, colorScheme.getMutedContainerTokens(),
this.registerDecorationAreaColorScheme(colorScheme, colorScheme.getSurfaceRenderColorTokens(),
areaTypes);
}

Expand All @@ -629,7 +629,7 @@ public void registerAsDecorationArea(RadianceColorScheme backgroundColorScheme,
}
}

public void registerAsDecorationArea(ContainerRenderColorTokens backgroundRenderColorTokens,
public void registerAsDecorationArea(SurfaceRenderColorTokens backgroundRenderColorTokens,
RadianceThemingSlices.DecorationAreaType... areaTypes) {
if (backgroundRenderColorTokens == null) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -978,16 +978,16 @@ public final RadianceColorScheme getBackgroundColorScheme(RadianceThemingSlices.
return this.backgroundColorSchemeMap.get(RadianceThemingSlices.DecorationAreaType.NONE);
}

public final ContainerRenderColorTokens getBackgroundRenderColorTokens(
public final SurfaceRenderColorTokens getBackgroundRenderColorTokens(
RadianceThemingSlices.DecorationAreaType decorationAreaType) {
// 1 - check the registered background scheme for this specific area type.
if (this.tonalBackgroundRenderColorTokensMap.containsKey(decorationAreaType)) {
return this.tonalBackgroundRenderColorTokensMap.get(decorationAreaType);
}
// 2 - check the registered scheme bundle for this specific area type.
if (this.tonalColorSchemeMap.containsKey(decorationAreaType)) {
ContainerRenderColorTokens registered = this.tonalColorSchemeMap.get(
decorationAreaType).getMutedContainerTokens();
SurfaceRenderColorTokens registered = this.tonalBackgroundRenderColorTokensMap.
get(decorationAreaType);
if (registered != null) {
return registered;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
import org.pushingpixels.radiance.theming.api.RadianceSkin;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;
import org.pushingpixels.radiance.theming.api.palette.ContainerColorTokens;
import org.pushingpixels.radiance.theming.api.palette.SurfaceRenderColorTokens;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.internal.utils.RadianceCoreUtilities;

Expand Down Expand Up @@ -146,7 +147,10 @@ private void paintTitleBackground(Graphics2D original, Component comp, int width
}

private void paintTitleBackground(Graphics2D original, Component comp, int width, int height,
ContainerRenderColorTokens renderColorTokens) {
SurfaceRenderColorTokens renderColorTokens) {
ContainerColorTokens containerColorTokens =
renderColorTokens.getSurfaceContainerRenderColorTokens().getContainerColorTokens();

// Create a new Graphics2D object so that we can apply clipping to it without having
// to reset the state after we're done
Graphics2D g2d = (Graphics2D) original.create();
Expand All @@ -161,11 +165,12 @@ private void paintTitleBackground(Graphics2D original, Component comp, int width

g2d.setClip(clipTop);
LinearGradientPaint gradientTop = new LinearGradientPaint(0, 0, width, 0,
new float[] { 0.0f, 0.5f, 1.0f }, new Color[] {
renderColorTokens.getContainerColorTokens().getContainer(),
renderColorTokens.getContainerColorTokens().getContainerLowest(),
renderColorTokens.getContainerColorTokens().getContainer() },
CycleMethod.REPEAT);
new float[] { 0.0f, 0.5f, 1.0f },
new Color[] {
containerColorTokens.getContainer(),
containerColorTokens.getContainerLowest(),
containerColorTokens.getContainer() },
CycleMethod.REPEAT);
g2d.setPaint(gradientTop);
g2d.fillRect(0, 0, width, height);

Expand All @@ -178,12 +183,13 @@ private void paintTitleBackground(Graphics2D original, Component comp, int width

g2d.setClip(clipBottom);
LinearGradientPaint gradientBottom = new LinearGradientPaint(0, 0, width, 0,
new float[] { 0.0f, 0.5f, 1.0f },
new Color[] {
renderColorTokens.getContainerColorTokens().getContainerHighest(),
renderColorTokens.getContainerColorTokens().getContainer(),
renderColorTokens.getContainerColorTokens().getContainerHighest() },
CycleMethod.REPEAT);
new float[] { 0.0f, 0.5f, 1.0f },
new Color[] {
containerColorTokens.getContainerHighest(),
containerColorTokens.getContainer(),
containerColorTokens.getContainerHighest()
},
CycleMethod.REPEAT);
g2d.setPaint(gradientBottom);
g2d.fillRect(0, 0, width, height);

Expand Down Expand Up @@ -239,7 +245,10 @@ private void paintExtraBackground(Graphics2D graphics, Container parent, Compone
}

private void paintExtraBackground(Graphics2D graphics, Container parent, Component comp,
int width, int height, ContainerRenderColorTokens renderColorTokens) {
int width, int height, SurfaceRenderColorTokens renderColorTokens) {
ContainerColorTokens containerColorTokens =
renderColorTokens.getSurfaceContainerRenderColorTokens().getContainerColorTokens();

Point offset = RadianceCoreUtilities.getOffsetInRootPaneCoords(comp);
JRootPane rootPane = SwingUtilities.getRootPane(parent);
// fix for bug 234 - Window doesn't have a root pane.
Expand All @@ -250,14 +259,15 @@ private void paintExtraBackground(Graphics2D graphics, Container parent, Compone
: layeredPane.getWidth() - layeredPaneInsets.left - layeredPaneInsets.right;

if (pWidth != 0) {
LinearGradientPaint gradientBottom = new LinearGradientPaint(-offset.x, 0,
-offset.x + pWidth, 0, new float[] { 0.0f, 0.5f, 1.0f },
new Color[] {
renderColorTokens.getContainerColorTokens().getContainerHighest(),
renderColorTokens.getContainerColorTokens().getContainer(),
renderColorTokens.getContainerColorTokens().getContainerHighest()
},
CycleMethod.REPEAT);
LinearGradientPaint gradientBottom = new LinearGradientPaint(
-offset.x, 0, -offset.x + pWidth, 0,
new float[] { 0.0f, 0.5f, 1.0f },
new Color[] {
containerColorTokens.getContainerHighest(),
containerColorTokens.getContainer(),
containerColorTokens.getContainerHighest()
},
CycleMethod.REPEAT);
Graphics2D g2d = (Graphics2D) graphics.create();
g2d.setPaint(gradientBottom);
g2d.fillRect(-offset.x, 0, pWidth, height);
Expand Down Expand Up @@ -293,8 +303,12 @@ public void paintDecorationArea(Graphics2D graphics, Component comp, RadianceThe

@Override
public void paintDecorationArea(Graphics2D graphics, Component comp,
RadianceThemingSlices.DecorationAreaType decorationAreaType, Shape contour,
ContainerRenderColorTokens renderColorTokens) {
RadianceThemingSlices.DecorationAreaType decorationAreaType, Shape contour,
SurfaceRenderColorTokens renderColorTokens) {

ContainerColorTokens containerColorTokens =
renderColorTokens.getSurfaceContainerRenderColorTokens().getContainerColorTokens();

Component parent = RadianceCoreUtilities.getHeaderParent(comp);
Point offset = RadianceCoreUtilities.getOffsetInRootPaneCoords(comp);
JRootPane rootPane = SwingUtilities.getRootPane(parent);
Expand All @@ -306,14 +320,15 @@ public void paintDecorationArea(Graphics2D graphics, Component comp,
: layeredPane.getWidth() - layeredPaneInsets.left - layeredPaneInsets.right;

if (pWidth != 0) {
LinearGradientPaint gradientBottom = new LinearGradientPaint(-offset.x, 0,
-offset.x + pWidth, 0, new float[] { 0.0f, 0.5f, 1.0f },
new Color[] {
renderColorTokens.getContainerColorTokens().getContainerHighest(),
renderColorTokens.getContainerColorTokens().getContainer(),
renderColorTokens.getContainerColorTokens().getContainerHighest()
},
CycleMethod.REPEAT);
LinearGradientPaint gradientBottom = new LinearGradientPaint(
-offset.x, 0, -offset.x + pWidth, 0,
new float[] { 0.0f, 0.5f, 1.0f },
new Color[] {
containerColorTokens.getContainerHighest(),
containerColorTokens.getContainer(),
containerColorTokens.getContainerHighest()
},
CycleMethod.REPEAT);
Graphics2D g2d = (Graphics2D) graphics.create();
g2d.setPaint(gradientBottom);
g2d.fill(contour);
Expand Down
Loading

0 comments on commit 67bbc2a

Please sign in to comment.