2
0
Эх сурвалжийг харах

Slider text now appears.
A fix for partial borders.
Starting to implement support for STATE_DISABLED.

Adam Blake 14 жил өмнө
parent
commit
690492a288

+ 32 - 20
gameplay/src/Control.cpp

@@ -84,6 +84,11 @@ namespace gameplay
         _state = STATE_NORMAL;
     }
 
+    bool Control::isEnabled()
+    {
+        return _state == STATE_DISABLED;
+    }
+
     Theme::Style::OverlayType Control::getOverlayType() const
     {
         switch (_state)
@@ -145,26 +150,33 @@ namespace gameplay
             float bottomY = pos.y + _size.y - border.bottom;
 
             // Draw themed border sprites.
-            if (border.left && border.top)
-                spriteBatch->draw(pos.x, pos.y, border.left, border.top, topLeft.u1, topLeft.v1, topLeft.u2, topLeft.v2, borderColor);
-            if (border.top)
-                spriteBatch->draw(pos.x + border.left, pos.y, midWidth, border.top, top.u1, top.v1, top.u2, top.v2, borderColor);
-            if (border.right && border.top)
-                spriteBatch->draw(rightX, pos.y, border.right, border.top, topRight.u1, topRight.v1, topRight.u2, topRight.v2, borderColor);
-            if (border.left)
-                spriteBatch->draw(pos.x, midY, border.left, midHeight, left.u1, left.v1, left.u2, left.v2, borderColor);
-            
-            spriteBatch->draw(pos.x + border.left, pos.y + border.top, _size.x - border.left - border.right, _size.y - border.top - border.bottom,
-                center.u1, center.v1, center.u2, center.v2, borderColor);
-
-            if (border.right)
-                spriteBatch->draw(rightX, midY, border.right, midHeight, right.u1, right.v1, right.u2, right.v2, borderColor);
-            if (border.bottom && border.left)
-                spriteBatch->draw(pos.x, bottomY, border.left, border.bottom, bottomLeft.u1, bottomLeft.v1, bottomLeft.u2, bottomLeft.v2, borderColor);
-            if (border.bottom)
-                spriteBatch->draw(midX, bottomY, midWidth, border.bottom, bottom.u1, bottom.v1, bottom.u2, bottom.v2, borderColor);
-            if (border.bottom && border.right)
-                spriteBatch->draw(rightX, bottomY, border.right, border.bottom, bottomRight.u1, bottomRight.v1, bottomRight.u2, bottomRight.v2, borderColor);
+            if (!border.left && !border.right && !border.top && !border.bottom)
+            {
+                // No border, just draw the image.
+                spriteBatch->draw(pos.x, pos.y, _size.x, _size.y, center.u1, center.v1, center.u2, center.v2, borderColor);
+            }
+            else
+            {
+                if (border.left && border.top)
+                    spriteBatch->draw(pos.x, pos.y, border.left, border.top, topLeft.u1, topLeft.v1, topLeft.u2, topLeft.v2, borderColor);
+                if (border.top)
+                    spriteBatch->draw(pos.x + border.left, pos.y, midWidth, border.top, top.u1, top.v1, top.u2, top.v2, borderColor);
+                if (border.right && border.top)
+                    spriteBatch->draw(rightX, pos.y, border.right, border.top, topRight.u1, topRight.v1, topRight.u2, topRight.v2, borderColor);
+                if (border.left)
+                    spriteBatch->draw(pos.x, midY, border.left, midHeight, left.u1, left.v1, left.u2, left.v2, borderColor);
+                if (border.left && border.right && border.top && border.bottom)
+                    spriteBatch->draw(pos.x + border.left, pos.y + border.top, _size.x - border.left - border.right, _size.y - border.top - border.bottom,
+                        center.u1, center.v1, center.u2, center.v2, borderColor);
+                if (border.right)
+                    spriteBatch->draw(rightX, midY, border.right, midHeight, right.u1, right.v1, right.u2, right.v2, borderColor);
+                if (border.bottom && border.left)
+                    spriteBatch->draw(pos.x, bottomY, border.left, border.bottom, bottomLeft.u1, bottomLeft.v1, bottomLeft.u2, bottomLeft.v2, borderColor);
+                if (border.bottom)
+                    spriteBatch->draw(midX, bottomY, midWidth, border.bottom, bottom.u1, bottom.v1, bottom.u2, bottom.v2, borderColor);
+                if (border.bottom && border.right)
+                    spriteBatch->draw(rightX, bottomY, border.right, border.bottom, bottomRight.u1, bottomRight.v1, bottomRight.u2, bottomRight.v2, borderColor);
+            }
         }
     }
 

