Skip to content

Commit

Permalink
Convert title pane icons into the tonal world
Browse files Browse the repository at this point in the history
For #400
  • Loading branch information
kirill-grouchnikov committed Nov 30, 2024
1 parent 8d58719 commit ca35c39
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
package org.pushingpixels.radiance.demo.theming.main.check;

import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;
import org.pushingpixels.radiance.theming.api.titlepane.DefaultTitlePaneButtonsProvider;
import org.pushingpixels.radiance.theming.api.titlepane.TitlePaneButtonProvider;

Expand Down Expand Up @@ -64,6 +65,33 @@ public void drawIcon(Graphics2D g, RadianceColorScheme scheme, float alpha, int

graphics.dispose();
}

@Override
public void drawIcon(Graphics2D g, ContainerRenderColorTokens renderColorTokens,
float alpha, int iconSize) {
Graphics2D graphics = (Graphics2D) g.create();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);

int start = iconSize / 4;
int end = iconSize - start;

Color primaryColor = renderColorTokens.getOnContainerColorTokens().getOnContainer();

Stroke primaryStroke = new BasicStroke(1.5f,
BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

graphics.setStroke(primaryStroke);
graphics.setColor(primaryColor);
// Triangle
graphics.drawLine(start, start, end, start);
graphics.drawLine(end, start, end, end);
graphics.drawLine(end, end, start, start);

graphics.dispose();
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public final ContainerRenderColorTokens getColorRenderTokens(Component comp,
throw new IllegalStateException("Color scheme shouldn't be null here. Please "
+ "report this issue");
}
return componentState.isActive() ? registered.getTonalContainerTokens()
return componentState.isActive() ? registered.getPrimaryContainerTokens()
: registered.getMutedContainerTokens();
}
}
Expand All @@ -428,7 +428,7 @@ public final ContainerRenderColorTokens getColorRenderTokens(Component comp,
if (registered == null) {
throw new IllegalStateException("Color scheme shouldn't be null here. Please report " + "this issue");
}
return componentState.isActive() ? registered.getTonalContainerTokens()
return componentState.isActive() ? registered.getPrimaryContainerTokens()
: registered.getMutedContainerTokens();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.pushingpixels.radiance.theming.api.RadianceThemingCortex;
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;
import org.pushingpixels.radiance.theming.internal.blade.BladeIconUtils;
import org.pushingpixels.radiance.theming.internal.utils.RadianceCoreUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceSizeUtils;
Expand Down Expand Up @@ -58,6 +59,12 @@ public void drawIcon(Graphics2D g, RadianceColorScheme scheme, float alpha, int
BladeIconUtils.drawCloseIcon(g, iconSize,
RadianceSizeUtils.getCloseIconStrokeWidth(iconSize), scheme);
}

@Override
public void drawIcon(Graphics2D g, ContainerRenderColorTokens renderColorTokens, float alpha, int iconSize) {
BladeIconUtils.drawCloseIcon(g, iconSize,
RadianceSizeUtils.getCloseIconStrokeWidth(iconSize), renderColorTokens);
}
}

@Override
Expand All @@ -75,6 +82,11 @@ public String getText(JRootPane rootPane) {
public void drawIcon(Graphics2D g, RadianceColorScheme scheme, float alpha, int iconSize) {
BladeIconUtils.drawRestoreIcon(g, iconSize, scheme);
}

@Override
public void drawIcon(Graphics2D g, ContainerRenderColorTokens renderColorTokens, float alpha, int iconSize) {
BladeIconUtils.drawRestoreIcon(g, iconSize, renderColorTokens);
}
}

@Override
Expand All @@ -92,6 +104,11 @@ public String getText(JRootPane rootPane) {
public void drawIcon(Graphics2D g, RadianceColorScheme scheme, float alpha, int iconSize) {
BladeIconUtils.drawIconifyIcon(g, iconSize, scheme);
}

@Override
public void drawIcon(Graphics2D g, ContainerRenderColorTokens renderColorTokens, float alpha, int iconSize) {
BladeIconUtils.drawIconifyIcon(g, iconSize, renderColorTokens);
}
}

