1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00

ControlCenter: Implement edit mode for customizing widgets

This commit is contained in:
bbedward
2025-09-23 14:38:01 -04:00
parent b9b1737639
commit c04177e45d
32 changed files with 2870 additions and 796 deletions

View File

@@ -4,20 +4,19 @@
layout(location = 0) in vec2 qt_TexCoord0;
layout(location = 0) out vec4 fragColor;
layout(binding = 1) uniform sampler2D source1; // Current wallpaper
layout(binding = 2) uniform sampler2D source2; // Next wallpaper
layout(binding = 1) uniform sampler2D source1;
layout(binding = 2) uniform sampler2D source2;
layout(std140, binding = 0) uniform buf {
mat4 qt_Matrix;
float qt_Opacity;
float progress; // 0.0 -> 1.0
float centerX; // 0..1
float centerY; // 0..1
float smoothness; // 0..1 (edge softness)
float aspectRatio; // width / height
float progress;
float centerX;
float centerY;
float smoothness;
float aspectRatio;
// Fill mode parameters
float fillMode; // 0=no(center), 1=crop(fill), 2=fit(contain), 3=stretch
float fillMode;
float imageWidth1;
float imageHeight1;
float imageWidth2;
@@ -29,7 +28,6 @@ layout(std140, binding = 0) uniform buf {
vec2 calculateUV(vec2 uv, float imgWidth, float imgHeight) {
vec2 transformedUV = uv;
if (ubuf.fillMode < 0.5) {
vec2 screenPixel = uv * vec2(ubuf.screenWidth, ubuf.screenHeight);
vec2 imageOffset = (vec2(ubuf.screenWidth, ubuf.screenHeight) - vec2(imgWidth, imgHeight)) * 0.5;
@@ -50,8 +48,6 @@ vec2 calculateUV(vec2 uv, float imgWidth, float imgHeight) {
vec2 imagePixel = (screenPixel - offset) / scale;
transformedUV = imagePixel / vec2(imgWidth, imgHeight);
}
// else stretch
return transformedUV;
}
@@ -65,34 +61,34 @@ vec4 sampleWithFillMode(sampler2D tex, vec2 uv, float imgWidth, float imgHeight)
void main() {
vec2 uv = qt_TexCoord0;
vec4 color1 = sampleWithFillMode(source1, uv, ubuf.imageWidth1, ubuf.imageHeight1);
vec4 color2 = sampleWithFillMode(source2, uv, ubuf.imageWidth2, ubuf.imageHeight2);
// Edge softness mapping
float edgeSoft = mix(0.001, 0.45, ubuf.smoothness * ubuf.smoothness);
// Aspect-corrected coordinates so the iris stays circular
vec2 center = vec2(ubuf.centerX, ubuf.centerY);
vec2 acUv = vec2(uv.x * ubuf.aspectRatio, uv.y);
vec2 acCenter = vec2(center.x * ubuf.aspectRatio, center.y);
float dist = length(acUv - acCenter);
vec2 q = acUv - acCenter;
// Max radius needed to cover the screen from the chosen center
float maxDistX = max(center.x * ubuf.aspectRatio, (1.0 - center.x) * ubuf.aspectRatio);
float maxDistY = max(center.y, 1.0 - center.y);
float maxDist = length(vec2(maxDistX, maxDistY));
float maxX = max(center.x * ubuf.aspectRatio, (1.0 - center.x) * ubuf.aspectRatio);
float maxY = max(center.y, 1.0 - center.y);
float maxDist = length(vec2(maxX, maxY));
float p = ubuf.progress;
p = p * p * (3.0 - 2.0 * p);
float radius = p * maxDist - edgeSoft;
float radius = p * maxDist;
// Soft circular edge: inside -> color2 (new), outside -> color1 (old)
// squash factor for the "eye" slit
float squash = mix(0.2, 1.0, p);
q.y /= squash;
float dist = length(q);
float t = smoothstep(radius - edgeSoft, radius + edgeSoft, dist);
vec4 col = mix(color2, color1, t);
// Exact snaps at ends
if (ubuf.progress <= 0.0) col = color1;
if (ubuf.progress >= 1.0) col = color2;