Skip to content

Commit

Permalink
First pass for tonal Mariner skin
Browse files Browse the repository at this point in the history
For #400
  • Loading branch information
kirill-grouchnikov committed Jan 17, 2025
1 parent 76e4cbd commit 5a9881b
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
import org.pushingpixels.radiance.theming.api.painter.fill.ClassicTonalFillPainter;
import org.pushingpixels.radiance.theming.api.painter.fill.GlassTonalFillPainter;
import org.pushingpixels.radiance.theming.api.painter.fill.SpecularRectangularFillPainter;
import org.pushingpixels.radiance.theming.api.palette.*;
import org.pushingpixels.radiance.theming.api.palette.ColorSchemeUtils;
import org.pushingpixels.radiance.theming.api.palette.RadianceColorScheme2;
import org.pushingpixels.radiance.theming.api.palette.SchemeResolverUtils;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.api.shaper.ClassicButtonShaper;
import org.pushingpixels.radiance.theming.internal.RadianceSynapse;

Expand Down Expand Up @@ -108,17 +111,15 @@ public SampleSkin(RadianceColorScheme accentScheme) {
ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFF20F490),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver()),
/* isDark */ false),
RadianceThemingSlices.ContainerColorTokensAssociationKind.MARK,
ComponentState.getActiveStates());

bundle2.registerContainerTokens(
ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFF20F490),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver()),
/* isDark */ false),
RadianceThemingSlices.ContainerColorTokensAssociationKind.HIGHLIGHT,
ComponentState.getActiveStates());

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.AutumnSkin;
import org.pushingpixels.radiance.theming.api.skin.MarinerSkin;

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

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

RadianceThemingCortex.GlobalScope.registerWidget("org.pushingpixels.radiance.theming" +
".extras.api.tabbed.TabHoverPreviewWidget", JTabbedPane.class, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,23 @@ public OfficeSilver2007TonalSkin() {
ContainerColorTokens rolloverContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFFD111),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver());
/* isDark */ false);
ContainerColorTokens selectedContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFFBD51),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver());
/* isDark */ false);
ContainerColorTokens rolloverSelectedContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFFA400),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver());
/* isDark */ false);
ContainerColorTokens pressedContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFF8C18),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver());
/* isDark */ false);
ContainerColorTokens pressedSelectedContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFF991C),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver());
/* isDark */ false);

// register state-specific color schemes on rollovers, presses and selections
officeSilverDefaultBundle.registerContainerTokens(rolloverContainerTokens,
Expand Down Expand Up @@ -343,27 +338,32 @@ public OfficeSilver2007TonalSkin() {
/* seed */ Hct.fromInt(0xFFFFD111),
/* isFidelity */ true,
/* isDark */ false,
/* contrastLevel */ 0.0,
/* colorResolver */ activeMarksColorResolver);
ContainerColorTokens selectedMarkContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFFBD51),
/* isFidelity */ true,
/* isDark */ false,
/* contrastLevel */ 0.0,
/* colorResolver */ activeMarksColorResolver);
ContainerColorTokens rolloverSelectedMarkContainerTokens =
ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFFA400),
/* isFidelity */ true,
/* isDark */ false,
/* contrastLevel */ 0.0,
/* colorResolver */ activeMarksColorResolver);
ContainerColorTokens pressedMarkContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFF8C18),
/* isFidelity */ true,
/* isDark */ false,
/* contrastLevel */ 0.0,
/* colorResolver */ activeMarksColorResolver);
ContainerColorTokens pressedSelectedMarkContainerTokens = ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFFF991C),
/* isFidelity */ true,
/* isDark */ false,
/* contrastLevel */ 0.0,
/* colorResolver */ activeMarksColorResolver);

// register state-specific color schemes on mark rollovers, presses and selections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
*/
package org.pushingpixels.radiance.theming.api.painter.overlay;

import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.ComponentState;
import org.pushingpixels.radiance.theming.api.RadianceSkin;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorSchemeUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceCoreUtilities;

