From dd82b734940597cab51e67f902beefc9508dba37 Mon Sep 17 00:00:00 2001 From: samuel <53528911+samuel-jimenez@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:02:03 -0600 Subject: [PATCH] Transparent shadow --- package/contents/ui/LunaIcon.qml | 81 ++++++++++++++++++--------- package/contents/ui/configGeneral.qml | 4 -- 2 files changed, 54 insertions(+), 31 deletions(-) diff --git a/package/contents/ui/LunaIcon.qml b/package/contents/ui/LunaIcon.qml index 22d2d15..6da061d 100644 --- a/package/contents/ui/LunaIcon.qml +++ b/package/contents/ui/LunaIcon.qml @@ -42,33 +42,60 @@ Item { property bool showCopernicus: false property int theta: 45 // Degrees: 0= new moon, 90= first quarter, 180= full moon, 270= third quarter - KSvg.Svg { - id: lunaSvg + Item { + id: lunaBackground - imagePath: lunarImage === '' ? '' : Qt.resolvedUrl("../data/" + lunarImage) + visible: false + anchors.centerIn: parent + width: Math.min(parent.width, parent.height) + height: Math.min(parent.width, parent.height) } KSvg.SvgItem { id: lunaSvgItem + imagePath: lunarImage === '' ? '' : Qt.resolvedUrl("../data/" + lunarImage) visible: false anchors.centerIn: parent - width: Math.min(parent.width, parent.height) - height: Math.min(parent.width, parent.height) - svg: lunaSvg + width: lunaBackground.width + height: lunaBackground.height // Rotation to compensate the moon's image basic position to a north pole view transformOrigin: Item.Center rotation: -lunarImageTweak } + Canvas { + id: lunaCanvas + + property string lunarImage: lunaIcon.lunarImage + property string diskColor: lunaIcon.diskColor + + width: lunaBackground.width + height: lunaBackground.height + visible: false + anchors.centerIn: parent + contextType: "2d" + onLunarImageChanged: requestPaint() + onDiskColorChanged: requestPaint() + onPaint: { + var radius = Math.floor(height / 2); + context.reset(); + context.globalAlpha = (lunarImage === '') ? 1 : 0; + context.fillStyle = diskColor; + context.translate(radius, radius); + context.beginPath(); + context.arc(0, 0, radius, 0, 2 * Math.PI); + context.closePath(); + context.fill(); + } + } + Canvas { id: shadow property int latitude: lunaIcon.latitude property int theta: lunaIcon.theta property bool showShadow: lunaIcon.showShadow - property string lunarImage: lunaIcon.lunarImage - property string diskColor: lunaIcon.diskColor property bool showGrid: lunaIcon.showGrid property bool showTycho: lunaIcon.showTycho property bool showCopernicus: lunaIcon.showCopernicus @@ -112,34 +139,24 @@ Item { context.stroke(); } - width: lunaSvgItem.width - height: lunaSvgItem.height + width: lunaBackground.width + height: lunaBackground.height visible: false anchors.centerIn: parent contextType: "2d" onLatitudeChanged: requestPaint() onThetaChanged: requestPaint() - onLunarImageChanged: requestPaint() - onDiskColorChanged: requestPaint() onShowGridChanged: requestPaint() onShowTychoChanged: requestPaint() onShowCopernicusChanged: requestPaint() onShowShadowChanged: requestPaint() onPaint: { - context.reset(); - context.globalAlpha = 0.9; - context.fillStyle = '#000000'; var radius = Math.floor(height / 2); var cosTheta = Math.cos(theta / 180 * Math.PI); - context.translate(radius, radius); var counterclockwisep = (theta < 180); - if (lunarImage === '') { - context.beginPath(); - context.fillStyle = diskColor; - context.arc(0, 0, radius, 0, 2 * Math.PI); - context.closePath(); - context.fill(); - } + context.reset(); + context.globalAlpha = 0.9; + context.translate(radius, radius); if (showShadow) { if (theta != 180) { context.beginPath(); @@ -171,10 +188,20 @@ Item { } } + Blend { + id: lunaSource + + anchors.fill: lunaBackground + source: lunaSvgItem + foregroundSource: lunaCanvas + mode: "normal" + visible: false + } + // Shadow acts as a transparency mask OpacityMask { - anchors.fill: lunaSvgItem - source: lunaSvgItem + anchors.fill: lunaBackground + source: lunaSource maskSource: shadow invert: true rotation: latitude - 90 @@ -183,8 +210,8 @@ Item { // Shadow is printed on top of the moon image Blend { - anchors.fill: lunaSvgItem - source: lunaSvgItem + anchors.fill: lunaBackground + source: lunaSource foregroundSource: shadow rotation: latitude - 90 mode: "normal" diff --git a/package/contents/ui/configGeneral.qml b/package/contents/ui/configGeneral.qml index 4c1f239..05217d3 100644 --- a/package/contents/ui/configGeneral.qml +++ b/package/contents/ui/configGeneral.qml @@ -46,9 +46,6 @@ KCM.SimpleKCM { onCfg_lunarIndexChanged: { cfg_lunarImage = imageChoices.get(cfg_lunarIndex).filename; cfg_lunarImageTweak = imageChoices.get(cfg_lunarIndex).tweak; - if (cfg_lunarImage == '') - cfg_transparentShadow = false; - } ImageChoices { @@ -306,7 +303,6 @@ KCM.SimpleKCM { id: transparentShadow text: i18n("Transparent shadow") - enabled: cfg_lunarImage != "" } } -- GitLab