소스 검색

Clearing alpha channel of a Form's framebuffer to 0.
Tweaking the particle editor theme to go with the alpha change.
Fixing Sean's fix of warnings in Font.
Supporting alignment and positioning of Forms.
Adding an important null-check in Theme.

Adam Blake 13 년 전
부모
커밋
b06b8e30be
6개의 변경된 파일131개의 추가작업 그리고 9개의 파일을 삭제
  1. 1 1
      gameplay/src/Container.cpp
  2. 2 2
      gameplay/src/Control.cpp
  3. 3 3
      gameplay/src/Font.cpp
  4. 122 2
      gameplay/src/Form.cpp
  5. 1 0
      gameplay/src/Layout.h
  6. 2 1
      gameplay/src/Theme.cpp

+ 1 - 1
gameplay/src/Container.cpp

@@ -264,7 +264,7 @@ void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needs
     if (_skin && needsClear)
     if (_skin && needsClear)
     {
     {
         GL_ASSERT( glEnable(GL_SCISSOR_TEST) );
         GL_ASSERT( glEnable(GL_SCISSOR_TEST) );
-        GL_ASSERT( glClearColor(0, 0, 0, 1) );
+        GL_ASSERT( glClearColor(0, 0, 0, 0) );
         float clearY = targetHeight - _clearBounds.y - _clearBounds.height;
         float clearY = targetHeight - _clearBounds.y - _clearBounds.height;
         GL_ASSERT( glScissor(_clearBounds.x, clearY,
         GL_ASSERT( glScissor(_clearBounds.x, clearY,
             _clearBounds.width, _clearBounds.height) );
             _clearBounds.width, _clearBounds.height) );

+ 2 - 2
gameplay/src/Control.cpp

@@ -7,7 +7,7 @@ namespace gameplay
 
 
 Control::Control()
 Control::Control()
     : _id(""), _state(Control::NORMAL), _bounds(Rectangle::empty()), _clipBounds(Rectangle::empty()), _viewportClipBounds(Rectangle::empty()),
     : _id(""), _state(Control::NORMAL), _bounds(Rectangle::empty()), _clipBounds(Rectangle::empty()), _viewportClipBounds(Rectangle::empty()),
-        _dirty(true), _consumeTouchEvents(true), _listeners(NULL), _styleOverridden(false)
+    _dirty(true), _consumeTouchEvents(true), _listeners(NULL), _styleOverridden(false), _skin(NULL), _clearBounds(Rectangle::empty())
 {
 {
 }
 }
 
 
@@ -881,7 +881,7 @@ void Control::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needsCl
     if (needsClear)
     if (needsClear)
     {
     {
         GL_ASSERT( glEnable(GL_SCISSOR_TEST) );
         GL_ASSERT( glEnable(GL_SCISSOR_TEST) );
-        GL_ASSERT( glClearColor(0, 0, 0, 1) );
+        GL_ASSERT( glClearColor(0, 0, 0, 0) );
         GL_ASSERT( glScissor(_clearBounds.x, targetHeight - _clearBounds.y - _clearBounds.height,
         GL_ASSERT( glScissor(_clearBounds.x, targetHeight - _clearBounds.y - _clearBounds.height,
             _clearBounds.width, _clearBounds.height) );
             _clearBounds.width, _clearBounds.height) );
         GL_ASSERT( glClear(GL_COLOR_BUFFER_BIT) );
         GL_ASSERT( glClear(GL_COLOR_BUFFER_BIT) );

+ 3 - 3
gameplay/src/Font.cpp

@@ -302,9 +302,9 @@ Font::Text* Font::createText(const char* text, const Rectangle& area, const Vect
                         {
                         {
                             // Simply copy values directly into the start of the index array
                             // Simply copy values directly into the start of the index array
                             batch->_indices[batch->_vertexCount] = batch->_vertexCount;
                             batch->_indices[batch->_vertexCount] = batch->_vertexCount;
-                            batch->_indices[batch->_vertexCount] = batch->_vertexCount + 1;
-                            batch->_indices[batch->_vertexCount] = batch->_vertexCount + 2;
-                            batch->_indices[batch->_vertexCount] = batch->_vertexCount + 3;
+                            batch->_indices[batch->_vertexCount + 1] = batch->_vertexCount + 1;
+                            batch->_indices[batch->_vertexCount + 2] = batch->_vertexCount + 2;
+                            batch->_indices[batch->_vertexCount + 3] = batch->_vertexCount + 3;
                             batch->_vertexCount += 4;
                             batch->_vertexCount += 4;
                             batch->_indexCount += 4;
                             batch->_indexCount += 4;
                         }
                         }

+ 122 - 2
gameplay/src/Form.cpp

@@ -93,6 +93,25 @@ Form* Form::create(const char* url)
     const char* styleName = formProperties->getString("style");
     const char* styleName = formProperties->getString("style");
     form->initialize(theme->getStyle(styleName), formProperties);
     form->initialize(theme->getStyle(styleName), formProperties);
 
 
+    // Alignment
+    if ((form->_alignment & Control::ALIGN_BOTTOM) == Control::ALIGN_BOTTOM)
+    {
+        form->_bounds.y = Game::getInstance()->getHeight() - form->_bounds.height;
+    }
+    else if ((form->_alignment & Control::ALIGN_VCENTER) == Control::ALIGN_VCENTER)
+    {
+        form->_bounds.y = Game::getInstance()->getHeight() * 0.5f - form->_bounds.height * 0.5f;
+    }
+
+    if ((form->_alignment & Control::ALIGN_RIGHT) == Control::ALIGN_RIGHT)
+    {
+        form->_bounds.x = Game::getInstance()->getWidth() - form->_bounds.width;
+    }
+    else if ((form->_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
+    {
+        form->_bounds.x = Game::getInstance()->getWidth() * 0.5f - form->_bounds.width * 0.5f;
+    }
+
     // Add all the controls to the form.
     // Add all the controls to the form.
     form->addControls(theme, formProperties);
     form->addControls(theme, formProperties);
 
 
@@ -266,7 +285,108 @@ void Form::update()
 {
 {
     if (isDirty())
     if (isDirty())
     {
     {
-        Container::update(Rectangle(0, 0, _bounds.width, _bounds.height), Vector2::zero());
+        _clearBounds.set(_absoluteClipBounds);
+
+        // Calculate the clipped bounds.
+        float x = 0;
+        float y = 0;
+        float width = _bounds.width;
+        float height = _bounds.height;
+
+        Rectangle clip(0, 0, _bounds.width, _bounds.height);
+
+        float clipX2 = clip.x + clip.width;
+        float x2 = clip.x + x + width;
+        if (x2 > clipX2)
+            width -= x2 - clipX2;
+
+        float clipY2 = clip.y + clip.height;
+        float y2 = clip.y + y + height;
+        if (y2 > clipY2)
+            height -= y2 - clipY2;
+
+        if (x < 0)
+        {
+            width += x;
+            x = -x;
+        }
+        else
+        {
+            x = 0;
+        }
+
+        if (y < 0)
+        {
+            height += y;
+            y = -y;
+        }
+        else
+        {
+            y = 0;
+        }
+
+        _clipBounds.set(x, y, width, height);
+
+        // Calculate the absolute bounds.
+        x = 0;
+        y = 0;
+        _absoluteBounds.set(x, y, _bounds.width, _bounds.height);
+
+        // Calculate the absolute viewport bounds.
+        // Absolute bounds minus border and padding.
+        const Theme::Border& border = getBorder(_state);
+        const Theme::Padding& padding = getPadding();
+
+        x += border.left + padding.left;
+        y += border.top + padding.top;
+        width = _bounds.width - border.left - padding.left - border.right - padding.right;
+        height = _bounds.height - border.top - padding.top - border.bottom - padding.bottom;
+
+        _viewportBounds.set(x, y, width, height);
+
+        // Calculate the clip area.
+        // Absolute bounds, minus border and padding,
+        // clipped to the parent container's clip area.
+        clipX2 = clip.x + clip.width;
+        x2 = x + width;
+        if (x2 > clipX2)
+            width = clipX2 - x;
+
+        clipY2 = clip.y + clip.height;
+        y2 = y + height;
+        if (y2 > clipY2)
+            height = clipY2 - y;
+
+        if (x < clip.x)
+        {
+            float dx = clip.x - x;
+            width -= dx;
+            x = clip.x;
+        }
+
+        if (y < clip.y)
+        {
+            float dy = clip.y - y;
+            height -= dy;
+            y = clip.y;
+        }
+ 
+        _viewportClipBounds.set(x, y, width, height);
+
+        _absoluteClipBounds.set(x - border.left - padding.left, y - border.top - padding.top,
+            width + border.left + padding.left + border.right + padding.right,
+            height + border.top + padding.top + border.bottom + padding.bottom);
+        if (_clearBounds.isEmpty())
+        {
+            _clearBounds.set(_absoluteClipBounds);
+        }
+
+        // Cache themed attributes for performance.
+        _skin = getSkin(_state);
+        _opacity = getOpacity(_state);
+
+        GP_ASSERT(_layout);
+        _layout->update(this);
     }
     }
 }
 }
 
 
@@ -293,7 +413,7 @@ void Form::draw()
 
 
         Game* game = Game::getInstance();
         Game* game = Game::getInstance();
         Rectangle prevViewport = game->getViewport();
         Rectangle prevViewport = game->getViewport();
-        game->setViewport(Rectangle(_bounds.x, _bounds.y, _bounds.width, _bounds.height));
+        game->setViewport(Rectangle(0, 0, _bounds.width, _bounds.height));
 
 
         GP_ASSERT(_theme);
         GP_ASSERT(_theme);
         _theme->setProjectionMatrix(_projectionMatrix);
         _theme->setProjectionMatrix(_projectionMatrix);

+ 1 - 0
gameplay/src/Layout.h

@@ -19,6 +19,7 @@ class Control;
 class Layout : public Ref
 class Layout : public Ref
 {
 {
     friend class Container;
     friend class Container;
+    friend class Form;
 
 
 public:
 public:
     /**
     /**

+ 2 - 1
gameplay/src/Theme.cpp

@@ -271,7 +271,8 @@ Theme* Theme::create(const char* url)
                     if (!font)
                     if (!font)
                     {
                     {
                         font = normal->getFont();
                         font = normal->getFont();
-                        font->addRef();
+                        if (font)
+                            font->addRef();
                     }
                     }
 
 
                     unsigned int fontSize;
                     unsigned int fontSize;