Recoil Posted June 10, 2015 Share Posted June 10, 2015 Doesn't someone who posts the first 3 topics in a forum get brownie points or something 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... Today I side tracked from my massive list-o-stuffs to do and tried to make buttons. So far I have 1 for the bank and 3 for the shop working. All 3 normal/down/hover images are on the same image that I adjust to Y position of in order to change the image. 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 On the ClientGraphics 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.     ' 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... OMG, that seems like too much to do, and that is only 4 of the buttons that have to be drawn. My main game form is already nearly 3k lines, and my ClientGraphics file is well over 5k lines...currently I am wrapping lines up into regions, but when they get over several hundred lines it defeats the purpose of using them in the first place. It seems like there has got to be a much better, more efficient, and cleaner way of doing this...my thoughts are creating a custom button class that can just be reused. But because of how intricate and tedious the current code base is this may not be an option. I need some thoughts on what I am doing, and an idea or two on a better way. Thanks guys! Link to comment Share on other sites More sharing options...
jcsnider Posted June 10, 2015 Share Posted June 10, 2015 There are some graphic libraries that handle most of this for you. http://tgui.net/ https://code.google.com/p/gwen-dotnet/ Both of those are compatible with .Net + SFML. With that said, they are both written in C# so if they don't work out of the box for you, you will have to edit the C# source to make changes. If you don't want to use a third party library then creating your own class or set of classes for rendering GUI elements will work fine, it should save you quite a bit of code in the long run. Link to comment Share on other sites More sharing options...
Recoil Posted June 10, 2015 Author Share Posted June 10, 2015 I was looking into both of those previously when I was wanting custom transparent panel controls that I could reuse. However, it seems anything outside of what is in the current code, and anything written in C# that is unable to transfer over to VB, is going to be a very foreign process for me, especially since there seem to be no straight forward examples. Last time I think I spent well over 4 wasted days of just trying to figure something out until you suggested just drawing the panels to the window. I'm probably just fried, having spent 6 straight days code, minus that sleep thing every now and then...I'm even having a difficult time trying to figure out how to make a reusable class. Hopefully I will be able to figure out soon to keep from rewriting code over and over. Link to comment Share on other sites More sharing options...
Recoil Posted June 10, 2015 Author Share Posted June 10, 2015 Okay, here is what I got so far... #Region "Imports" Imports System.Drawing Imports System.Drawing.Imaging Imports System.IO Imports SFML.Graphics Imports SFML.Window #End Region Public Class OrionButton   Private TempButtonBitmap As Bitmap   Public ButtonLocation As Rectangle   Private _mButtonGfx As Texture   Private _mButtonGfxInfo As GraphicInfo   'Public MouseOverOffsetY As Integer = 22   'Public MouseDownOffsetY As Integer = 44     Dim _transcolor As Drawing.Color   Dim _memStream As MemoryStream     ' Button Parent   'Dim windowSprite As Sprite   Structure GraphicInfo     Dim Width As Long     Dim Height As Long   End Structure     Private _mMyRenderWindow As RenderWindow   Public Property MyRenderWindow As RenderWindow     Get       Return _mMyRenderWindow     End Get     Set(value As RenderWindow)       _mMyRenderWindow = value     End Set   End Property   Private _mGfxImage As Bitmap   Public Property GfxImage As Bitmap     Get       Return _mGfxImage     End Get     Set(value As Bitmap)       _mGfxImage = value     End Set   End Property   Private _mMouseOverButton As Boolean '= False   Public Property MouseOverButton As Boolean '= False     Get       Return _mMouseOverButton     End Get     Set(value As Boolean)       _mMouseOverButton = value     End Set   End Property   Private _mMouseDownButton As Boolean '= False   Public Property MouseDownButton As Boolean '= False     Get       Return _mMouseDownButton     End Get     Set(value As Boolean)       _mMouseDownButton = value     End Set   End Property   Public Sub Init(ByVal agfximage As Bitmap)     _mGfxImage = agfximage     _mMouseOverButton = False     _mMouseDownButton = False     ' Button     _mButtonGfxInfo = New GraphicInfo     'If FileExist(_mGfxImage) Then     TempButtonBitmap = New Bitmap(_mGfxImage)     _mButtonGfxInfo.Width = TempButtonBitmap.Width     _mButtonGfxInfo.Height = TempButtonBitmap.Height     _transcolor = TempButtonBitmap.GetPixel(0, 0)     _memStream = New MemoryStream()     TempButtonBitmap.Save(_memStream, ImageFormat.Png)     _mButtonGfx = New Texture(_memStream)     _memStream.Dispose()     'End If   End Sub   Public Sub New()       End Sub   Public Sub DrawButton(ByVal arenderwindow As RenderWindow)     _mMyRenderWindow = arenderwindow     Dim ButtonOffset As Integer = 0     If _mMouseOverButton = True Then       ButtonOffset = 22 'MouseOverOffsetY     ElseIf _mMouseDownButton = True Then       ButtonOffset = 44 'MouseDownOffsetY     End If     ' Button Image     Dim ButtonSprite As Sprite = New Sprite(_mButtonGfx)     ButtonSprite.TextureRect = New IntRect(0, ButtonOffset, TempButtonBitmap.Width, TempButtonBitmap.Height / 3)     ButtonSprite.Position = New Vector2f(0, 0) '(windowSprite.Position.X + TempBankWindowBitmap.Width / 2) - (TempButtonBitmap.Width / 2), ((windowSprite.Position.Y + TempBankWindowBitmap.Height) - TempButtonBitmap.Height / 3) - 3)     ButtonLocation = New Rectangle(ButtonSprite.Position.X, ButtonSprite.Position.Y, ButtonSprite.GetLocalBounds().Width, ButtonSprite.GetLocalBounds().Height)     _mMyRenderWindow.Draw(ButtonSprite)   End Sub   Sub Dispose()     If Not TempButtonBitmap Is Nothing Then TempButtonBitmap.Dispose()   End Sub End Class In ClientGraphics... Declaration: Dim testButton As OrionButton Initilization:     testButton = New OrionButton     If FileExist(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT) Then       Dim bmp As New Bitmap(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT)       testButton.Init(bmp)     End If Then when I need to draw: testButton.DrawButton(GameWindow) It's working, but my brain is not very well. Can you suggest changes that should be made to the class? I know I have to pass the location in which is not an issue, but once I get this working I can do this for ALL the bloody panels too and save a whole bunch of lines! Link to comment Share on other sites More sharing options...
Recoil Posted June 10, 2015 Author Share Posted June 10, 2015 Almost there... I am trying to catch the mouse events on the custom control, so I have inherited picturebox in order to get all the properties of a picturebox just like the GameScreen where I am currently handling all the events. The private subs for the mouse events do not work for a new control. So I am trying this:     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)     MessageBox.Show("mouse move...")     MyBase.OnMouseMove(e)   End Sub I just need to catch the mouse moving on it, or some mouse sub, in order to shift the Y position of the image. This will work when I set them from the GameScreen's MouseMove event, but not the one for the control. Any suggestions? Link to comment Share on other sites More sharing options...
Damian666 Posted June 10, 2015 Share Posted June 10, 2015 c,c,combo breaker!!! but seriously, no clue what so ever... but your almost there man, you can do it Link to comment Share on other sites More sharing options...
Recoil Posted June 10, 2015 Author Share Posted June 10, 2015 Nothing...I am finding nothing. Currently I can set the control's MouseIsOver and MouseIsDown boolean values in the same place I am setting the boolean values for the other drawn images, on the GameScreen mouse events. I am trying to bypass that requirement, and have them set in the actual control itself. Here is my current class without the non-working mouse subs: #Region "Imports" Imports System.Drawing Imports System.Drawing.Imaging Imports System.IO Imports System.Windows.Forms Imports SFML.Graphics Imports SFML.Window #End Region Public Class OrionButton   Inherits PictureBox     Private _tempButtonBitmap As Bitmap   Private _mButtonGfx As Texture   Private Const MouseOverOffsetY As Integer = 22   Private Const MouseDownOffsetY As Integer = 44   Private _memStream As MemoryStream   Private _mButtonLocation As Rectangle   Private _mMyRenderWindow As RenderWindow   Private _mGfxImage As Bitmap   Private _mMouseIsOver As Boolean   Private _mMouseIsDown As Boolean   Public Property ButtonLocation As Rectangle     Get       Return _mButtonLocation     End Get     Set(value As Rectangle)       _mButtonLocation = value     End Set   End Property   Public Property MyRenderWindow As RenderWindow     Get       Return _mMyRenderWindow     End Get     Set(value As RenderWindow)       _mMyRenderWindow = value     End Set   End Property   Public Property GfxImage As Bitmap     Get       Return _mGfxImage     End Get     Set(value As Bitmap)       _mGfxImage = value     End Set   End Property   Public Property MouseIsOver As Boolean     Get       Return _mMouseIsOver     End Get     Set(value As Boolean)       _mMouseIsDown = value     End Set   End Property   Public Property MouseIsDown As Boolean '= False     Get       Return _mMouseIsDown     End Get     Set(value As Boolean)       _mMouseIsDown = value     End Set   End Property   Public Sub New()   End Sub   Public Sub Init(ByVal agfximage As Bitmap)     _mGfxImage = agfximage     _mMouseIsOver = False     _mMouseIsDown = False     ' Button     _tempButtonBitmap = New Bitmap(_mGfxImage)     _memStream = New MemoryStream()     _tempButtonBitmap.Save(_memStream, ImageFormat.Png)     _mButtonGfx = New Texture(_memStream)     _memStream.Dispose()     'End If   End Sub   Public Sub DrawButton(ByVal arenderwindow As RenderWindow, ByVal locX As Integer, ByVal locY As Integer)     _mMyRenderWindow = arenderwindow     Dim buttonOffset As Integer = 0     If MouseIsOver = True Then       buttonOffset = MouseOverOffsetY     ElseIf _mMouseIsDown = True Then       buttonOffset = MouseDownOffsetY     End If     ' Button Image     Dim buttonSprite As Sprite = New Sprite(_mButtonGfx)     buttonSprite.TextureRect = New IntRect(0, buttonOffset, _tempButtonBitmap.Width, _tempButtonBitmap.Height / 3)     buttonSprite.Position = New Vector2f(locX, locY) '((locX + bmp.Width / 2) - (TempButtonBitmap.Width / 2), ((locY + bmp.Height) - TempButtonBitmap.Height / 3) - 3)     _mButtonLocation = New Rectangle(buttonSprite.Position.X, buttonSprite.Position.Y, buttonSprite.GetLocalBounds().Width, buttonSprite.GetLocalBounds().Height)     _mMyRenderWindow.Draw(buttonSprite)   End Sub   Sub Disposer()     If Not _tempButtonBitmap Is Nothing Then _tempButtonBitmap.Dispose()   End Sub   Private Sub OrionButton_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown     If ButtonLocation.Contains(e.Location) Then       _mMouseIsDown = True       _mMouseIsOver = False     Else       _mMouseIsDown = False     End If   End Sub End Class (Following in ClientGraphics) Declaration: Public testButton As OrionButton Initialization: testButton = New OrionButton If FileExist(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT) Then   Dim bmp As New Bitmap(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT)   testButton.Init(bmp) End If Drawing: testButton.DrawButton(GameWindow, 0, 0) Disposing: testButton.Disposer() And in the frmMainGame, GameScreen_MouseUp: '#TESTBUTTON If InBank Then   If testButton.ButtonLocation.Contains(e.Location) Then     testButton.MouseIsOver = False     CloseBank()   End If I have to do something similar in all 3 mouse events for the GameScreen(up/down/move). If I had the ability to use the custom controls mouse subs that would essentially make this a finished product. Link to comment Share on other sites More sharing options...
jcsnider Posted June 10, 2015 Share Posted June 10, 2015 How about throwing all of the buttons into a single array? Then whenever there is a mouse event iterate through that array and call the respective mouse functions. Link to comment Share on other sites More sharing options...
Recoil Posted June 10, 2015 Author Share Posted June 10, 2015 I'm not sure how I wold do that with the way my current subs are doing. I have the majority of the stuff in mouse down, but I am going to have to move most of that when an actual button is created so it will display the MouseIsDown image. I'm not sure if the copy you have include the mouse subs like I ahve now, but my shortest looks like: Private Sub GameScreen_MouseUp(sender As Object, e As MouseEventArgs) Handles GameScreen.MouseUp     ' If user clicks down, moves mouse off button location, then mouse up, need to reset MouseDownOffset     ShopBuyItemMouseDownButton = False     ShopSellItemMouseDownButton = False     ShopLeaveMouseDownButton = False     BankLeaveMouseDownButton = False     If UiVisible Then       If StatusWindowLocation.Contains(e.Location) Then         ' Do nothing...       End If       If ActionWindowLocation.Contains(e.Location) Then         ' Do nothing...       End If       If InventoryWindowLocation.Contains(e.Location) Then         If InventoryWindowVisible Then           Dim i As Long           Dim recPos As Rectangle           If InTrade > 0 Then Exit Sub           If InBank Or InShop Then Exit Sub           If DragInvSlotNum > 0 Then             For i = 1 To MaxInv               With recPos                 .Y = InventoryWindowLocation.Y + InvTop + ((InvOffsetY + 32) * ((i - 1) \ InvColumns))                 .Height = PIC_Y                 .X = InventoryWindowLocation.X + InvLeft + ((InvOffsetX + 32) * (((i - 1) Mod InvColumns)))                 .Width = PIC_X               End With               If e.Location.X >= recPos.Left And e.Location.X <= recPos.Right Then                 If e.Location.Y >= recPos.Top And e.Location.Y <= recPos.Bottom Then '                   If DragInvSlotNum <> i Then                     SendChangeInvSlots(DragInvSlotNum, i)                     Exit For                   End If                 End If               End If             Next           End If           DragInvSlotNum = 0           pnlTmpInv.Visible = False         End If ' InventoryWindowVisible         If SkillWindowVisible Then           ' Do nothing...         End If         If OptionsWindowVisible Then           ' Do nothing...         End If         If CharWindowVisible Then           ' Do nothing...         End If       End If ' PanelWindowLocation     End If ' UIVisible     If InBank Then       '#TESTBUTTON       If testButton.ButtonLocation.Contains(e.Location) Then         testButton.MouseIsOver = False         'CloseBank()       End If       If BankLeaveButtonLocation.Contains(e.Location) Then         BankLeaveMouseOverButton = False         CloseBank()       End If       Dim i As Long       Dim x As Long, y As Long       Dim recPos As Rectangle       x = e.Location.X       y = e.Location.Y       ' TODO : Add sub to change bankslots client side first so there's no delay in switching       If DragBankSlotNum > 0 Then         For i = 1 To MaxBank           With recPos             .Y = BankItemWindowLocation.Y + BankTop + ((BankOffsetY + 32) * ((i - 1) \ BankColumns))             .Height = PIC_Y             .X = BankItemWindowLocation.X + BankLeft + ((BankOffsetX + 32) * (((i - 1) Mod BankColumns)))             .Width = PIC_X           End With           If x >= recPos.Left And x <= recPos.Right Then             If y >= recPos.Top And y <= recPos.Bottom Then               If DragBankSlotNum <> i Then                 ChangeBankSlots(DragBankSlotNum, i)                 Exit For               End If             End If           End If         Next       End If       DragBankSlotNum = 0       pnlTempBank.Visible = False     End If     If InShop > 0 Then       If ShopBuyItemButtonLocation.Contains(e.Location) Then         ShopBuyItemMouseOverButton = False         If ShopAction = 1 Then Exit Sub         ShopAction = 1 ' buying an item         AddText("Click on the item in the shop you wish to buy.")       End If       If ShopSellItemButtonLocation.Contains(e.Location) Then         ShopSellItemMouseOverButton = False         If ShopAction = 2 Then Exit Sub         ShopAction = 2 ' selling an item         AddText("Double-click on the item in your inventory you wish to sell.")       End If       If ShopLeaveButtonLocation.Contains(e.Location) Then         ShopLeaveMouseOverButton = False         Dim buffer As ByteBuffer         buffer = New ByteBuffer         buffer.WriteLong(ClientPackets.CCloseShop)         SendData(buffer.ToArray())         buffer = Nothing         InShop = 0         ShopAction = 0       End If             Dim shopItem As Long       Dim x As Long, y As Long       x = e.Location.X       y = e.Location.Y       shopItem = IsShopItem(x, y)       If shopItem > 0 Then         Select Case ShopAction           Case 0 ' no action, give cost             With Shop(InShop).TradeItem(shopItem)               AddText("You can buy this item for " & .CostValue & " " & Trim$(Item(.CostItem).Name) & ".")             End With           Case 1 ' buy item             ' buy item code             BuyItem(shopItem)         End Select       End If     End If     If InTrade Then       ' Do nothing...     End If     GameScreen.Focus()   End Sub It is going through and checking if UiVisible, InBank, or InShop, etc, then going through all of the necessary commands. I really dislike having the long, drawn out If/Else statements, but it seems with the current setup that is the only thing I could figure out that would work. Regardless if they are in an array or not I would still have to check the locations to perform certain tasks. Even if I was able to get the control class to automatically swap the image from the mouse location, I'm not going to be cutting out very many lines of code, and my mouse events for the GameScreen are still going to be huge. It may be time to look into a redesign. Link to comment Share on other sites More sharing options...
Recoil Posted June 11, 2015 Author Share Posted June 11, 2015 Alright, this thread has become longer than I had planned and I still can't figure the mouse event issue out... But I did figure out that if I include another boolean property (IsButton), and a windowOffset, I can bypass the button offsets and use this for both the button and panels... The OrionGfxControl: #Region "Imports" Imports System.Drawing Imports System.Drawing.Imaging Imports System.IO Imports System.Windows.Forms Imports SFML.Graphics Imports SFML.Window #End Region Public Class OrionGfxControl   Inherits Control   Private _tempButtonBitmap As Bitmap   Private _mButtonGfx As Texture   Private _memStream As MemoryStream   Private _mIsButton As Boolean   Private _mControlLocation As Rectangle   Private _mMyRenderWindow As RenderWindow   Private _mGfxImage As Bitmap   Private _mMouseIsOver As Boolean   Private _mMouseIsDown As Boolean   Public Property Is_Button As Boolean     Get       Return _mIsButton     End Get     Set(value As Boolean)       _mIsButton = value     End Set   End Property   Public Property ControlLocation As Rectangle     Get       Return _mControlLocation     End Get     Set(value As Rectangle)       _mControlLocation = value     End Set   End Property   Public Property MyRenderWindow As RenderWindow     Get       Return _mMyRenderWindow     End Get     Set(value As RenderWindow)       _mMyRenderWindow = value     End Set   End Property   Public Property GfxImage As Bitmap     Get       Return _mGfxImage     End Get     Set(value As Bitmap)       _mGfxImage = value     End Set   End Property   Public Property MouseIsOver As Boolean     Get       Return _mMouseIsOver     End Get     Set(value As Boolean)       _mMouseIsOver = value     End Set   End Property   Public Property MouseIsDown As Boolean     Get       Return _mMouseIsDown     End Get     Set(value As Boolean)       _mMouseIsDown = value     End Set   End Property   Public Sub New(ByVal isButton As Boolean)     Is_Button = isButton   End Sub   Public Sub Init(ByVal agfximage As Bitmap)     _mGfxImage = agfximage     _mMouseIsOver = False     _mMouseIsDown = False         _tempButtonBitmap = New Bitmap(_mGfxImage)     _memStream = New MemoryStream()     _tempButtonBitmap.Save(_memStream, ImageFormat.Png)     _mButtonGfx = New Texture(_memStream)     _memStream.Dispose()       End Sub   Public Sub DrawControl(ByVal arenderwindow As RenderWindow, ByVal locX As Integer, ByVal locY As Integer)     _mMyRenderWindow = arenderwindow     Dim buttonOffset As Integer = 0     Dim windowOffset As Integer = _tempButtonBitmap.Height     If Is_Button Then       If _mMouseIsOver = True Then         buttonOffset = (_tempButtonBitmap.Height / 3)       ElseIf _mMouseIsDown = True Then         buttonOffset = ((_tempButtonBitmap.Height / 3) * 2)       End If       windowOffset = _tempButtonBitmap.Height / 3     End If     Dim buttonSprite As Sprite = New Sprite(_mButtonGfx)     buttonSprite.TextureRect = New IntRect(0, buttonOffset, _tempButtonBitmap.Width, windowOffset)     buttonSprite.Position = New Vector2f(locX, locY)     _mControlLocation = New Rectangle(buttonSprite.Position.X, buttonSprite.Position.Y, buttonSprite.GetLocalBounds().Width, buttonSprite.GetLocalBounds().Height)     _mMyRenderWindow.Draw(buttonSprite)   End Sub   Sub Disposer()     If Not _tempButtonBitmap Is Nothing Then _tempButtonBitmap.Dispose()   End Sub EndClass Declaration compared to 12 lines of code: Public BankWindow As OrionGfxControl Public BankItemWindow As OrionGfxControl Public BankLeaveButton As OrionGfxControl Initialization compared to 36 lines of code:     BankWindow = New OrionGfxControl(False)     If FileExist(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankWindow" & GFX_EXT) Then       Dim bmp As New Bitmap(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankWindow" & GFX_EXT)       BankWindow.Init(bmp)     End If     BankItemWindow = New OrionGfxControl(False)     If FileExist(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankItemWindow" & GFX_EXT) Then       Dim bmp As New Bitmap(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankItemWindow" & GFX_EXT)       BankItemWindow.Init(bmp)     End If     BankLeaveButton = New OrionGfxControl(True)     If FileExist(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT) Then       Dim bmp As New Bitmap(Application.StartupPath & GFX_PATH & BANKWINDOW_PATH & "BankLeaveButton" & GFX_EXT)       BankLeaveButton.Init(bmp)     End If Drawing compared to 21 lines of code:     BankWindow.DrawControl(GameWindow, (frmMainGame.GameScreen.Width / 2) - (BankWindow.ControlLocation.Width / 2), 10)     BankItemWindow.DrawControl(GameWindow, ((BankWindow.ControlLocation.X + BankWindow.ControlLocation.Width / 2)) - (BankItemWindow.ControlLocation.Width / 2), ((BankWindow.ControlLocation.Y + BankWindow.ControlLocation.Height / 2)) - (BankItemWindow.ControlLocation.Height / 2))     BankLeaveButton.DrawControl(GameWindow, ((BankWindow.ControlLocation.X + BankWindow.ControlLocation.Width / 2)) - (BankLeaveButton.ControlLocation.Width / 2), ((BankWindow.ControlLocation.Y + BankWindow.ControlLocation.Height)) - (BankLeaveButton.ControlLocation.Height) - 3) Then I draw all the inventory stuff onto the BankItemPanel. There is still only 3 lines to for disposing, but they are much shorter:     BankWindow.Disposer()     BankItemWindow.Disposer()     BankLeaveButton.Disposer() Even though I think it would be better to have 2 separate classes for the panels and buttons, there isn't much that is changed. I want to see if I can use the same class for the item graphics too, but those consist of arrays of items and may not be as easy to do...but I am going to look into it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now