Kaynağa Gözat

Removing elapsedTime param from Form::update so that scrolling doesn't require an API change.

Adam Blake 13 yıl önce
ebeveyn
işleme
1ee9150c0c

+ 2 - 2
gameplay/src/AbsoluteLayout.cpp

@@ -40,7 +40,7 @@ Layout::Type AbsoluteLayout::getType()
     return Layout::LAYOUT_ABSOLUTE;
 }
 
-void AbsoluteLayout::update(const Container* container, long elapsedTime)
+void AbsoluteLayout::update(const Container* container)
 {
     GP_ASSERT(container);
 
@@ -53,7 +53,7 @@ void AbsoluteLayout::update(const Container* container, long elapsedTime)
         GP_ASSERT(control);
 
         align(control, container);
-        control->update(container->getClip(), Vector2::zero(), elapsedTime);
+        control->update(container->getClip(), Vector2::zero());
     }
 }
 

+ 1 - 1
gameplay/src/AbsoluteLayout.h

@@ -41,7 +41,7 @@ protected:
      *
      * @param container The container to update.
      */
-    void update(const Container* container, long elapsedTime);
+    void update(const Container* container);
 
 private:
     

+ 2 - 2
gameplay/src/CheckBox.cpp

@@ -94,9 +94,9 @@ bool CheckBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int cont
     return Button::touchEvent(evt, x, y, contactIndex);
 }
 
-void CheckBox::update(const Rectangle& clip, const Vector2& offset, long elapsedTime)
+void CheckBox::update(const Rectangle& clip, const Vector2& offset)
 {
-    Label::update(clip, offset, elapsedTime);
+    Label::update(clip, offset);
 
     Vector2 size;
     if (_imageSize.isZero())

+ 1 - 1
gameplay/src/CheckBox.h

@@ -120,7 +120,7 @@ protected:
      *
      * @param clip The clipping rectangle of this control's parent container.
      */
-    void update(const Rectangle& clip, const Vector2& offset, long elapsedTime);
+    void update(const Rectangle& clip, const Vector2& offset);
 
     /**
      * Draw the checkbox icon associated with this control.

+ 12 - 6
gameplay/src/Container.cpp

@@ -280,10 +280,10 @@ Animation* Container::getAnimation(const char* id) const
     return NULL;
 }
 
-void Container::update(const Rectangle& clip, const Vector2& offset, long elapsedTime)
+void Container::update(const Rectangle& clip, const Vector2& offset)
 {
     // Update this container's viewport.
-    Control::update(clip, offset, elapsedTime);
+    Control::update(clip, offset);
 
     // Get scrollbar images and diminish clipping bounds to make room for scrollbars.
     if ((_scrollState & SCROLL_HORIZONTAL) == SCROLL_HORIZONTAL)
@@ -305,10 +305,10 @@ void Container::update(const Rectangle& clip, const Vector2& offset, long elapse
     }
 
     GP_ASSERT(_layout);
-    _layout->update(this, elapsedTime);
+    _layout->update(this);
 
     if (_scrollState != SCROLL_NONE)
-        this->updateScroll(this, elapsedTime);
+        this->updateScroll(this);
 }
 
 void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needsClear, float targetHeight)
@@ -572,10 +572,16 @@ Layout::Type Container::getLayoutType(const char* layoutString)
     }
 }
 
-void Container::updateScroll(const Container* container, long elapsedTime)
+void Container::updateScroll(const Container* container)
 {
     GP_ASSERT(container);
 
+    // Update Time.
+    static long lastFrameTime = Game::getGameTime();
+    long frameTime = Game::getGameTime();
+    long elapsedTime = (frameTime - lastFrameTime);
+    lastFrameTime = frameTime;
+
     const Rectangle& containerBounds = container->getBounds();
     const Theme::Border& containerBorder = container->getBorder(container->getState());
     const Theme::Padding& containerPadding = container->getPadding();
@@ -670,7 +676,7 @@ void Container::updateScroll(const Container* container, long elapsedTime)
     for (unsigned int i = 0; i < controlsCount; i++)
     {
         Control* control = controls.at(i);
-        control->update(container->getClip(), _scrollPosition, elapsedTime);
+        control->update(container->getClip(), _scrollPosition);
     }
 }
 

+ 2 - 2
gameplay/src/Container.h

@@ -170,7 +170,7 @@ protected:
      *
      * @param clip The clipping rectangle of this container's parent container.
      */
-    virtual void update(const Rectangle& clip, const Vector2& offset, long elapsedTime);
+    virtual void update(const Rectangle& clip, const Vector2& offset);
 
     /**
      * Touch callback on touch events.  Controls return true if they consume the touch event.
@@ -225,7 +225,7 @@ protected:
     /**
      * Update scroll position and velocity.
      */
-    void updateScroll(const Container* container, long elapsedTime);
+    void updateScroll(const Container* container);
 
     bool touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
 

+ 1 - 1
gameplay/src/Control.cpp

@@ -708,7 +708,7 @@ void Control::notifyListeners(Listener::EventType eventType)
     }
 }
 
