Quellcode durchsuchen

Alignment of controls within their parent containers.
Renamed 'alignment' within a style to 'textAlignment'.
Auto-sizing forms to the size of the screen.
Auto-sizing controls to fit in their parent container.
Control::set/getAlignment
Control::set/getAutoWidth/Height
Fix for additive blending in ParticleEmitter.cpp (now additive with alpha)
Added splash screen to particles sample.
Added ability to edit start and end colors to particles sample.

Adam Blake vor 13 Jahren
Ursprung
Commit
0b2e47a385

+ 7 - 7
gameplay.sln

@@ -25,7 +25,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample03-character", "gamep
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gameplay-encoder", "gameplay-encoder\gameplay-encoder.vcxproj", "{9D69B743-4872-4DD1-8E30-0087C64298D7}"
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample04-particles", "gameplay-samples\sample04-particles\sample04-particles.vcxproj", "{F47B5740-3C0C-BACE-4C2B-EE23A358D499}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample04-particles", "gameplay-samples\sample04-particles\sample04-particles.vcxproj", "{BB38678F-2614-C502-956C-0FFD84566556}"
 	ProjectSection(ProjectDependencies) = postProject
 		{1032BA4B-57EB-4348-9E03-29DD63E80E4A} = {1032BA4B-57EB-4348-9E03-29DD63E80E4A}
 	EndProjectSection
@@ -73,12 +73,12 @@ Global
 		{9D69B743-4872-4DD1-8E30-0087C64298D7}.DebugMem|Win32.Build.0 = Debug|Win32
 		{9D69B743-4872-4DD1-8E30-0087C64298D7}.Release|Win32.ActiveCfg = Release|Win32
 		{9D69B743-4872-4DD1-8E30-0087C64298D7}.Release|Win32.Build.0 = Release|Win32
-		{F47B5740-3C0C-BACE-4C2B-EE23A358D499}.Debug|Win32.ActiveCfg = Debug|Win32
-		{F47B5740-3C0C-BACE-4C2B-EE23A358D499}.Debug|Win32.Build.0 = Debug|Win32
-		{F47B5740-3C0C-BACE-4C2B-EE23A358D499}.DebugMem|Win32.ActiveCfg = DebugMem|Win32
-		{F47B5740-3C0C-BACE-4C2B-EE23A358D499}.DebugMem|Win32.Build.0 = DebugMem|Win32
-		{F47B5740-3C0C-BACE-4C2B-EE23A358D499}.Release|Win32.ActiveCfg = Release|Win32
-		{F47B5740-3C0C-BACE-4C2B-EE23A358D499}.Release|Win32.Build.0 = Release|Win32
+		{BB38678F-2614-C502-956C-0FFD84566556}.Debug|Win32.ActiveCfg = Debug|Win32
+		{BB38678F-2614-C502-956C-0FFD84566556}.Debug|Win32.Build.0 = Debug|Win32
+		{BB38678F-2614-C502-956C-0FFD84566556}.DebugMem|Win32.ActiveCfg = DebugMem|Win32
+		{BB38678F-2614-C502-956C-0FFD84566556}.DebugMem|Win32.Build.0 = DebugMem|Win32
+		{BB38678F-2614-C502-956C-0FFD84566556}.Release|Win32.ActiveCfg = Release|Win32
+		{BB38678F-2614-C502-956C-0FFD84566556}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 1 - 1
gameplay/android/jni/Android.mk

@@ -16,7 +16,7 @@ LOCAL_PATH := $(call my-dir)/../../src
 
 include $(CLEAR_VARS)
 LOCAL_MODULE    := libgameplay