+ 1 - 0
gameplay/src/Control.h

@@ -82,6 +82,7 @@ public:
 
     void disable();
     void enable();
+    bool isEnabled();
 
     Theme::Style::OverlayType getOverlayType() const;
 

+ 59 - 56
gameplay/src/Form.cpp

@@ -298,68 +298,71 @@ namespace gameplay
         {
             Form* form = *it;
 
-            Node* node = form->_node;
-            if (node)
+            if (form->isEnabled())
             {
-                Scene* scene = node->getScene();
-                Camera* camera = scene->getActiveCamera();
-
-                if (camera)
+                Node* node = form->_node;
+                if (node)
                 {
-                    // Get info about the form's position.
-                    Matrix m = node->getMatrix();
-                    const Vector2& size = form->getSize();
-                    Vector3 min(0, 0, 0);
-                    m.transformPoint(&min);
-
-                    // Unproject point into world space.
-                    Ray ray;
-                    camera->pickRay(NULL, x, y, &ray);
-
-                    // Find the quad's plane.
-                    // We know its normal is the quad's forward vector.
-                    Vector3 normal = node->getForwardVectorWorld();
-
-                    // To get the plane's distance from the origin,
-                    // 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.
-                    float collisionDistance = ray.intersects(plane);
-                    if (collisionDistance != Ray::INTERSECTS_NONE)
-                    {
-                        // Multiply the ray's direction vector by collision distance
-                        // and add that to the ray's origin.
-                        Vector3 point = ray.getOrigin() + collisionDistance*ray.getDirection();
+                    Scene* scene = node->getScene();
+                    Camera* camera = scene->getActiveCamera();
 
-                        // Project this point into the plane.
-                        m.invert();
-                        m.transformPoint(&point);
-
-                        // Pass the touch event on.
-                        form->touchEvent(evt, point.x, size.y - point.y, contactIndex);
+                    if (camera)
+                    {
+                        // Get info about the form's position.
+                        Matrix m = node->getMatrix();
+                        const Vector2& size = form->getSize();
+                        Vector3 min(0, 0, 0);
+                        m.transformPoint(&min);
+
+                        // Unproject point into world space.
+                        Ray ray;
+                        camera->pickRay(NULL, x, y, &ray);
+
+                        // Find the quad's plane.
+                        // We know its normal is the quad's forward vector.
+                        Vector3 normal = node->getForwardVectorWorld();
+
+                        // To get the plane's distance from the origin,
+                        // 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.
+                        float collisionDistance = ray.intersects(plane);
+                        if (collisionDistance != Ray::INTERSECTS_NONE)
+                        {
+                            // Multiply the ray's direction vector by collision distance
+                            // and add that to the ray's origin.
+                            Vector3 point = ray.getOrigin() + collisionDistance*ray.getDirection();
+
+                            // Project this point into the plane.
+                            m.invert();
+                            m.transformPoint(&point);
+
+                            // Pass the touch event on.
+                            form->touchEvent(evt, point.x, size.y - point.y, contactIndex);
+                        }
                     }
                 }
-            }
-            else
-            {
-                // Simply compare with the form's bounds.
-                const Vector2& size = form->getSize();
-                const Vector2& position = form->getPosition();
-
-                if (form->getState() == Control::STATE_ACTIVE ||
-                    (x >= position.x &&
-                     x <= position.x + size.x &&
-                     y >= position.y &&
-                     y <= position.y + size.y))
+                else
                 {
-                    // Pass on the event's position relative to the form.
-                    form->touchEvent(evt, x - position.x, y - position.y, contactIndex);
+                    // Simply compare with the form's bounds.
+                    const Vector2& size = form->getSize();
+                    const Vector2& position = form->getPosition();
+
+                    if (form->getState() == Control::STATE_ACTIVE ||
+                        (x >= position.x &&
+                         x <= position.x + size.x &&
+                         y >= position.y &&
+                         y <= position.y + size.y))
+                    {
+                        // Pass on the event's position relative to the form.
+                        form->touchEvent(evt, x - position.x, y - position.y, contactIndex);
+                    }
                 }
             }
         }

+ 0 - 5
gameplay/src/Slider.cpp

@@ -161,9 +161,4 @@ void Slider::drawSprites(SpriteBatch* spriteBatch, const Vector2& position)
     }
 }
 
-void Slider::drawText(const Vector2& position)
-{
-
-}
-
 }

+ 0 - 1
gameplay/src/Slider.h

@@ -20,7 +20,6 @@ public:
     void touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
 
     void drawSprites(SpriteBatch* spriteBatch, const Vector2& position);
-    void drawText(const Vector2& position);
 
     void setValue(float value);
     float getValue();