Skip to content

Commit

Permalink
Second pass for tonal split pane dividers
Browse files Browse the repository at this point in the history
For #400
  • Loading branch information
kirill-grouchnikov committed Jan 20, 2025
1 parent 1204725 commit 9a13d5c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -918,4 +918,55 @@ public static void drawSplitDividerBumpImage(Graphics g, RadianceSplitPaneDivide
});
graphics.dispose();
}


public static void drawSplitDividerBumpImage(Graphics g, RadianceSplitPaneDivider divider,
int x, int y, int width, int height, boolean isHorizontal,
ContainerColorTokens colorTokens, ComponentState state) {
Graphics2D graphics = (Graphics2D) g.create();
graphics.translate(x, y);

// 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, offsetX, offsetY, scaledWidth, scaledHeight, scaleFactor) -> {
int componentFontSize = RadianceSizeUtils.getComponentFontSize(divider);
int bumpDotDiameter = (int) (scaleFactor *
RadianceSizeUtils.getBigDragBumpDiameter(componentFontSize));
int bumpCellSize = (int) (1.5 * bumpDotDiameter + 1);
int bumpRows = isHorizontal ? 1 : Math.max(1, scaledHeight / bumpCellSize - 1);
int bumpColumns = isHorizontal ? Math.max(1, (scaledWidth - 2) / bumpCellSize) : 1;

int bumpRowOffset = (scaledHeight - bumpCellSize * bumpRows) / 2;
int bumpColOffset = 1 + (scaledWidth - bumpCellSize * bumpColumns) / 2;

for (int col = 0; col < bumpColumns; col++) {
int cx = bumpColOffset + col * bumpCellSize;
for (int row = 0; row < bumpRows; row++) {
int cy = bumpRowOffset + row * bumpCellSize + (bumpCellSize - bumpDotDiameter) / 2;

graphics1X.translate(cx, cy);

float containerSurfaceAlpha =
(state.isDisabled() ? colorTokens.getContainerSurfaceDisabledAlpha() : 1.0f);
graphics1X.setComposite(getAlphaComposite(containerSurfaceAlpha * 0.8f));
graphics1X.setColor(colorTokens.getOnContainer());
graphics1X.fillOval(0, 0, bumpDotDiameter, bumpDotDiameter);

float containerOutlineAlpha =
(state.isDisabled() ? colorTokens.getContainerOutlineDisabledAlpha() : 1.0f);
graphics1X.setComposite(getAlphaComposite(containerOutlineAlpha * 0.32f));
RadianceBorderPainter borderPainter = RadianceCoreUtilities.getBorderPainter(divider);
borderPainter.paintBorder(graphics1X, divider, bumpDotDiameter, bumpDotDiameter,
new Ellipse2D.Float(0, 0, bumpDotDiameter, bumpDotDiameter), null, colorTokens);

graphics1X.translate(-cx, -cy);
}
}
});
graphics.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
package org.pushingpixels.radiance.theming.internal.utils;

import org.pushingpixels.radiance.theming.api.ComponentState;
import org.pushingpixels.radiance.theming.api.RadianceSkin;
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.ContainerColorTokens;
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.blade.BladeArrowIconUtils;
Expand Down Expand Up @@ -195,7 +197,9 @@ public void paint(Graphics g) {
Map<ComponentState, StateTransitionTracker.StateContributionInfo> activeStates = modelStateInfo
.getStateContributionMap();

float alpha = RadianceColorSchemeUtilities.getAlpha(this.splitPane, currState);
RadianceSkin skin = RadianceCoreUtilities.getSkin(this.splitPane);
float alpha = (skin instanceof TonalSkin) ? 1.0f
: RadianceColorSchemeUtilities.getAlpha(this.splitPane, currState);

// compute the grip handle dimension
int minSizeForGripPresence = RadianceSizeUtils
Expand All @@ -215,19 +219,30 @@ public void paint(Graphics g) {
int gripY = (thumbHeight - gripHeight) / 2;

// draw the grip bumps
for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
.entrySet()) {
for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry
: activeStates.entrySet()) {
ComponentState activeState = activeEntry.getKey();
float contribution = activeEntry.getValue().getContribution();
if (contribution == 0.0f)
if (contribution == 0.0f) {
continue;
}

ComponentState activeState = activeEntry.getKey();
graphics.setComposite(WidgetUtilities.getAlphaComposite(this.splitPane,
if (skin instanceof TonalSkin) {
graphics.setComposite(WidgetUtilities.getAlphaComposite(this.splitPane,
contribution, g));
BladeIconUtils.drawSplitDividerBumpImage(graphics, this, gripX, gripY,
thumbWidth, gripHeight, false, RadianceColorSchemeUtilities.getContainerTokens(
this,
RadianceThemingSlices.ContainerColorTokensAssociationKind.MARK, activeState,
RadianceThemingSlices.ContainerType.MUTED),
activeState);
} else {
graphics.setComposite(WidgetUtilities.getAlphaComposite(this.splitPane,
alpha * contribution, g));
BladeIconUtils.drawSplitDividerBumpImage(graphics, this, gripX, gripY,
thumbWidth, gripHeight, false,
RadianceColorSchemeUtilities.getColorScheme(this,
RadianceThemingSlices.ColorSchemeAssociationKind.MARK, activeState));
BladeIconUtils.drawSplitDividerBumpImage(graphics, this, gripX, gripY,
thumbWidth, gripHeight, false, RadianceColorSchemeUtilities.getColorScheme(
this, RadianceThemingSlices.ColorSchemeAssociationKind.MARK, activeState));
}
}
}
} else {
Expand All @@ -244,19 +259,28 @@ public void paint(Graphics g) {
int gripY = 1;

// draw the grip bumps
for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry : activeStates
.entrySet()) {
for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry
: activeStates.entrySet()) {
ComponentState activeState = activeEntry.getKey();
float contribution = activeEntry.getValue().getContribution();
if (contribution == 0.0f)
if (contribution == 0.0f) {
continue;
}

ComponentState activeState = activeEntry.getKey();
graphics.setComposite(WidgetUtilities.getAlphaComposite(this.splitPane,
if (skin instanceof TonalSkin) {
graphics.setComposite(WidgetUtilities.getAlphaComposite(this.splitPane, contribution, g));
BladeIconUtils.drawSplitDividerBumpImage(graphics, this, gripX, gripY,
gripWidth, thumbHeight, true, RadianceColorSchemeUtilities.getContainerTokens(
this, RadianceThemingSlices.ContainerColorTokensAssociationKind.MARK,
activeState, RadianceThemingSlices.ContainerType.MUTED),
activeState);
} else {
graphics.setComposite(WidgetUtilities.getAlphaComposite(this.splitPane,
alpha * contribution, g));
BladeIconUtils.drawSplitDividerBumpImage(graphics, this, gripX, gripY,
gripWidth, thumbHeight, true,
RadianceColorSchemeUtilities.getColorScheme(this,
RadianceThemingSlices.ColorSchemeAssociationKind.MARK, activeState));
BladeIconUtils.drawSplitDividerBumpImage(graphics, this, gripX, gripY,
gripWidth, thumbHeight, true, RadianceColorSchemeUtilities.getColorScheme(
this, RadianceThemingSlices.ColorSchemeAssociationKind.MARK, activeState));
}
}
}
}
Expand Down

0 comments on commit 9a13d5c

Please sign in to comment.