Browse Source

Curve drawing now draws keyframe points
Extended GUICanvas so drawn elements with the same canvas can have different depth

BearishSun 9 năm trước cách đây
mục cha
commit
7dd47a2e26

+ 32 - 6
Source/BansheeEngine/Include/BsGUICanvas.h

@@ -47,8 +47,11 @@ namespace BansheeEngine
 		 * @param[in]	a		Starting point of the line, relative to the canvas origin (top-left).
 		 * @param[in]	b		Ending point of the line, relative to the canvas origin (top-left).
 		 * @param[in]	color	Color of the line.
+		 * @param[in]	depth	Depth at which to draw the element. Elements with higher depth will be drawn before others.
+		 *						Additionally elements of the same type (triangle or line) will be drawn in order they are
+		 *						submitted if they share the same depth.
 		 */
-		void drawLine(const Vector2I& a, const Vector2I& b, const Color& color = Color::White);
+		void drawLine(const Vector2I& a, const Vector2I& b, const Color& color = Color::White, UINT8 depth = 128);
 
 		/** 
 		 * Draws multiple lines following the path by the provided vertices. First vertex connects to the second vertex,
@@ -57,8 +60,11 @@ namespace BansheeEngine
 		 * @param[in]	vertices	Points to use for drawing the line. Must have at least two elements. All points are 
 		 *							relative to the canvas origin (top-left).
 		 * @param[in]	color		Color of the line.
+		 * @param[in]	depth		Depth at which to draw the element. Elements with higher depth will be drawn before 
+		 *							others. Additionally elements of the same type (triangle or line) will be drawn in order
+		 *							they are submitted if they share the same depth.
 		 */
-		void drawPolyLine(const Vector<Vector2I>& vertices, const Color& color = Color::White);
+		void drawPolyLine(const Vector<Vector2I>& vertices, const Color& color = Color::White, UINT8 depth = 128);
 
 		/** 
 		 * Draws a quad with a the provided texture displayed.
@@ -69,9 +75,12 @@ namespace BansheeEngine
 		 * @param[in]	scaleMode	Scale mode to use when sizing the texture. Only relevant if the provided quad size
 		 *							doesn't match the texture size.
 		 * @param[in]	color		Color to tint the drawn texture with.
+		 * @param[in]	depth		Depth at which to draw the element. Elements with higher depth will be drawn before 
+		 *							others. Additionally elements of the same type (triangle or line) will be drawn in order
+		 *							they are submitted if they share the same depth.
 		 */
 		void drawTexture(const HSpriteTexture& texture, const Rect2I& area, 
-			TextureScaleMode scaleMode = TextureScaleMode::StretchToFit, const Color& color = Color::White);
+			TextureScaleMode scaleMode = TextureScaleMode::StretchToFit, const Color& color = Color::White, UINT8 depth = 128);
 
 		/** 
 		 * Draws a triangle strip. First three vertices are used to form the initial triangle, and every next vertex will
@@ -80,8 +89,11 @@ namespace BansheeEngine
 		 * @param[in]	vertices	A set of points defining the triangles. Must have at least three elements. All points
 		 *							are relative to the canvas origin (top-left).
 		 * @param[in]	color		Color of the triangles.
+		 * @param[in]	depth		Depth at which to draw the element. Elements with higher depth will be drawn before
+		 *							others. Additionally elements of the same type (triangle or line) will be drawn in order
+		 *							they are submitted if they share the same depth.
 		 */
-		void drawTriangleStrip(const Vector<Vector2I>& vertices, const Color& color = Color::White);
+		void drawTriangleStrip(const Vector<Vector2I>& vertices, const Color& color = Color::White, UINT8 depth = 128);
 
 		/** 
 		 * Draws a triangle list. Every three vertices in the list represent a unique triangle.
@@ -89,8 +101,11 @@ namespace BansheeEngine
 		 * @param[in]	vertices	A set of points defining the triangles. Must have at least three elements, and its size
 		 *							must be a multiple of three.
 		 * @param[in]	color		Color of the triangles.
+		 * @param[in]	depth		Depth at which to draw the element. Elements with higher depth will be drawn before
+		 *							others. Additionally elements of the same type (triangle or line) will be drawn in order
+		 *							they are submitted if they share the same depth.
 		 */
