-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
366 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...a/org/pushingpixels/radiance/theming/api/painter/overlay/TopBezelTonalOverlayPainter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.