protected internal override void Draw(GuiRender render) { var padding = 2.0f; var cursorHeight = FontSize * 0.9f; var textPosition = new Point2f(padding * 2, Utility.Center(Size.Height, mTextBuffer.Size.Height)); var cursorPosition = new Point2f(textPosition.X + ( Cursor == 0 ? 0 : mTextBuffer.GetCharacterPostLocation(Cursor - 1)), Utility.Center(Size.Height, cursorHeight)); var area = new Rectanglef(0, 0, Size.Width, Size.Height); render.FillRectangle(area, Style.Background); render.DrawRectangle(area, Style.Padding, padding); render.DrawText(textPosition, mTextBuffer, Style.Text); if (mPassTime < HalfDuration || Gui.GlobalElementStatus.FocusElement != this) { return; } render.DrawLine(cursorPosition, cursorPosition + new Vector2f(0, cursorHeight), Style.Cursor, padding); }
private void DrawImage(Rectanglef rectangle, Image image, Colorf color, GuiRenderMode mode) { //fill rectangle with texture //the result color's alpha is equal texture.alpha * opacity //do not render image if (image.GpuTexture == null) { return; } var transform = new GuiTransform(); var renderConfig = new GuiRenderConfig() { Color = color, Config = new Vector4((int)mode) }; //1.scale the rectangle transform.World = Matrix4x4.CreateScale(rectangle.Right - rectangle.Left, rectangle.Bottom - rectangle.Top, 1.0f); //2.translate it transform.World *= Matrix4x4.CreateTranslation(rectangle.Left, rectangle.Top, 0.0f); //3.keep transform matrix data transform.World *= Transform; //set projection matrix transform.Project = mProject; mTransformBuffer.Update(transform); mRenderConfigBuffer.Update(renderConfig); mDevice.SetVertexBuffer(mSquareVertexBuffer); mDevice.SetIndexBuffer(mSquareIndexBuffer); mDevice.SetBuffer(mTransformBuffer, mTransformBufferSlot, GpuShaderType.All); mDevice.SetBuffer(mRenderConfigBuffer, mRenderConfigBufferSlot, GpuShaderType.All); mDevice.SetResourceUsage(image.GpuResourceUsage, mTextureSlot, GpuShaderType.All); mDevice.DrawIndexed(6, 0, 0); }
public virtual void DrawText(Rectanglef rectangle, Text text, Colorf color) { DrawImage(rectangle, text.Image, color, GuiRenderMode.Text); }
public virtual void DrawImage(Rectanglef rectangle, Image image, float opacity = 1.0f) { DrawImage(rectangle, image, new Colorf(1.0f, 1.0f, 1.0f, opacity)); }
public virtual void DrawImage(Rectanglef rectangle, Image image, Colorf color) { DrawImage(rectangle, image, color, GuiRenderMode.Image); }
public virtual void DrawRectangle(Rectanglef rectangle, Colorf color, float padding = 2.0f) { //draw rectangle with color //padding means the width of edge //color.Alpha means the opacity of edge //read rectangle data var outSide = rectangle; //inside rectangle will smaller than outside var inSide = new Rectanglef( outSide.Left + padding, outSide.Top + padding, outSide.Right - padding, outSide.Bottom - padding); //first, we need compute the vertex buffer for our rectangle //we do not need tex coord of vertex //we can compute the index buffer at init the render GuiVertex[] vertics = new GuiVertex[] { new GuiVertex() { Position = new Vector3f(outSide.Left, outSide.Top, 0) }, new GuiVertex() { Position = new Vector3f(outSide.Right, outSide.Top, 0) }, new GuiVertex() { Position = new Vector3f(outSide.Right, outSide.Bottom, 0) }, new GuiVertex() { Position = new Vector3f(outSide.Left, outSide.Bottom, 0) }, new GuiVertex() { Position = new Vector3f(inSide.Left, inSide.Top, 0) }, new GuiVertex() { Position = new Vector3f(inSide.Right, inSide.Top, 0) }, new GuiVertex() { Position = new Vector3f(inSide.Right, inSide.Bottom, 0) }, new GuiVertex() { Position = new Vector3f(inSide.Left, inSide.Bottom, 0) } }; //update vertex buffer mRectangleVertexBuffer.Update(vertics); //second, update constant buffer var transform = new GuiTransform() { World = Transform, Project = mProject }; var renderConfig = new GuiRenderConfig() { Color = color, Config = new Vector4(0) }; mTransformBuffer.Update(transform); mRenderConfigBuffer.Update(renderConfig); //set buffer and shader mDevice.SetVertexBuffer(mRectangleVertexBuffer); mDevice.SetIndexBuffer(mRectangleIndexBuffer); mDevice.SetBuffer(mTransformBuffer, mTransformBufferSlot, GpuShaderType.All); mDevice.SetBuffer(mRenderConfigBuffer, mRenderConfigBufferSlot, GpuShaderType.All); //draw mDevice.DrawIndexed(24, 0, 0); }