-LOCAL_SRC_FILES := AbsoluteLayout.cpp Animation.cpp AnimationClip.cpp AnimationController.cpp AnimationTarget.cpp AnimationValue.cpp AudioBuffer.cpp AudioController.cpp AudioListener.cpp AudioSource.cpp BoundingBox.cpp BoundingSphere.cpp Button.cpp Camera.cpp CheckBox.cpp Container.cpp Control.cpp Curve.cpp DebugNew.cpp DepthStencilTarget.cpp Effect.cpp FileSystem.cpp Font.cpp Form.cpp FrameBuffer.cpp Frustum.cpp Game.cpp gameplay-main-android.cpp gameplay-main-qnx.cpp gameplay-main-win32.cpp Image.cpp Joint.cpp Label.cpp Light.cpp Material.cpp MaterialParameter.cpp Matrix.cpp Mesh.cpp MeshBatch.cpp MeshPart.cpp MeshSkin.cpp Model.cpp Node.cpp Package.cpp ParticleEmitter.cpp Pass.cpp PhysicsCharacter.cpp PhysicsCollisionObject.cpp PhysicsCollisionShape.cpp PhysicsConstraint.cpp PhysicsController.cpp PhysicsFixedConstraint.cpp PhysicsGenericConstraint.cpp PhysicsGhostObject.cpp PhysicsHingeConstraint.cpp PhysicsMotionState.cpp PhysicsRigidBody.cpp PhysicsSocketConstraint.cpp PhysicsSpringConstraint.cpp Plane.cpp PlatformAndroid.cpp PlatformQNX.cpp PlatformWin32.cpp Properties.cpp Quaternion.cpp RadioButton.cpp Ray.cpp Rectangle.cpp Ref.cpp RenderState.cpp RenderTarget.cpp Scene.cpp SceneLoader.cpp Slider.cpp SpriteBatch.cpp Technique.cpp TextBox.cpp Texture.cpp Theme.cpp ThemeStyle.cpp Transform.cpp Vector2.cpp Vector3.cpp Vector4.cpp VertexAttributeBinding.cpp VertexFormat.cpp VerticalLayout.cpp
+LOCAL_SRC_FILES := AbsoluteLayout.cpp Animation.cpp AnimationClip.cpp AnimationController.cpp AnimationTarget.cpp AnimationValue.cpp AudioBuffer.cpp AudioController.cpp AudioListener.cpp AudioSource.cpp BoundingBox.cpp BoundingSphere.cpp Button.cpp Camera.cpp CheckBox.cpp Container.cpp Control.cpp Curve.cpp DebugNew.cpp DepthStencilTarget.cpp Effect.cpp FileSystem.cpp Font.cpp Form.cpp FrameBuffer.cpp Frustum.cpp Game.cpp gameplay-main-android.cpp gameplay-main-qnx.cpp gameplay-main-win32.cpp Image.cpp Joint.cpp Label.cpp Layout.cpp Light.cpp Material.cpp MaterialParameter.cpp Matrix.cpp Mesh.cpp MeshBatch.cpp MeshPart.cpp MeshSkin.cpp Model.cpp Node.cpp Package.cpp ParticleEmitter.cpp Pass.cpp PhysicsCharacter.cpp PhysicsCollisionObject.cpp PhysicsCollisionShape.cpp PhysicsConstraint.cpp PhysicsController.cpp PhysicsFixedConstraint.cpp PhysicsGenericConstraint.cpp PhysicsGhostObject.cpp PhysicsHingeConstraint.cpp PhysicsMotionState.cpp PhysicsRigidBody.cpp PhysicsSocketConstraint.cpp PhysicsSpringConstraint.cpp Plane.cpp PlatformAndroid.cpp PlatformQNX.cpp PlatformWin32.cpp Properties.cpp Quaternion.cpp RadioButton.cpp Ray.cpp Rectangle.cpp Ref.cpp RenderState.cpp RenderTarget.cpp Scene.cpp SceneLoader.cpp Slider.cpp SpriteBatch.cpp Technique.cpp TextBox.cpp Texture.cpp Theme.cpp ThemeStyle.cpp Transform.cpp Vector2.cpp Vector3.cpp Vector4.cpp VertexAttributeBinding.cpp VertexFormat.cpp VerticalLayout.cpp
 LOCAL_CFLAGS := -D__ANDROID__ -I"../../external-deps/bullet/include" -I"../../external-deps/libpng/include"
 LOCAL_STATIC_LIBRARIES := android_native_app_glue
 

+ 1 - 0
gameplay/gameplay.vcxproj

@@ -48,6 +48,7 @@
     <ClCompile Include="src\Image.cpp" />
     <ClCompile Include="src\Joint.cpp" />
     <ClCompile Include="src\Label.cpp" />
+    <ClCompile Include="src\Layout.cpp" />
     <ClCompile Include="src\Light.cpp" />
     <ClCompile Include="src\Material.cpp" />
     <ClCompile Include="src\MeshBatch.cpp" />

+ 3 - 0
gameplay/gameplay.vcxproj.filters

@@ -276,6 +276,9 @@
     <ClCompile Include="src\ThemeStyle.cpp">
       <Filter>src</Filter>
     </ClCompile>
+    <ClCompile Include="src\Layout.cpp">
+      <Filter>src</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="src\Animation.h">

