Skip to content

Commit

Permalink
Shader-based fill painters
Browse files Browse the repository at this point in the history
Add a shader that emulates specular highlight, and use that in some of the skins

Closes #4
  • Loading branch information
kirill-grouchnikov committed Dec 24, 2021
1 parent 82db528 commit 4f6f215
Show file tree
Hide file tree
Showing 45 changed files with 208 additions and 62 deletions.
Expand Up @@ -767,16 +767,6 @@ internal fun AuroraCommandButton(
val width = buttonSize.width.toFloat()
val height = buttonSize.height.toFloat()

val openDelta = 3
val deltaLeft =
if (buttonSides.openSides.contains(Side.Left)) openDelta else 0
val deltaRight =
if (buttonSides.openSides.contains(Side.Right)) openDelta else 0
val deltaTop =
if (buttonSides.openSides.contains(Side.Top)) openDelta else 0
val deltaBottom =
if (buttonSides.openSides.contains(Side.Bottom)) openDelta else 0

withTransform({
clipRect(
left = 0.0f,
Expand All @@ -786,13 +776,13 @@ internal fun AuroraCommandButton(
clipOp = ClipOp.Intersect
)
translate(
left = -actionAreaOffset.x - deltaLeft.toFloat(),
top = -actionAreaOffset.y - deltaTop.toFloat()
left = -actionAreaOffset.x,
top = -actionAreaOffset.y
)
}) {
val outline = buttonShaper.getButtonOutline(
width = width + deltaLeft + deltaRight,
height = height + deltaTop + deltaBottom,
width = width,
height = height,
extraInsets = 0.5f,
isInner = false,
sides = buttonSides,
Expand All @@ -815,10 +805,7 @@ internal fun AuroraCommandButton(
drawingCache.colorScheme.foreground = Color.Black
fillPainter.paintContourBackground(
this,
buttonSize.asSize(
deltaLeft + deltaRight,
deltaTop + deltaBottom
),
buttonSize.asSize(),
outline,
drawingCache.colorScheme,
actionAlpha
Expand All @@ -836,8 +823,8 @@ internal fun AuroraCommandButton(

val innerOutline =
if (borderPainter.isPaintingInnerOutline) buttonShaper.getButtonOutline(
width = width + deltaLeft + deltaRight,
height = height + deltaTop + deltaBottom,
width = width,
height = height,
extraInsets = 1.0f,
isInner = true,
sides = buttonSides,
Expand All @@ -846,10 +833,7 @@ internal fun AuroraCommandButton(

borderPainter.paintBorder(
this,
buttonSize.asSize(
deltaLeft + deltaRight,
deltaTop + deltaBottom
),
buttonSize.asSize(),
outline,
innerOutline,
drawingCache.colorScheme,
Expand Down Expand Up @@ -979,16 +963,6 @@ internal fun AuroraCommandButton(
val width = buttonSize.width.toFloat()
val height = buttonSize.height.toFloat()

val openDelta = 3
val deltaLeft =
if (buttonSides.openSides.contains(Side.Left)) openDelta else 0
val deltaRight =
if (buttonSides.openSides.contains(Side.Right)) openDelta else 0
val deltaTop =
if (buttonSides.openSides.contains(Side.Top)) openDelta else 0
val deltaBottom =
if (buttonSides.openSides.contains(Side.Bottom)) openDelta else 0

withTransform({
clipRect(
left = 0.0f,
Expand All @@ -998,13 +972,13 @@ internal fun AuroraCommandButton(
clipOp = ClipOp.Intersect
)
translate(
left = -popupAreaOffset.x - deltaLeft.toFloat(),
top = -popupAreaOffset.y - deltaTop.toFloat()
left = -popupAreaOffset.x,
top = -popupAreaOffset.y
)
}) {
val outline = buttonShaper.getButtonOutline(
width = width + deltaLeft + deltaRight,
height = height + deltaTop + deltaBottom,
width = width,
height = height,
extraInsets = 0.5f,
isInner = false,
sides = buttonSides,
Expand All @@ -1027,10 +1001,7 @@ internal fun AuroraCommandButton(
drawingCache.colorScheme.foreground = Color.Black
fillPainter.paintContourBackground(
this,
buttonSize.asSize(
deltaLeft + deltaRight,
deltaTop + deltaBottom
),
buttonSize.asSize(),
outline,
drawingCache.colorScheme,
popupAlpha
Expand All @@ -1048,8 +1019,8 @@ internal fun AuroraCommandButton(

val innerOutline =
if (borderPainter.isPaintingInnerOutline) buttonShaper.getButtonOutline(
width = width + deltaLeft + deltaRight,
height = height + deltaTop + deltaBottom,
width = width,
height = height,
extraInsets = 1.0f,
isInner = true,
sides = buttonSides,
Expand All @@ -1058,10 +1029,7 @@ internal fun AuroraCommandButton(

borderPainter.paintBorder(
this,
buttonSize.asSize(
deltaLeft + deltaRight,
deltaTop + deltaBottom
),
buttonSize.asSize(),
outline,
innerOutline,
drawingCache.colorScheme,
Expand Down
Expand Up @@ -36,5 +36,5 @@ internal fun AuroraSize.asSize(density: Density): Size {
return Size(width / density.density, height / density.density)
}

internal fun AuroraSize.asSize(extraWidth: Int, extraHeight: Int) =
internal fun AuroraSize.asSize(extraWidth: Int = 0, extraHeight: Int = 0) =
Size((width + extraWidth).toFloat(), (height + extraHeight).toFloat())
Binary file modified docs/images/theming/skins/autumn-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/autumn.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/business-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/business.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/businessblacksteel-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/businessblacksteel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/businessbluesteel-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/businessbluesteel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/cerulean-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/cerulean.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/dust-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/dust.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/dustcoffee-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/dustcoffee.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/mistaqua-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/mistaqua.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/mistsilver-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/mistsilver.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/moderate-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/moderate.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/nebula-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/nebula.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/nebulaamethyst-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/nebulaamethyst.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/nebulabrickwall-filtered.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/theming/skins/nebulabrickwall.png
Binary file modified docs/images/theming/skins/raven-filtered.png
Binary file modified docs/images/theming/skins/raven.png
Binary file modified docs/images/theming/skins/sahara-filtered.png
Binary file modified docs/images/theming/skins/sahara.png
Expand Up @@ -22,6 +22,7 @@ import org.pushingpixels.aurora.theming.painter.border.CompositeBorderPainter
import org.pushingpixels.aurora.theming.painter.border.DelegateBorderPainter
import org.pushingpixels.aurora.theming.painter.decoration.MarbleNoiseDecorationPainter
import org.pushingpixels.aurora.theming.painter.fill.MatteFillPainter
import org.pushingpixels.aurora.theming.painter.fill.SpecularRectangularFillPainter
import org.pushingpixels.aurora.theming.painter.overlay.BottomLineOverlayPainter
import org.pushingpixels.aurora.theming.painter.overlay.TopShadowOverlayPainter
import org.pushingpixels.aurora.theming.shaper.ClassicButtonShaper
Expand Down Expand Up @@ -103,7 +104,7 @@ private fun autumnSkinColors(): AuroraSkinColors {

fun autumnSkin(): AuroraSkinDefinition {
val painters = AuroraPainters(
fillPainter = MatteFillPainter(),
fillPainter = SpecularRectangularFillPainter(MatteFillPainter(), 0.2f),
borderPainter = CompositeBorderPainter(
displayName = "Autumn",
outer = DelegateBorderPainter(
Expand Down
Expand Up @@ -20,6 +20,7 @@ import org.pushingpixels.aurora.theming.colorscheme.AuroraSkinColors
import org.pushingpixels.aurora.theming.painter.border.ClassicBorderPainter
import org.pushingpixels.aurora.theming.painter.decoration.BrushedMetalDecorationPainter
import org.pushingpixels.aurora.theming.painter.fill.ClassicFillPainter
import org.pushingpixels.aurora.theming.painter.fill.SpecularRectangularFillPainter
import org.pushingpixels.aurora.theming.painter.overlay.BottomLineOverlayPainter
import org.pushingpixels.aurora.theming.painter.overlay.TopShadowOverlayPainter
import org.pushingpixels.aurora.theming.shaper.ClassicButtonShaper
Expand Down Expand Up @@ -86,7 +87,7 @@ private fun businessBaseSkinColors(accentBuilder: AccentBuilder): AuroraSkinColo

private fun businessBasePainters(): AuroraPainters {
val painters = AuroraPainters(
fillPainter = ClassicFillPainter(),
fillPainter = SpecularRectangularFillPainter(ClassicFillPainter(), 0.5f),
borderPainter = ClassicBorderPainter(),
decorationPainter = BrushedMetalDecorationPainter()
)
Expand Down
Expand Up @@ -20,6 +20,7 @@ import org.pushingpixels.aurora.theming.colorscheme.AuroraSkinColors
import org.pushingpixels.aurora.theming.painter.border.GlassBorderPainter
import org.pushingpixels.aurora.theming.painter.decoration.ArcDecorationPainter
import org.pushingpixels.aurora.theming.painter.fill.ClassicFillPainter
import org.pushingpixels.aurora.theming.painter.fill.SpecularRectangularFillPainter
import org.pushingpixels.aurora.theming.painter.overlay.TopShadowOverlayPainter
import org.pushingpixels.aurora.theming.shaper.ClassicButtonShaper
import org.pushingpixels.aurora.theming.utils.getColorSchemes
Expand Down Expand Up @@ -192,7 +193,7 @@ private fun ceruleanSkinColors(): AuroraSkinColors {

fun ceruleanSkin(): AuroraSkinDefinition {
val painters = AuroraPainters(
fillPainter = ClassicFillPainter(),
fillPainter = SpecularRectangularFillPainter(ClassicFillPainter(), 0.5f),
borderPainter = GlassBorderPainter(),
decorationPainter = ArcDecorationPainter()
)
Expand Down
Expand Up @@ -23,6 +23,7 @@ import org.pushingpixels.aurora.theming.painter.border.CompositeBorderPainter
import org.pushingpixels.aurora.theming.painter.border.DelegateBorderPainter
import org.pushingpixels.aurora.theming.painter.decoration.MatteDecorationPainter
import org.pushingpixels.aurora.theming.painter.fill.MatteFillPainter
import org.pushingpixels.aurora.theming.painter.fill.SpecularRectangularFillPainter
import org.pushingpixels.aurora.theming.painter.overlay.BottomLineOverlayPainter
import org.pushingpixels.aurora.theming.painter.overlay.TopLineOverlayPainter
import org.pushingpixels.aurora.theming.shaper.ClassicButtonShaper
Expand Down Expand Up @@ -147,7 +148,7 @@ private fun dustBaseSkinColors(accentBuilder: AccentBuilder): AuroraSkinColors {

private fun dustBasePainters(): AuroraPainters {
val painters = AuroraPainters(
fillPainter = MatteFillPainter(),
fillPainter = SpecularRectangularFillPainter(MatteFillPainter(), 0.8f),
borderPainter = CompositeBorderPainter(
displayName = "Dust",
outer = ClassicBorderPainter(),
Expand Down
Expand Up @@ -104,7 +104,11 @@ private fun marinerSkinColors(): AuroraSkinColors {
val headerSchemeBundle = AuroraColorSchemeBundle(
headerColorScheme, headerColorScheme, headerColorScheme
)
headerSchemeBundle.registerAlpha(0.4f, ComponentState.DisabledSelected, ComponentState.DisabledUnselected)
headerSchemeBundle.registerAlpha(
0.4f,
ComponentState.DisabledSelected,
ComponentState.DisabledUnselected
)
headerSchemeBundle.registerColorScheme(
headerColorScheme, ColorSchemeAssociationKind.Fill,
ComponentState.DisabledSelected, ComponentState.DisabledUnselected
Expand Down
Expand Up @@ -21,6 +21,7 @@ import org.pushingpixels.aurora.theming.colorscheme.AuroraSkinColors
import org.pushingpixels.aurora.theming.painter.border.ClassicBorderPainter
import org.pushingpixels.aurora.theming.painter.decoration.MatteDecorationPainter
import org.pushingpixels.aurora.theming.painter.fill.MatteFillPainter
import org.pushingpixels.aurora.theming.painter.fill.SpecularRectangularFillPainter
import org.pushingpixels.aurora.theming.shaper.PillButtonShaper
import org.pushingpixels.aurora.theming.utils.getColorSchemes

Expand Down Expand Up @@ -85,7 +86,7 @@ private fun mistBaseSkinColors(accentBuilder: AccentBuilder): AuroraSkinColors {

private fun mistBasePainters(): AuroraPainters {
return AuroraPainters(
fillPainter = MatteFillPainter(),
fillPainter = SpecularRectangularFillPainter(MatteFillPainter(), 0.5f),
borderPainter = ClassicBorderPainter(),
decorationPainter = MatteDecorationPainter()
)
Expand Down
Expand Up @@ -22,6 +22,7 @@ import org.pushingpixels.aurora.theming.colorscheme.SteelBlueColorScheme
import org.pushingpixels.aurora.theming.painter.border.ClassicBorderPainter
import org.pushingpixels.aurora.theming.painter.decoration.MatteDecorationPainter
import org.pushingpixels.aurora.theming.painter.fill.GlassFillPainter
import org.pushingpixels.aurora.theming.painter.fill.SpecularRectangularFillPainter
import org.pushingpixels.aurora.theming.painter.overlay.BottomLineOverlayPainter
import org.pushingpixels.aurora.theming.painter.overlay.TopShadowOverlayPainter
import org.pushingpixels.aurora.theming.shaper.ClassicButtonShaper
Expand Down Expand Up @@ -63,7 +64,7 @@ private fun moderateSkinColors(): AuroraSkinColors {

fun moderateSkin(): AuroraSkinDefinition {
val painters = AuroraPainters(
fillPainter = GlassFillPainter(),
fillPainter = SpecularRectangularFillPainter(GlassFillPainter(), 0.5f),
borderPainter = ClassicBorderPainter(),
decorationPainter = MatteDecorationPainter()
)
Expand Down
Expand Up @@ -19,6 +19,7 @@ import org.pushingpixels.aurora.theming.colorscheme.*
import org.pushingpixels.aurora.theming.painter.border.FlatBorderPainter
import org.pushingpixels.aurora.theming.painter.decoration.ArcDecorationPainter
import org.pushingpixels.aurora.theming.painter.decoration.MarbleNoiseDecorationPainter
import org.pushingpixels.aurora.theming.painter.fill.SpecularRectangularFillPainter
import org.pushingpixels.aurora.theming.painter.fill.SubduedFillPainter
import org.pushingpixels.aurora.theming.painter.overlay.BottomLineOverlayPainter
import org.pushingpixels.aurora.theming.painter.overlay.BottomShadowOverlayPainter
Expand Down Expand Up @@ -142,7 +143,7 @@ private fun nebulaBaseSkinColors(accentBuilder: AccentBuilder): AuroraSkinColors

private fun nebulaBasePainters(): AuroraPainters {
val painters = AuroraPainters(
fillPainter = SubduedFillPainter(),
fillPainter = SpecularRectangularFillPainter(SubduedFillPainter(), 0.3f),
borderPainter = FlatBorderPainter(),
decorationPainter = MarbleNoiseDecorationPainter(
textureAlpha = 0.2f,
Expand Down
Expand Up @@ -22,6 +22,7 @@ import org.pushingpixels.aurora.theming.colorscheme.EbonyColorScheme
import org.pushingpixels.aurora.theming.painter.border.GlassBorderPainter
import org.pushingpixels.aurora.theming.painter.decoration.ArcDecorationPainter
import org.pushingpixels.aurora.theming.painter.fill.GlassFillPainter
import org.pushingpixels.aurora.theming.painter.fill.SpecularRectangularFillPainter
import org.pushingpixels.aurora.theming.shaper.ClassicButtonShaper
import org.pushingpixels.aurora.theming.utils.getColorSchemes

Expand Down Expand Up @@ -145,7 +146,7 @@ fun ravenSkin(): AuroraSkinDefinition {
displayName = "Raven",
colors = ravenSkinColors(),
painters = AuroraPainters(
fillPainter = GlassFillPainter(),
fillPainter = SpecularRectangularFillPainter(GlassFillPainter(), 0.6f),
borderPainter = GlassBorderPainter(),
decorationPainter = ArcDecorationPainter()
),
Expand Down
Expand Up @@ -22,6 +22,7 @@ import org.pushingpixels.aurora.theming.colorscheme.MetallicColorScheme
import org.pushingpixels.aurora.theming.painter.border.ClassicBorderPainter
import org.pushingpixels.aurora.theming.painter.decoration.MatteDecorationPainter
import org.pushingpixels.aurora.theming.painter.fill.ClassicFillPainter
import org.pushingpixels.aurora.theming.painter.fill.SpecularRectangularFillPainter
import org.pushingpixels.aurora.theming.painter.overlay.BottomLineOverlayPainter
import org.pushingpixels.aurora.theming.painter.overlay.TopShadowOverlayPainter
import org.pushingpixels.aurora.theming.shaper.ClassicButtonShaper
Expand Down Expand Up @@ -56,7 +57,7 @@ private fun saharaSkinColors(): AuroraSkinColors {

fun saharaSkin(): AuroraSkinDefinition {
val painters = AuroraPainters(
fillPainter = ClassicFillPainter(),
fillPainter = SpecularRectangularFillPainter(ClassicFillPainter(), 0.6f),
borderPainter = ClassicBorderPainter(),
decorationPainter = MatteDecorationPainter()
)
Expand Down
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.ui.graphics.ShaderBrush
import androidx.compose.ui.graphics.addOutline
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.clipPath
import androidx.compose.ui.unit.Density
import org.jetbrains.skia.Data
import org.jetbrains.skia.RuntimeEffect
import org.pushingpixels.aurora.theming.colorscheme.AuroraColorScheme
Expand All @@ -37,7 +38,12 @@ abstract class ShaderWrapperFillPainter(
val runtimeEffect: RuntimeEffect,
val baseFillPainter: AuroraFillPainter
) : AuroraFillPainter {
abstract fun getShaderData(size: Size, fillScheme: AuroraColorScheme, alpha: Float): Data
abstract fun getShaderData(
density: Density,
outline: Outline,
fillScheme: AuroraColorScheme,
alpha: Float
): Data

override fun paintContourBackground(
drawScope: DrawScope,
Expand All @@ -56,7 +62,7 @@ abstract class ShaderWrapperFillPainter(
)

val shader = runtimeEffect.makeShader(
uniforms = getShaderData(size, fillScheme, alpha),
uniforms = getShaderData(drawScope, outline, fillScheme, alpha),
children = null,
localMatrix = null,
isOpaque = false
Expand Down

0 comments on commit 4f6f215

Please sign in to comment.