Browse Source

Fix bug where clicking towards ends of characters wouldn't position the caret.

Jon Watte 10 years ago
parent
commit
d6941a68d8
1 changed files with 3 additions and 1 deletions
  1. 3 1
      gameplay/src/Font.cpp

+ 3 - 1
gameplay/src/Font.cpp

@@ -1371,9 +1371,11 @@ int Font::getIndexOrLocation(const char* text, const Rectangle& area, unsigned i
                 }
                 }
 
 
                 // Check against inLocation.
                 // Check against inLocation.
+                //  Note: g.width is smaller than g.advance, so if I only check against g.width, I will 
+                //  miss locations towards the right of the character.
                 if (destIndex == (int)charIndex ||
                 if (destIndex == (int)charIndex ||
                     (destIndex == -1 &&
                     (destIndex == -1 &&
-                    inLocation.x >= xPos && inLocation.x < floor(xPos + g.width*scale + spacing) &&
+                    inLocation.x >= xPos && inLocation.x < floor(xPos + g.advance*scale + spacing) &&
                     inLocation.y >= yPos && inLocation.y < yPos + size))
                     inLocation.y >= yPos && inLocation.y < yPos + size))
                 {
                 {
                     outLocation->x = xPos;
                     outLocation->x = xPos;