-		void drawTriangleList(const Vector<Vector2I>& vertices, const Color& color = Color::White);
+		void drawTriangleList(const Vector<Vector2I>& vertices, const Color& color = Color::White, UINT8 depth = 128);
 
 		/**
 		 * Draws a piece of text with the wanted font. The text will be aligned to the top-left corner of the provided
@@ -102,9 +117,12 @@ namespace BansheeEngine
 		 * @param[in]	font		Font to draw the text with.
 		 * @param[in]	size		Size of the font.
 		 * @param[in]	color		Color of the text.
+		 * @param[in]	depth		Depth at which to draw the element. Elements with higher depth will be drawn before
+		 *							others. Additionally elements of the same type (triangle or line) will be drawn in order
+		 *							they are submitted if they share the same depth.
 		 */
 		void drawText(const WString& text, const Vector2I& position, const HFont& font, UINT32 size = 10, 
-			const Color& color = Color::White);
+			const Color& color = Color::White, UINT8 depth = 128);
 
 		/** Clears the canvas, removing any previously drawn elements. */
 		void clear();
@@ -136,6 +154,7 @@ namespace BansheeEngine
 			UINT32 renderElemStart;
 			UINT32 renderElemEnd;
 			UINT32 dataId;
+			UINT8 depth;
 
 			union
 			{
@@ -198,6 +217,12 @@ namespace BansheeEngine
 		void _fillBuffer(UINT8* vertices, UINT32* indices, UINT32 vertexOffset, UINT32 indexOffset,
 			UINT32 maxNumVerts, UINT32 maxNumIndices, UINT32 renderElementIdx) const override;
 
+		/** @copydoc GUIElement::_getRenderElementDepth */
+		UINT32 _getRenderElementDepth(UINT32 renderElementIdx) const override;
+
+		/** @copydoc GUIElement::_getRenderElementDepthRange */
+		UINT32 _getRenderElementDepthRange() const override { return mDepthRange; }
+
 		/** @copydoc GUIElement::updateRenderElementsInternal */
 		void updateRenderElementsInternal() override;
 
@@ -221,6 +246,7 @@ namespace BansheeEngine
 
 		Vector<CanvasElement> mElements;
 		UINT32 mNumRenderElements;
+		UINT8 mDepthRange;
 
 		Vector<ImageElementData> mImageData;
 		Vector<TextElementData> mTextData;

+ 30 - 10
Source/BansheeEngine/Source/BsGUICanvas.cpp

@@ -22,7 +22,7 @@ namespace BansheeEngine
 	}
 
 	GUICanvas::GUICanvas(const String& styleName, const GUIDimensions& dimensions)
-		:GUIElement(styleName, dimensions), mNumRenderElements(0), mForceTriangleBuild(false)
+		:GUIElement(styleName, dimensions), mNumRenderElements(0), mDepthRange(1), mForceTriangleBuild(false)
 	{
 
 	}
@@ -42,12 +42,12 @@ namespace BansheeEngine
 		return new (bs_alloc<GUICanvas>()) GUICanvas(getStyleName<GUICanvas>(styleName), GUIDimensions::create());
 	}
 
-	void GUICanvas::drawLine(const Vector2I& a, const Vector2I& b, const Color& color)
+	void GUICanvas::drawLine(const Vector2I& a, const Vector2I& b, const Color& color, UINT8 depth)
 	{
-		drawPolyLine({ a, b }, color);
+		drawPolyLine({ a, b }, color, depth);
 	}
 
