From 8b9c14c827c305fea06399d08aaf438cd580b5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 25 May 2021 11:30:11 +0800 Subject: [PATCH] add text shadow --- doric-Qt/example/doric/resources/text.qml | 25 +++++++++++++++++++ .../example/doric/shader/DoricTextNode.cpp | 7 ++++++ 2 files changed, 32 insertions(+) diff --git a/doric-Qt/example/doric/resources/text.qml b/doric-Qt/example/doric/resources/text.qml index d2d5c82d..6006b1ac 100644 --- a/doric-Qt/example/doric/resources/text.qml +++ b/doric-Qt/example/doric/resources/text.qml @@ -1,5 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.5 +import QtGraphicalEffects 1.12 import "util.mjs" as Util import "gravity.mjs" as Gravity @@ -98,4 +99,28 @@ TextArea { mouseAreaBridge.onClick(wrapper) } } + + property var shadowColor + property var shadowRadius + property var shadowOffsetX + property var shadowOffsetY + property var shadowOpacity + + onShadowOpacityChanged: { + if (shadowOpacity > 0) { + layer.enabled = true + } else { + layer.enabled = false + } + } + + layer.enabled: false + layer.effect: DropShadow { + horizontalOffset: shadowOffsetX + verticalOffset: shadowOffsetY + radius: shadowRadius + samples: 16 + color: shadowColor + transparentBorder: true + } } diff --git a/doric-Qt/example/doric/shader/DoricTextNode.cpp b/doric-Qt/example/doric/shader/DoricTextNode.cpp index a44648e3..6bd6e1a0 100644 --- a/doric-Qt/example/doric/shader/DoricTextNode.cpp +++ b/doric-Qt/example/doric/shader/DoricTextNode.cpp @@ -32,6 +32,13 @@ void DoricTextNode::blend(QQuickItem *view, QString name, QJsonValue prop) { view->setProperty("textAlignment", prop.toInt()); } else if (name == "fontStyle") { view->setProperty("fontStyle", prop.toString()); + } else if (name == "shadow") { + view->setProperty("shadowColor", QVariant::fromValue(DoricUtils::doricColor( + prop["color"].toInt()))); + view->setProperty("shadowRadius", prop["radius"].toDouble()); + view->setProperty("shadowOffsetX", prop["offsetX"].toDouble()); + view->setProperty("shadowOffsetY", prop["offsetY"].toDouble()); + view->setProperty("shadowOpacity", prop["opacity"].toDouble()); } else { DoricViewNode::blend(view, name, prop); }