Expand Down Expand Up @@ -91,10 +94,15 @@ private BottomShadowOverlayPainter() {

@Override
public void paintOverlay(Graphics2D graphics, Component comp,
RadianceThemingSlices.DecorationAreaType decorationAreaType, int width, int height,
RadianceSkin skin) {
Color shadowColor = RadianceColorUtilities.deriveByBrightness(
RadianceColorUtilities.getBackgroundFillColor(comp), -0.4f);
RadianceThemingSlices.DecorationAreaType decorationAreaType, int width, int height,
RadianceSkin skin) {

Color shadowColor = (skin instanceof TonalSkin)
? RadianceColorSchemeUtilities.getContainerTokens(comp,
ComponentState.ENABLED, RadianceThemingSlices.ContainerType.NEUTRAL)
.getContainerOutline()
:RadianceColorUtilities.deriveByBrightness(
RadianceColorUtilities.getBackgroundFillColor(comp), -0.4f);

Component topMostWithSameDecorationAreaType = RadianceCoreUtilities
.getTopMostParentWithDecorationAreaType(comp,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* 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.overlay;

import org.pushingpixels.radiance.common.api.RadianceCommonCortex;
import org.pushingpixels.radiance.theming.api.RadianceSkin;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices;
import org.pushingpixels.radiance.theming.api.colorscheme.ContainerColorTokensSingleColorQuery;
import org.pushingpixels.radiance.theming.api.palette.ExtendedContainerColorTokens;
import org.pushingpixels.radiance.theming.internal.utils.RadianceCoreUtilities;

import javax.swing.*;
import java.awt.*;

/**
* Overlay painter that paints a bezel line at the top edge of the relevant
* decoration area. This class is part of officially supported API.
*
* @author Kirill Grouchnikov
*/
public final class TopBezelTonalOverlayPainter implements RadianceOverlayPainter {
/**
* Used to compute the color of the top line painted by this overlay
* painter.
*/
ContainerColorTokensSingleColorQuery colorSchemeQueryTop;

/**
* Used to compute the color of the bottom line painted by this overlay
* painter.
*/
ContainerColorTokensSingleColorQuery colorSchemeQueryBottom;

/**
* Creates a new overlay painter that paints a bezel line at the top edge of
* the relevant decoration area
*
* @param colorSchemeQueryTop Used to compute the color of the top line painted by this
* overlay painter.
* @param colorSchemeQueryBottom Used to compute the color of the bottom line painted by this
* overlay painter.
*/
public TopBezelTonalOverlayPainter(
ContainerColorTokensSingleColorQuery colorSchemeQueryTop,
ContainerColorTokensSingleColorQuery colorSchemeQueryBottom) {

this.colorSchemeQueryTop = colorSchemeQueryTop;
this.colorSchemeQueryBottom = colorSchemeQueryBottom;
}

@Override
public void paintOverlay(Graphics2D g, Component comp,
RadianceThemingSlices.DecorationAreaType decorationAreaType, int width, int height,
RadianceSkin skin) {
Component topMostWithSameDecorationAreaType = RadianceCoreUtilities
.getTopMostParentWithDecorationAreaType(comp,
decorationAreaType);

Point inTopMost = SwingUtilities.convertPoint(comp, new Point(0, 0),
topMostWithSameDecorationAreaType);
int dy = inTopMost.y;

Graphics2D graphics = (Graphics2D) g.create();
// Important - do not set KEY_STROKE_CONTROL to VALUE_STROKE_PURE, as that instructs AWT
// to not normalize coordinates to paint at full pixels, and will result in blurry
// outlines.
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

RadianceCommonCortex.paintAtScale1x(graphics, 0, 0, width, height,
(graphics1X, x, y, scaledWidth, scaledHeight, scaleFactor) -> {
ExtendedContainerColorTokens surfaceTokens =
skin.getBackgroundExtendedContainerTokens(decorationAreaType);

graphics1X.setColor(this.colorSchemeQueryTop.query(
surfaceTokens.getBaseContainerTokens()));

int topY = -(int) (scaleFactor * dy);
graphics1X.drawLine(0, topY, scaledWidth, topY);

graphics1X.setColor(this.colorSchemeQueryBottom.query(
surfaceTokens.getBaseContainerTokens()));

int bezelY = 1 - (int) (scaleFactor * dy);
graphics1X.drawLine(0, bezelY, scaledWidth, bezelY);
});

graphics.dispose();
}

@Override
public String getDisplayName() {
return "Top Bezel";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -500,17 +500,26 @@ public ContainerColorTokens getSystemEmergencyContainerTokens() {
};
}

public static ContainerColorTokens getContainerTokens(
Hct seed,
boolean isFidelity,
boolean isDark) {
return getContainerTokens(seed, isFidelity, isDark, 0.0,
PaletteResolverUtils.getPaletteTonalColorResolver());
}

public static ContainerColorTokens getContainerTokens(
Hct seed,
boolean isFidelity,
boolean isDark,
double contrastLevel,
PaletteContainerColorsResolver colorResolver) {

DynamicPalette dynamicPalette = new DynamicPalette(
/* sourceColorHct */ seed,
/* isFidelity */ isFidelity,
/* isDark */ isDark,
/* contrastLevel */ 0.0,
/* contrastLevel */ contrastLevel,
/* palette */ TonalPalette.fromHct(seed));

return new ContainerColorTokens() {
Expand Down Expand Up @@ -581,20 +590,30 @@ public float getContainerOutlineDisabledAlpha() {
};
}

public static ExtendedContainerColorTokens getExtendedContainerTokens(
Hct seed,
boolean isFidelity,
boolean isDark) {
return getExtendedContainerTokens(seed, isFidelity, isDark, 0.0,
PaletteResolverUtils.getPaletteTonalColorResolver());
}

public static ExtendedContainerColorTokens getExtendedContainerTokens(
Hct seed,
boolean isFidelity,
boolean isDark,
double contrastLevel,
PaletteContainerColorsResolver colorResolver) {

DynamicPalette dynamicPalette = new DynamicPalette(
/* sourceColorHct */ seed,
/* isFidelity */ isFidelity,
/* isDark */ isDark,
/* contrastLevel */ 0.0,
/* contrastLevel */ contrastLevel,
/* palette */ TonalPalette.fromHct(seed));

ContainerColorTokens baseTokens = getContainerTokens(seed, isFidelity, isDark, colorResolver);
ContainerColorTokens baseTokens = getContainerTokens(seed, isFidelity, isDark,
contrastLevel, colorResolver);

return new ExtendedContainerColorTokens() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public AutumnTonalSkin() {
/* seed */ Hct.fromInt(0xFFFDBD72),
/* isFidelity */ true,
/* isDark */ false,
/* contrastLevel */ 0.0,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver().overlayWith(
PaletteContainerColorsResolverOverlay.builder()
.onContainer(DynamicPalette::getTonalContainerOutline)
Expand All @@ -226,6 +227,7 @@ public AutumnTonalSkin() {
/* seed */ Hct.fromInt(0xFFFFCA8B),
/* isFidelity */ true,
/* isDark */ false,
/* contrastLevel */ 0.0,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver().overlayWith(
PaletteContainerColorsResolverOverlay.builder()
.onContainer(DynamicPalette::getOnTonalContainerVariant)
Expand All @@ -246,8 +248,7 @@ public AutumnTonalSkin() {
ColorSchemeUtils.getExtendedContainerTokens(
/* seed */ Hct.fromInt(0xFFFED8B2),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver()),
/* isDark */ false),
RadianceThemingSlices.DecorationAreaType.CONTROL_PANE);

this.buttonShaper = new ClassicButtonShaper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.pushingpixels.radiance.theming.api.*;
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ColorSchemeUtils;
import org.pushingpixels.radiance.theming.api.palette.PaletteResolverUtils;
import org.pushingpixels.radiance.theming.api.palette.RadianceColorScheme2;
import org.pushingpixels.radiance.theming.api.palette.SchemeResolverUtils;

Expand Down Expand Up @@ -119,8 +118,7 @@ public BusinessBlackSteelTonalSkin() {
.withWindowChromeHighlightsAccent(ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFF85A3B5),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver()))
/* isDark */ false))
.withActiveControlsAccent(ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.FidelityPaletteSource(
Hct.fromInt(0xFF98B7CC), Hct.fromInt(0xFFC4C8CC), Hct.fromInt(0xFFE4EAF0)),
Expand All @@ -130,8 +128,7 @@ public BusinessBlackSteelTonalSkin() {
.withHighlightsAccent(ColorSchemeUtils.getContainerTokens(
/* seed */ Hct.fromInt(0xFFA1BCCF),
/* isFidelity */ true,
/* isDark */ false,
/* colorResolver */ PaletteResolverUtils.getPaletteTonalColorResolver())));
/* isDark */ false)));

RadianceColorScheme2 controlPaneColorScheme = ColorSchemeUtils.getColorScheme(
/* palettesSource */ new ColorSchemeUtils.FidelityPaletteSource(
Expand Down
Loading

0 comments on commit 5a9881b

Please sign in to comment.