-	void GUICanvas::drawPolyLine(const Vector<Vector2I>& vertices, const Color& color)
+	void GUICanvas::drawPolyLine(const Vector<Vector2I>& vertices, const Color& color, UINT8 depth)
 	{
 		if(vertices.size() < 2)
 			return;
@@ -60,6 +60,9 @@ namespace BansheeEngine
 		element.dataId = (UINT32)mTriangleElementData.size();
 		element.vertexStart = (UINT32)mVertexData.size();
 		element.numVertices = (UINT32)vertices.size();
+		element.depth = depth;
+
+		mDepthRange = std::max(mDepthRange, (UINT8)(depth + 1));
 
 		mTriangleElementData.push_back(TriangleElementData());
 		TriangleElementData& elemData = mTriangleElementData.back();
@@ -69,8 +72,6 @@ namespace BansheeEngine
 		for (auto& vertex : vertices)
 		{
 			Vector2 point = Vector2((float)vertex.x, (float)vertex.y);
-			point += Vector2(0.5f, 0.5f); // Offset to the middle of the pixel
-
 			mVertexData.push_back(point);
 		}
 
@@ -79,7 +80,7 @@ namespace BansheeEngine
 	}
 
 	void GUICanvas::drawTexture(const HSpriteTexture& texture, const Rect2I& area, TextureScaleMode scaleMode, 
-		const Color& color)
+		const Color& color, UINT8 depth)
 	{
 		mElements.push_back(CanvasElement());
 		CanvasElement& element = mElements.back();
@@ -89,12 +90,15 @@ namespace BansheeEngine
 		element.dataId = (UINT32)mImageData.size();
 		element.scaleMode = scaleMode;
 		element.imageSprite = bs_new<ImageSprite>();
+		element.depth = depth;
+
+		mDepthRange = std::max(mDepthRange, (UINT8)(depth + 1));
 
 		mImageData.push_back({ texture, area });
 		_markContentAsDirty();
 	}
 
