I have been drawing text with rectangles for buttons as a temporary solution just to get something up and running. The rectangles would be used to check the location of the mouse on mouse up, mouse down, and mouse over subs. This worked but looked horrid...
I started working on creating buttons to replace that. On the mouse events it checks if the location contains the mouse, then turns on a global variable. (Mouse Move Sub)
If InBank Then
If BankLeaveButtonLocation.Contains(e.Location) Then
If BankLeaveMouseDownButton = False Then
BankLeaveMouseOverButton = True
End If
Else
BankLeaveMouseOverButton = False
End If
Then I have to declare the image for the button.
' Bank Leave Button
Public BankLeaveButtonGfx As Texture
Public BankLeaveButtonGfxInfo As GraphicInfo
Public TempBankLeaveButtonBitmap As Bitmap
Public BankLeaveButtonLocation As Rectangle
Then I have to initialize the button graphics with the rest of the graphics.
' Bank Leave Button
BankLeaveButtonGfxInfo = New GraphicInfo
If FileExist(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT) Then
TempBankLeaveButtonBitmap = New Bitmap(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT)
BankLeaveButtonGfxInfo.Width = TempBankLeaveButtonBitmap.Width
BankLeaveButtonGfxInfo.Height = TempBankLeaveButtonBitmap.Height
_transcolor = TempBankLeaveButtonBitmap.GetPixel(0, 0)
_memStream = New MemoryStream()
TempBankLeaveButtonBitmap.Save(_memStream, ImageFormat.Png)
BankLeaveButtonGfx = New Texture(_memStream)
_memStream.Dispose()
End If
When the panel is drawing, then drawing the button, I have to check what the global variable is first and set the Y position.
Dim BankLeaveButtonOffset As Integer = 0
If BankLeaveMouseOverButton = True Then
BankLeaveButtonOffset = MouseOverOffsetY
ElseIf BankLeaveMouseDownButton = True Then
BankLeaveButtonOffset = MouseDownOffsetY
End If
Then draw the button in my render loop.
' Bank Leave Button Background
Dim windowLeaveButtonSprite As Sprite = New Sprite(BankLeaveButtonGfx)
windowLeaveButtonSprite.TextureRect = New IntRect(0, BankLeaveButtonOffset, TempBankLeaveButtonBitmap.Width, TempBankLeaveButtonBitmap.Height / 3)
windowLeaveButtonSprite.Position = New Vector2f((windowSprite.Position.X + TempBankWindowBitmap.Width / 2) - (TempBankLeaveButtonBitmap.Width / 2), ((windowSprite.Position.Y + TempBankWindowBitmap.Height) - TempBankLeaveButtonBitmap.Height / 3) - 3)
BankLeaveButtonLocation = New Rectangle(windowLeaveButtonSprite.Position.X, windowLeaveButtonSprite.Position.Y, windowLeaveButtonSprite.GetLocalBounds().Width, windowLeaveButtonSprite.GetLocalBounds().Height)
GameWindow.Draw(windowLeaveButtonSprite)
Then I dispose of the TempBitmap along with the rest of the TempBitmaps...All that is just drawing 1 button, and only list 1 event that it changes.
However, I have to have several buttons drawn on the screen at various times. Ideally I should create a class, but I am lost on what I will need to do to accomplish this with what I am doing to draw them now. Can someone help me figure out what to do?