Browse Source

Merge pull request #1741 from jwatte/next

These are all the changes I want to commit in one merge
Sean Taylor 10 years ago
parent
commit
91759d39ce

+ 4 - 4
gameplay/src/AnimationClip.cpp

@@ -588,7 +588,7 @@ bool AnimationClip::update(float elapsedTime)
 
 void AnimationClip::onBegin()
 {
-    addRef();
+    this->addRef();
 
     // Initialize animation to play.
     setClipStateBit(CLIP_IS_STARTED_BIT);
@@ -622,12 +622,12 @@ void AnimationClip::onBegin()
     // Fire script begin event
     fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(AnimationClip, clipBegin), this);
 
-    release();
+    this->release();
 }
 
 void AnimationClip::onEnd()
 {
-    addRef();
+    this->addRef();
 
     _blendWeight = 1.0f;
     resetClipStateBit(CLIP_ALL_BITS);
@@ -647,7 +647,7 @@ void AnimationClip::onEnd()
     // Fire script end event
     fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(AnimationClip, clipEnd), this);
 
-    release();
+    this->release();
 }
 
 bool AnimationClip::isClipStateBitSet(unsigned char bit) const

+ 1 - 0
gameplay/src/Container.cpp

@@ -67,6 +67,7 @@ Container::~Container()
     std::vector<Control*>::iterator it;
     for (it = _controls.begin(); it < _controls.end(); it++)
     {
+        (*it)->_parent = nullptr;
         SAFE_RELEASE((*it));
     }
     SAFE_RELEASE(_layout);

+ 7 - 2
gameplay/src/Control.cpp

@@ -973,6 +973,11 @@ void Control::addListener(Control::Listener* listener, int eventFlags)
     {
         addSpecificListener(listener, Control::Listener::TEXT_CHANGED);
     }
+
+    if ((eventFlags & Control::Listener::ACTIVATED) == Control::Listener::ACTIVATED)
+    {
+        addSpecificListener(listener, Control::Listener::ACTIVATED);
+    }
 }
 
 void Control::removeListener(Control::Listener* listener)
@@ -1055,7 +1060,7 @@ void Control::notifyListeners(Control::Listener::EventType eventType)
     // This method runs untrusted code by notifying listeners of events.
     // If the user calls exit() or otherwise releases this control, we
     // need to keep it alive until the method returns.
-    addRef();
+    this->addRef();
 
     controlEvent(eventType);
 
@@ -1075,7 +1080,7 @@ void Control::notifyListeners(Control::Listener::EventType eventType)
 
     fireScriptEvent<void>(GP_GET_SCRIPT_EVENT(Control, controlEvent), dynamic_cast<void*>(this), eventType);
 
-    release();
+    this->release();
 }
 
 void Control::controlEvent(Control::Listener::EventType evt)

+ 5 - 0
gameplay/src/Control.h

@@ -169,6 +169,11 @@ public:
              */
             RIGHT_CLICK     = 0x40,
 
+            /**
+             * Event triggered when a control is activated in another manner (such as pressing enter in text control)
+             */
+            ACTIVATED       = 0x80,
+
             /**
              * Event triggered when a control gains focus.
              */

+ 3 - 1
gameplay/src/Font.cpp