-	void GUICanvas::drawTriangleStrip(const Vector<Vector2I>& vertices, const Color& color)
+	void GUICanvas::drawTriangleStrip(const Vector<Vector2I>& vertices, const Color& color, UINT8 depth)
 	{
 		if (vertices.size() < 3)
 		{
@@ -110,6 +114,9 @@ namespace BansheeEngine
 		element.dataId = (UINT32)mTriangleElementData.size();
 		element.vertexStart = (UINT32)mVertexData.size();
 		element.numVertices = (UINT32)(vertices.size() - 2) * 3;
+		element.depth = depth;
+
+		mDepthRange = std::max(mDepthRange, (UINT8)(depth + 1));
 
 		// Convert strip to list
 		for(UINT32 i = 2; i < (UINT32)vertices.size(); i++)
@@ -137,7 +144,7 @@ namespace BansheeEngine
 		_markContentAsDirty();
 	}
 
-	void GUICanvas::drawTriangleList(const Vector<Vector2I>& vertices, const Color& color)
+	void GUICanvas::drawTriangleList(const Vector<Vector2I>& vertices, const Color& color, UINT8 depth)
 	{
 		if (vertices.size() < 3 || vertices.size() % 3 != 0)
 		{
@@ -153,6 +160,9 @@ namespace BansheeEngine
 		element.dataId = (UINT32)mTriangleElementData.size();
 		element.vertexStart = (UINT32)mVertexData.size();
 		element.numVertices = (UINT32)vertices.size();
+		element.depth = depth;
+
+		mDepthRange = std::max(mDepthRange, (UINT8)(depth + 1));
 
 		for (auto& vertex : vertices)
 			mVertexData.push_back(Vector2((float)vertex.x, (float)vertex.y));
@@ -167,7 +177,7 @@ namespace BansheeEngine
 	}
 
 	void GUICanvas::drawText(const WString& text, const Vector2I& position, const HFont& font, UINT32 size, 
-		const Color& color)
+		const Color& color, UINT8 depth)
 	{
 		mElements.push_back(CanvasElement());
 		CanvasElement& element = mElements.back();
@@ -177,6 +187,9 @@ namespace BansheeEngine
 		element.dataId = (UINT32)mTextData.size();
 		element.size = size;
 		element.textSprite = bs_new<TextSprite>();
+		element.depth = depth;
+
+		mDepthRange = std::max(mDepthRange, (UINT8)(depth + 1));
 
 		mTextData.push_back({ text, font, position });
 		_markContentAsDirty();
@@ -195,6 +208,7 @@ namespace BansheeEngine
 
 		mElements.clear();
 		mNumRenderElements = 0;
+		mDepthRange = 1;
 
 		mVertexData.clear();
 		mImageData.clear();
@@ -210,6 +224,12 @@ namespace BansheeEngine
 		return mNumRenderElements;
 	}
 
+	UINT32 GUICanvas::_getRenderElementDepth(UINT32 renderElementIdx) const
+	{
+		const CanvasElement& element = findElement(renderElementIdx);
+		return _getDepth() + element.depth;
+	}
+
 	const SpriteMaterialInfo& GUICanvas::_getMaterial(UINT32 renderElementIdx, SpriteMaterial** material) const
 	{
 		static const SpriteMaterialInfo defaultMatInfo;

+ 38 - 0
Source/MBansheeEditor/Windows/Animation/GUICurveDrawing.cs

@@ -182,6 +182,37 @@ namespace BansheeEditor
             canvas.DrawLine(start, end, COLOR_DARK_GRAY);
         }
 
+        /// <summary>
+        /// Draws a keyframe a the specified time and value.
+        /// </summary>
+        /// <param name="t">Time to draw the keyframe at.</param>
+        /// <param name="y">Y value to draw the keyframe at.</param>
+        /// <param name="selected">Determines should the keyframe be drawing using the selected color scheme, or normally.
+        ///                        </param>
+        private void DrawKeyframe(float t, float y, bool selected)
+        {
+            int heightOffset = height / 2; // So that y = 0 is at center of canvas
+
+            int xPos = (int)((t / GetRange()) * drawableWidth) + GUIGraphTime.PADDING;
+            int yPos = heightOffset - (int)((y/yRange)*height);
+
+            Vector2I a = new Vector2I(xPos - 3, yPos);
+            Vector2I b = new Vector2I(xPos, yPos - 3);
+            Vector2I c = new Vector2I(xPos + 3, yPos);
+            Vector2I d = new Vector2I(xPos, yPos + 3);
+
+            // Draw diamond shape
+            Vector2I[] linePoints = new Vector2I[] { a, b, c, d, a };
+            Vector2I[] trianglePoints = new Vector2I[] { b, c, a, d };
+
+            canvas.DrawTriangleStrip(trianglePoints, Color.White, 101);
+
+            if (selected)
+                canvas.DrawPolyLine(linePoints, Color.BansheeOrange, 100);
+            else
+                canvas.DrawPolyLine(linePoints, Color.Black, 100);
+        }
+
         /// <summary>
         /// Returns the range of times displayed by the timeline rounded to the multiple of FPS.
         /// </summary>
@@ -236,6 +267,13 @@ namespace BansheeEditor
             {
                 Color color = GetUniqueColor(idx);
                 DrawCurve(curve, color);
+
+                // Draw keyframes
+                KeyFrame[] keyframes = curve.Native.KeyFrames;
+
+                for (int i = 0; i < keyframes.Length; i++)
+                    DrawKeyframe(keyframes[i].time, keyframes[i].value, false);
+
                 idx++;
             }
 

+ 68 - 30
Source/MBansheeEngine/GUI/GUICanvas.cs

@@ -54,10 +54,13 @@ namespace BansheeEngine
         /// </summary>
         /// <param name="a">Starting point of the line, relative to the canvas origin (top-left).</param>
         /// <param name="b">Ending point of the line, relative to the canvas origin (top-left).</param>
-        public void DrawLine(Vector2I a, Vector2I b)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawLine(Vector2I a, Vector2I b, byte depth = 128)
         {
             Color color = Color.White;
-            Internal_DrawLine(mCachedPtr, ref a, ref b, ref color);
+            Internal_DrawLine(mCachedPtr, ref a, ref b, ref color, depth);
         }
 
         /// <summary>
@@ -66,9 +69,12 @@ namespace BansheeEngine
         /// <param name="a">Starting point of the line, relative to the canvas origin (top-left).</param>
         /// <param name="b">Ending point of the line, relative to the canvas origin (top-left).</param>
         /// <param name="color">Color of the line.</param>
-        public void DrawLine(Vector2I a, Vector2I b, Color color)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawLine(Vector2I a, Vector2I b, Color color, byte depth = 128)
         {
-            Internal_DrawLine(mCachedPtr, ref a, ref b, ref color);
+            Internal_DrawLine(mCachedPtr, ref a, ref b, ref color, depth);
         }
 
         /// <summary>
@@ -77,10 +83,13 @@ namespace BansheeEngine
         /// </summary>
         /// <param name="vertices">Points to use for drawing the line. Must have at least two elements. All points are 
         ///                        relative to the canvas origin(top-left).</param>
-        public void DrawPolyLine(Vector2I[] vertices)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawPolyLine(Vector2I[] vertices, byte depth = 128)
         {
             Color color = Color.White;
-            Internal_DrawPolyLine(mCachedPtr, vertices, ref color);
+            Internal_DrawPolyLine(mCachedPtr, vertices, ref color, depth);
         }
 
         /// <summary>
@@ -90,9 +99,12 @@ namespace BansheeEngine
         /// <param name="vertices">Points to use for drawing the line. Must have at least two elements. All points are 
         ///                        relative to the canvas origin(top-left).</param>
         /// <param name="color">Color of the line.</param>
-        public void DrawPolyLine(Vector2I[] vertices, Color color)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawPolyLine(Vector2I[] vertices, Color color, byte depth = 128)
         {
-            Internal_DrawPolyLine(mCachedPtr, vertices, ref color);
+            Internal_DrawPolyLine(mCachedPtr, vertices, ref color, depth);
         }
 
         /// <summary>
@@ -103,15 +115,18 @@ namespace BansheeEngine
         ///                    (top-left). If size is zero, the default texture size will be used.</param>
         /// <param name="scaleMode">Scale mode to use when sizing the texture. Only relevant if the provided quad size 
         ///                         doesn't match the texture size.</param>
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
         public void DrawTexture(SpriteTexture texture, Rect2I area,
-            GUITextureScaleMode scaleMode = GUITextureScaleMode.StretchToFit)
+            GUITextureScaleMode scaleMode = GUITextureScaleMode.StretchToFit, byte depth = 128)
         {
             IntPtr texturePtr = IntPtr.Zero;
             if (texture != null)
                 texturePtr = texture.GetCachedPtr();
 
             Color color = Color.White;
-            Internal_DrawTexture(mCachedPtr, texturePtr, ref area, scaleMode, ref color);
+            Internal_DrawTexture(mCachedPtr, texturePtr, ref area, scaleMode, ref color, depth);
         }
 
         /// <summary>
