Browse Source

Merge pull request #1106 from reven86/next-clean

Bugfixes
Sean Paul Taylor 12 năm trước cách đây
mục cha
commit
8f7305af80
2 tập tin đã thay đổi với 10 bổ sung5 xóa
  1. 8 4
      gameplay/src/SpriteBatch.cpp
  2. 2 1
      gameplay/src/TextBox.cpp

+ 8 - 4
gameplay/src/SpriteBatch.cpp

@@ -406,17 +406,19 @@ bool SpriteBatch::clipSprite(const Rectangle& clip, float& x, float& y, float& w
         return false;
     }
 
-    const float uvWidth = u2 - u1;
-    const float uvHeight = v2 - v1;
+    float uvWidth = u2 - u1;
+    float uvHeight = v2 - v1;
 
     // Moving x to the right.
     if (x < clip.x)
     {
         const float percent = (clip.x - x) / width;
         const float dx = clip.x - x;
+        const float du = uvWidth * percent;
         x = clip.x;
         width -= dx;
-        u1 += uvWidth * percent;
+        u1 += du;
+        uvWidth -= du;
     }
 
     // Moving y down.
@@ -424,9 +426,11 @@ bool SpriteBatch::clipSprite(const Rectangle& clip, float& x, float& y, float& w
     {
         const float percent = (clip.y - y) / height;
         const float dy = clip.y - y;
+        const float dv = uvHeight * percent;
         y = clip.y;
         height -= dy;
-        v1 += uvHeight * percent;
+        v1 += dv;
+        uvHeight -= dv;
     }
 
     // Moving width to the left.

+ 2 - 1
gameplay/src/TextBox.cpp

@@ -397,7 +397,8 @@ void TextBox::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
             Vector4 color = _caretImage->getColor();
             color.w *= _opacity;
 
-            spriteBatch->draw(_caretLocation.x - (region.width / 2.0f), _caretLocation.y, region.width, _fontSize, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _viewportClipBounds);
+            float caretWidth = region.width * _fontSize / region.height;
+            spriteBatch->draw(_caretLocation.x - caretWidth * 0.5f, _caretLocation.y, caretWidth, _fontSize, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _viewportClipBounds);
         }
     }