@@ -1371,9 +1371,11 @@ int Font::getIndexOrLocation(const char* text, const Rectangle& area, unsigned i
                 }
 
                 // 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 ||
                     (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))
                 {
                     outLocation->x = xPos;

+ 1 - 1
gameplay/src/Label.h

@@ -47,7 +47,7 @@ public:
      *
      * @param text The text to display.
      */
-    void setText(const char* text);
+    virtual void setText(const char* text);
 
     /**
      * Get the text displayed by this label.

+ 2 - 0
gameplay/src/Ref.cpp

@@ -32,11 +32,13 @@ Ref::~Ref()
 
 void Ref::addRef()
 {
+    GP_ASSERT(_refCount > 0 && _refCount < 1000000);
     ++_refCount;
 }
 
 void Ref::release()
 {
+    GP_ASSERT(_refCount > 0 && _refCount < 1000000);
     if ((--_refCount) <= 0)
     {
 #ifdef GP_USE_MEM_LEAK_DETECTION

+ 17 - 0
gameplay/src/TextBox.cpp

@@ -257,6 +257,7 @@ bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
             {
                 case Keyboard::KEY_RETURN:
                     // TODO: Support multi-line
+                    notifyListeners(Control::Listener::ACTIVATED);
                     break;
                 case Keyboard::KEY_ESCAPE:
                     break;
@@ -394,6 +395,16 @@ unsigned int TextBox::drawText(Form* form, const Rectangle& clip)
     return 0;
 }
 
+void TextBox::setText(char const *text)
+{
+    Label::setText(text);
+    if (_caretLocation > _text.length())
+    {
+        _caretLocation = _text.length();
+    }
+    notifyListeners(Control::Listener::TEXT_CHANGED);
+}
+
 void TextBox::setCaretLocation(int x, int y)
 {
     Control::State state = getState();
@@ -450,7 +461,13 @@ void TextBox::setCaretLocation(int x, int y)
     }
 
     if (index != -1)
+    {
         _caretLocation = index;
+    }
+    else
+    {
+        _caretLocation = _text.length();
+    }
 }
 
 void TextBox::getCaretLocation(Vector2* p)

+ 5 - 0
gameplay/src/TextBox.h

@@ -112,6 +112,11 @@ public:
 
     virtual void addListener(Control::Listener* listener, int eventFlags);
 
+    /**
+     * Update the text being edited.
+     */
+    void setText(char const *text) override;
+
 protected:
 
     /**

+ 1 - 0
gameplay/src/Theme.cpp

@@ -73,6 +73,7 @@ Theme* Theme::getDefault()
         if (!__defaultTheme)
         {
             // Create an empty theme so that UI's with no theme don't just crash
+            GP_WARN("Creating default (empty) UI Theme.");
             __defaultTheme = new Theme();
             unsigned int color = 0x00000000;
             __defaultTheme->_texture = Texture::create(Texture::RGBA, 1, 1, (unsigned char*)&color, false);

+ 7 - 23
gameplay/src/Transform.cpp

@@ -99,43 +99,27 @@ const char* Transform::getTypeName() const
 
 const Matrix& Transform::getMatrix() const
 {
-    if (_matrixDirtyBits)
+    if (_matrixDirtyBits & (DIRTY_TRANSLATION | DIRTY_ROTATION | DIRTY_SCALE))
     {
         if (!isStatic())
         {
-            bool hasTranslation = !_translation.isZero();
             bool hasScale = !_scale.isOne();
             bool hasRotation = !_rotation.isIdentity();
 
             // Compose the matrix in TRS order since we use column-major matrices with column vectors and
             // multiply M*v (as opposed to XNA and DirectX that use row-major matrices with row vectors and multiply v*M).
-            if (hasTranslation || (_matrixDirtyBits & DIRTY_TRANSLATION) == DIRTY_TRANSLATION)
+            Matrix::createTranslation(_translation, &_matrix);
+            if (hasRotation)
             {
-                Matrix::createTranslation(_translation, &_matrix);
-                if (hasRotation || (_matrixDirtyBits & DIRTY_ROTATION) == DIRTY_ROTATION)
-                {
-                    _matrix.rotate(_rotation);
-                }
-                if (hasScale || (_matrixDirtyBits & DIRTY_SCALE) == DIRTY_SCALE)
-                {
-                    _matrix.scale(_scale);
-                }
+                _matrix.rotate(_rotation);
             }
-            else if (hasRotation || (_matrixDirtyBits & DIRTY_ROTATION) == DIRTY_ROTATION)
+            if (hasScale)
             {
-                Matrix::createRotation(_rotation, &_matrix);
-                if (hasScale || (_matrixDirtyBits & DIRTY_SCALE) == DIRTY_SCALE)
-                {
-                    _matrix.scale(_scale);
-                }
-            }
-            else if (hasScale || (_matrixDirtyBits & DIRTY_SCALE) == DIRTY_SCALE)
-            {
-                Matrix::createScale(_scale, &_matrix);
+                _matrix.scale(_scale);
             }
         }
 
-        _matrixDirtyBits &= ~DIRTY_TRANSLATION & ~DIRTY_ROTATION & ~DIRTY_SCALE;
+        _matrixDirtyBits &= ~(DIRTY_TRANSLATION | DIRTY_ROTATION | DIRTY_SCALE);
     }
 
     return _matrix;

+ 4 - 0
tools/encoder/src/EncoderArguments.cpp

@@ -387,6 +387,10 @@ EncoderArguments::FileFormat EncoderArguments::getFileFormat() const
     {
         return FILEFORMAT_TTF;
     }
+    if (ext.compare("otf") == 0)
+    {
+        return FILEFORMAT_OTF;
+    }
     if (ext.compare("gpb") == 0)
     {
         return FILEFORMAT_GPB;

+ 1 - 0
tools/encoder/src/EncoderArguments.h

@@ -21,6 +21,7 @@ public:
         FILEFORMAT_FBX,
         FILEFORMAT_TMX,
         FILEFORMAT_TTF,
+        FILEFORMAT_OTF,
         FILEFORMAT_GPB,
         FILEFORMAT_PNG,
         FILEFORMAT_RAW

+ 1 - 0
tools/encoder/src/main.cpp

@@ -114,6 +114,7 @@ int main(int argc, const char** argv)
             break;
         }
     case EncoderArguments::FILEFORMAT_TTF:
+    case EncoderArguments::FILEFORMAT_OTF:
         {
             std::vector<unsigned int> fontSizes = arguments.getFontSizes();