-void Control::update(const Rectangle& clip, const Vector2& offset, long elapsedTime)
+void Control::update(const Rectangle& clip, const Vector2& offset)
 {
     _clearBounds.set(_absoluteClipBounds);
 

+ 1 - 1
gameplay/src/Control.h

@@ -738,7 +738,7 @@ protected:
      * @param clip The clipping rectangle of this control's parent container.
      * @param offset Layout-computed positioning offset to add to the control's position.
      */
-    virtual void update(const Rectangle& clip, const Vector2& offset, long elapsedTime);
+    virtual void update(const Rectangle& clip, const Vector2& offset);
 
     /**
      * Draw the images associated with this control.

+ 2 - 2
gameplay/src/FlowLayout.cpp

@@ -39,7 +39,7 @@ Layout::Type FlowLayout::getType()
     return Layout::LAYOUT_FLOW;
 }
 
-void FlowLayout::update(const Container* container, long elapsedTime)
+void FlowLayout::update(const Container* container)
 {
     GP_ASSERT(container);
     const Rectangle& containerBounds = container->getBounds();
@@ -80,7 +80,7 @@ void FlowLayout::update(const Container* container, long elapsedTime)
         control->setPosition(xPosition, yPosition);
         if (control->isDirty() || control->isContainer())
         {
-            control->update(container->getClip(), Vector2::zero(), elapsedTime);
+            control->update(container->getClip(), Vector2::zero());
         }
 
         xPosition += bounds.width + margin.right;

+ 1 - 1
gameplay/src/FlowLayout.h

@@ -34,7 +34,7 @@ protected:
      *
      * @param container The container to update.
      */
-    void update(const Container* container, long elapsedTime);
+    void update(const Container* container);
 
 private:
 

+ 3 - 3
gameplay/src/Form.cpp

@@ -279,7 +279,7 @@ void Form::setNode(Node* node)
     }
 }
 
-void Form::update(long elapsedTime)
+void Form::update()
 {
     if (isDirty())
     {
@@ -403,10 +403,10 @@ void Form::update(long elapsedTime)
         }
 
         GP_ASSERT(_layout);
-        _layout->update(this, elapsedTime);
+        _layout->update(this);
 
         if (_scrollState != SCROLL_NONE)
-            this->updateScroll(this, elapsedTime);
+            this->updateScroll(this);
     }
 }
 

+ 1 - 1
gameplay/src/Form.h

@@ -135,7 +135,7 @@ public:
     /**
      * Updates each control within this form, and positions them according to its layout.
      */
-    void update(long elapsedTime);
+    void update();
 
     /**
      * Draws this form.

+ 2 - 2
gameplay/src/Label.cpp

@@ -67,9 +67,9 @@ const char* Label::getText()
     return _text.c_str();
 }
 
-void Label::update(const Rectangle& clip, const Vector2& offset, long elapsedTime)
+void Label::update(const Rectangle& clip, const Vector2& offset)
 {
-    Control::update(clip, offset, elapsedTime);
+    Control::update(clip, offset);
 
     _textBounds.set(_viewportBounds);
 

+ 1 - 1
gameplay/src/Label.h

@@ -93,7 +93,7 @@ protected:
      * @param clip The clipping rectangle of this label's parent container.
      * @param offset The scroll offset of this label's parent container.
      */
