diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2018-11-21 12:55:24 +0200 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2018-11-26 06:00:07 +0000 |
commit | d53d85e208b5c400142f0389ef16f073229af908 (patch) | |
tree | 1db06622f9a5a48f68089c80358061599378aa6d | |
parent | 8f9519aa3b2b4aba0ec585b2e2d193fcb23c8a0d (diff) |
Add support for fixed size text areas
Task-number: QT3DS-2110
Change-Id: I5383303b089d5c6572120a4e4f7731d0c9b35ded
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
15 files changed, 100 insertions, 7 deletions
diff --git a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp index e412bab4..6d413244 100644 --- a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp +++ b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.cpp @@ -226,6 +226,8 @@ struct DataConstructor<SObjectRefType> #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_wordwrap L"wordwrap" +#define QT3DS_WCHAR_T_boundingbox L"boundingbox" #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 55fb0b34..729ffa8f 100644 --- a/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h +++ b/src/Authoring/QT3DSDM/Systems/Qt3DSDMComposerTypeDefinitions.h @@ -282,6 +282,8 @@ class IPropertySystem; 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(wordwrap, m_WordWrap, TDataStrPtr, L"WrapWord") \ + HANDLE_COMPOSER_PROPERTY(boundingbox, m_BoundingBox, SFloat2, SFloat2(0, 0)) \ 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 8ab0eb1f..d871dbca 100644 --- a/src/Authoring/Studio/Render/StudioRendererTranslation.cpp +++ b/src/Authoring/Studio/Render/StudioRendererTranslation.cpp @@ -466,6 +466,8 @@ struct STranslatorDataModelParser #define Text_DropShadowOffset m_Text.m_DropShadowOffset #define Text_DropShadowHorizontalAlignment m_Text.m_DropShadowHorizontalAlignment #define Text_DropShadowVerticalAlignment m_Text.m_DropShadowVerticalAlignment +#define Text_WordWrap m_Text.m_WordWrap +#define Text_BoundingBox m_Text.m_BoundingBox #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 0a748562..e1b185c8 100644 --- a/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp +++ b/src/Runtime/Source/Engine/Source/Qt3DSRenderRuntimeBindingImplTranslation.cpp @@ -629,6 +629,10 @@ struct SRuntimePropertyParser #define Text_DropShadowOffset ATTRIBUTE_DROPSHADOWOFFSET #define Text_DropShadowHorizontalAlignment ATTRIBUTE_DROPSHADOWHORZALIGN #define Text_DropShadowVerticalAlignment ATTRIBUTE_DROPSHADOWVERTALIGN +#define Text_WordWrap ATTRIBUTE_WORDWRAP +#define Text_BoundingBox ATTRIBUTE_BOUNDINGBOX +#define Text_BoundingBox_X ATTRIBUTE_BOUNDINGBOX_X +#define Text_BoundingBox_Y ATTRIBUTE_BOUNDINGBOX_Y #define Text_TextColor ATTRIBUTE_TEXTCOLOR #define Text_TextColor_R ATTRIBUTE_TEXTCOLOR_R #define Text_TextColor_G ATTRIBUTE_TEXTCOLOR_G @@ -1159,7 +1163,6 @@ struct STextTranslator : public SNodeTranslator ITERATE_QT3DS_RENDER_TEXT_PROPERTIES case Q3DStudio::ATTRIBUTE_TEXTTYPE: case Q3DStudio::ATTRIBUTE_RENDERSTYLE: - case Q3DStudio::ATTRIBUTE_WORDWRAP: case Q3DStudio::ATTRIBUTE_HORZSCROLL: case Q3DStudio::ATTRIBUTE_VERTSCROLL: case Q3DStudio::ATTRIBUTE_BOXHEIGHT: diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderText.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderText.cpp index 7fc39ccc..6eb56109 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderText.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/GraphObjects/Qt3DSRenderText.cpp @@ -42,6 +42,8 @@ STextRenderInfo::STextRenderInfo() , m_DropShadowOffset(10) , m_DropShadowHorizontalAlignment(TextHorizontalAlignment::Right) , m_DropShadowVerticalAlignment(TextVerticalAlignment::Bottom) + , m_WordWrap(TextWordWrap::WrapWord) + , m_BoundingBox(QT3DSVec2(0 ,0)) , 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 ecdc072a..8b151b78 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderTextTypes.h +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderTextTypes.h @@ -59,6 +59,16 @@ namespace render { }; }; + struct TextWordWrap + { + enum Enum { + Unknown = 0, + Clip, + WrapWord, + WrapAnywhere, + }; + }; + struct STextDimensions { QT3DSU32 m_TextWidth; @@ -156,6 +166,8 @@ namespace render { QT3DSF32 m_DropShadowOffset; TextHorizontalAlignment::Enum m_DropShadowHorizontalAlignment; TextVerticalAlignment::Enum m_DropShadowVerticalAlignment; + TextWordWrap::Enum m_WordWrap; + QT3DSVec2 m_BoundingBox; QT3DSF32 m_ScaleX; // Pixel scale in X QT3DSF32 m_ScaleY; // Pixel scale in Y diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h index 683cd9d1..347f549b 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Include/Qt3DSRenderUIPSharedTranslation.h @@ -100,6 +100,12 @@ namespace render { }; template <> + struct SEnumParseMap<TextWordWrap::Enum> + { + static SEnumNameMap *GetMap(); + }; + + template <> struct SEnumParseMap<AAModeValues::Enum> { static SEnumNameMap *GetMap(); @@ -442,6 +448,8 @@ namespace render { 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_ENUM_PROPERTY(Text, WordWrap, TextDirty) \ + HANDLE_QT3DS_RENDER_REAL_VEC2_PROPERTY(Text, BoundingBox, 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/Source/Qt3DSQtTextRenderer.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSQtTextRenderer.cpp index c80c6727..27242300 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSQtTextRenderer.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSQtTextRenderer.cpp @@ -504,7 +504,16 @@ struct Qt3DSQtTextRenderer : public ITextRenderer int shadowRgb = int(2.55f * (100 - int(inSrcText.m_DropShadowStrength))); QStringList lineList; QVector<qreal> lineWidths; - QRectF boundingBox = textBoundingBox(inSrcText, fm, lineList, lineWidths); + QRectF boundingBox; + const bool dynamicTextArea = inSrcText.m_BoundingBox.isZero(); + + if (dynamicTextArea) { + boundingBox = textBoundingBox(inSrcText, fm, lineList, lineWidths); + } else { + lineList << inSrcText.m_Text.c_str(); + lineWidths << inSrcText.m_BoundingBox.x; + boundingBox = QRectF(0, 0, inSrcText.m_BoundingBox.x, inSrcText.m_BoundingBox.y); + } if (boundingBox.width() <= 0 || boundingBox.height() <= 0) { return ITextRenderer::UploadData(toU8DataRef((char *)nullptr, 0), inTexture, 4, 4, @@ -560,7 +569,24 @@ struct Qt3DSQtTextRenderer : public ITextRenderer } } - int lineHeight = fm.height(); + int wordWrapFlags = 0; + if (dynamicTextArea) { + wordWrapFlags = Qt::TextDontClip; + } else { + switch (inSrcText.m_WordWrap) { + case TextWordWrap::WrapWord: + wordWrapFlags = Qt::TextWordWrap | Qt::TextDontClip; + break; + case TextWordWrap::WrapAnywhere: + wordWrapFlags = Qt::TextWrapAnywhere | Qt::TextDontClip; + break; + case TextWordWrap::Clip: + default: + break; + } + } + + int lineHeight = dynamicTextArea ? fm.height() : finalHeight; QT3DSF32 nextHeight = 0; for (int i = 0; i < lineList.size(); ++i) { const QString &line = lineList.at(i); @@ -583,13 +609,13 @@ struct Qt3DSQtTextRenderer : public ITextRenderer // 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); + alignToQtAlign(inSrcText.m_VerticalAlignment) | wordWrapFlags + | 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) | wordWrapFlags + | Qt::AlignLeft, line, &actualBound); nextHeight += QT3DSF32(lineHeight) + inSrcText.m_Leading; } diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderTextTextureCache.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderTextTextureCache.cpp index e3b44fab..1d9e7cf9 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderTextTextureCache.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderTextTextureCache.cpp @@ -56,8 +56,11 @@ struct hash<STextRenderInfo> retval = retval ^ hash<bool>()(inInfo.m_DropShadow); retval = retval ^ hash<float>()(inInfo.m_DropShadowStrength); retval = retval ^ hash<float>()(inInfo.m_DropShadowOffset); + retval = retval ^ hash<float>()(inInfo.m_BoundingBox.x); + retval = retval ^ hash<float>()(inInfo.m_BoundingBox.y); retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_DropShadowHorizontalAlignment)); retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_DropShadowVerticalAlignment)); + retval = retval ^ hash<int>()(static_cast<int>(inInfo.m_WordWrap)); retval = retval ^ hash<bool>()(inInfo.m_EnableAcceleratedFont); return retval; } @@ -90,6 +93,8 @@ struct STextRenderInfoAndHash && m_Info.m_DropShadowHorizontalAlignment == inOther.m_Info.m_DropShadowHorizontalAlignment && m_Info.m_DropShadowVerticalAlignment == inOther.m_Info.m_DropShadowVerticalAlignment + && m_Info.m_BoundingBox == inOther.m_Info.m_BoundingBox + && m_Info.m_WordWrap == inOther.m_Info.m_WordWrap && 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 290dd4f3..17c792ca 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPLoader.cpp @@ -796,6 +796,8 @@ struct SRenderUIPLoader : public IDOMReferenceResolver #define Text_DropShadowOffset "dropshadowoffset" #define Text_DropShadowHorizontalAlignment "dropshadowhorzalign" #define Text_DropShadowVerticalAlignment "dropshadowvertalign" +#define Text_WordWrap "wordwrap" +#define Text_BoundingBox "boundingbox" #define Text_TextColor "textcolor" #define Text_BackColor "backcolor" #define Text_EnableAcceleratedFont "enableacceleratedfont" diff --git a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPSharedTranslation.cpp b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPSharedTranslation.cpp index 99e075d6..f82a1853 100644 --- a/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPSharedTranslation.cpp +++ b/src/Runtime/Source/Qt3DSRuntimeRender/Source/Qt3DSRenderUIPSharedTranslation.cpp @@ -107,6 +107,9 @@ namespace render { #define WCHAR_T_Cloud L"Cloud" #define WCHAR_T_Fluid L"Fluid" #define WCHAR_T_User L"User" +#define WCHAR_T_Clip L"Clip" +#define WCHAR_T_WrapWord L"WrapWord" +#define WCHAR_T_WrapAnywhere L"WrapAnywhere" #define CHAR_T_Directional "Directional" #define CHAR_T_Point "Point" @@ -183,6 +186,9 @@ namespace render { #define CHAR_T_Cloud "Cloud" #define CHAR_T_Fluid "Fluid" #define CHAR_T_User "User" +#define CHAR_T_Clip "Clip" +#define CHAR_T_WrapWord "WrapWord" +#define CHAR_T_WrapAnywhere "WrapAnywhere" #define DEFINE_NAME_MAP_ENTRY(enumval, name) \ { \ @@ -240,6 +246,13 @@ namespace render { { (QT3DSU32)-1, NULL }, }; + SEnumNameMap g_TextWordWrapMap[] = { + DEFINE_NAME_MAP_ENTRY(TextWordWrap::Clip, Clip), + DEFINE_NAME_MAP_ENTRY(TextWordWrap::WrapWord, WrapWord), + DEFINE_NAME_MAP_ENTRY(TextWordWrap::WrapAnywhere, WrapAnywhere), + { (QT3DSU32)-1, NULL }, + }; + SEnumNameMap g_ProgressiveAAValuesMap[] = { DEFINE_NAME_MAP_ENTRY(AAModeValues::NoAA, None), DEFINE_NAME_MAP_ENTRY(AAModeValues::SSAA, SSAA), @@ -379,6 +392,11 @@ namespace render { return g_TextVerticalAlignmentMap; } + SEnumNameMap *SEnumParseMap<TextWordWrap::Enum>::GetMap() + { + return g_TextWordWrapMap; + } + SEnumNameMap *SEnumParseMap<AAModeValues::Enum>::GetMap() { return g_ProgressiveAAValuesMap; } SEnumNameMap *SEnumParseMap<LayerBlendTypes::Enum>::GetMap() { return g_LayerBlendTypesMap; } diff --git a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h index 1c26977d..55557541 100644 --- a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h +++ b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.h @@ -212,6 +212,9 @@ enum EAttribute { ATTRIBUTE_DROPSHADOWOFFSET = 0x024A9C5E, // dropshadowoffset ATTRIBUTE_DROPSHADOWHORZALIGN = 0x00D1BC39, // dropshadowhorzalign ATTRIBUTE_DROPSHADOWVERTALIGN = 0x038D589B, // dropshadowvertalign + ATTRIBUTE_BOUNDINGBOX = 0x02F3B6D9, // boundingbox + ATTRIBUTE_BOUNDINGBOX_X = 0x0272C10F, // boundingbox.x + ATTRIBUTE_BOUNDINGBOX_Y = 0x0273C14E, // boundingbox.y 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 072743bf..88af61a6 100644 --- a/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt +++ b/src/Runtime/Source/Runtime/Include/Qt3DSAttributeHashes.txt @@ -179,6 +179,9 @@ dropshadowstrength dropshadowoffset dropshadowhorzalign dropshadowvertalign +boundingbox +boundingbox.x +boundingbox.y tracking leading renderstyle diff --git a/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp b/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp index 40d64a0a..615f34cd 100644 --- a/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp +++ b/src/Runtime/Source/Runtime/Source/Qt3DSAttributeHashes.cpp @@ -221,6 +221,9 @@ const char *GetAttributeString(const EAttribute inAttribute) case ATTRIBUTE_DROPSHADOWOFFSET: return "dropshadowoffset"; case ATTRIBUTE_DROPSHADOWHORZALIGN: return "dropshadowhorzalign"; case ATTRIBUTE_DROPSHADOWVERTALIGN: return "dropshadowvertalign"; + case ATTRIBUTE_BOUNDINGBOX: return "boundingbox"; + case ATTRIBUTE_BOUNDINGBOX_X: return "boundingbox.x"; + case ATTRIBUTE_BOUNDINGBOX_Y: return "boundingbox.y"; 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 7fb4fb02..35da1aee 100644 --- a/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml +++ b/src/Runtime/res/DataModelMetadata/en-us/MetaData.xml @@ -453,6 +453,8 @@ <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="boundingbox" formalName="Text Area" description="Fixed size text area. If not set,\ntext area grows with text." type="Float2" default="0 0" /> + <Property name="wordwrap" formalName="Word Wrapping" description="Word wrapping. Has effect only if fixed size\ntext area is used.\nClip: Cut text if it does not fit.\nWrapWord: Wrap between words, if possible.\nWrapAnywhere: Wrap even in the middle\nof words." list="Clip:WrapWord:WrapAnywhere" default="WrapWord" /> <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" /> |