Skip to content

Commit

Permalink
First pass for tonal Autumn skin
Browse files Browse the repository at this point in the history
For #400
  • Loading branch information
kirill-grouchnikov committed Jan 6, 2025
1 parent 7f51493 commit d7f550e
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.painter.border.RadianceBorderPainter;
import org.pushingpixels.radiance.theming.api.palette.ContainerColorTokens;
import org.pushingpixels.radiance.theming.api.palette.ExtendedContainerColorTokens;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.internal.painter.DecorationPainterUtils;

import javax.swing.*;
import javax.swing.border.Border;
Expand Down Expand Up @@ -89,10 +87,8 @@ protected void paintComponent(Graphics g) {
RadianceSkin skin = RadianceThemingCortex.ComponentScope.getCurrentSkin(this);
Color accentedFill;
if (skin instanceof TonalSkin) {
ExtendedContainerColorTokens colorTokens = skin.getBackgroundExtendedContainerTokens(
DecorationPainterUtils.getDecorationType(this));
accentedFill = colorTokens.getBaseContainerTokens()
.getContainerSurfaceLow();
accentedFill = skin.getContainerTokens(this, ComponentState.ENABLED,
RadianceThemingSlices.ContainerType.NEUTRAL).getContainerSurfaceLow();
} else {
RadianceThemingSlices.DecorationAreaType decorationAreaType =
RadianceThemingCortex.ComponentOrParentChainScope.getDecorationType(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.pushingpixels.radiance.demo.theming.main.Check;
import org.pushingpixels.radiance.theming.api.RadianceSkin;
import org.pushingpixels.radiance.theming.api.RadianceThemingCortex;
import org.pushingpixels.radiance.theming.api.skin.BusinessBlackSteelSkin;
import org.pushingpixels.radiance.theming.api.skin.AutumnSkin;

import javax.swing.*;
import java.awt.*;
Expand All @@ -41,7 +41,7 @@

public class TonalCheck {
public static void main(String[] args) {
RadianceSkin tonalSkin = new BusinessBlackSteelSkin.BusinessBlackSteelTonalSkin();
RadianceSkin tonalSkin = new AutumnSkin.AutumnTonalSkin();
//new ControlStates.SampleSkin(new AquaColorScheme());

RadianceThemingCortex.GlobalScope.registerWidget("org.pushingpixels.radiance.theming" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void paintTitleBackground(Graphics2D graphics, Component comp,
ExtendedContainerColorTokens tileContainerTokens =
skin.getBackgroundExtendedContainerTokens(decorationAreaType);
if (this.baseDecorationPainter == null) {
graphics.setColor(tileContainerTokens.getBaseContainerTokens().getContainerSurfaceHigh());
graphics.setColor(tileContainerTokens.getBaseContainerTokens().getContainerSurface());
graphics.fillRect(0, 0, width, height);
} else {
this.baseDecorationPainter.paintDecorationArea(graphics, comp, decorationAreaType,
Expand Down Expand Up @@ -173,8 +173,7 @@ private void paintExtraBackground(Graphics2D graphics, Component comp,
if (this.baseDecorationPainter != null) {
this.baseDecorationPainter.paintDecorationArea(graphics, comp, decorationAreaType, width, height, skin);
} else {
graphics.setColor(tileContainerTokens.getBaseContainerTokens()
.getContainerSurfaceHigh());
graphics.setColor(tileContainerTokens.getBaseContainerTokens().getContainerSurface());
graphics.fillRect(0, 0, width, height);
}
Graphics2D temp = (Graphics2D) graphics.create();
Expand Down Expand Up @@ -224,8 +223,7 @@ public void paintDecorationArea(Graphics2D graphics, Component comp,
this.baseDecorationPainter.paintDecorationArea(graphics, comp, decorationAreaType,
contour, colorTokens);
} else {
graphics.setColor(colorTokens.getBaseContainerTokens()
.getContainerSurfaceHigh());
graphics.setColor(colorTokens.getBaseContainerTokens().getContainerSurface());
graphics.fill(contour);
}
Graphics2D temp = (Graphics2D) graphics.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class MatteFillPainter extends FractionBasedFillPainter {
public static final MatteFillPainter INSTANCE = new MatteFillPainter();

/**
* Creates a new classic gradient painter.
* Creates a new matte fill painter.
*/
public MatteFillPainter() {
super("Matte",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2005-2025 Radiance Kirill Grouchnikov. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* o Neither the name of the copyright holder nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.pushingpixels.radiance.theming.api.painter.fill;

import org.pushingpixels.radiance.theming.api.colorscheme.ContainerColorTokensSingleColorQuery;

/**
* Fill painter that draws visuals with matte appearance. This class is part
* of officially supported API.
*
* @author Kirill Grouchnikov
*/
public class MatteTonalFillPainter extends FractionBasedTonalFillPainter {
/**
* Reusable instance of this painter.
*/
public static final MatteTonalFillPainter INSTANCE = new MatteTonalFillPainter();

/**
* Creates a new matte fill painter.
*/
public MatteTonalFillPainter() {
super("Classic",
new float[] {0.0f, 1.0f},
new ContainerColorTokensSingleColorQuery[] {
ContainerColorTokensSingleColorQuery.CONTAINER_LOW,
ContainerColorTokensSingleColorQuery.CONTAINER
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,58 @@ public static ContainerColorTokens getLightTonalBalancedContainerTokens(Hct seed
/* palette */ TonalPalette.fromHct(seed));
}

public static ExtendedContainerColorTokens getLightTonalExtendedContainerTokens(
Hct sourceColorHct, boolean isFidelity, TonalPalette palette) {

DynamicPalette dynamicPalette = new DynamicPalette(
/* sourceColorHct */ sourceColorHct,
/* isFidelity */ isFidelity,
/* isDark */ false,
/* contrastLevel */ 0.0,
/* palette */ palette);

PaletteContainerColorsResolver paletteColorResolver =
PaletteResolverUtils.getPaletteTonalColorResolver();

ContainerColorTokens baseTokens = getContainerTokens(dynamicPalette, paletteColorResolver);

return new ExtendedContainerColorTokens() {
@Override
public Color getSurface() {
return paletteColorResolver.getSurface(dynamicPalette);
}

@Override
public Color getSurfaceDim() {
return paletteColorResolver.getSurfaceDim(dynamicPalette);
}

@Override
public Color getSurfaceBright() {
return paletteColorResolver.getSurfaceBright(dynamicPalette);
}

@Override
public ContainerColorTokens getBaseContainerTokens() {
return baseTokens;
}
};
}

public static ExtendedContainerColorTokens getLightTonalFidelityExtendedContainerTokens(Hct seed) {
return ColorSchemeUtils.getLightTonalExtendedContainerTokens(
/* sourceColorHct */ seed,
/* isFidelity */ true,
/* palette */ TonalPalette.fromHct(seed));
}

public static ExtendedContainerColorTokens getLightTonalBalancedExtendedContainerTokens(Hct seed) {
return ColorSchemeUtils.getLightTonalExtendedContainerTokens(
/* sourceColorHct */ seed,
/* isFidelity */ false,
/* palette */ TonalPalette.fromHct(seed));
}

public static ContainerColorTokens tint(ContainerColorTokens original, float tintFactor) {
return new ContainerColorTokens() {
@Override
Expand Down Expand Up @@ -1007,4 +1059,82 @@ public float getContainerOutlineDisabledAlpha() {
}
};
}

public static ContainerColorTokens shade(ContainerColorTokens original, float shadeFactor) {
return new ContainerColorTokens() {
@Override
public boolean isDark() {
return original.isDark();
}

@Override
public Color getContainerSurfaceLowest() {
return new Color(Blend.cam16Ucs(original.getContainerSurfaceLowest().getRGB(),
Color.BLACK.getRGB(), shadeFactor));
}

@Override
public Color getContainerSurfaceLow() {
return new Color(Blend.cam16Ucs(original.getContainerSurfaceLow().getRGB(),
Color.BLACK.getRGB(), shadeFactor));
}

@Override
public Color getContainerSurface() {
return new Color(Blend.cam16Ucs(original.getContainerSurface().getRGB(),
Color.BLACK.getRGB(), shadeFactor));
}

@Override
public Color getContainerSurfaceHigh() {
return new Color(Blend.cam16Ucs(original.getContainerSurfaceHigh().getRGB(),
Color.BLACK.getRGB(), shadeFactor));
}

@Override
public Color getContainerSurfaceHighest() {
return new Color(Blend.cam16Ucs(original.getContainerSurfaceHighest().getRGB(),
Color.BLACK.getRGB(), shadeFactor));
}

@Override
public Color getOnContainer() {
return new Color(Blend.cam16Ucs(original.getOnContainer().getRGB(),
Color.BLACK.getRGB(), shadeFactor));
}

@Override
public Color getOnContainerVariant() {
return new Color(Blend.cam16Ucs(original.getOnContainerVariant().getRGB(),
Color.BLACK.getRGB(), shadeFactor));
}

@Override
public Color getContainerOutline() {
return new Color(Blend.cam16Ucs(original.getContainerOutline().getRGB(),
Color.BLACK.getRGB(), shadeFactor));
}

@Override
public Color getContainerOutlineVariant() {
return new Color(Blend.cam16Ucs(original.getContainerOutlineVariant().getRGB(),
Color.BLACK.getRGB(), shadeFactor));
}

@Override
public float getContainerSurfaceDisabledAlpha() {
return original.getContainerSurfaceDisabledAlpha();
}

@Override
public float getOnContainerDisabledAlpha() {
return original.getOnContainerDisabledAlpha();
}

@Override
public float getContainerOutlineDisabledAlpha() {
return original.getContainerOutlineDisabledAlpha();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@
import java.awt.*;

public interface PaletteContainerColorsResolver {
Color getContainerSurfaceLowest(DynamicPalette dynamicScheme);
Color getContainerSurfaceLow(DynamicPalette dynamicScheme);
Color getContainerSurface(DynamicPalette dynamicScheme);
Color getContainerSurfaceHigh(DynamicPalette dynamicScheme);
Color getContainerSurfaceHighest(DynamicPalette dynamicScheme);
Color getSurface(DynamicPalette dynamicPalette);
Color getSurfaceDim(DynamicPalette dynamicPalette);
Color getSurfaceBright(DynamicPalette dynamicPalette);

Color getOnContainer(DynamicPalette dynamicScheme);
Color getOnContainerVariant(DynamicPalette dynamicScheme);
Color getContainerSurfaceLowest(DynamicPalette dynamicPalette);
Color getContainerSurfaceLow(DynamicPalette dynamicPalette);
Color getContainerSurface(DynamicPalette dynamicPalette);
Color getContainerSurfaceHigh(DynamicPalette dynamicPalette);
Color getContainerSurfaceHighest(DynamicPalette dynamicPalette);

Color getContainerOutline(DynamicPalette dynamicScheme);
Color getContainerOutlineVariant(DynamicPalette dynamicScheme);
Color getOnContainer(DynamicPalette dynamicPalette);
Color getOnContainerVariant(DynamicPalette dynamicPalette);

Color getContainerOutline(DynamicPalette dynamicPalette);
Color getContainerOutlineVariant(DynamicPalette dynamicPalette);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ public class PaletteResolverUtils {
public static PaletteContainerColorsResolver getPaletteTonalColorResolver() {
PaletteContainerColorsResolver result =
new PaletteContainerColorsResolver() {
@Override
public Color getSurface(DynamicPalette dynamicPalette) {
return new Color(dynamicPalette.getSurface());
}

@Override
public Color getSurfaceBright(DynamicPalette dynamicPalette) {
return new Color(dynamicPalette.getSurfaceBright());
}

@Override
public Color getSurfaceDim(DynamicPalette dynamicPalette) {
return new Color(dynamicPalette.getSurfaceDim());
}

@Override
public Color getContainerSurfaceLowest(DynamicPalette dynamicPalette) {
return new Color(dynamicPalette.getTonalContainerSurfaceLowest());
Expand Down
Loading

0 comments on commit d7f550e

Please sign in to comment.