@@ -123,14 +138,17 @@ namespace BansheeEngine
         /// <param name="color">Color to tint the drawn texture with.</param>
         /// <param name="scaleMode">Scale mode to use when sizing the texture. Only relevant if the provided quad size 
         ///                         doesn't match the texture size.</param>
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
         public void DrawTexture(SpriteTexture texture, Rect2I area, Color color,
-            GUITextureScaleMode scaleMode = GUITextureScaleMode.StretchToFit)
+            GUITextureScaleMode scaleMode = GUITextureScaleMode.StretchToFit, byte depth = 128)
         {
             IntPtr texturePtr = IntPtr.Zero;
             if (texture != null)
                 texturePtr = texture.GetCachedPtr();
 
-            Internal_DrawTexture(mCachedPtr, texturePtr, ref area, scaleMode, ref color);
+            Internal_DrawTexture(mCachedPtr, texturePtr, ref area, scaleMode, ref color, depth);
         }
 
         /// <summary>
@@ -139,10 +157,13 @@ namespace BansheeEngine
         /// </summary>
         /// <param name="vertices">A set of points defining the triangles. Must have at least three elements. All points
         ///                        are relative to the canvas origin(top-left).</param>
-        public void DrawTriangleStrip(Vector2I[] vertices)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawTriangleStrip(Vector2I[] vertices, byte depth = 128)
         {
             Color color = Color.White;
-            Internal_DrawTriangleStrip(mCachedPtr, vertices, ref color);
+            Internal_DrawTriangleStrip(mCachedPtr, vertices, ref color, depth);
         }
 
         /// <summary>
