hehe nice.
For a practice, I'm trying to design what you would call a "Simple GUI" for my game. Basicly it's 4 type objects, TWindow, TButton, TTextfield and TTextview. This should be good practice, I called it "QGI" which means Quick Game Interface.
QGI.bmx just needs to be included into a project for it to work. But I've been having "mouse Over" Problems with my button object...
I feel my button doesn't light up fast enough so I tried to use "Flip 0", it did improve it however it feels as though my style of coding or teh way I coded it is making it slow.
So maybe you could check how good and optimised my code is, it's quite readable.
Ok first file is the main.bmx:
QGI File
I'm only working with the TWindow and TButton, I haven't worked really on the others yet.
I appreciate the help Czar Flavius!
For a practice, I'm trying to design what you would call a "Simple GUI" for my game. Basicly it's 4 type objects, TWindow, TButton, TTextfield and TTextview. This should be good practice, I called it "QGI" which means Quick Game Interface.
QGI.bmx just needs to be included into a project for it to work. But I've been having "mouse Over" Problems with my button object...
I feel my button doesn't light up fast enough so I tried to use "Flip 0", it did improve it however it feels as though my style of coding or teh way I coded it is making it slow.
So maybe you could check how good and optimised my code is, it's quite readable.
Ok first file is the main.bmx:
SuperStrict Graphics 800,600,0 Include "QGI.bmx" ' Windows Global test:QGI_TWindow=New QGI_TWindow test.Create(5,5,100,85) ' Objects test.Buttons=New QGI_TButton[4] For Local i:Int=0 To test.Buttons.Length-1 test.Buttons[i]=New QGI_TButton Next test.Buttons[0].Create(10,10,90,15,"Testing") test.Buttons[0].bgColor(50,50,50,100,50,100) test.Buttons[0].bdColor(100,100,150,200,100,200) test.Buttons[0].txColor(255,255,255,255,150,255) test.Buttons[1].Create(10,30,90,15,"Testing") test.Buttons[1].bgColor(50,50,50,100,50,100) test.Buttons[1].bdColor(100,100,150,200,100,200) test.Buttons[1].txColor(255,255,255,255,150,255) test.Buttons[2].Create(10,50,90,15,"Testing") test.Buttons[2].bgColor(50,50,50,100,50,100) test.Buttons[2].bdColor(100,100,150,200,100,200) test.Buttons[2].txColor(255,255,255,255,150,255) test.Buttons[3].Create(10,70,90,15,"Testing") test.Buttons[3].bgColor(50,50,50,100,50,100) test.Buttons[3].bdColor(100,100,150,200,100,200) test.Buttons[3].txColor(255,255,255,255,150,255) While Not KeyHit(KEY_ESCAPE) test.Update() Flip ; Cls Wend End
QGI File
Type QGI_TWindow Field Title:String Field Xpos:Int Field Ypos:Int Field Width:Int Field Height:Int ' Color Scheme Field bg_red:Int, bg_green:Int, bg_blue:Int Field bd_red:Int, bd_green:Int, bd_blue:Int Field tx_red:Int, tx_green:Int, tx_blue:Int ' Internal Objects Field Buttons:QGI_TButton[] Field Textfields:QGI_TTextfield[] Field Textviews:QGI_TTextview[] Method Create( xstart:Int, ystart:Int, wstart:Int, hstart:Int ) Xpos=xstart Ypos=ystart Width=wstart Height=hstart End Method ' Draw Window Method Draw() SetColor(255,255,255) DrawLine( Xpos, Ypos, Xpos+Width, Ypos) ' top DrawLine( Xpos, Ypos+Height, Xpos+Width, Ypos+Height ) ' bottom DrawLine( Xpos, Ypos, Xpos, Ypos+Height ) ' left DrawLine( Xpos+Width, Ypos, Xpos+Width, Ypos+Height ) ' right End Method ' Handles Every Objects Method Update() ' Buttons For Local i:Int = 0 To Buttons.Length-1 Buttons[i].Update() Next ' Textfields For Local i2:Int = 0 To Textfields.length-1 Textfields[i2].Update() Next ' Textviews For Local i3:Int = 0 To Textviews.Length-1 Textviews[i3].Update() Next Draw() End Method End Type Type QGI_TButton Field Text:String Field Clicked:Int Field Xpos:Int Field Ypos:Int Field Width:Int=10 Field Height:Int=15 ' Color Scheme Field bg_red:Int, bg_green:Int, bg_blue:Int Field bd_red:Int, bd_green:Int, bd_blue:Int Field tx_red:Int, tx_green:Int, tx_blue:Int Field mbg_red:Int, mbg_green:Int, mbg_blue:Int Field mbd_red:Int, mbd_green:Int, mbd_blue:Int Field mtx_red:Int, mtx_green:Int, mtx_blue:Int ' Create Method Create( xstart:Int, ystart:Int, wstart:Int, hstart:Int, txtstart:String ) Xpos=xstart Ypos=ystart Width=wstart Height=hstart Text=txtstart End Method ' Set Colors Method bgColor( r:Int, g:Int, b:Int, mr:Int, mg:Int, mb:Int ) bg_red=r bg_green=g bg_blue=b mbg_red=mr mbg_green=mg mbg_blue=mb End Method Method bdColor( r:Int, g:Int, b:Int, mr:Int, mg:Int, mb:Int ) bd_red=r bd_green=g bd_blue=b mbd_red=mr mbd_green=mg mbd_blue=mb End Method Method txColor( r:Int, g:Int, b:Int, mr:Int, mg:Int, mb:Int ) tx_red=r tx_green=g tx_blue=b mtx_red=mr mtx_green=mg mtx_blue=mb End Method ' Drawing Method Draw() If(MouseX()>Xpos)And(MouseX()<Xpos+Width)And(MouseY()>Ypos)And(MouseY()<Ypos+Height) ' Background SetColor( mbg_red, mbg_green, mbg_blue ) DrawRect Xpos, Ypos, Width, Height ' Borders SetColor( mbd_red, mbd_green, mbd_blue ) DrawLine( Xpos, Ypos, Xpos+Width, Ypos) ' top DrawLine( Xpos, Ypos+Height, Xpos+Width, Ypos+Height ) ' bottom DrawLine( Xpos, Ypos, Xpos, Ypos+Height ) ' left DrawLine( Xpos+Width, Ypos, Xpos+Width, Ypos+Height ) ' right ' Text SetColor( mtx_red, mtx_green, mtx_blue ) DrawText Text,Xpos+1,Ypos+1 Else ' Background SetColor( bg_red, bg_green, bg_blue ) DrawRect Xpos, Ypos, Width, Height ' Borders SetColor( bd_red, bd_green, bd_blue ) DrawLine( Xpos, Ypos, Xpos+Width, Ypos) ' top DrawLine( Xpos, Ypos+Height, Xpos+Width, Ypos+Height ) ' bottom DrawLine( Xpos, Ypos, Xpos, Ypos+Height ) ' left DrawLine( Xpos+Width, Ypos, Xpos+Width, Ypos+Height ) ' right ' Text SetColor( tx_red, tx_green, tx_blue ) DrawText Text,Xpos+1,Ypos+1 EndIf End Method ' Handles Everything Method Update() Draw() End Method End Type Type QGI_TTextfield Field Name:String Field Text:String Field Selected:Int ' Color Scheme Field bg_red:Int, bg_green:Int, bg_blue:Int Field bd_red:Int, bd_green:Int, bd_blue:Int Field tx_red:Int, tx_green:Int, tx_blue:Int ' Drawing Method Draw() End Method ' Handles Everything Method Update() End Method End Type Type QGI_TTextview Field Name:String Field Text:String[] ' Color Scheme Field bg_red:Int, bg_green:Int, bg_blue:Int Field bd_red:Int, bd_green:Int, bd_blue:Int Field tx_red:Int, tx_green:Int, tx_blue:Int ' Drawing Method Draw() End Method ' Handles Everything Method Update() End Method End Type
I'm only working with the TWindow and TButton, I haven't worked really on the others yet.
I appreciate the help Czar Flavius!