+ 2 - 39
gameplay/src/AbsoluteLayout.cpp

@@ -47,46 +47,9 @@ namespace gameplay
         {
             Control* control = controls[i];
 
-            if (control->_alignment != Control::ALIGN_TOP_LEFT ||
-                control->_autoWidth || control->_autoHeight)
-            {
-                Rectangle controlBounds = control->getBounds();
-                const Rectangle& containerBounds = container->getBounds();
-
-                if (control->_autoWidth)
-                {
-                    controlBounds.width = containerBounds.width;
-                }
-
-                if (control->_autoHeight)
-                {
-                    controlBounds.height = containerBounds.height;
-                }
-
-                // Vertical alignment
-                if ((control->_alignment & Control::ALIGN_BOTTOM) == Control::ALIGN_BOTTOM)
-                {
-                    controlBounds.y = containerBounds.height - controlBounds.height;
-                }
-                else if ((control->_alignment & Control::ALIGN_VCENTER) == Control::ALIGN_VCENTER)
-                {
-                    controlBounds.y = containerBounds.height / 2.0f - controlBounds.height / 2.0f;
-                }
-
-                // Horizontal alignment
-                if ((control->_alignment & Control::ALIGN_RIGHT) == Control::ALIGN_RIGHT)
-                {
-                    controlBounds.x = containerBounds.width - controlBounds.width;
-                }
-                else if ((control->_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
-                {
-                    controlBounds.x = containerBounds.width / 2.0f - controlBounds.width / 2.0f;
-                }
-
-                control->setBounds(controlBounds);
-            }
+            align(control, container);
 
-            if (control->isDirty())
+            if (control->isDirty() || control->isContainer())
             {
                 control->update(container->getClip());
             }

+ 5 - 0
gameplay/src/Button.h

@@ -17,8 +17,13 @@ namespace gameplay
  * button <buttonID>
  * {
  *      style       = <styleID>
+ *      alignment   = <Control::Alignment constant> // Note: 'position' will be ignored.
  *      position    = <x, y>
+ *      autoWidth   = <bool>
+ *      autoHeight  = <bool>
  *      size        = <width, height>
+ *      width       = <width>   // Can be used in place of 'size', e.g. with 'autoHeight = true'
+ *      height      = <height>  // Can be used in place of 'size', e.g. with 'autoWidth = true'
  *      text        = <string>
  * }
  */

+ 5 - 0
gameplay/src/CheckBox.h

@@ -17,8 +17,13 @@ namespace gameplay
  * checkBox <checkBoxID>
  * {
  *      style       = <styleID>
+ *      alignment   = <Control::Alignment constant> // Note: 'position' will be ignored.
  *      position    = <x, y>
+ *      autoWidth   = <bool>
+ *      autoHeight  = <bool>
  *      size        = <width, height>
+ *      width       = <width>   // Can be used in place of 'size', e.g. with 'autoHeight = true'
+ *      height      = <height>  // Can be used in place of 'size', e.g. with 'autoWidth = true'
  *      text        = <string>
  *      checked     = <bool>
  *      iconSize    = <width, height>   // The size to draw the checkbox icon, if different from its size in the texture.

+ 1 - 4
gameplay/src/Container.cpp

@@ -231,10 +231,7 @@ namespace gameplay
         // Update this container's viewport.
         Control::update(clip);
 
-        if (isDirty())
-        {
-            _layout->update(this);
-        }
+        _layout->update(this);
     }
 
     void Container::drawBorder(SpriteBatch* spriteBatch, const Rectangle& clip)

+ 7 - 2
gameplay/src/Container.h

@@ -17,8 +17,13 @@ namespace gameplay
  *      // Container properties.
  *      layout   = <Layout::Type>        // A value from the Layout::Type enum.  E.g.: LAYOUT_VERTICAL
  *      style    = <styleID>           // A style from the form's theme.
- *      position = <x, y>               // Position of the container on-screen, measured in pixels.
- *      size     = <width, height>      // Size of the container, measured in pixels.
+ *      alignment   = <Control::Alignment constant> // Note: 'position' will be ignored.
+ *      position    = <x, y>    // Position of the container on-screen, measured in pixels.
+ *      autoWidth   = <bool>
+ *      autoHeight  = <bool>
+ *      size        = <width, height>   // Size of the container, measured in pixels.
+ *      width       = <width>   // Can be used in place of 'size', e.g. with 'autoHeight = true'
+ *      height      = <height>  // Can be used in place of 'size', e.g. with 'autoWidth = true'
  *   
  *      // All the nested controls within this container.
  *      container 

+ 25 - 0
gameplay/src/Control.cpp

@@ -119,6 +119,31 @@ namespace gameplay
         return _bounds.height;
     }
 
+    void Control::setAlignment(Alignment alignment)
+    {
+        _alignment = alignment;
+    }
+
+    Control::Alignment Control::getAlignment() const
+    {
+        return _alignment;
+    }
+
+    void Control::setAutoWidth(bool autoWidth)
+    {
+        _autoWidth = autoWidth;
+    }
+
+    bool Control::getAutoWidth() const
+    {
+        return _autoWidth;
+    }
+
+    void Control::setAutoHeight(bool autoHeight)
+    {
+        _autoHeight = autoHeight;
+    }
+
     void Control::setOpacity(float opacity, unsigned char states)
     {
         overrideStyle();

+ 44 - 0
gameplay/src/Control.h

@@ -233,6 +233,50 @@ public:
      */
     float getHeight() const;
 
+    /**
+     * Set the alignment of this control within its parent container.
+     *
+     * @param alignment This control's alignment.
+     */
+    void setAlignment(Alignment alignment);
+
+    /**
+     * Get the alignment of this control within its parent container.
+     *
+     * @return The alignment of this control within its parent container.
+     */
+    Alignment getAlignment() const;
+
+    /**
+     * Set this control to fit horizontally within its parent container.
+     *
+     * @param autoWidth Whether to size this control to fit horizontally within its parent container.
+     */
+    void setAutoWidth(bool autoWidth);
+
+    /**
+     * Get whether this control's width is set to automatically adjust to
+     * fit horizontally within its parent container.
+     *
+     * @return Whether this control's width is set to automatically adjust.
+     */
+    bool getAutoWidth() const;
+
+    /**
+     * Set this control to fit vertically within its parent container.
+     *
+     * @param autoWidth Whether to size this control to fit vertically within its parent container.
+     */
+    void setAutoHeight(bool autoHeight);
+
+    /**
+     * Get whether this control's height is set to automatically adjust to
+     * fit vertically within its parent container.
+     *
+     * @return Whether this control's height is set to automatically adjust.
+     */
+    bool getAutoHeight() const;
+
     /**
      * Set the size of this control's border.
      *

+ 4 - 1
gameplay/src/Form.cpp

@@ -151,7 +151,10 @@ namespace gameplay
 
     void Form::update()
     {
-        Container::update(Rectangle(0, 0, _bounds.width, _bounds.height));
+        if (isDirty())
+        {
+            Container::update(Rectangle(0, 0, _bounds.width, _bounds.height));
+        }
     }
 
     void Form::draw()

+ 6 - 0
gameplay/src/Form.h

@@ -35,6 +35,12 @@ public:
      *      style    = <styleID>                // A style from the referenced theme.
      *      position = <x, y>                   // Position of the form on-screen, measured in pixels.
      *      size     = <width, height>          // Size of the form, measured in pixels.
+     *      alignment   = <Control::Alignment constant> // Note: 'position' will be ignored.
+     *      autoWidth   = <bool>                // Will result in a form the width of the display.
+     *      autoHeight  = <bool>                // Will result in a form the height of the display.
+     *      size        = <width, height>
+     *      width       = <width>               // Can be used in place of 'size', e.g. with 'autoHeight = true'
+     *      height      = <height>              // Can be used in place of 'size', e.g. with 'autoWidth = true'
      *   
      *      // All the nested controls within this form.
      *      container 

+ 5 - 0
gameplay/src/Label.h

@@ -15,8 +15,13 @@ namespace gameplay
  * label <labelID>
  * {
  *      style       = <styleID>
+ *      alignment   = <Control::Alignment constant> // Note: 'position' will be ignored.
  *      position    = <x, y>
+ *      autoWidth   = <bool>
+ *      autoHeight  = <bool>
  *      size        = <width, height>
+ *      width       = <width>   // Can be used in place of 'size', e.g. with 'autoHeight = true'
+ *      height      = <height>  // Can be used in place of 'size', e.g. with 'autoWidth = true'
  *      text        = <string>
  * }
  */

+ 9 - 0
gameplay/src/Layout.h

@@ -7,6 +7,7 @@ namespace gameplay
 {
 
 class Container;
+class Control;
 
 /**
  * The layout interface for UI containers.
@@ -58,6 +59,14 @@ protected:
      * @param container The container to update.
      */
     virtual void update(const Container* container) = 0;
+
+    /**
+     * Align a control within a container.
+     *
+     * @param control The control to align.
+     * @param container The container to align the control within.
+     */
+    virtual void align(Control* control, const Container* container);
 };
 
 }

+ 6 - 1
gameplay/src/ParticleEmitter.cpp

@@ -34,6 +34,11 @@ ParticleEmitter::ParticleEmitter(SpriteBatch* batch, unsigned int particleCountM
 
     _spriteBatch->getStateBlock()->setDepthWrite(false);
     _spriteBatch->getStateBlock()->setDepthTest(true);
+    /*
+    _spriteBatch->getStateBlock()->setBlend(true);
+    _spriteBatch->getStateBlock()->setBlendSrc(RenderState::BLEND_SRC_ALPHA);
+    _spriteBatch->getStateBlock()->setBlendDst(RenderState::BLEND_ONE_MINUS_SRC_ALPHA);
+    */
 }
 
 ParticleEmitter::~ParticleEmitter()
@@ -524,7 +529,7 @@ void ParticleEmitter::setTextureBlending(TextureBlending textureBlending)
             break;
         case BLEND_ADDITIVE:
             _spriteBatch->getStateBlock()->setBlend(true);
-            _spriteBatch->getStateBlock()->setBlendSrc(RenderState::BLEND_ONE);
+            _spriteBatch->getStateBlock()->setBlendSrc(RenderState::BLEND_SRC_ALPHA);
             _spriteBatch->getStateBlock()->setBlendDst(RenderState::BLEND_ONE);
             break;
         case BLEND_MULTIPLIED:

+ 5 - 0
gameplay/src/RadioButton.h

@@ -19,8 +19,13 @@ namespace gameplay
  * radioButton <RadioButton ID>
  * {
  *      style       = <Style ID>
+ *      alignment   = <Control::Alignment constant> // Note: 'position' will be ignored.
  *      position    = <x, y>
+ *      autoWidth   = <bool>
+ *      autoHeight  = <bool>
  *      size        = <width, height>
+ *      width       = <width>   // Can be used in place of 'size', e.g. with 'autoHeight = true'
+ *      height      = <height>  // Can be used in place of 'size', e.g. with 'autoWidth = true'
  *      text        = <string>
  *      group       = <string>
  *      iconSize    = <width, height>   // The size to draw the radio button icon, if different from its size in the texture.

+ 5 - 0
gameplay/src/TextBox.h

@@ -21,8 +21,13 @@ namespace gameplay
  * label <labelID>
  * {
  *      style       = <styleID>
+ *      alignment   = <Control::Alignment constant> // Note: 'position' will be ignored.
  *      position    = <x, y>
+ *      autoWidth   = <bool>
+ *      autoHeight  = <bool>
  *      size        = <width, height>
+ *      width       = <width>   // Can be used in place of 'size', e.g. with 'autoHeight = true'
+ *      height      = <height>  // Can be used in place of 'size', e.g. with 'autoWidth = true'
  *      text        = <string>
  * }
  */

+ 2 - 28
gameplay/src/VerticalLayout.cpp

@@ -69,33 +69,7 @@ namespace gameplay
         {
             Control* control = controls.at(i);
 
-            if (control->_alignment != Control::ALIGN_TOP_LEFT ||
-                control->_autoWidth || control->_autoHeight)
-            {
-                Rectangle controlBounds = control->getBounds();
-                const Rectangle& containerBounds = container->getBounds();
-
-                if (control->_autoWidth)
-                {
-                    controlBounds.width = containerBounds.width;
-                }
-
-                if (control->_autoHeight)
-                {
-                    controlBounds.height = containerBounds.height;
-                }
-
-                if ((control->_alignment & Control::ALIGN_RIGHT) == Control::ALIGN_RIGHT)
-                {
-                    controlBounds.x = containerBounds.width - controlBounds.width;
-                }
-                else if ((control->_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
-                {
-                    controlBounds.x = containerBounds.width / 2.0f - controlBounds.width / 2.0f;
-                }
-
-                control->setBounds(controlBounds);
-            }
+            align(control, container);
 
             const Rectangle& bounds = control->getClipBounds();
             const Theme::Margin& margin = control->getMargin();
@@ -103,7 +77,7 @@ namespace gameplay
             yPosition += margin.top;
 
             control->setPosition(0, yPosition);
-            if (control->isDirty())
+            if (control->isDirty() || control->isContainer())
             {
                 control->update(container->getClip());
             }