@@ -152,9 +173,12 @@ namespace BansheeEngine
         /// <param name="vertices">A set of points defining the triangles. Must have at least three elements. All points
         ///                        are relative to the canvas origin(top-left).</param>
         /// <param name="color">Color of the triangles.</param>
-        public void DrawTriangleStrip(Vector2I[] vertices, Color color)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawTriangleStrip(Vector2I[] vertices, Color color, byte depth = 128)
         {
-            Internal_DrawTriangleStrip(mCachedPtr, vertices, ref color);
+            Internal_DrawTriangleStrip(mCachedPtr, vertices, ref color, depth);
         }
 
         /// <summary>
@@ -162,10 +186,13 @@ namespace BansheeEngine
         /// </summary>
         /// <param name="vertices">A set of points defining the triangles. Must have at least three elements, and its size
         ///                        must be a multiple of three.</param>
-        public void DrawTriangleList(Vector2I[] vertices)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawTriangleList(Vector2I[] vertices, byte depth = 128)
         {
             Color color = Color.White;
-            Internal_DrawTriangleList(mCachedPtr, vertices, ref color);
+            Internal_DrawTriangleList(mCachedPtr, vertices, ref color, depth);
         }
 
         /// <summary>
@@ -174,9 +201,12 @@ namespace BansheeEngine
         /// <param name="vertices">A set of points defining the triangles. Must have at least three elements, and its size
         ///                        must be a multiple of three.</param>
         /// <param name="color">Color of the triangles.</param>
-        public void DrawTriangleList(Vector2I[] vertices, Color color)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawTriangleList(Vector2I[] vertices, Color color, byte depth = 128)
         {
-            Internal_DrawTriangleList(mCachedPtr, vertices, ref color);
+            Internal_DrawTriangleList(mCachedPtr, vertices, ref color, depth);
         }
 
         /// <summary>
@@ -189,13 +219,16 @@ namespace BansheeEngine
         /// <param name="font">Font to draw the text with.</param>
         /// <param name="color">Color of the text.</param>
         /// <param name="size">Size of the font.</param>
-        public void DrawText(string text, Vector2I position, Font font, Color color, int size = 10)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawText(string text, Vector2I position, Font font, Color color, int size = 10, byte depth = 128)
         {
             IntPtr fontPtr = IntPtr.Zero;
             if (font != null)
                 fontPtr = font.GetCachedPtr();
 
-            Internal_DrawText(mCachedPtr, text, ref position, fontPtr, size, ref color);
+            Internal_DrawText(mCachedPtr, text, ref position, fontPtr, size, ref color, depth);
         }
 
         /// <summary>
@@ -207,14 +240,17 @@ namespace BansheeEngine
         ///                        relative to the canvas origin(top-left).</param>
         /// <param name="font">Font to draw the text with.</param>
         /// <param name="size">Size of the font.</param>
-        public void DrawText(string text, Vector2I position, Font font, int size = 10)
+        /// <param name="depth">Depth at which to draw the element. Elements with higher depth will be drawn before others.
+        ///                     Additionally elements of the same type (triangle or line) will be drawn in order they are
+        ///                     submitted if they share the same depth.</param>
+        public void DrawText(string text, Vector2I position, Font font, int size = 10, byte depth = 128)
         {
             IntPtr fontPtr = IntPtr.Zero;
             if (font != null)
                 fontPtr = font.GetCachedPtr();
 
             Color color = Color.White;
-            Internal_DrawText(mCachedPtr, text, ref position, fontPtr, size, ref color);
+            Internal_DrawText(mCachedPtr, text, ref position, fontPtr, size, ref color, depth);
         }
 
         /// <summary>
