소스 검색

Clearing a form's FBO on creation / resize.
Adding zOrder to controls.

Adam Blake 13 년 전
부모
커밋
8e27bfa0f5
5개의 변경된 파일46개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      gameplay/src/Container.cpp
  2. 3 0
      gameplay/src/Container.h
  3. 15 0
      gameplay/src/Control.cpp
  4. 6 0
      gameplay/src/Control.h
  5. 12 0
      gameplay/src/Form.cpp

+ 10 - 0
gameplay/src/Container.cpp

@@ -304,6 +304,8 @@ void Container::update(const Rectangle& clip, const Vector2& offset)
         _viewportClipBounds.width -= _scrollBarVertical->getRegion().width;
     }
 
+    std::sort(_controls.begin(), _controls.end(), &sortControlsByZOrder);
+
     GP_ASSERT(_layout);
     _layout->update(this);
 
@@ -795,4 +797,12 @@ Container::ScrollState Container::getScrollState(const char* scrollState)
     return Container::SCROLL_NONE;
 }
 
+bool sortControlsByZOrder(Control* c1, Control* c2)
+{
+    if (c1->getZOrder() < c2->getZOrder())
+        return true;
+
+    return false;
+}
+
 }

+ 3 - 0
gameplay/src/Container.h

@@ -306,6 +306,9 @@ private:
     Container(const Container& copy);
 };
 
+// Sort funtion for use with _controls.sort(), based on Z-Order.
+bool sortControlsByZOrder(Control* c1, Control* c2);
+
 }
 
 #endif

+ 15 - 0
gameplay/src/Control.cpp

@@ -42,6 +42,7 @@ void Control::initialize(Theme::Style* style, Properties* properties)
     _alignment = getAlignment(properties->getString("alignment"));
     _autoWidth = properties->getBool("autoWidth");
     _autoHeight = properties->getBool("autoHeight");
+    _zOrder = properties->getInt("zOrder");
 
     Vector2 position;
     Vector2 size;
@@ -608,6 +609,20 @@ bool Control::getConsumeTouchEvents()
     return _consumeTouchEvents;
 }
 
+int Control::getZOrder() const
+{
+    return _zOrder;
+}
+
+void Control::setZOrder(int zOrder)
+{
+    if (zOrder != _zOrder)
+    {
+        _zOrder = zOrder;
+        _dirty = true;
+    }
+}
+
 void Control::addListener(Control::Listener* listener, int eventFlags)
 {
     GP_ASSERT(listener);

+ 6 - 0
gameplay/src/Control.h

@@ -659,6 +659,10 @@ public:
      */
     Theme::Style* getStyle() const;
 
+    int getZOrder() const;
+
+    void setZOrder(int zOrder);
+
     /**
      * Add a listener to be notified of specific events affecting
      * this control.  Event types can be OR'ed together.
@@ -889,6 +893,8 @@ protected:
      */
     float _opacity;
 
+    int _zOrder;
+
 private:
 
     /*

+ 12 - 0
gameplay/src/Form.cpp

@@ -191,6 +191,18 @@ void Form::setSize(float width, float height)
         _spriteBatch = SpriteBatch::create(_frameBuffer->getRenderTarget()->getTexture());
         GP_ASSERT(_spriteBatch);
 
+        // Clear FBO.
+        _frameBuffer->bind();
+        Game* game = Game::getInstance();
+        Rectangle prevViewport = game->getViewport();
+        game->setViewport(Rectangle(0, 0, width, height));
+        _theme->setProjectionMatrix(_projectionMatrix);
+        GL_ASSERT( glClearColor(0, 0, 0, 0) );
+        GL_ASSERT( glClear(GL_COLOR_BUFFER_BIT) );
+        GL_ASSERT( glClearColor(0, 0, 0, 1) );
+        _theme->setProjectionMatrix(_defaultProjectionMatrix);
+        FrameBuffer::bindDefault();
+
         _bounds.width = width;
         _bounds.height = height;
         _dirty = true;