Explorar el Código

Some TextBox, Font, and Label related fixes.

Adam Blake hace 14 años
padre
commit
69f4c30037
Se han modificado 5 ficheros con 37 adiciones y 38 borrados
  1. 22 22
      gameplay/src/Font.cpp
  2. 9 13
      gameplay/src/Form.cpp
  3. 1 1
      gameplay/src/Label.cpp
  4. 4 1
      gameplay/src/TextBox.cpp
  5. 1 1
      gameplay/src/Theme.cpp

+ 22 - 22
gameplay/src/Font.cpp

@@ -205,7 +205,7 @@ void Font::drawText(const char* text, int x, int y, const Vector4& color, unsign
                 switch (delimiter)
                 {
                 case ' ':
-                    xPos += size>>1;
+                    xPos += (float)size*0.5f;
                     break;
                 case '\r':
                 case '\n':
@@ -213,7 +213,7 @@ void Font::drawText(const char* text, int x, int y, const Vector4& color, unsign
                     xPos = x;
                     break;
                 case '\t':
-                    xPos += (size>>1)*4;
+                    xPos += ((float)size*0.5f)*4;
                     break;
                 case 0:
                     done = true;
@@ -254,7 +254,7 @@ void Font::drawText(const char* text, int x, int y, const Vector4& color, unsign
             switch (c)
             {
             case ' ':
-                xPos += size>>1;
+                xPos += (float)size*0.5f;
                 break;
             case '\r':
             case '\n':
@@ -262,7 +262,7 @@ void Font::drawText(const char* text, int x, int y, const Vector4& color, unsign
                 xPos = x;
                 break;
             case '\t':
-                xPos += (size>>1)*4;
+                xPos += ((float)size*0.5f)*4;
                 break;
             default:
                 int index = c - 32; // HACK for ASCII
@@ -270,7 +270,7 @@ void Font::drawText(const char* text, int x, int y, const Vector4& color, unsign
                 {
                     Glyph& g = _glyphs[index];
                     _batch->draw(xPos, yPos, g.width * scale, size, g.uvs[0], g.uvs[1], g.uvs[2], g.uvs[3], color);
-                    xPos += g.width * scale + (size>>3);
+                    xPos += g.width * scale + ((float)size*0.125f);
                     break;
                 }
             }
@@ -338,7 +338,7 @@ void Font::drawText(const char* text, const Rectangle& area, const Vector4& colo
                     switch (delimiter)
                     {
                         case ' ':
-                            delimWidth += size>>1;
+                            delimWidth += (float)size*0.5f;
                             lineLength++;
                             break;
                         case '\r':
@@ -355,7 +355,7 @@ void Font::drawText(const char* text, const Rectangle& area, const Vector4& colo
                             delimWidth = 0;
                             break;
                         case '\t':
-                            delimWidth += (size>>1)*4;
+                            delimWidth += ((float)size*0.5f)*4;
                             lineLength++;
                             break;
                         case 0:
@@ -575,7 +575,7 @@ void Font::drawText(const char* text, const Rectangle& area, const Vector4& colo
                         _batch->draw(xPos, yPos, g.width * scale, size, g.uvs[0], g.uvs[1], g.uvs[2], g.uvs[3], color);
                     }
                 }
-                xPos += g.width*scale + (size>>3);
+                xPos += g.width*scale + ((float)size*0.125f);
             }
         }
 
@@ -716,7 +716,7 @@ void Font::measureText(const char* text, const Rectangle& viewport, unsigned int
                 switch (delimiter)
                 {
                     case ' ':
-                        delimWidth += size>>1;
+                        delimWidth += (float)size*0.5f;
                         break;
                     case '\r':
                     case '\n':
@@ -752,7 +752,7 @@ void Font::measureText(const char* text, const Rectangle& viewport, unsigned int
                         delimWidth = 0;
                         break;
                     case '\t':
-                        delimWidth += (size>>1)*4;
+                        delimWidth += ((float)size*0.5f)*4;
                         break;
                     case 0:
                         reachedEOF = true;
@@ -1006,7 +1006,7 @@ unsigned int Font::getIndexAtLocation(const char* text, const Rectangle& area, u
 void Font::getLocationAtIndex(const char* text, const Rectangle& clip, unsigned int size, Vector2* outLocation, const unsigned int destIndex,
                               Justify justify, bool wrap, bool rightToLeft)
 {
-    getIndexOrLocation(text, clip, size, *outLocation, outLocation, destIndex, justify, wrap, rightToLeft);
+    getIndexOrLocation(text, clip, size, *outLocation, outLocation, (const int)destIndex, justify, wrap, rightToLeft);
 }
 
 unsigned int Font::getIndexOrLocation(const char* text, const Rectangle& area, unsigned int size, const Vector2& inLocation, Vector2* outLocation,
@@ -1064,7 +1064,7 @@ unsigned int Font::getIndexOrLocation(const char* text, const Rectangle& area, u
                     switch (delimiter)
                     {
                         case ' ':
-                            delimWidth += size>>1;
+                            delimWidth += (float)size*0.5f;
                             lineLength++;
                             break;
                         case '\r':
@@ -1081,7 +1081,7 @@ unsigned int Font::getIndexOrLocation(const char* text, const Rectangle& area, u
                             delimWidth = 0;
                             break;
                         case '\t':
-                            delimWidth += (size>>1)*4;
+                            delimWidth += ((float)size*0.5f)*4;
                             lineLength++;
                             break;
                         case 0:
@@ -1247,7 +1247,7 @@ unsigned int Font::getIndexOrLocation(const char* text, const Rectangle& area, u
 
         if (destIndex == charIndex ||
             (destIndex == -1 &&
-             inLocation.x >= xPos && inLocation.x < xPos + (size>>3) &&
+             inLocation.x >= xPos && inLocation.x < floor(xPos + ((float)size*0.125f)) &&
              inLocation.y >= yPos && inLocation.y < yPos + size))
         {
             outLocation->x = xPos;
@@ -1320,7 +1320,7 @@ unsigned int Font::getIndexOrLocation(const char* text, const Rectangle& area, u
                 // Check against inLocation.
                 if (destIndex == charIndex ||
                     (destIndex == -1 &&
-                    inLocation.x >= xPos && inLocation.x < xPos + g.width*scale + (size>>3) &&
+                    inLocation.x >= xPos && inLocation.x < floor(xPos + g.width*scale + ((float)size*0.125f)) &&
                     inLocation.y >= yPos && inLocation.y < yPos + size))
                 {
                     outLocation->x = xPos;
@@ -1328,7 +1328,7 @@ unsigned int Font::getIndexOrLocation(const char* text, const Rectangle& area, u
                     return charIndex;
                 }
 
-                xPos += g.width*scale + (size>>3);
+                xPos += g.width*scale + ((float)size*0.125f);
                 charIndex++;
             }
         }
@@ -1414,17 +1414,17 @@ unsigned int Font::getTokenWidth(const char* token, unsigned int length, unsigne
         switch (c)
         {
         case ' ':
-            tokenWidth += size>>1;
+            tokenWidth += (float)size*0.5f;
             break;
         case '\t':
-            tokenWidth += (size>>1)*4;
+            tokenWidth += ((float)size*0.5f)*4;
             break;
         default:
             int glyphIndex = c - 32;
             if (glyphIndex >= 0 && glyphIndex < (int)_glyphCount)
             {
                 Glyph& g = _glyphs[glyphIndex];
-                tokenWidth += g.width * scale + (size>>3);
+                tokenWidth += g.width * scale + ((float)size*0.125f);
             }
             break;
         }
@@ -1467,7 +1467,7 @@ int Font::handleDelimiters(const char** token, const unsigned int size, const in
             delimiter == 0)
     {
         if ((stopAtPosition &&
-            stopAtPosition->x >= *xPos && stopAtPosition->x < *xPos + (size>>1) &&
+            stopAtPosition->x >= *xPos && stopAtPosition->x < floor(*xPos + ((float)size*0.5f)) &&
             stopAtPosition->y >= *yPos && stopAtPosition->y < *yPos + size) ||
             (currentIndex >= 0 && destIndex >= 0 && currentIndex + *lineLength == destIndex))
         {
@@ -1478,7 +1478,7 @@ int Font::handleDelimiters(const char** token, const unsigned int size, const in
         switch (delimiter)
         {
             case ' ':
-                *xPos += size>>1;
+                *xPos += (float)size*0.5f;
                 (*lineLength)++;
                 if (charIndex)
                 {
@@ -1510,7 +1510,7 @@ int Font::handleDelimiters(const char** token, const unsigned int size, const in
                 }
                 break;
             case '\t':
-                *xPos += (size>>1)*4;
+                *xPos += ((float)size*0.5f)*4;
                 (*lineLength)++;
                 if (charIndex)
                 {

+ 9 - 13
gameplay/src/Form.cpp

@@ -308,11 +308,9 @@ namespace gameplay
                 {
                     // Get info about the form's position.
                     Matrix m = node->getMatrix();
-                    Vector2 size = form->getSize();
+                    const Vector2& size = form->getSize();
                     Vector3 min(0, 0, 0);
-                    Vector3 max(size.x, size.y, 0);
                     m.transformPoint(&min);
-                    m.transformPoint(&max);
 
                     // Unproject point into world space.
                     Ray ray;
@@ -323,13 +321,12 @@ namespace gameplay
                     Vector3 normal = node->getForwardVectorWorld();
 
                     // To get the plane's distance from the origin,
-                    // we'll find the distance to the plane defined
-                    // by the quad's upVector and one of its points
-                    // from the plane defined by the same vector
-                    // and the origin.
-                    float a = normal.x; float b = normal.y; float c = normal.z;
-                    float d = -(a*min.x) - (b*min.y) - (c*min.z);
-                    float distance = abs(d) /  sqrt(a*a + b*b + c*c);
+                    // we'll find the distance from the plane defined
+                    // by the quad's forward vector and one of its points
+                    // to the plane defined by the same vector and the origin.
+                    const float& a = normal.x; const float& b = normal.y; const float& c = normal.z;
+                    const float d = -(a*min.x) - (b*min.y) - (c*min.z);
+                    const float distance = abs(d) /  sqrt(a*a + b*b + c*c);
                     Plane plane(normal, distance);
 
                     // Check for collision with plane.
@@ -341,15 +338,14 @@ namespace gameplay
                         // and add that to the ray's origin.
                         Vector3 rayOrigin = ray.getOrigin();
                         Vector3 rayDirection = ray.getDirection();
-
                         float alpha = (distance - normal.dot(rayOrigin)) / normal.dot(rayDirection);
                         Vector3 point = rayOrigin + alpha*rayDirection;
 
-                        // If the resulting point lies within the quad,
-                        // project it into the form's space.
+                        // Project this point into the plane.
                         m.invert();
                         m.transformPoint(&point);
 
+                        // If this point lies within the form, pass the touch event on.
                         if (point.x >= 0 && point.x <= size.x &&
                             point.y >= 0 && point.y <= size.y)
                         {

+ 1 - 1
gameplay/src/Label.cpp

@@ -77,7 +77,7 @@ namespace gameplay
         _viewport.set(pos.x + border.left + padding.left,
                       pos.y + border.top + padding.top,
                       _size.x - border.left - padding.left - border.right - padding.right,
-                      _size.y - border.top - padding.top - border.bottom - padding.bottom - font->getSize());
+                      _size.y - border.top - padding.top - border.bottom - padding.bottom - overlay->getFontSize());
     }
 
     void Label::drawText(const Vector2& position)

+ 4 - 1
gameplay/src/TextBox.cpp

@@ -213,6 +213,9 @@ void TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
                         }
                         break;
                     }
+                    case Keyboard::KEY_RETURN:
+                        // TODO: Handle line-break insertion correctly.
+                        break;
                     default:
                     {
                         // Insert character into string.
@@ -250,7 +253,7 @@ void TextBox::update(const Vector2& position)
     _viewport.set(pos.x + border.left + padding.left,
                   pos.y + border.top + padding.top,
                   _size.x - border.left - padding.left - border.right - padding.right,
-                  _size.y - border.top - padding.top - border.bottom - padding.bottom - font->getSize());
+                  _size.y - border.top - padding.top - border.bottom - padding.bottom - overlay->getFontSize());
 
     // Get index into string and cursor location from the last recorded touch location.
     if (_state == STATE_FOCUS)

+ 1 - 1
gameplay/src/Theme.cpp

@@ -233,7 +233,7 @@ namespace gameplay
                     if (strcmp(innerSpacename, "normal") == 0)
                     {
                         Vector4 textColor(0, 0, 0, 1);
-                        if (space->exists("color"))
+                        if (innerSpace->exists("textColor"))
                         {
                             innerSpace->getColor("textColor", &textColor);
                         }