@@ -230,25 +266,27 @@ namespace BansheeEngine
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_DrawLine(IntPtr nativeInstance, ref Vector2I a, ref Vector2I b,
-            ref Color color);
+            ref Color color, byte depth);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_DrawPolyLine(IntPtr nativeInstance, Vector2I[] vertices,
-            ref Color color);
+            ref Color color, byte depth);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_DrawTexture(IntPtr nativeInstance, IntPtr texture, ref Rect2I area,
-            GUITextureScaleMode scaleMode, ref Color color);
+            GUITextureScaleMode scaleMode, ref Color color, byte depth);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_DrawTriangleStrip(IntPtr nativeInstance, Vector2I[] vertices, ref Color color);
+        private static extern void Internal_DrawTriangleStrip(IntPtr nativeInstance, Vector2I[] vertices, ref Color color, 
+            byte depth);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void Internal_DrawTriangleList(IntPtr nativeInstance, Vector2I[] vertices, ref Color color);
+        private static extern void Internal_DrawTriangleList(IntPtr nativeInstance, Vector2I[] vertices, ref Color color, 
+            byte depth);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_DrawText(IntPtr nativeInstance, string text, ref Vector2I position,
-            IntPtr font, int size, ref Color color);
+            IntPtr font, int size, ref Color color, byte depth);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_Clear(IntPtr nativeInstance);

+ 6 - 6
Source/SBansheeEngine/Include/BsScriptGUICanvas.h

@@ -24,14 +24,14 @@ namespace BansheeEngine
 		/* 								CLR HOOKS						   		*/
 		/************************************************************************/
 		static void internal_createInstance(MonoObject* instance, MonoString* style, MonoArray* guiOptions);
-		static void internal_drawLine(ScriptGUICanvas* nativeInstance, Vector2I* a, Vector2I* b, Color* color);
-		static void internal_drawPolyLine(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color);
+		static void internal_drawLine(ScriptGUICanvas* nativeInstance, Vector2I* a, Vector2I* b, Color* color, UINT8 depth);
+		static void internal_drawPolyLine(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color, UINT8 depth);
 		static void internal_drawTexture(ScriptGUICanvas* nativeInstance, ScriptSpriteTexture* texture, Rect2I* area,
-			TextureScaleMode scaleMode, Color* color);
-		static void internal_drawTriangleStrip(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color);
-		static void internal_drawTriangleList(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color);
+			TextureScaleMode scaleMode, Color* color, UINT8 depth);
+		static void internal_drawTriangleStrip(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color, UINT8 depth);
+		static void internal_drawTriangleList(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color, UINT8 depth);
 		static void internal_drawText(ScriptGUICanvas* nativeInstance, MonoString* text, Vector2I* position, 
-			ScriptFont* font, UINT32 size, Color* color);
+			ScriptFont* font, UINT32 size, Color* color, UINT8 depth);
 		static void internal_clear(ScriptGUICanvas* nativeInstance);
 	};
 

+ 16 - 12
Source/SBansheeEngine/Source/BsScriptGUICanvas.cpp

@@ -43,13 +43,15 @@ namespace BansheeEngine
 		new (bs_alloc<ScriptGUICanvas>()) ScriptGUICanvas(instance, guiCanvas);
 	}
 
-	void ScriptGUICanvas::internal_drawLine(ScriptGUICanvas* nativeInstance, Vector2I* a, Vector2I* b, Color* color)
+	void ScriptGUICanvas::internal_drawLine(ScriptGUICanvas* nativeInstance, Vector2I* a, Vector2I* b, Color* color, 
+		UINT8 depth)
 	{
 		GUICanvas* canvas = (GUICanvas*)nativeInstance->getGUIElement();
-		canvas->drawLine(*a, *b, *color);
+		canvas->drawLine(*a, *b, *color, depth);
 	}
 
