forked from Shinonome/dots-hyprland
make materialcookie use rounded polygons
This commit is contained in:
@@ -86,118 +86,124 @@ Item {
|
|||||||
DropShadow {
|
DropShadow {
|
||||||
source: cookie
|
source: cookie
|
||||||
anchors.fill: source
|
anchors.fill: source
|
||||||
horizontalOffset: 0
|
|
||||||
verticalOffset: 1
|
|
||||||
radius: 8
|
radius: 8
|
||||||
samples: radius * 2 + 1
|
samples: radius * 2 + 1
|
||||||
color: root.colShadow
|
color: root.colShadow
|
||||||
transparentBorder: true
|
transparentBorder: true
|
||||||
|
|
||||||
|
RotationAnimation on rotation {
|
||||||
|
running: Config.options.background.clock.cookie.constantlyRotate
|
||||||
|
duration: 30000
|
||||||
|
easing.type: Easing.Linear
|
||||||
|
loops: Animation.Infinite
|
||||||
|
from: 360
|
||||||
|
to: 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialCookie {
|
MaterialCookie {
|
||||||
id: cookie
|
id: cookie
|
||||||
z: 0
|
z: 0
|
||||||
|
visible: false // The DropShadow already draws it
|
||||||
implicitSize: root.implicitSize
|
implicitSize: root.implicitSize
|
||||||
amplitude: implicitSize / 70
|
|
||||||
sides: Config.options.background.clock.cookie.sides
|
sides: Config.options.background.clock.cookie.sides
|
||||||
color: root.colBackground
|
color: root.colBackground
|
||||||
constantlyRotate: Config.options.background.clock.cookie.constantlyRotate
|
}
|
||||||
|
|
||||||
// Hour/minutes numbers/dots/lines
|
// Hour/minutes numbers/dots/lines
|
||||||
MinuteMarks {
|
MinuteMarks {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
color: root.colOnBackground
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stupid extra hour marks in the middle
|
||||||
|
FadeLoader {
|
||||||
|
id: hourMarksLoader
|
||||||
|
anchors.centerIn: parent
|
||||||
|
shown: Config.options.background.clock.cookie.hourMarks
|
||||||
|
sourceComponent: HourMarks {
|
||||||
|
implicitSize: 135 * (1.75 - 0.75 * hourMarksLoader.opacity)
|
||||||
color: root.colOnBackground
|
color: root.colOnBackground
|
||||||
|
colOnBackground: ColorUtils.mix(root.colBackgroundInfo, root.colOnBackground, 0.5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Number column in the middle
|
||||||
|
FadeLoader {
|
||||||
|
id: timeColumnLoader
|
||||||
|
anchors.centerIn: parent
|
||||||
|
shown: Config.options.background.clock.cookie.timeIndicators
|
||||||
|
scale: 1.4 - 0.4 * timeColumnLoader.shown
|
||||||
|
Behavior on scale {
|
||||||
|
animation: Appearance.animation.elementResize.numberAnimation.createObject(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stupid extra hour marks in the middle
|
sourceComponent: TimeColumn {
|
||||||
FadeLoader {
|
color: root.colBackgroundInfo
|
||||||
id: hourMarksLoader
|
|
||||||
anchors.centerIn: parent
|
|
||||||
shown: Config.options.background.clock.cookie.hourMarks
|
|
||||||
sourceComponent: HourMarks {
|
|
||||||
implicitSize: 135 * (1.75 - 0.75 * hourMarksLoader.opacity)
|
|
||||||
color: root.colOnBackground
|
|
||||||
colOnBackground: ColorUtils.mix(root.colBackgroundInfo, root.colOnBackground, 0.5)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Number column in the middle
|
// Hour hand
|
||||||
FadeLoader {
|
FadeLoader {
|
||||||
id: timeColumnLoader
|
anchors.fill: parent
|
||||||
anchors.centerIn: parent
|
z: 1
|
||||||
shown: Config.options.background.clock.cookie.timeIndicators
|
shown: Config.options.background.clock.cookie.hourHandStyle !== "hide"
|
||||||
scale: 1.4 - 0.4 * timeColumnLoader.shown
|
sourceComponent: HourHand {
|
||||||
Behavior on scale {
|
clockHour: root.clockHour
|
||||||
animation: Appearance.animation.elementResize.numberAnimation.createObject(this)
|
clockMinute: root.clockMinute
|
||||||
}
|
style: Config.options.background.clock.cookie.hourHandStyle
|
||||||
|
color: root.colHourHand
|
||||||
sourceComponent: TimeColumn {
|
|
||||||
color: root.colBackgroundInfo
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Hour hand
|
// Minute hand
|
||||||
FadeLoader {
|
FadeLoader {
|
||||||
|
anchors.fill: parent
|
||||||
|
z: 2
|
||||||
|
shown: Config.options.background.clock.cookie.minuteHandStyle !== "hide"
|
||||||
|
sourceComponent: MinuteHand {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
z: 1
|
clockMinute: root.clockMinute
|
||||||
shown: Config.options.background.clock.cookie.hourHandStyle !== "hide"
|
style: Config.options.background.clock.cookie.minuteHandStyle
|
||||||
sourceComponent: HourHand {
|
color: root.colMinuteHand
|
||||||
clockHour: root.clockHour
|
|
||||||
clockMinute: root.clockMinute
|
|
||||||
style: Config.options.background.clock.cookie.hourHandStyle
|
|
||||||
color: root.colHourHand
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Minute hand
|
// Second hand
|
||||||
FadeLoader {
|
FadeLoader {
|
||||||
anchors.fill: parent
|
id: secondHandLoader
|
||||||
z: 2
|
z: (Config.options.background.clock.cookie.secondHandStyle === "line") ? 2 : 3
|
||||||
shown: Config.options.background.clock.cookie.minuteHandStyle !== "hide"
|
shown: Config.options.time.secondPrecision && Config.options.background.clock.cookie.secondHandStyle !== "hide"
|
||||||
sourceComponent: MinuteHand {
|
anchors.fill: parent
|
||||||
anchors.fill: parent
|
sourceComponent: SecondHand {
|
||||||
clockMinute: root.clockMinute
|
id: secondHand
|
||||||
style: Config.options.background.clock.cookie.minuteHandStyle
|
clockSecond: root.clockSecond
|
||||||
color: root.colMinuteHand
|
style: Config.options.background.clock.cookie.secondHandStyle
|
||||||
}
|
color: root.colSecondHand
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Second hand
|
// Center dot
|
||||||
FadeLoader {
|
FadeLoader {
|
||||||
id: secondHandLoader
|
z: 4
|
||||||
z: (Config.options.background.clock.cookie.secondHandStyle === "line") ? 2 : 3
|
anchors.centerIn: parent
|
||||||
shown: Config.options.time.secondPrecision && Config.options.background.clock.cookie.secondHandStyle !== "hide"
|
shown: Config.options.background.clock.cookie.minuteHandStyle !== "bold"
|
||||||
anchors.fill: parent
|
sourceComponent: Rectangle {
|
||||||
sourceComponent: SecondHand {
|
color: Config.options.background.clock.cookie.minuteHandStyle === "medium" ? root.colBackground : root.colMinuteHand
|
||||||
id: secondHand
|
implicitWidth: 6
|
||||||
clockSecond: root.clockSecond
|
implicitHeight: implicitWidth
|
||||||
style: Config.options.background.clock.cookie.secondHandStyle
|
radius: width / 2
|
||||||
color: root.colSecondHand
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Center dot
|
// Date
|
||||||
FadeLoader {
|
FadeLoader {
|
||||||
z: 4
|
anchors.fill: parent
|
||||||
anchors.centerIn: parent
|
shown: Config.options.background.clock.cookie.dateStyle !== "hide"
|
||||||
shown: Config.options.background.clock.cookie.minuteHandStyle !== "bold"
|
|
||||||
sourceComponent: Rectangle {
|
|
||||||
color: Config.options.background.clock.cookie.minuteHandStyle === "medium" ? root.colBackground : root.colMinuteHand
|
|
||||||
implicitWidth: 6
|
|
||||||
implicitHeight: implicitWidth
|
|
||||||
radius: width / 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Date
|
sourceComponent: DateIndicator {
|
||||||
FadeLoader {
|
color: root.colBackgroundInfo
|
||||||
anchors.fill: parent
|
style: Config.options.background.clock.cookie.dateStyle
|
||||||
shown: Config.options.background.clock.cookie.dateStyle !== "hide"
|
|
||||||
|
|
||||||
sourceComponent: DateIndicator {
|
|
||||||
color: root.colBackgroundInfo
|
|
||||||
style: Config.options.background.clock.cookie.dateStyle
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -14,7 +14,10 @@ Item {
|
|||||||
// 12 Dots
|
// 12 Dots
|
||||||
FadeLoader {
|
FadeLoader {
|
||||||
id: dotsLoader
|
id: dotsLoader
|
||||||
anchors.fill: parent
|
anchors {
|
||||||
|
fill: parent
|
||||||
|
margins: 10
|
||||||
|
}
|
||||||
shown: root.style === "dots"
|
shown: root.style === "dots"
|
||||||
sourceComponent: Dots {
|
sourceComponent: Dots {
|
||||||
color: root.color
|
color: root.color
|
||||||
@@ -37,7 +40,10 @@ Item {
|
|||||||
// Lines
|
// Lines
|
||||||
FadeLoader {
|
FadeLoader {
|
||||||
id: linesLoader
|
id: linesLoader
|
||||||
anchors.fill: parent
|
anchors {
|
||||||
|
fill: parent
|
||||||
|
margins: 10
|
||||||
|
}
|
||||||
shown: root.style === "full"
|
shown: root.style === "full"
|
||||||
sourceComponent: Lines {
|
sourceComponent: Lines {
|
||||||
color: root.color
|
color: root.color
|
||||||
|
|||||||
@@ -2,69 +2,38 @@ import QtQuick
|
|||||||
import QtQuick.Shapes
|
import QtQuick.Shapes
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import qs.modules.common
|
import qs.modules.common
|
||||||
|
import qs.modules.common.widgets.shapes
|
||||||
|
import "shapes/geometry/offset.js" as Offset
|
||||||
|
import "shapes/shapes/corner-rounding.js" as CornerRounding
|
||||||
|
import "shapes/shapes/rounded-polygon.js" as RoundedPolygon
|
||||||
|
import "shapes/material-shapes.js" as MaterialShapes
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
property int sides: 12
|
||||||
property real sides: 12
|
|
||||||
property int implicitSize: 100
|
property int implicitSize: 100
|
||||||
property real amplitude: implicitSize / 50
|
property alias color: shapeCanvas.color
|
||||||
property int renderPoints: 360
|
|
||||||
property color color: "#605790"
|
|
||||||
property alias strokeWidth: shapePath.strokeWidth
|
|
||||||
property bool constantlyRotate: false
|
|
||||||
|
|
||||||
implicitWidth: implicitSize
|
implicitWidth: implicitSize
|
||||||
implicitHeight: implicitSize
|
implicitHeight: implicitSize
|
||||||
|
|
||||||
property real shapeRotation: 0
|
property var cornerRounding: new CornerRounding.CornerRounding(1.1 / Math.max(sides, 1))
|
||||||
|
|
||||||
Loader {
|
ShapeCanvas {
|
||||||
active: constantlyRotate
|
id: shapeCanvas
|
||||||
sourceComponent: FrameAnimation {
|
|
||||||
running: true
|
|
||||||
onTriggered: {
|
|
||||||
shapeRotation += 0.05
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Behavior on sides {
|
|
||||||
animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
Shape {
|
|
||||||
id: shape
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
preferredRendererType: Shape.CurveRenderer
|
roundedPolygon: switch(sides) {
|
||||||
|
case 0: return MaterialShapes.getCircle();
|
||||||
ShapePath {
|
case 1: return MaterialShapes.getCircle();
|
||||||
id: shapePath
|
case 4: return MaterialShapes.getCookie4Sided();
|
||||||
strokeWidth: 0
|
case 6: return MaterialShapes.getCookie6Sided();
|
||||||
fillColor: root.color
|
case 7: return MaterialShapes.getCookie7Sided();
|
||||||
pathHints: ShapePath.PathSolid & ShapePath.PathNonIntersecting
|
case 9: return MaterialShapes.getCookie9Sided();
|
||||||
|
case 12: return MaterialShapes.getCookie12Sided();
|
||||||
PathPolyline {
|
default: return RoundedPolygon.RoundedPolygon.star(sides, 1, 0.8, root.cornerRounding)
|
||||||
property var pointsList: {
|
.transformed((x, y) => MaterialShapes.rotate30.map(new Offset.Offset(x, y)))
|
||||||
var points = []
|
.normalized();
|
||||||
var cx = shape.width / 2 // center x
|
|
||||||
var cy = shape.height / 2 // center y
|
|
||||||
var steps = root.renderPoints
|
|
||||||
var radius = root.implicitSize / 2 - root.amplitude
|
|
||||||
for (var i = 0; i <= steps; i++) {
|
|
||||||
var angle = (i / steps) * 2 * Math.PI
|
|
||||||
var rotatedAngle = angle * root.sides + Math.PI/2 + (root.shapeRotation * root.constantlyRotate)
|
|
||||||
var wave = Math.sin(rotatedAngle) * root.amplitude
|
|
||||||
var x = Math.cos(angle) * (radius + wave) + cx
|
|
||||||
var y = Math.sin(angle) * (radius + wave) + cy
|
|
||||||
points.push(Qt.point(x, y))
|
|
||||||
}
|
|
||||||
return points
|
|
||||||
}
|
|
||||||
|
|
||||||
path: pointsList
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user