-    void update(const Rectangle& clip, const Vector2& offset, long elapsedTime);
+    void update(const Rectangle& clip, const Vector2& offset);
 
     /**
      * Draw this label's text.

+ 1 - 1
gameplay/src/Layout.h

@@ -68,7 +68,7 @@ protected:
      *
      * @param container The container to update.
      */
-    virtual void update(const Container* container, long elapsedTime) = 0;
+    virtual void update(const Container* container) = 0;
 
     /**
      * Align a control within a container.

+ 2 - 2
gameplay/src/RadioButton.cpp

@@ -122,9 +122,9 @@ void RadioButton::clearSelected(const std::string& groupId)
     }
 }
 
-void RadioButton::update(const Rectangle& clip, const Vector2& offset, long elapsedTime)
+void RadioButton::update(const Rectangle& clip, const Vector2& offset)
 {
-    Label::update(clip, offset, elapsedTime);
+    Label::update(clip, offset);
 
     Vector2 size;
     if (_imageSize.isZero())

+ 1 - 1
gameplay/src/RadioButton.h

@@ -114,7 +114,7 @@ protected:
      *
      * @param clip The clipping rectangle of this control's parent container.
      */
-    void update(const Rectangle& clip, const Vector2& offset, long elapsedTime);
+    void update(const Rectangle& clip, const Vector2& offset);
 
     /**
      * Draw the images associated with this control.

+ 2 - 2
gameplay/src/Slider.cpp

@@ -141,9 +141,9 @@ bool Slider::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contac
     return Control::touchEvent(evt, x, y, contactIndex);
 }
 
-void Slider::update(const Rectangle& clip, const Vector2& offset, long elapsedTime)
+void Slider::update(const Rectangle& clip, const Vector2& offset)
 {
-    Label::update(clip, offset, elapsedTime);
+    Label::update(clip, offset);
 
     _minImage = getImage("minCap", _state);
     _maxImage = getImage("maxCap", _state);

+ 1 - 1
gameplay/src/Slider.h

@@ -156,7 +156,7 @@ protected:
      * @param clip The clipping rectangle of this slider's parent container.
      * @param offset The scroll offset of this slider's parent container.
      */
-    void update(const Rectangle& clip, const Vector2& offset, long elapsedTime);
+    void update(const Rectangle& clip, const Vector2& offset);
 
     /**
      * The minimum value for the Slider.

+ 2 - 2
gameplay/src/TextBox.cpp

@@ -291,9 +291,9 @@ void TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
     _lastKeypress = key;
 }
 
-void TextBox::update(const Rectangle& clip, const Vector2& offset, long elapsedTime)
+void TextBox::update(const Rectangle& clip, const Vector2& offset)
 {
-    Label::update(clip, offset, elapsedTime);
+    Label::update(clip, offset);
 
     _fontSize = getFontSize(_state);
     _caretImage = getImage("textCaret", _state);

+ 1 - 1
gameplay/src/TextBox.h

@@ -112,7 +112,7 @@ protected:
      *
      * @param clip The clipping rectangle of this control's parent container.
      */
-    void update(const Rectangle& clip, const Vector2& offset, long elapsedTime);
+    void update(const Rectangle& clip, const Vector2& offset);
 
     /**
      * Draw the images associated with this control.

+ 2 - 2
gameplay/src/VerticalLayout.cpp

@@ -43,7 +43,7 @@ Layout::Type VerticalLayout::getType()
     return Layout::LAYOUT_VERTICAL;
 }
 
-void VerticalLayout::update(const Container* container, long elapsedTime)
+void VerticalLayout::update(const Container* container)
 {
     GP_ASSERT(container);
 
@@ -82,7 +82,7 @@ void VerticalLayout::update(const Container* container, long elapsedTime)
         yPosition += margin.top;
 
         control->setPosition(margin.left, yPosition);
-        control->update(container->getClip(), Vector2::zero(), elapsedTime);
+        control->update(container->getClip(), Vector2::zero());
 
         yPosition += bounds.height + margin.bottom;
 

+ 1 - 1
gameplay/src/VerticalLayout.h

@@ -67,7 +67,7 @@ protected:
      *
      * @param container The container to update.
      */
-    void update(const Container* container, long elapsedTime);
+    void update(const Container* container);
 
     /**
      * Flag determining whether this layout will start laying out controls from the bottom of the container.