public LiveSphere() { int num = this.sphereDiv; int num2 = this.sphereDiv * 2; this.spherePrim = new UIPrimitive((DrawMode)4, (num + 1) * (num2 + 1), num * 2 * (num2 + 1)); this.spherePrim.Culling = true; this.spherePrim.InternalShaderType = InternalShaderType.LiveSphere; float num3 = 3.14159274f / (float)num; float num4 = 6.28318548f / (float)num2; float num5 = 1f / (float)num2; float num6 = 1f / (float)num; for (int i = 0; i < num + 1; i++) { for (int j = 0; j < num2 + 1; j++) { float num7 = -(float)Math.Sin((double)((float)i * num3)) * (float)Math.Cos((double)((float)j * num4)); float num8 = -(float)Math.Cos((double)((float)i * num3)); float num9 = -(float)Math.Sin((double)((float)i * num3)) * (float)Math.Sin((double)((float)j * num4)); UIPrimitiveVertex vertex = this.spherePrim.GetVertex(i * (num2 + 1) + j); vertex.Position3D = new Vector3(num7, num8, num9); vertex.U = num5 * (float)j; vertex.V = num6 * (float)i; } } ushort[] array = new ushort[num * 2 * (num2 + 1)]; for (int k = 0; k < num; k++) { for (int l = 0; l < num2 + 1; l++) { array[k * (num2 + 1) * 2 + l * 2] = (ushort)(k * (num2 + 1) + l); array[k * (num2 + 1) * 2 + l * 2 + 1] = (ushort)((k + 1) * (num2 + 1) + l); } } this.spherePrim.SetIndices(array); base.RootUIElement.AddChildLast(this.spherePrim); this.LightDirection = new Vector4((float)(Math.Sin((double)this.LightZAngle) * Math.Cos((double)this.LightYAngle)), (float)Math.Cos((double)this.LightZAngle), (float)(Math.Sin((double)this.LightZAngle) * Math.Sin((double)this.LightYAngle)), 0f); this.spherePrim.ShaderUniforms["Shininess"] = new float[] { this.Shininess }; this.spherePrim.ShaderUniforms["Specular"] = new float[] { this.Specular }; this.SetSize(this.radius * 2f, this.radius * 2f); this.flickGesture = new FlickGestureDetector(); this.flickGesture.Direction = FlickDirection.All; this.flickGesture.FlickDetected += new EventHandler <FlickEventArgs>(this.FlickEventHandler); base.AddGestureDetector(this.flickGesture); this.dragGesture = new DragGestureDetector(); this.dragGesture.DragDetected += new EventHandler <DragEventArgs>(this.DragEventHandler); base.AddGestureDetector(this.dragGesture); this.PriorityHit = true; }
protected internal override void Render() { if (!this.isExistRenderedVertex()) { return; } GraphicsContext graphicsContext = UISystem.GraphicsContext; ShaderProgramManager.ShaderProgramUnit shaderProgramUnit = ShaderProgramManager.GetShaderProgramUnit(base.InternalShaderType); graphicsContext.SetShaderProgram(shaderProgramUnit.ShaderProgram); Texture2D texture = base.GetTexture(); graphicsContext.SetTexture(0, texture); bool flag = false; bool flag2 = false; bool flag3 = false; for (int i = 0; i < this.vertexCount; i++) { UIPrimitiveVertex uIPrimitiveVertex = this.vertices[i]; flag |= uIPrimitiveVertex.NeedUpdatePosition; flag2 |= uIPrimitiveVertex.NeedUpdateColor; flag3 |= uIPrimitiveVertex.NeedUpdateTexcoord; uIPrimitiveVertex.NeedUpdatePosition = false; uIPrimitiveVertex.NeedUpdateColor = false; uIPrimitiveVertex.NeedUpdateTexcoord = false; } if (this.needUpdateVertexAll || flag) { float[] array = new float[this.VertexCount * 3]; int num = 0; for (int j = 0; j < this.VertexCount; j++) { UIPrimitiveVertex uIPrimitiveVertex2 = this.vertices[j]; array[num++] = uIPrimitiveVertex2.X; array[num++] = uIPrimitiveVertex2.Y; array[num++] = uIPrimitiveVertex2.Z; } this.vertexBuffer.SetVertices(0, array, 0, 0, this.VertexCount); } if (this.needUpdateVertexAll || flag) { float[] array2 = new float[this.VertexCount * 4]; int num2 = 0; for (int k = 0; k < this.VertexCount; k++) { UIPrimitiveVertex uIPrimitiveVertex3 = this.vertices[k]; array2[num2++] = uIPrimitiveVertex3.Color.R; array2[num2++] = uIPrimitiveVertex3.Color.G; array2[num2++] = uIPrimitiveVertex3.Color.B; array2[num2++] = uIPrimitiveVertex3.Color.A; } this.vertexBuffer.SetVertices(1, array2, 0, 0, this.VertexCount); } if (texture != null) { if (this.needUpdateVertexAll || flag3) { float[] array3 = new float[this.VertexCount * 2]; int num3 = 0; for (int l = 0; l < this.VertexCount; l++) { UIPrimitiveVertex uIPrimitiveVertex4 = this.vertices[l]; array3[num3++] = uIPrimitiveVertex4.U; array3[num3++] = uIPrimitiveVertex4.V; } this.vertexBuffer.SetVertices(2, array3, 0, 0, this.VertexCount); } } else if ((this.needUpdateVertexAll || flag3) && this.vertexCount > 0) { this.vertices[0].NeedUpdateTexcoord = true; } if (this.needUpdateIndices) { if (this.indexCount > 0) { this.vertexBuffer.SetIndices(this.indices, 0, 0, this.indexCount); } this.needUpdateIndices = false; } this.needUpdateVertexAll = false; graphicsContext.SetVertexBuffer(0, this.vertexBuffer); this.updateLocalToWorld(); Matrix4 matrix; UISystem.viewProjectionMatrix.Multiply(ref this.localToWorld, out matrix); shaderProgramUnit.ShaderProgram.SetUniformValue(shaderProgramUnit.UniformIndexOfModelViewProjection, ref matrix); shaderProgramUnit.ShaderProgram.SetUniformValue(shaderProgramUnit.UniformIndexOfAlpha, this.finalAlpha); using (List <string> .Enumerator enumerator = shaderProgramUnit.OtherUniformNames.GetEnumerator()) { while (enumerator.MoveNext()) { string current = enumerator.Current; if (base.ShaderUniforms.ContainsKey(current)) { shaderProgramUnit.ShaderProgram.SetUniformValue(shaderProgramUnit.Uniforms[current], base.ShaderUniforms[current]); } } } int num4 = (this.indexCount > 0) ? this.indexCount : this.VertexCount; graphicsContext.DrawArrays(this.DrawMode, 0, num4); }
public static void SetupNinePatch(UIPrimitive primitive, float width, float height, float offsetX, float offsetY, ImageRect imageRect, NinePatchMargin ninePatchMargin) { if (primitive.MaxVertexCount < 16) { throw new ArgumentOutOfRangeException("primitive", "UIPrimitive MaxVertexCount is out of range."); } if (primitive.MaxIndexCount < 28) { throw new ArgumentOutOfRangeException("primitive", "UIPrimitive MaxIndexCount is out of range."); } if (primitive.Image != null) { float[] array = new float[] { 0f, (float)ninePatchMargin.Left, width - (float)ninePatchMargin.Right, width }; float[] array2 = new float[] { 0f, (float)ninePatchMargin.Top, height - (float)ninePatchMargin.Bottom, height }; if (array[1] > width) { array[1] = width; } if (array[2] < 0f) { array[2] = 0f; } if (array[1] > array[2]) { array[1] = (array[2] = (array[1] + array[2]) / 2f); } if (array2[1] > height) { array2[1] = height; } if (array2[2] < 0f) { array2[2] = 0f; } if (array2[1] > array2[2]) { array2[1] = (array2[2] = (array2[1] + array2[2]) / 2f); } int num = 0; int num2 = 0; int width2 = primitive.Image.Width; int height2 = primitive.Image.Height; int num3 = width2; int num4 = height2; if (imageRect.X < width2 && imageRect.Y < height2 && imageRect.Width > 0 && imageRect.Height > 0) { if (imageRect.X > 0) { num = imageRect.X; } num3 = num + imageRect.Width; if (num3 > width2) { num3 = width2; } if (imageRect.Y > 0) { num2 = imageRect.Y; } num4 = num2 + imageRect.Height; if (num4 > height2) { num4 = height2; } } float num5 = (float)width2; float num6 = (float)height2; float num7 = ((float)ninePatchMargin.Left < array[1] - array[0]) ? ((float)(num + ninePatchMargin.Left)) : ((float)num + array[1] - array[0]); float num8 = ((float)ninePatchMargin.Right < array[3] - array[2]) ? ((float)(num3 - ninePatchMargin.Right)) : ((float)num3 - (array[3] - array[2])); float num9 = ((float)ninePatchMargin.Top < array2[1] - array2[0]) ? ((float)(num2 + ninePatchMargin.Top)) : ((float)num2 + array2[1] - array2[0]); float num10 = ((float)ninePatchMargin.Bottom < array2[3] - array2[2]) ? ((float)(num4 - ninePatchMargin.Bottom)) : ((float)num4 - (array2[3] - array2[2])); float[] array3 = new float[] { (float)num / num5, num7 / num5, num8 / num5, (float)num3 / num5 }; float[] array4 = new float[] { (float)num2 / num6, num9 / num6, num10 / num6, (float)num4 / num6 }; if (array3[2] < array3[0]) { array3[2] = array3[0]; } if (array4[2] < array4[0]) { array4[2] = array4[0]; } if (array3[1] > array3[3]) { array3[1] = array3[3]; } if (array4[1] > array4[3]) { array4[1] = array4[3]; } primitive.VertexCount = 16; primitive.SetIndices(new ushort[] { 0, 4, 1, 5, 2, 6, 3, 7, 7, 4, 4, 8, 5, 9, 6, 10, 7, 11, 11, 8, 8, 12, 9, 13, 10, 14, 11, 15 }); primitive.IndexCount = 28; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { UIPrimitiveVertex vertex = primitive.GetVertex(i * 4 + j); vertex.X = array[j] + offsetX; vertex.Y = array2[i] + offsetY; vertex.U = array3[j]; vertex.V = array4[i]; } } } }
public static void SetupVerticalThreePatch(UIPrimitive primitive, float width, float height, float offsetX, float offsetY, float topMargin, float bottomMargin) { if (primitive.MaxVertexCount < 8) { throw new ArgumentOutOfRangeException("primitive", "UIPrimitive MaxVertexCount is out of range."); } if (primitive.Image != null) { int height2 = primitive.Image.Height; if ((float)height2 == 0f) { return; } float num = (float)height2; float[] array = new float[] { 0f, width }; float[] array2 = new float[] { 0f, (topMargin < height) ? topMargin : height, (bottomMargin < height) ? (height - bottomMargin) : 0f, height }; if (array2[1] > array2[2]) { array2[1] = (array2[2] = (array2[1] + array2[2]) / 2f); } float[] array3 = new float[] { 0f, 1f }; float num2 = (topMargin < array2[1]) ? topMargin : array2[1]; float num3 = (bottomMargin < height - array2[2]) ? bottomMargin : (height - array2[2]); float[] array4 = new float[] { 0f, num2 / num, (num - num3) / num, 1f }; if (array4[2] < 0f) { array4[2] = 0f; } if (array4[1] > 1f) { array4[1] = 1f; } primitive.VertexCount = 8; primitive.SetIndices(new ushort[] { 0, 1, 2, 3, 4, 5, 6, 7 }); primitive.IndexCount = 8; for (int i = 0; i < 4; i++) { for (int j = 1; j >= 0; j--) { UIPrimitiveVertex vertex = primitive.GetVertex(i * 2 + j); vertex.X = array[j] + offsetX; vertex.Y = array2[i] + offsetY; vertex.U = array3[j]; vertex.V = array4[i]; } } } }
public static void SetupHorizontalThreePatch(UIPrimitive primitive, float width, float height, float offsetX, float offsetY, float leftMargin, float rightMargin) { if (primitive.MaxVertexCount < 8) { throw new ArgumentOutOfRangeException("primitive", "UIPrimitive MaxVertexCount is out of range."); } if (primitive.Image != null) { int width2 = primitive.Image.Width; if ((float)width2 == 0f) { return; } float num = (float)width2; float[] array = new float[] { 0f, (leftMargin < width) ? leftMargin : width, (rightMargin < width) ? (width - rightMargin) : 0f, width }; if (array[1] > array[2]) { array[1] = (array[2] = (array[1] + array[2]) / 2f); } float[] array2 = new float[] { 0f, height }; float num2 = (leftMargin < array[1]) ? leftMargin : array[1]; float num3 = (rightMargin < width - array[2]) ? rightMargin : (width - array[2]); float[] array3 = new float[] { 0f, num2 / num, (num - num3) / num, 1f }; float[] array4 = new float[] { 0f, 1f }; if (array3[2] < 0f) { array3[2] = 0f; } if (array3[1] > 1f) { array3[1] = 1f; } primitive.VertexCount = 8; primitive.SetIndices(new ushort[] { 0, 4, 1, 5, 2, 6, 3, 7 }); primitive.IndexCount = 8; for (int i = 0; i < 2; i++) { for (int j = 0; j < 4; j++) { UIPrimitiveVertex vertex = primitive.GetVertex(i * 4 + j); vertex.X = array[j] + offsetX; vertex.Y = array2[i] + offsetY; vertex.U = array3[j]; vertex.V = array4[i]; } } } }