-	void ScriptGUICanvas::internal_drawPolyLine(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color)
+	void ScriptGUICanvas::internal_drawPolyLine(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color, 
+		UINT8 depth)
 	{
 		GUICanvas* canvas = (GUICanvas*)nativeInstance->getGUIElement();
 
@@ -59,11 +61,11 @@ namespace BansheeEngine
 		Vector<Vector2I> nativeVertices(size);
 		memcpy(nativeVertices.data(), verticesArray.getRawPtr<Vector2I>(), sizeof(Vector2I) * size);
 
-		canvas->drawPolyLine(nativeVertices, *color);
+		canvas->drawPolyLine(nativeVertices, *color, depth);
 	}
 
 	void ScriptGUICanvas::internal_drawTexture(ScriptGUICanvas* nativeInstance, ScriptSpriteTexture* texture, Rect2I* area,
-		TextureScaleMode scaleMode, Color* color)
+		TextureScaleMode scaleMode, Color* color, UINT8 depth)
 	{
 		GUICanvas* canvas = (GUICanvas*)nativeInstance->getGUIElement();
 
@@ -71,10 +73,11 @@ namespace BansheeEngine
 		if (texture != nullptr)
 			nativeTexture = texture->getHandle();
 
-		canvas->drawTexture(nativeTexture, *area, scaleMode, *color);
+		canvas->drawTexture(nativeTexture, *area, scaleMode, *color, depth);
 	}
 	
-	void ScriptGUICanvas::internal_drawTriangleStrip(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color)
+	void ScriptGUICanvas::internal_drawTriangleStrip(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color, 
+		UINT8 depth)
 	{
 		GUICanvas* canvas = (GUICanvas*)nativeInstance->getGUIElement();
 
@@ -84,10 +87,11 @@ namespace BansheeEngine
 		Vector<Vector2I> nativeVertices(size);
 		memcpy(nativeVertices.data(), verticesArray.getRawPtr<Vector2I>(), sizeof(Vector2I) * size);
 
-		canvas->drawTriangleStrip(nativeVertices, *color);
+		canvas->drawTriangleStrip(nativeVertices, *color, depth);
 	}
 
-	void ScriptGUICanvas::internal_drawTriangleList(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color)
+	void ScriptGUICanvas::internal_drawTriangleList(ScriptGUICanvas* nativeInstance, MonoArray* vertices, Color* color, 
+		UINT8 depth)
 	{
 		GUICanvas* canvas = (GUICanvas*)nativeInstance->getGUIElement();
 
@@ -97,11 +101,11 @@ namespace BansheeEngine
 		Vector<Vector2I> nativeVertices(size);
 		memcpy(nativeVertices.data(), verticesArray.getRawPtr<Vector2I>(), sizeof(Vector2I) * size);
 
-		canvas->drawTriangleList(nativeVertices, *color);
+		canvas->drawTriangleList(nativeVertices, *color, depth);
 	}
 
 	void ScriptGUICanvas::internal_drawText(ScriptGUICanvas* nativeInstance, MonoString* text, Vector2I* position,
-		ScriptFont* font, UINT32 size, Color* color)
+		ScriptFont* font, UINT32 size, Color* color, UINT8 depth)
 	{
 		GUICanvas* canvas = (GUICanvas*)nativeInstance->getGUIElement();
 		WString nativeText = MonoUtil::monoToWString(text);
@@ -110,7 +114,7 @@ namespace BansheeEngine
 		if (font != nullptr)
 			nativeFont = font->getHandle();
 
-		canvas->drawText(nativeText, *position, nativeFont, size, *color);
+		canvas->drawText(nativeText, *position, nativeFont, size, *color, depth);
 	}
 
 	void ScriptGUICanvas::internal_clear(ScriptGUICanvas* nativeInstance)