diff options
15 files changed, 120 insertions, 12 deletions
diff --git a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp index 98712791..e412bab4 100644 --- a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp +++ b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp @@ -221,6 +221,11 @@ struct DataConstructor<SObjectRefType> #define QT3DS_WCHAR_T_vertalign L"vertalign" #define QT3DS_WCHAR_T_leading L"leading" #define QT3DS_WCHAR_T_tracking L"tracking" +#define QT3DS_WCHAR_T_dropshadow L"dropshadow" +#define QT3DS_WCHAR_T_dropshadowstrength L"dropshadowstrength" +#define QT3DS_WCHAR_T_dropshadowoffset L"dropshadowoffset" +#define QT3DS_WCHAR_T_dropshadowhorzalign L"dropshadowhorzalign" +#define QT3DS_WCHAR_T_dropshadowvertalign L"dropshadowvertalign" #define QT3DS_WCHAR_T_enableacceleratedfont L"enableacceleratedfont" #define QT3DS_WCHAR_T_importfile L"importfile" #define QT3DS_WCHAR_T_fileid L"fileid" diff --git a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h index e734f53f..55fb0b34 100644 --- a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h +++ b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h @@ -277,6 +277,11 @@ class IPropertySystem; HANDLE_COMPOSER_PROPERTY(vertalign, m_VertAlign, TDataStrPtr, L"Middle") \ HANDLE_COMPOSER_PROPERTY(leading, m_Leading, float, 0.f) \ HANDLE_COMPOSER_PROPERTY(tracking, m_Tracking, float, 0.f) \ + HANDLE_COMPOSER_PROPERTY(dropshadow, m_DropShadow, bool, false) \ + HANDLE_COMPOSER_PROPERTY(dropshadowstrength, m_DropShadowStrength, float, 80.f) \ + HANDLE_COMPOSER_PROPERTY(dropshadowoffset, m_DropShadowOffset, float, 10.f) \ + HANDLE_COMPOSER_PROPERTY(dropshadowhorzalign, m_DropShadowHorizontalAlignment, TDataStrPtr, L"Right") \ + HANDLE_COMPOSER_PROPERTY(dropshadowvertalign, m_DropShadowVerticalAlignment, TDataStrPtr, L"Bottom") \ HANDLE_COMPOSER_PROPERTY(enableacceleratedfont, m_EnableAcceleratedFont, bool, false) \ HANDLE_COMPOSER_PROPERTY_DUPLICATE(controlledproperty, m_ControlledProperty, TDataStrPtr, L"") diff --git a/src/Authoring/Studio/Render/StudioRendererTranslation.cpp b/src/Authoring/Studio/Render/StudioRendererTranslation.cpp index f4b7d3a2..8ab0eb1f 100644 --- a/src/Authoring/Studio/Render/StudioRendererTranslation.cpp +++ b/src/Authoring/Studio/Render/StudioRendererTranslation.cpp @@ -461,6 +461,11 @@ struct STranslatorDataModelParser #define Text_VerticalAlignment m_Text.m_VertAlign #define Text_Leading m_Text.m_Leading #define Text_Tracking m_Text.m_Tracking +#define Text_DropShadow m_Text.m_DropShadow +#define Text_DropShadowStrength m_Text.m_DropShadowStrength +#define Text_DropShadowOffset m_Text.m_DropShadowOffset +#define Text_DropShadowHorizontalAlignment m_Text.m_DropShadowHorizontalAlignment +#define Text_DropShadowVerticalAlignment m_Text.m_DropShadowVerticalAlignment #define Text_TextColor m_Text.m_TextColor #define Text_EnableAcceleratedFont m_Text.m_EnableAcceleratedFont #define Path_Width m_Path.m_Width diff --git a/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp b/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp index 1eb7fa48..0a748562 100644 --- a/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp +++ b/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp @@ -624,6 +624,11 @@ struct SRuntimePropertyParser #define Text_VerticalAlignment ATTRIBUTE_VERTALIGN #define Text_Leading ATTRIBUTE_LEADING #define Text_Tracking ATTRIBUTE_TRACKING +#define Text_DropShadow ATTRIBUTE_DROPSHADOW +#define Text_DropShadowStrength ATTRIBUTE_DROPSHADOWSTRENGTH +#define Text_DropShadowOffset ATTRIBUTE_DROPSHADOWOFFSET +#define Text_DropShadowHorizontalAlignment ATTRIBUTE_DROPSHADOWHORZALIGN +#define Text_DropShadowVerticalAlignment ATTRIBUTE_DROPSHADOWVERTALIGN #define Text_TextColor ATTRIBUTE_TEXTCOLOR #define Text_TextColor_R ATTRIBUTE_TEXTCOLOR_R #define Text_TextColor_G ATTRIBUTE_TEXTCOLOR_G diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderText.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderText.cpp index 6cbfaa3c..7fc39ccc 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderText.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderText.cpp @@ -37,6 +37,11 @@ STextRenderInfo::STextRenderInfo() , m_VerticalAlignment(TextVerticalAlignment::Middle) , m_Leading(0) , m_Tracking(0) + , m_DropShadow(false) + , m_DropShadowStrength(80) + , m_DropShadowOffset(10) + , m_DropShadowHorizontalAlignment(TextHorizontalAlignment::Right) + , m_DropShadowVerticalAlignment(TextVerticalAlignment::Bottom) , m_ScaleX(0) , m_ScaleY(0) , m_EnableAcceleratedFont(false) diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderTextTypes.h b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderTextTypes.h index e0487fff..ecdc072a 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderTextTypes.h +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderTextTypes.h @@ -151,6 +151,11 @@ namespace render { TextVerticalAlignment::Enum m_VerticalAlignment; QT3DSF32 m_Leading; // space between lines QT3DSF32 m_Tracking; // space between letters + bool m_DropShadow; + QT3DSF32 m_DropShadowStrength; + QT3DSF32 m_DropShadowOffset; + TextHorizontalAlignment::Enum m_DropShadowHorizontalAlignment; + TextVerticalAlignment::Enum m_DropShadowVerticalAlignment; QT3DSF32 m_ScaleX; // Pixel scale in X QT3DSF32 m_ScaleY; // Pixel scale in Y @@ -163,4 +168,4 @@ namespace render { } } -#endif
\ No newline at end of file +#endif diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h index eb19f51f..683cd9d1 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h @@ -437,6 +437,11 @@ namespace render { HANDLE_QT3DS_RENDER_ENUM_PROPERTY(Text, VerticalAlignment, TextDirty) \ HANDLE_QT3DS_RENDER_PROPERTY(Text, Leading, TextDirty) \ HANDLE_QT3DS_RENDER_PROPERTY(Text, Tracking, TextDirty) \ + HANDLE_QT3DS_RENDER_PROPERTY(Text, DropShadow, TextDirty) \ + HANDLE_QT3DS_RENDER_PROPERTY(Text, DropShadowStrength, TextDirty) \ + HANDLE_QT3DS_RENDER_PROPERTY(Text, DropShadowOffset, TextDirty) \ + HANDLE_QT3DS_RENDER_ENUM_PROPERTY(Text, DropShadowHorizontalAlignment, TextDirty) \ + HANDLE_QT3DS_RENDER_ENUM_PROPERTY(Text, DropShadowVerticalAlignment, TextDirty) \ HANDLE_QT3DS_RENDER_COLOR_VEC3_PROPERTY(Text, TextColor, Dirty) \ HANDLE_QT3DS_RENDER_COLOR_PROPERTY(Text, TextColor, Dirty) \ HANDLE_QT3DS_RENDER_PROPERTY(Text, EnableAcceleratedFont, Dirty) diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplShaders.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplShaders.cpp index ac8869a1..c3fc2d4d 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplShaders.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/RendererImpl/Qt3DSRendererImplShaders.cpp @@ -2127,9 +2127,10 @@ namespace render { // flip the y uv coord if the dimension's z variable is set << "\tif ( text_textdimensions.z > 0.0 ) theCoords.y = 1.0 - theCoords.y;" << Endl; fragmentGenerator.Append( - "\tfloat alpha_mask = texture2D( text_image, theCoords ).r * text_textcolor.a;"); - fragmentGenerator.Append("\tfragOutput = vec4(mix(text_backgroundcolor.rgb, " - "text_textcolor.rgb, alpha_mask), alpha_mask );"); + "\tvec4 c = texture2D(text_image, theCoords);"); + fragmentGenerator.Append( + "\tfragOutput = vec4(mix(text_backgroundcolor.rgb, " + "text_textcolor.rgb, c.rgb), c.a) * text_textcolor.a;"); vertexGenerator.Append("}"); fragmentGenerator.Append("}"); diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSQtTextRenderer.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSQtTextRenderer.cpp index febc446e..c80c6727 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSQtTextRenderer.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSQtTextRenderer.cpp @@ -494,7 +494,6 @@ struct Qt3DSQtTextRenderer : public ITextRenderer return qtAlign; } - // The system will use the 'r' channel as an alpha mask in order to render the text. STextTextureDetails RenderText(const STextRenderInfo &inSrcText, NVRenderTexture2D &inTexture) override { @@ -502,12 +501,13 @@ struct Qt3DSQtTextRenderer : public ITextRenderer updateFontInfo(fi, inSrcText); QFontMetricsF fm(fi.font); + int shadowRgb = int(2.55f * (100 - int(inSrcText.m_DropShadowStrength))); QStringList lineList; QVector<qreal> lineWidths; QRectF boundingBox = textBoundingBox(inSrcText, fm, lineList, lineWidths); if (boundingBox.width() <= 0 || boundingBox.height() <= 0) { - return ITextRenderer::UploadData(toU8DataRef((char *)NULL, 0), inTexture, 4, 4, + return ITextRenderer::UploadData(toU8DataRef((char *)nullptr, 0), inTexture, 4, 4, 0, 0, NVRenderTextureFormats::RGBA8, true); } @@ -515,7 +515,7 @@ struct Qt3DSQtTextRenderer : public ITextRenderer int finalWidth = NextMultipleOf4(boundingBox.width()); int finalHeight = NextMultipleOf4(boundingBox.height()); - QImage image(finalWidth, finalHeight, QImage::Format_Grayscale8); + QImage image(finalWidth, finalHeight, QImage::Format_ARGB32); image.fill(0); QPainter painter(&image); painter.setPen(Qt::white); @@ -534,6 +534,32 @@ struct Qt3DSQtTextRenderer : public ITextRenderer break; // Do nothing } + qreal shadowOffsetX = 0.; + qreal shadowOffsetY = 0.; + if (inSrcText.m_DropShadow) { + const qreal offset = qreal(inSrcText.m_DropShadowOffset) / 10.; + switch (inSrcText.m_DropShadowHorizontalAlignment) { + case TextHorizontalAlignment::Left: + shadowOffsetX = -offset; + break; + case TextHorizontalAlignment::Right: + shadowOffsetX = offset; + break; + default: + break; + } + switch (inSrcText.m_DropShadowVerticalAlignment) { + case TextVerticalAlignment::Top: + shadowOffsetY = -offset; + break; + case TextVerticalAlignment::Bottom: + shadowOffsetY = offset; + break; + default: + break; + } + } + int lineHeight = fm.height(); QT3DSF32 nextHeight = 0; for (int i = 0; i < lineList.size(); ++i) { @@ -551,17 +577,27 @@ struct Qt3DSQtTextRenderer : public ITextRenderer } QRectF bound(xTranslation, qreal(nextHeight), lineWidths.at(i), lineHeight); QRectF actualBound; + if (inSrcText.m_DropShadow) { + QRectF boundShadow(xTranslation + shadowOffsetX, nextHeight + shadowOffsetY, + qreal(lineWidths.at(i)), lineHeight); + // shadow is a darker shade of the given font color + painter.setPen(QColor(shadowRgb, shadowRgb, shadowRgb)); + painter.drawText(boundShadow, + alignToQtAlign(inSrcText.m_VerticalAlignment) | + Qt::TextDontClip | Qt::AlignLeft, line, &actualBound); + painter.setPen(Qt::white); // coloring is done in the shader + } painter.drawText(bound, - alignToQtAlign(inSrcText.m_VerticalAlignment) | - Qt::TextDontClip | Qt::AlignLeft, line, &actualBound); + alignToQtAlign(inSrcText.m_VerticalAlignment) | + Qt::TextDontClip | Qt::AlignLeft, line, &actualBound); nextHeight += QT3DSF32(lineHeight) + inSrcText.m_Leading; } return ITextRenderer::UploadData(toU8DataRef(image.bits(), image.byteCount()), inTexture, - image.width(), image.height(), image.width(), image.height(), - NVRenderTextureFormats::Luminance8, true); - + image.width(), image.height(), + image.width(), image.height(), + NVRenderTextureFormats::RGBA8, true); } STextTextureDetails RenderText(const STextRenderInfo &inText, diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderTextTextureCache.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderTextTextureCache.cpp index ce7b4689..e3b44fab 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderTextTextureCache.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderTextTextureCache.cpp @@ -53,6 +53,11 @@ struct hash<STextRenderInfo> retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_VerticalAlignment)); retval = retval ^ hash<float>()(inInfo.m_Leading); retval = retval ^ hash<float>()(inInfo.m_Tracking); + retval = retval ^ hash<bool>()(inInfo.m_DropShadow); + retval = retval ^ hash<float>()(inInfo.m_DropShadowStrength); + retval = retval ^ hash<float>()(inInfo.m_DropShadowOffset); + retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_DropShadowHorizontalAlignment)); + retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_DropShadowVerticalAlignment)); retval = retval ^ hash<bool>()(inInfo.m_EnableAcceleratedFont); return retval; } @@ -79,6 +84,12 @@ struct STextRenderInfoAndHash && m_Info.m_VerticalAlignment == inOther.m_Info.m_VerticalAlignment && m_Info.m_Leading == inOther.m_Info.m_Leading && m_Info.m_Tracking == inOther.m_Info.m_Tracking + && m_Info.m_DropShadow == inOther.m_Info.m_DropShadow + && m_Info.m_DropShadowStrength == inOther.m_Info.m_DropShadowStrength + && m_Info.m_DropShadowOffset == inOther.m_Info.m_DropShadowOffset + && m_Info.m_DropShadowHorizontalAlignment + == inOther.m_Info.m_DropShadowHorizontalAlignment + && m_Info.m_DropShadowVerticalAlignment == inOther.m_Info.m_DropShadowVerticalAlignment && m_Info.m_EnableAcceleratedFont == inOther.m_Info.m_EnableAcceleratedFont && m_ScaleFactor == inOther.m_ScaleFactor; } diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp index 70280b0e..290dd4f3 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp @@ -791,6 +791,11 @@ struct SRenderUIPLoader : public IDOMReferenceResolver #define Text_VerticalAlignment "vertalign" #define Text_Leading "leading" #define Text_Tracking "tracking" +#define Text_DropShadow "dropshadow" +#define Text_DropShadowStrength "dropshadowstrength" +#define Text_DropShadowOffset "dropshadowoffset" +#define Text_DropShadowHorizontalAlignment "dropshadowhorzalign" +#define Text_DropShadowVerticalAlignment "dropshadowvertalign" #define Text_TextColor "textcolor" #define Text_BackColor "backcolor" #define Text_EnableAcceleratedFont "enableacceleratedfont" diff --git a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h index 2a497bf4..1c26977d 100644 --- a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h +++ b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h @@ -207,6 +207,11 @@ enum EAttribute { ATTRIBUTE_TEXTCOLOR_B = 0x00D9ED96, // textcolor.b ATTRIBUTE_SIZE = 0x00F2C81F, // size ATTRIBUTE_FONT = 0x03412331, // font + ATTRIBUTE_DROPSHADOW = 0x03E3F231, // dropshadow + ATTRIBUTE_DROPSHADOWSTRENGTH = 0x03F8B7D0, // dropshadowstrength + ATTRIBUTE_DROPSHADOWOFFSET = 0x024A9C5E, // dropshadowoffset + ATTRIBUTE_DROPSHADOWHORZALIGN = 0x00D1BC39, // dropshadowhorzalign + ATTRIBUTE_DROPSHADOWVERTALIGN = 0x038D589B, // dropshadowvertalign ATTRIBUTE_TRACKING = 0x02A25049, // tracking ATTRIBUTE_LEADING = 0x016A6BDA, // leading ATTRIBUTE_RENDERSTYLE = 0x03567B85, // renderstyle diff --git a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt index 90948c07..072743bf 100644 --- a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt +++ b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt @@ -174,6 +174,11 @@ textcolor.g textcolor.b size font +dropshadow +dropshadowstrength +dropshadowoffset +dropshadowhorzalign +dropshadowvertalign tracking leading renderstyle diff --git a/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp b/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp index 4d201d72..40d64a0a 100644 --- a/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp +++ b/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp @@ -216,6 +216,11 @@ const char *GetAttributeString(const EAttribute inAttribute) case ATTRIBUTE_TEXTCOLOR_B: return "textcolor.b"; case ATTRIBUTE_SIZE: return "size"; case ATTRIBUTE_FONT: return "font"; + case ATTRIBUTE_DROPSHADOW: return "dropshadow"; + case ATTRIBUTE_DROPSHADOWSTRENGTH: return "dropshadowstrength"; + case ATTRIBUTE_DROPSHADOWOFFSET: return "dropshadowoffset"; + case ATTRIBUTE_DROPSHADOWHORZALIGN: return "dropshadowhorzalign"; + case ATTRIBUTE_DROPSHADOWVERTALIGN: return "dropshadowvertalign"; case ATTRIBUTE_TRACKING: return "tracking"; case ATTRIBUTE_LEADING: return "leading"; case ATTRIBUTE_RENDERSTYLE: return "renderstyle"; diff --git a/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml b/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml index f7cf465f..7fb4fb02 100644 --- a/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml +++ b/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml @@ -453,5 +453,10 @@ <Property name="vertalign" formalName="Vertical Alignment" description="Vertical Alignment" list="Top:Middle:Bottom" default="Middle" /> <Property name="leading" formalName="Leading" description="Leading" /> <Property name="tracking" formalName="Tracking" description="Tracking" /> + <Property name="dropshadow" formalName="Drop-Shadow" description="Add a drop-shadow to the text.\nThe shadow is a darker shade of the given color." type="Boolean" default="False" /> + <Property name="dropshadowstrength" formalName="Shadow Darkness" description="Darkness of the shadow in percents.\n100 is black, 0 is the same color as the text." min="0" max="100" type="Float" default="80" /> + <Property name="dropshadowoffset" formalName="Shadow Offset" description="Offset of the shadow. It\nis relative to the font size." min="1" max="100" type="Float" default="10" /> + <Property name="dropshadowhorzalign" formalName="Horizontal Position" description="Horizontal position of the shadow" list="Left:Center:Right" default="Right" /> + <Property name="dropshadowvertalign" formalName="Vertical Position" description="Vertical position of the shadow" list="Top:Middle:Bottom" default="Bottom" /> </Text> </MetaData> |