Drawing the Rectangular RU, with some notations:
Dim sWidth As Integer
Dim dSurface As Bitmap
Dim bWidth As Integer
Dim shrt As Integer
Dim lng As Integer
Dim st1 As String
Dim imageAttrs As New Imaging.ImageAttributes
imageAttrs.SetWrapMode(System.Drawing.Drawing2D.WrapMode.Tile)
'This little call takes no measurable time, and can be ignored.
UpdateRWPB()
'Figure out which size is being drawn.
Select Case zoomLevel
Case 0
bWidth = GetBorderWidth(16)
shrt = 16
lng = CInt(16 * aspectRatio)
sWidth = GetSplitterWidth(16)
st1 = veryShortName
dSurface = New Bitmap(m16Base)
Case 1
bWidth = GetBorderWidth(32)
shrt = 32
lng = CInt(32 * aspectRatio)
sWidth = GetSplitterWidth(32)
st1 = veryShortName
dSurface = New Bitmap(m32Base)
Case 2
bWidth = GetBorderWidth(64)
shrt = 64
lng = CInt(64 * aspectRatio)
sWidth = GetSplitterWidth(64)
st1 = longerName
dSurface = New Bitmap(m64Base)
Case 3
bWidth = GetBorderWidth(128)
shrt = 128
lng = CInt(128 * aspectRatio)
sWidth = GetSplitterWidth(128)
st1 = longerName
dSurface = New Bitmap(m128Base)
Case Else
bWidth = GetBorderWidth(256)
shrt = 256
lng = CInt(256 * aspectRatio)
sWidth = GetSplitterWidth(256)
st1 = longerName
dSurface = New Bitmap(m256Base)
End Select
'This next call sets up the locations for all the splitters, fish, and
'other located regions. It takes 2ms, but is necessary.
SizeLocations(zoomLevel)
Dim grph As Drawing.Graphics = Drawing.Graphics.FromImage(dSurface)
'Draw the outer border.
grph.FillRectangle(mFillBrush, 0, 0, bWidth, lng)
grph.FillRectangle(mFillBrush, 0, 0, shrt, bWidth)
grph.FillRectangle(mFillBrush, shrt - bWidth, 0, bWidth, lng)
grph.FillRectangle(mFillBrush, 0, lng - bWidth, shrt, bWidth)
'Draw the inner border. (only drawn if there is a color to draw)
If mInnerBrush IsNot Nothing Then
grph.FillRectangle(mInnerBrush, bWidth, bWidth, bWidth, lng - bWidth - bWidth)
grph.FillRectangle(mFillBrush, bWidth, bWidth, shrt - bWidth - bWidth, bWidth)
grph.FillRectangle(mFillBrush, shrt - bWidth, bWidth, bWidth, lng - bWidth - bWidth)
grph.FillRectangle(mFillBrush, bWidth, lng - bWidth, shrt - bWidth - bWidth, bWidth)
End If
'Fill the first one, which has a height of twice the splitter width, with the splitter in the middle.
'These are the squares mentioned in the post. None are in the posted image.
'NOTE: This needs to be tested, twice the splitter width may be ugly.
For x As Integer = 0 To mKeywayList.Count - 1
'Left side keyway.
grph.FillRectangle(Brushes.BlanchedAlmond, 0, CInt(((lng / 100) * mKeywayList(x))) - (2 * sWidth), 2 * bWidth, 2 * sWidth)
'Right side keyway.
grph.FillRectangle(Brushes.BlanchedAlmond, shrt - (2 * bWidth), CInt(((lng / 100) * mKeywayList(x))) - (2 * sWidth), 2 * bWidth, 2 * sWidth)
Next
'Then draw in the depthables, but only for sizes greater than 0.
If zoomLevel > 0 Then
For Each dpth In mDepthable
Dim lRect As Rectangle
'This has to be drawn before the flip to get the images working right.
If dpth.Distance = 0 Then
lRect = New Rectangle(bWidth, lng - (2 * sWidth), shrt - (2 * bWidth), 2 * sWidth)
Else
lRect = New Rectangle(bWidth, CInt((dpth.Distance * (lng / 100))) - sWidth, shrt - (2 * bWidth), 2 * sWidth)
End If
grph.DrawImage(Spill, lRect, 0, 0, lRect.Width, lRect.Height, GraphicsUnit.Pixel, imageAttrs)
Next
End If
'This step rotates the image.
grph.Dispose()
Dim d2 As Bitmap
'Now rotate the image prior to adding fish and RWPB.
If mDirection = HISInCommon.Direction.East Then
dSurface.RotateFlip(RotateFlipType.Rotate270FlipNone)
d2 = New Bitmap(lng, shrt + 16)
ElseIf mDirection = HISInCommon.Direction.West Then
dSurface.RotateFlip(RotateFlipType.Rotate90FlipNone)
d2 = New Bitmap(lng, shrt + 16)
ElseIf mDirection = HISInCommon.Direction.North Then
dSurface.RotateFlip(RotateFlipType.Rotate180FlipX)
d2 = New Bitmap(shrt, lng + 16)
Else
d2 = New Bitmap(shrt, lng + 16)
End If
grph = Drawing.Graphics.FromImage(d2)
grph.FillRectangle(mBackBrush, 0, 0, d2.Width, d2.Height)
grph.DrawImage(dSurface, 0, 0, d2.Width, d2.Height - 16)
dSurface.Dispose()
dSurface = d2
Dim hAccum As Integer
'Need to draw in the splitters.
'The drawing is at the bottom of the RU, so the final RU draws nothing.
hAccum = 0
For x As Integer = 0 To mRUList.Count - 2
'het is the length in pixels of the RU along the direction of flow.
'haccum is the accumulator of those heights as we work down the RU list.
'het= CInt((lng / 100) * mERaiser.IRUBO.GetLength(mRUList(x).RU.RUID))
If mDirection = HISInCommon.Direction.East Then
grph.FillRectangle(Brushes.Black, (mRUList(x).RULocation.Width + hAccum) - (sWidth \ 2), 0, sWidth, shrt)
hAccum += mRUList(x).RULocation.Width
ElseIf mDirection = HISInCommon.Direction.West Then
grph.FillRectangle(Brushes.Black, lng - (hAccum + mRUList(x).RULocation.Width) - (sWidth \ 2), 0, sWidth, shrt)
hAccum += mRUList(x).RULocation.Width
ElseIf mDirection = HISInCommon.Direction.North Then
grph.FillRectangle(Brushes.Black, 0, lng - (hAccum + mRUList(x).RULocation.Height) - (sWidth \ 2), shrt, sWidth)
hAccum += mRUList(x).RULocation.Height
Else
grph.FillRectangle(Brushes.Black, 0, (mRUList(x).RULocation.Height + hAccum) - (sWidth \ 2), shrt, sWidth)
hAccum += mRUList(x).RULocation.Height
End If
Next
'Now, for each rectangle, need to draw a fish if there is a fish to draw.
For x As Integer = 0 To mRUList.Count - 1
If mRUList(x).RU.AUID.Count > 0 Then
'There is a fish to draw.
'Superimpose the fish.
If mRUList(x).FishSelected Then
HISInCommon.Tools.SuperImposeFishAni(grph, mRUList(x).fishLocation.Top, mRUList(x).fishLocation.Left, mRUList(x).fishLocation.Width, mRUList(x).fishLocation.Height, HISInCommon.FishImages.SelectedSquareFish)
Else
HISInCommon.Tools.SuperImposeFishAni(grph, mRUList(x).fishLocation.Top, mRUList(x).fishLocation.Left, mRUList(x).fishLocation.Width, mRUList(x).fishLocation.Height, HISInCommon.FishImages.SquareFish)
End If
End If
'Show the RWPB icons.
For y As Integer = 0 To 7
If mRWPBInterfaces(y) IsNot Nothing AndAlso mRUList(x).RWPB(y).Height > 0 Then
'Dim bmp = New Bitmap(mRWPBInterfaces(y).DisplayFactors.DisplayIcon, mRUList(x).RWPB(y).Width, mRUList(x).RWPB(y).Height)
grph.DrawImage(mRWPBInterfaces(y).DisplayFactors.DisplayIcon, mRUList(x).RWPB(y))
'bmp.Dispose()
End If
Next
Next
'Now draw in the string
If mMyFont IsNot Nothing Then
Dim alng As New StringFormat()
alng.Alignment = StringAlignment.Center
alng.FormatFlags = (StringFormatFlags.NoWrap Or StringFormatFlags.NoClip)
Dim lFont As Font = mMyFont
Dim stringSize = grph.MeasureString(st1, mMyFont, Point.Empty, alng)
If stringSize.Width > dSurface.Width Then
Do
lFont = New Font(mMyFont.Name, mMyFont.SizeInPoints - 1, mMyFont.Style)
stringSize = grph.MeasureString(st1, lFont, Point.Empty, alng)
Loop While stringSize.Width > dSurface.Width
End If
grph.DrawString(st1, lFont, mTextBrush, New RectangleF(0, dSurface.Height - 14, dSurface.Width, 14), alng)
If lFont IsNot mMyFont Then
lFont.Dispose()
End If
alng.Dispose()
End If
Select Case zoomLevel
Case 0
m16 = dSurface
m16Sel = changeBrightness(dSurface)
Case 1
m32 = dSurface
m32Sel = changeBrightness(dSurface)
Case 2
m64 = dSurface
m64Sel = changeBrightness(dSurface)
Case 3
m128 = dSurface
m128Sel = changeBrightness(dSurface)
Case 4
m256 = dSurface
m256Sel = changeBrightness(dSurface)
End Select
imageAttrs.Dispose()