@Override
Expand All @@ -109,6 +126,11 @@ public String getText(JRootPane rootPane) {
public void drawIcon(Graphics2D g, RadianceColorScheme scheme, float alpha, int iconSize) {
BladeIconUtils.drawMaximizeIcon(g, iconSize, scheme);
}

@Override
public void drawIcon(Graphics2D g, ContainerRenderColorTokens renderColorTokens, float alpha, int iconSize) {
BladeIconUtils.drawMaximizeIcon(g, iconSize, renderColorTokens);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
package org.pushingpixels.radiance.theming.api.titlepane;

import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;

import javax.swing.*;
import java.awt.*;
Expand All @@ -46,4 +47,10 @@ public interface TitlePaneButtonProvider {
* Draws the icon for this button.
*/
void drawIcon(Graphics2D g, RadianceColorScheme scheme, float alpha, int iconSize);

/**
* Draws the icon for this button.
*/
default void drawIcon(Graphics2D g, ContainerRenderColorTokens renderColorTokens,
float alpha, int iconSize) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
package org.pushingpixels.radiance.theming.internal.blade;

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.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.internal.animation.StateTransitionTracker;
import org.pushingpixels.radiance.theming.internal.animation.TransitionAwareUI;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorSchemeUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceCoreUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceSizeUtils;
import org.pushingpixels.radiance.theming.internal.utils.icon.TransitionAware;

Expand Down Expand Up @@ -135,7 +138,16 @@ public void paintIcon(Component c, Graphics g, int x, int y) {

Graphics2D graphics = (Graphics2D) g.create();
graphics.translate(x, y);
this.delegate.drawColorSchemeIcon(graphics, mutableColorScheme, iconAlpha);
RadianceSkin skin = RadianceCoreUtilities.getSkin(c);
if (skin instanceof TonalSkin) {
this.delegate.drawColorSchemeIcon(graphics,
BladeUtils.getDefaultColorSchemeDelegate(this.component,
this.colorSchemeAssociationKindDelegate)
.getRenderColorTokensForCurrentState(currState),
iconAlpha);
} else {
this.delegate.drawColorSchemeIcon(graphics, mutableColorScheme, iconAlpha);
}
graphics.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.pushingpixels.radiance.theming.api.painter.border.RadianceBorderPainter;
import org.pushingpixels.radiance.theming.api.painter.fill.FractionBasedFillPainter;
import org.pushingpixels.radiance.theming.api.painter.fill.RadianceFillPainter;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceOutlineUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceSizeUtils;
Expand Down Expand Up @@ -374,6 +375,30 @@ public static void drawCloseIcon(Graphics2D g, int iconSize,
graphics.dispose();
}

public static void drawCloseIcon(Graphics2D g, int iconSize,
float primaryStrokeWidth, ContainerRenderColorTokens renderColorTokens) {
Graphics2D graphics = (Graphics2D) g.create();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);

int start = iconSize / 4;
int end = iconSize - start;

Color primaryColor = renderColorTokens.getOnContainerColorTokens().getOnContainer();

Stroke primaryStroke = new BasicStroke(primaryStrokeWidth,
BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

graphics.setStroke(primaryStroke);
graphics.setColor(primaryColor);
graphics.drawLine(start, start, end, end);
graphics.drawLine(start, end, end, start);

graphics.dispose();
}

public static void drawIconifyIcon(Graphics2D g, int iconSize,
RadianceColorScheme scheme) {
Graphics2D graphics = (Graphics2D) g.create();
Expand All @@ -393,6 +418,25 @@ public static void drawIconifyIcon(Graphics2D g, int iconSize,
graphics.dispose();
}

public static void drawIconifyIcon(Graphics2D g, int iconSize,
ContainerRenderColorTokens renderColorTokens) {
Graphics2D graphics = (Graphics2D) g.create();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);

int start = iconSize / 4 - 2;
int end = 3 * iconSize / 4;
int size = end - start - 2;

Color primaryColor = renderColorTokens.getOnContainerColorTokens().getOnContainer();

graphics.setColor(primaryColor);
graphics.fillRect(start + 2, end - 1, size, 3);
graphics.dispose();
}

public static void drawMaximizeIcon(Graphics2D g, int iconSize,
RadianceColorScheme scheme) {
Graphics2D graphics = (Graphics2D) g.create();
Expand All @@ -418,6 +462,31 @@ public static void drawMaximizeIcon(Graphics2D g, int iconSize,
graphics.dispose();
}

public static void drawMaximizeIcon(Graphics2D g, int iconSize,
ContainerRenderColorTokens renderColorTokens) {
Graphics2D graphics = (Graphics2D) g.create();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);

int start = iconSize / 4 - 1;
int end = iconSize - start;

Color primaryColor = renderColorTokens.getOnContainerColorTokens().getOnContainer();

graphics.setColor(primaryColor);
// top (thicker)
graphics.fillRect(start, start, end - start, 2);
// left
graphics.fillRect(start, start, 1, end - start);
// right
graphics.fillRect(end - 1, start, 1, end - start);
// bottom
graphics.fillRect(start, end - 1, end - start, 1);
graphics.dispose();
}

public static void drawRestoreIcon(Graphics2D g, int iconSize,
RadianceColorScheme scheme) {
Graphics2D graphics = (Graphics2D) g.create();
Expand Down Expand Up @@ -460,6 +529,48 @@ public static void drawRestoreIcon(Graphics2D g, int iconSize,
graphics.dispose();
}

public static void drawRestoreIcon(Graphics2D g, int iconSize,
ContainerRenderColorTokens renderColorTokens) {
Graphics2D graphics = (Graphics2D) g.create();
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);

int start = iconSize / 4 - 1;
int end = iconSize - start;
int smallSquareSize = end - start - 3;
Color primaryColor = renderColorTokens.getOnContainerColorTokens().getOnContainer();

graphics.setColor(primaryColor);

// "Main" rectangle
int mainStartX = start;
int mainStartY = end - smallSquareSize;
// top (thicker)
graphics.fillRect(mainStartX, mainStartY, smallSquareSize, 2);
// left
graphics.fillRect(mainStartX, mainStartY, 1, smallSquareSize);
// right
graphics.fillRect(mainStartX + smallSquareSize - 1, mainStartY, 1, smallSquareSize);
// bottom
graphics.fillRect(mainStartX, mainStartY + smallSquareSize - 1, smallSquareSize, 1);

// "Secondary rectangle"
int secondaryStartX = mainStartX + 3;
int secondaryStartY = mainStartY - 3;
// top (thicker)
graphics.fillRect(secondaryStartX, secondaryStartY, smallSquareSize, 2);
// right
graphics.fillRect(secondaryStartX + smallSquareSize - 1, secondaryStartY, 1,
smallSquareSize);
// bottom (partial)
graphics.fillRect(mainStartX + smallSquareSize + 1, secondaryStartY + smallSquareSize - 1,
2, 1);

graphics.dispose();
}

public static void drawHexaMarker(Graphics2D g, int value, RadianceColorScheme colorScheme) {
value %= 16;
boolean isDark = colorScheme.isDark();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
package org.pushingpixels.radiance.theming.internal.blade;

import org.pushingpixels.radiance.theming.api.ComponentState;
import org.pushingpixels.radiance.theming.api.RadianceSkin;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices.ColorSchemeAssociationKind;
import org.pushingpixels.radiance.theming.api.RadianceThemingSlices.ComponentStateFacet;
import org.pushingpixels.radiance.theming.api.colorscheme.RadianceColorScheme;
import org.pushingpixels.radiance.theming.api.palette.ContainerRenderColorTokens;
import org.pushingpixels.radiance.theming.api.palette.TonalSkin;
import org.pushingpixels.radiance.theming.internal.animation.StateTransitionTracker;
import org.pushingpixels.radiance.theming.internal.animation.TransitionAwareUI;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorSchemeUtilities;
Expand Down Expand Up @@ -61,6 +64,9 @@ public class BladeTransitionAwareIcon implements Icon {
public interface Delegate {
void drawColorSchemeIcon(Graphics2D g, RadianceColorScheme scheme, float alpha);

default void drawColorSchemeIcon(Graphics2D g, ContainerRenderColorTokens renderColorTokens,
float alpha) {}

Dimension getIconDimension();
}

Expand Down Expand Up @@ -158,7 +164,17 @@ public void paintIcon(Component c, Graphics g, int x, int y) {

Graphics2D graphics = (Graphics2D) g.create();
graphics.translate(x, y);
this.delegate.drawColorSchemeIcon(graphics, mutableColorScheme, iconAlpha);

RadianceSkin skin = RadianceCoreUtilities.getSkin(c);
if (skin instanceof TonalSkin) {
this.delegate.drawColorSchemeIcon(graphics,
BladeUtils.getDefaultColorSchemeDelegate(c,
this.colorSchemeAssociationKindDelegate)
.getRenderColorTokensForCurrentState(currState),
iconAlpha);
} else {
this.delegate.drawColorSchemeIcon(graphics, mutableColorScheme, iconAlpha);
}
graphics.dispose();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.pushingpixels.radiance.theming.api.ComponentState;
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.internal.animation.StateTransitionTracker;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorSchemeUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorUtilities;
Expand Down Expand Up @@ -222,6 +223,14 @@ public static void populateColorScheme(
public interface ColorSchemeDelegate {
RadianceColorScheme getColorSchemeForCurrentState(ComponentState state);
RadianceColorScheme getColorSchemeForActiveState(ComponentState state);

default ContainerRenderColorTokens getRenderColorTokensForCurrentState(ComponentState state) {
return null;
}

default ContainerRenderColorTokens getRenderColorTokensForActiveState(ComponentState state) {
return null;
}
}

public static ColorSchemeDelegate getDefaultColorSchemeDelegate(Component component,
Expand All @@ -238,6 +247,18 @@ public RadianceColorScheme getColorSchemeForActiveState(ComponentState state) {
return RadianceColorSchemeUtilities.getColorScheme(component,
colorSchemeAssociationKindDelegate.getColorSchemeAssociationKind(state), state);
}

@Override
public ContainerRenderColorTokens getRenderColorTokensForCurrentState(ComponentState state) {
return RadianceColorSchemeUtilities.getColorRenderTokens(component,
colorSchemeAssociationKindDelegate.getColorSchemeAssociationKind(state), state);
}

@Override
public ContainerRenderColorTokens getRenderColorTokensForActiveState(ComponentState state) {
return RadianceColorSchemeUtilities.getColorRenderTokens(component,
colorSchemeAssociationKindDelegate.getColorSchemeAssociationKind(state), state);
}
};
}

Expand Down
Loading

0 comments on commit ca35c39

Please sign in to comment.