Browse Source

Getting CheckBox and TextBox to work on QNX. Fixing Ray.intersects(Plane).

Adam Blake 14 years ago
parent
commit
25e1b0abd7

+ 3 - 2
gameplay/src/CheckBox.cpp

@@ -6,7 +6,7 @@ namespace gameplay
 
 static std::vector<CheckBox*> __checkBoxes;
 
-CheckBox::CheckBox()
+CheckBox::CheckBox() : _checked(false)
 {
 }
 
@@ -27,6 +27,7 @@ CheckBox* CheckBox::create(Theme::Style* style, Properties* properties)
     checkbox->_id = properties->getId();
     properties->getVector2("position", &checkbox->_position);
     properties->getVector2("size", &checkbox->_size);
+    checkbox->_checked = properties->getBool("checked");
     checkbox->_text = properties->getString("text");
 
     __checkBoxes.push_back(checkbox);
@@ -141,4 +142,4 @@ void CheckBox::drawText(const Vector2& position)
     _dirty = false;
 }
 
-}
+}

+ 5 - 13
gameplay/src/Form.cpp

@@ -330,27 +330,19 @@ namespace gameplay
                     Plane plane(normal, distance);
 
                     // Check for collision with plane.
-                    float collides = ray.intersects(plane);
-                    if (collides != Ray::INTERSECTS_NONE)
+                    float collisionDistance = ray.intersects(plane);
+                    if (collisionDistance != Ray::INTERSECTS_NONE)
                     {
-                        // Check for collision with form.
                         // Multiply the ray's direction vector by collision distance
                         // 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;
+                        Vector3 point = ray.getOrigin() + collisionDistance*ray.getDirection();
 
                         // 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)
-                        {
-                            form->touchEvent(evt, point.x, size.y - point.y, contactIndex);
-                        }
+                        // Pass the touch event on.
+                        form->touchEvent(evt, point.x, size.y - point.y, contactIndex);
                     }
                 }
             }

+ 2 - 2
gameplay/src/PlatformQNX.cpp

@@ -940,12 +940,12 @@ int Platform::enterMessagePump()
                         // Suppress key repeats
                         if ((flags & KEY_REPEAT) == 0)
                         {
-                            Game::getInstance()->keyEvent(evt, getKey(value));
+                            keyEventInternal(evt, getKey(value));
                             if (evt == gameplay::Keyboard::KEY_PRESS && flags & KEY_SYM_VALID)
                             {
                                 int unicode = getUnicode(value);
                                 if (unicode)
-                                    Game::getInstance()->keyEvent(gameplay::Keyboard::KEY_CHAR, unicode);
+                                    keyEventInternal(gameplay::Keyboard::KEY_CHAR, unicode);
                             }
                         }
                         break;

+ 4 - 4
gameplay/src/Ray.cpp

@@ -107,8 +107,8 @@ float Ray::intersects(const Plane& plane) const
 {
     const Vector3& normal = plane.getNormal();
     // If the origin of the ray is on the plane then the distance is zero.
-    float m = (normal.dot(_origin) + plane.getDistance());
-    if (fabs(m) < MATH_EPSILON)
+    float alpha = plane.getDistance() - normal.dot(_origin);
+    if (fabs(alpha) < MATH_EPSILON)
     {
         return 0.0f;
     }
@@ -124,8 +124,8 @@ float Ray::intersects(const Plane& plane) const
     
     // Calculate the distance along the ray's direction vector to the point where
     // the ray intersects the plane (if it is negative the plane is behind the ray).
-    float d = -m / dot;
-    if ( d < 0.0f )
+    float d = alpha / dot;
+    if (d < 0.0f)
     {
         return INTERSECTS_NONE;
     }

+ 4 - 5
gameplay/src/Slider.h

@@ -13,10 +13,6 @@ namespace gameplay
 class Slider : public Button
 {
 public:
-
-    Slider();
-    ~Slider();
-
     static Slider* create(Theme::Style* style, Properties* properties);
     static Slider* create(const char* id, float min, float max, float defaultPosition = 0.0f, float step = 1.0f);
     static Slider* getSlider(const char* id);
@@ -29,8 +25,11 @@ public:
     void setValue(float value);
     float getValue();
 
-private:
+protected:
+    Slider();
+    ~Slider();
 
+private:
     float _min;
     float _max;
     float _step;

+ 3 - 0
gameplay/src/TextBox.cpp

@@ -1,4 +1,5 @@
 #include "TextBox.h"
+#include "Game.h"
 
 namespace gameplay
 {
@@ -70,6 +71,7 @@ void TextBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int conta
             if (_state == STATE_NORMAL)
             {
                 _state = STATE_ACTIVE;
+                Game::getInstance()->displayKeyboard(true);
             }
             break;
         case Touch::TOUCH_MOVE:
@@ -92,6 +94,7 @@ void TextBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int conta
             else
             {
                 _state = STATE_NORMAL;
+                Game::getInstance()->displayKeyboard(false);
             }
             break;
         }