Browse Source

Added Text effect enhancement: Stroke generated procedurally

Bengt Soderstrom 9 years ago
parent
commit
46b9af52ec
2 changed files with 35 additions and 1 deletions
  1. 33 0
      Source/Urho3D/UI/Text.cpp
  2. 2 1
      Source/Urho3D/UI/Text.h

+ 33 - 0
Source/Urho3D/UI/Text.cpp

@@ -47,6 +47,7 @@ const char* textEffects[] =
     "Stroke 3",
     "Stroke 4",
     "Stroke 5",
+    "Stroke Custom",
     0
 };
 
@@ -310,6 +311,38 @@ void Text::GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData,
             ConstructBatch(pageBatch, pageGlyphLocation, -1, -5, &effectColor_, effectDepthBias_);
             ConstructBatch(pageBatch, pageGlyphLocation, 0, 0);
             break;
+
+        case TE_STROKECUSTOM:
+            /*
+            int thickness = 12;
+            // Samples should be even or glyph may be redrawn in wrong x y pos making stroke corners rough
+            // Adding to thickness helps with thickness of 1 not having enought samples for this formula
+            // or certain fonts with reflex corners requiring more glyph samples for a smooth stroke when large
+            int samples = thickness * thickness + (thickness % 2 == 0 ? 4 : 3);
+            float angle = 360.f / samples;
+            for (int i = 0; i < samples; ++i)
+            {
+                float x = cos(angle * i * M_PI / 180.f) * thickness;
+                float y = sin(angle * i * M_PI / 180.f) * thickness;
+                ConstructBatch(pageBatch, pageGlyphLocation, (int)x, (int)y, &effectColor_, effectDepthBias_);
+            }
+            ConstructBatch(pageBatch, pageGlyphLocation, 0, 0);
+            */
+
+            int thickness = 12;
+            // Samples should be even or glyph may be redrawn in wrong x y pos making stroke corners rough
+            // Adding to thickness helps with thickness of 1 not having enought samples for this formula
+            // or certain fonts with reflex corners requiring more glyph samples for a smooth stroke when large
+            int samples = thickness * thickness + (thickness % 2 == 0 ? 4 : 3);
+            float angle = 360.f / samples;
+            for (int i = 0; i < samples; ++i)
+            {
+                float x = i * thickness;
+                float y = i * thickness;
+                ConstructBatch(pageBatch, pageGlyphLocation, (int)x, (int)y, &effectColor_, effectDepthBias_);
+            }
+            ConstructBatch(pageBatch, pageGlyphLocation, 0, 0);
+            break;
         }
 
         UIBatch::AddOrMerge(pageBatch, batches);

+ 2 - 1
Source/Urho3D/UI/Text.h

@@ -42,7 +42,8 @@ enum TextEffect
     TE_STROKE2,
     TE_STROKE3,
     TE_STROKE4,
-    TE_STROKE5
+    TE_STROKE5,
+    TE_STROKECUSTOM
 };
 
 /// Cached character location and size within text. Used for queries related to text editing.