Skip to content

Commit

Permalink
New implementation of split pane divider bump drawing
Browse files Browse the repository at this point in the history
This was missed in the Blade conversion from offscreen images. Replace the old code with direct rendering
  • Loading branch information
kirill-grouchnikov committed Jan 20, 2025
1 parent db7b7a6 commit 1204725
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@
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.ContainerColorTokens;
import org.pushingpixels.radiance.theming.internal.utils.RadianceColorUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceOutlineUtilities;
import org.pushingpixels.radiance.theming.internal.utils.RadianceSizeUtils;
import org.pushingpixels.radiance.theming.internal.utils.WidgetUtilities;
import org.pushingpixels.radiance.theming.internal.utils.*;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -876,4 +873,49 @@ else if (finalAlpha > 1.0f)
return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, finalAlpha);
}

public static void drawSplitDividerBumpImage(Graphics g, RadianceSplitPaneDivider divider,
int x, int y, int width, int height, boolean isHorizontal,
RadianceColorScheme colorScheme) {
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);

graphics1X.setComposite(getAlphaComposite(0.8f));
graphics1X.setColor(colorScheme.getMarkColor());
graphics1X.fillOval(0, 0, bumpDotDiameter, bumpDotDiameter);

graphics1X.setComposite(getAlphaComposite(0.32f));
RadianceBorderPainter borderPainter = RadianceCoreUtilities.getBorderPainter(divider);
borderPainter.paintBorder(graphics1X, divider, bumpDotDiameter, bumpDotDiameter,
new Ellipse2D.Float(0, 0, bumpDotDiameter, bumpDotDiameter), null, colorScheme);

graphics1X.translate(-cx, -cy);
}
}
});
graphics.dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.pushingpixels.radiance.common.api.RadianceCommonCortex;
import org.pushingpixels.radiance.theming.api.RadianceThemingCortex;
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.internal.utils.filters.ColorSchemeFilter;
import org.pushingpixels.radiance.theming.internal.utils.filters.ImageColorFilter;
Expand All @@ -41,7 +40,6 @@
import javax.swing.*;
import java.awt.*;
import java.awt.MultipleGradientPaint.CycleMethod;
import java.awt.geom.Ellipse2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
Expand All @@ -64,64 +62,6 @@ else if (finalAlpha > 1.0f)
return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, finalAlpha);
}

/**
* Paints the bump dots on the split pane dividers.
*
* @param g Graphics context.
* @param divider Split pane divider.
* @param x X coordinate of the bump dots.
* @param y Y coordinate of the bump dots.
* @param width Width of the bump dots area.
* @param height Height of the bump dots area.
* @param isHorizontal Indicates whether the dots are horizontal.
* @param colorScheme Color scheme.
*/
public static void paintSplitDividerBumpImage(Graphics g, RadianceSplitPaneDivider divider,
int x, int y, int width, int height, boolean isHorizontal,
RadianceColorScheme colorScheme) {
Graphics2D graphics = (Graphics2D) g.create();
graphics.translate(x, y);

graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);

int componentFontSize = RadianceSizeUtils.getComponentFontSize(divider);
int bumpDotDiameter = RadianceSizeUtils.getBigDragBumpDiameter(componentFontSize);
int bumpCellSize = (int) (1.5 * bumpDotDiameter + 1);
int bumpRows = isHorizontal ? 1 : Math.max(1, height / bumpCellSize - 1);
int bumpColumns = isHorizontal ? Math.max(1, (width - 2) / bumpCellSize) : 1;

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

double scale = RadianceCommonCortex.getScaleFactor(divider);
BufferedImage singleDot = RadianceCoreUtilities.getBlankImage(
scale, bumpDotDiameter, bumpDotDiameter);
Graphics2D dotGraphics = (Graphics2D) singleDot.getGraphics();
dotGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
dotGraphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
RenderingHints.VALUE_STROKE_PURE);

dotGraphics.setColor(colorScheme.getMarkColor());
dotGraphics.fillOval(0, 0, bumpDotDiameter, bumpDotDiameter);

dotGraphics.setComposite(getAlphaComposite(0.4f));
RadianceBorderPainter borderPainter = RadianceCoreUtilities.getBorderPainter(divider);
borderPainter.paintBorder(dotGraphics, divider, bumpDotDiameter, bumpDotDiameter,
new Ellipse2D.Float(0, 0, bumpDotDiameter, bumpDotDiameter), null, colorScheme);

graphics.setComposite(WidgetUtilities.getAlphaComposite(divider, 0.8f, g));
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;
RadianceCommonCortex.drawImageWithScale(graphics, scale, singleDot, cx, cy);
}
}
graphics.dispose();
}

/**
* Retrieves a single crayon of the specified color and dimensions for the crayon panel in color
* chooser.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.pushingpixels.radiance.theming.internal.animation.StateTransitionTracker;
import org.pushingpixels.radiance.theming.internal.animation.TransitionAwareUI;
import org.pushingpixels.radiance.theming.internal.blade.BladeArrowIconUtils;
import org.pushingpixels.radiance.theming.internal.blade.BladeIconUtils;
import org.pushingpixels.radiance.theming.internal.blade.BladeTransitionAwareIcon;
import org.pushingpixels.radiance.theming.internal.painter.BackgroundPaintingUtils;
import org.pushingpixels.radiance.theming.internal.ui.RadianceSplitPaneUI;
Expand Down Expand Up @@ -223,7 +224,7 @@ public void paint(Graphics g) {
ComponentState activeState = activeEntry.getKey();
graphics.setComposite(WidgetUtilities.getAlphaComposite(this.splitPane,
alpha * contribution, g));
RadianceImageCreator.paintSplitDividerBumpImage(graphics, this, gripX, gripY,
BladeIconUtils.drawSplitDividerBumpImage(graphics, this, gripX, gripY,
thumbWidth, gripHeight, false,
RadianceColorSchemeUtilities.getColorScheme(this,
RadianceThemingSlices.ColorSchemeAssociationKind.MARK, activeState));
Expand Down Expand Up @@ -252,7 +253,7 @@ public void paint(Graphics g) {
ComponentState activeState = activeEntry.getKey();
graphics.setComposite(WidgetUtilities.getAlphaComposite(this.splitPane,
alpha * contribution, g));
RadianceImageCreator.paintSplitDividerBumpImage(graphics, this, gripX, gripY,
BladeIconUtils.drawSplitDividerBumpImage(graphics, this, gripX, gripY,
gripWidth, thumbHeight, true,
RadianceColorSchemeUtilities.getColorScheme(this,
RadianceThemingSlices.ColorSchemeAssociationKind.MARK, activeState));
Expand Down

0 comments on commit 1204725

Please sign in to comment.