In the meantime I have these functions that I ported over from D3DFunc and put in a Class.vb to be included in a project. They include the Box, Line, Dot, and RoundedRectangle functions. Incidentally, I had to use a bit of a workaround for RoundRectFilled function because I couldn't figure out how to get it not to draw that first line in the outline... so I had it make two Vector4 arrays: One for the TriangleFan and one for the LineList. The nice part about this is that I was able to include one more overload that lets you set separate colors for the outline and the fill on the RoundedRect.
Of course you will have to included a reference in your project to DirectX and Direct3D. Full credit to Cloggy for the original functions in C++. Most of my work was just translation:
Imports System.Drawing
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class Drawing
Private g_Foreground As Color
Public Sub New()
g_Foreground = Color.White
End Sub
Public Overloads Sub Box(ByVal Left As Integer, ByVal Top As Integer, ByVal Right As Integer, ByVal Bottom As Integer)
GradientBox(Left, Top, Right, Bottom, g_Foreground, g_Foreground, g_Foreground, g_Foreground)
End Sub
Public Overloads Sub Box(ByVal Left As Integer, ByVal Top As Integer, ByVal Right As Integer, ByVal Bottom As Integer, ByVal Color As Color)
GradientBox(Left, Top, Right, Bottom, Color, Color, Color, Color)
End Sub
Public Overloads Sub Box(ByVal Left As Integer, ByVal Top As Integer, ByVal Right As Integer, ByVal Bottom As Integer, ByVal LeftTopColor As Color, ByVal RightTopColor As Color, ByVal LeftBottomColor As Color, ByVal RightBottomColor As Color)
GradientBox(Left, Top, Right, Bottom, LeftTopColor, RightTopColor, LeftBottomColor, RightBottomColor)
End Sub
Private Sub GradientBox(ByVal Left As Integer, ByVal Top As Integer, ByVal Right As Integer, ByVal Bottom As Integer, ByVal LeftTopColor As Color, ByVal RightTopColor As Color, ByVal LeftBottomColor As Color, ByVal RightBottomColor As Color)
Dim device As Microsoft.DirectX.Direct3D.Device
device = New Microsoft.DirectX.Direct3D.Device(DGDKPlugins.CDarkGDK.oDBDisplay.GetDirect3DDevice)
Dim vertices As CustomVertex.TransformedColored() = New CustomVertex.TransformedColored(0 To 3) {} 'create an array of vertices
vertices(0).Position = New Vector4(Left, Top, 0, 1)
vertices(0).Color = LeftTopColor.ToArgb
vertices(1).Position = New Vector4(Right, Top, 0, 1)
vertices(1).Color = RightTopColor.ToArgb
vertices(2).Position = New Vector4(Left, Bottom, 0, 1)
vertices(2).Color = LeftBottomColor.ToArgb
vertices(3).Position = New Vector4(Right, Bottom, 0, 1)
vertices(3).Color = RightBottomColor.ToArgb
device.SetTexture(0, Nothing)
device.SetTexture(1, Nothing)
device.SetRenderState(RenderStates.AlphaBlendEnable, True)
device.SetRenderState(RenderStates.SourceBlend, Blend.SourceAlpha)
device.SetRenderState(RenderStates.DestinationBlend, Blend.InvSourceAlpha)
device.SetRenderState(RenderStates.FillMode, FillMode.Solid)
device.SetRenderState(RenderStates.ZEnable, 0)
device.VertexFormat = CustomVertex.TransformedColored.Format
device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, vertices)
End Sub
Public Overloads Sub Dot(ByVal X As Integer, ByVal Y As Integer)
ColorDot(X, Y, g_Foreground)
End Sub
Public Overloads Sub Dot(ByVal X As Integer, ByVal Y As Integer, ByVal DotColor As Color)
ColorDot(X, Y, DotColor)
End Sub
Private Sub ColorDot(ByVal X As Integer, ByVal Y As Integer, ByVal DotColor As Color)
Dim device As Microsoft.DirectX.Direct3D.Device
device = New Microsoft.DirectX.Direct3D.Device(DGDKPlugins.CDarkGDK.oDBDisplay.GetDirect3DDevice)
Dim vertex As CustomVertex.TransformedColored = New CustomVertex.TransformedColored
vertex.Position = New Vector4(X, Y, 0, 1)
vertex.Color = DotColor.ToArgb
device.SetTexture(0, Nothing)
device.SetTexture(1, Nothing)
device.SetRenderState(RenderStates.AlphaBlendEnable, True)
device.SetRenderState(RenderStates.SourceBlend, Blend.SourceAlpha)
device.SetRenderState(RenderStates.DestinationBlend, Blend.InvSourceAlpha)
device.SetRenderState(RenderStates.FillMode, FillMode.Solid)
device.SetRenderState(RenderStates.ZEnable, 0)
device.VertexFormat = CustomVertex.TransformedColored.Format
device.DrawUserPrimitives(PrimitiveType.PointList, 1, vertex)
End Sub
Public Overloads Sub line(ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer)
GradientLine(X1, Y1, X2, Y2, g_Foreground, g_Foreground)
End Sub
Public Overloads Sub Line(ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer, ByVal LineColor1 As Color, ByVal LineColor2 As Color)
GradientLine(X1, Y1, X2, Y2, LineColor1, LineColor2)
End Sub
Private Sub GradientLine(ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer, ByVal LineColor1 As Color, ByVal LineColor2 As Color)
Dim device As Microsoft.DirectX.Direct3D.Device
device = New Microsoft.DirectX.Direct3D.Device(DGDKPlugins.CDarkGDK.oDBDisplay.GetDirect3DDevice)
Dim vertices As CustomVertex.TransformedColored() = New CustomVertex.TransformedColored(0 To 1) {} 'create an array of vertices
vertices(0).Position = New Vector4(X1, Y1, 0, 1)
vertices(0).Color = LineColor1.ToArgb
vertices(1).Position = New Vector4(X2, Y2, 0, 1)
vertices(1).Color = LineColor2.ToArgb
device.SetTexture(0, Nothing)
device.SetTexture(1, Nothing)
device.SetRenderState(RenderStates.AlphaBlendEnable, True)
device.SetRenderState(RenderStates.SourceBlend, Blend.SourceAlpha)
device.SetRenderState(RenderStates.DestinationBlend, Blend.InvSourceAlpha)
device.SetRenderState(RenderStates.FillMode, FillMode.Solid)
device.SetRenderState(RenderStates.ZEnable, 0)
device.VertexFormat = CustomVertex.TransformedColored.Format
device.DrawUserPrimitives(PrimitiveType.LineList, 1, vertices)
End Sub
Public Overloads Sub RoundRectangle(ByVal iX1 As Integer, ByVal iY1 As Integer, ByVal iX2 As Integer, ByVal iY2 As Integer, ByVal iRadius As Integer, ByVal Filled As Boolean)
If Filled = False Then
RoundRectUnfilled(iX1, iY1, iX2 - iX1, iY2 - iY1, iRadius, g_Foreground)
Else
RoundRectFilled(iX1, iY1, iX2 - iX1, iY2 - iY1, iRadius, g_Foreground, g_Foreground)
End If
End Sub
Public Overloads Sub RoundRectangle(ByVal iX1 As Integer, ByVal iY1 As Integer, ByVal iX2 As Integer, ByVal iY2 As Integer, ByVal iRadius As Integer, ByVal RectColor As Color, ByVal Filled As Boolean)
If Filled = False Then
RoundRectUnfilled(iX1, iY1, iX2 - iX1, iY2 - iY1, iRadius, RectColor)
Else
RoundRectFilled(iX1, iY1, iX2 - iX1, iY2 - iY1, iRadius, RectColor, RectColor)
End If
End Sub
Public Overloads Sub RoundRectangle(ByVal iX1 As Integer, ByVal iY1 As Integer, ByVal iX2 As Integer, ByVal iY2 As Integer, ByVal iRadius As Integer, ByVal OutlineColor As Color, ByVal RectColor As Color, ByVal Filled As Boolean)
If Filled = False Then
RoundRectUnfilled(iX1, iY1, iX2 - iX1, iY2 - iY1, iRadius, RectColor)
Else
RoundRectFilled(iX1, iY1, iX2 - iX1, iY2 - iY1, iRadius, OutlineColor, RectColor)
End If
End Sub
Private Sub RoundRectUnfilled(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal iRadius As Integer, ByVal RectColour As Color)
Dim device As Microsoft.DirectX.Direct3D.Device
device = New Microsoft.DirectX.Direct3D.Device(DGDKPlugins.CDarkGDK.oDBDisplay.GetDirect3DDevice)
Dim iVertexCount As Integer = 32
If Width > Height Then
If iRadius * 2 > Height Then
iRadius = Height 2
End If
Else
If iRadius * 2 > Width Then
iRadius = Width 2
End If
End If
If iRadius < 1 Then
iRadius = 1
End If
If iRadius < 20 Then
iVertexCount = 16
End If
' Line list, batch draw everything
Dim g_lineList As CustomVertex.TransformedColored() = New CustomVertex.TransformedColored(0 To (iVertexCount + 4)) {}
' Check memory was allocated successfully
If g_lineList Is Nothing Then
Return
End If
' Position data
Dim iAX As Single = 0
Dim iAY As Single = 0
Dim iBX As Single = 0
Dim iBY As Single = 0
' Angle of current vert.
Dim fAngle As Single
'g_lineList(0).Position = New Vector4(CSng(iX + iW / 2), CSng(iY + iH / 2), 1, 1)
'g_lineList(0).Color = dwColour.ToArgb
Dim VertsPerCorner As Integer = (iVertexCount + 4) / 4
For i As Integer = 0 To VertsPerCorner - 1
fAngle = i / CSng(iVertexCount) * 6.2831853071795862
iAX = ((Math.Sin(fAngle) * iRadius))
iAY = ((Math.Cos(fAngle) * iRadius))
g_lineList(i).Position = New Vector4(CSng(iAX + X + Width - iRadius), CSng(iAY + Y + Height - iRadius), 1.0, 1.0)
g_lineList(i).Color = RectColour.ToArgb
If i = 0 Then
g_lineList(iVertexCount + 4).Position = New Vector4(CSng(iAX + X + Width - iRadius), CSng(iAY + Y + Height - iRadius), 1.0, 1.0)
g_lineList(iVertexCount + 4).Color = RectColour.ToArgb
End If
g_lineList(VertsPerCorner * 2 - 1 - i).Position = New Vector4(CSng(X + iAX + Width - iRadius), CSng(Y - iAY + iRadius), 1, 1)
g_lineList(VertsPerCorner * 2 - 1 - i).Color = RectColour.ToArgb
g_lineList(i + VertsPerCorner * 2).Position = New Vector4(CSng(X - iAX + iRadius), CSng(Y - iAY + iRadius), 1, 1)
g_lineList(i + VertsPerCorner * 2).Color = RectColour.ToArgb
g_lineList(VertsPerCorner * 4 - 1 - i).Position = New Vector4(CSng(X - iAX + iRadius), CSng(Y + iAY + Height - iRadius), 1, 1)
g_lineList(VertsPerCorner * 4 - 1 - i).Color = RectColour.ToArgb
Next i
' Draw
device.SetTexture(0, Nothing)
device.SetTexture(1, Nothing)
device.SetRenderState(RenderStates.AlphaBlendEnable, True)
device.SetRenderState(RenderStates.SourceBlend, Blend.SourceAlpha)
device.SetRenderState(RenderStates.DestinationBlend, Blend.InvSourceAlpha)
device.SetRenderState(RenderStates.FillMode, FillMode.Solid)
device.SetRenderState(RenderStates.ZEnable, 0)
device.VertexFormat = CustomVertex.TransformedColored.Format
device.DrawUserPrimitives(PrimitiveType.LineStrip, (iVertexCount + 4), g_lineList)
' Delete allocated memory
g_lineList = Nothing
End Sub
Private Sub RoundRectFilled(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByVal iRadius As Integer, ByVal OutlineColor As Color, ByVal RectColour As Color)
Dim device As Microsoft.DirectX.Direct3D.Device
device = New Microsoft.DirectX.Direct3D.Device(DGDKPlugins.CDarkGDK.oDBDisplay.GetDirect3DDevice)
Dim iVertexCount As Integer = 32
If Width > Height Then
If iRadius * 2 > Height Then
iRadius = Height 2
End If
Else
If iRadius * 2 > Width Then
iRadius = Width 2
End If
End If
If iRadius < 1 Then
iRadius = 1
End If
If iRadius < 20 Then
iVertexCount = 16
End If
' Line list, batch draw everything
Dim g_triangleFan As CustomVertex.TransformedColored() = New CustomVertex.TransformedColored(0 To (iVertexCount + 5)) {}
Dim g_lineList As CustomVertex.TransformedColored() = New CustomVertex.TransformedColored(0 To (iVertexCount + 4)) {}
' Check memory was allocated successfully
If g_triangleFan Is Nothing Then
Return
End If
' Position data
Dim iAX As Single = 0
Dim iAY As Single = 0
Dim iBX As Single = 0
Dim iBY As Single = 0
' Angle of current vert.
Dim fAngle As Single
g_triangleFan(0).Position = New Vector4(CSng(X + Width / 2), CSng(Y + Height / 2), 1, 1)
g_triangleFan(0).Color = RectColour.ToArgb
Dim VertsPerCorner As Integer = (iVertexCount + 4) / 4
For i As Integer = 0 To VertsPerCorner - 1
fAngle = i / CSng(iVertexCount) * 6.2831853071795862
iAX = ((Math.Sin(fAngle) * iRadius))
iAY = ((Math.Cos(fAngle) * iRadius))
g_triangleFan(i + 1).Position = New Vector4(CSng(iAX + X + Width - iRadius), CSng(iAY + Y + Height - iRadius), 1.0, 1.0)
g_triangleFan(i + 1).Color = RectColour.ToArgb
g_lineList(i).Position = New Vector4(CSng(iAX + X + Width - iRadius), CSng(iAY + Y + Height - iRadius), 1.0, 1.0)
g_lineList(i).Color = OutlineColor.ToArgb
If i = 0 Then
g_triangleFan(iVertexCount + 5).Position = New Vector4(CSng(iAX + X + Width - iRadius), CSng(iAY + Y + Height - iRadius), 1.0, 1.0)
g_triangleFan(iVertexCount + 5).Color = RectColour.ToArgb
g_lineList(iVertexCount + 4).Position = New Vector4(CSng(iAX + X + Width - iRadius), CSng(iAY + Y + Height - iRadius), 1.0, 1.0)
g_lineList(iVertexCount + 4).Color = OutlineColor.ToArgb
End If
g_triangleFan(VertsPerCorner * 2 - 1 - i + 1).Position = New Vector4(CSng(X + iAX + Width - iRadius), CSng(Y - iAY + iRadius), 1, 1)
g_triangleFan(VertsPerCorner * 2 - 1 - i + 1).Color = RectColour.ToArgb
g_lineList(VertsPerCorner * 2 - 1 - i).Position = New Vector4(CSng(X + iAX + Width - iRadius), CSng(Y - iAY + iRadius), 1, 1)
g_lineList(VertsPerCorner * 2 - 1 - i).Color = OutlineColor.ToArgb
g_triangleFan(i + VertsPerCorner * 2 + 1).Position = New Vector4(CSng(X - iAX + iRadius), CSng(Y - iAY + iRadius), 1, 1)
g_triangleFan(i + VertsPerCorner * 2 + 1).Color = RectColour.ToArgb
g_lineList(i + VertsPerCorner * 2).Position = New Vector4(CSng(X - iAX + iRadius), CSng(Y - iAY + iRadius), 1, 1)
g_lineList(i + VertsPerCorner * 2).Color = OutlineColor.ToArgb
g_triangleFan(VertsPerCorner * 4 - 1 - i + 1).Position = New Vector4(CSng(X - iAX + iRadius), CSng(Y + iAY + Height - iRadius), 1, 1)
g_triangleFan(VertsPerCorner * 4 - 1 - i + 1).Color = RectColour.ToArgb
g_lineList(VertsPerCorner * 4 - 1 - i).Position = New Vector4(CSng(X - iAX + iRadius), CSng(Y + iAY + Height - iRadius), 1, 1)
g_lineList(VertsPerCorner * 4 - 1 - i).Color = OutlineColor.ToArgb
Next i
' Draw
device.SetTexture(0, Nothing)
device.SetTexture(1, Nothing)
device.SetRenderState(RenderStates.AlphaBlendEnable, True)
device.SetRenderState(RenderStates.SourceBlend, Blend.SourceAlpha)
device.SetRenderState(RenderStates.DestinationBlend, Blend.InvSourceAlpha)
device.SetRenderState(RenderStates.CullMode, Cull.Clockwise)
device.SetRenderState(RenderStates.FillMode, FillMode.Solid)
device.SetRenderState(RenderStates.ZEnable, 0)
device.VertexFormat = CustomVertex.TransformedColored.Format
device.DrawUserPrimitives(PrimitiveType.TriangleFan, (iVertexCount + 4), g_triangleFan)
device.DrawUserPrimitives(PrimitiveType.LineStrip, (iVertexCount + 4), g_lineList)
' Delete allocated memory
g_triangleFan = Nothing
End Sub
End Class
Design documents?!? What design documents??? I thought we were just going to wing it!!!